cmds.c (223308) | cmds.c (223328) |
---|---|
1/* $NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $ */ | 1/* $NetBSD: cmds.c,v 1.17 2010/01/12 06:55:47 lukem Exp $ */ 2/* from NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp */ |
2 3/*- | 3 4/*- |
4 * Copyright (c) 1996-2005 The NetBSD Foundation, Inc. | 5 * Copyright (c) 1996-2009 The NetBSD Foundation, Inc. |
5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Luke Mewburn. 9 * 10 * This code is derived from software contributed to The NetBSD Foundation 11 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 12 * NASA Ames Research Center. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. | 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Luke Mewburn. 10 * 11 * This code is derived from software contributed to The NetBSD Foundation 12 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 13 * NASA Ames Research Center. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. |
22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgement: 24 * This product includes software developed by the NetBSD 25 * Foundation, Inc. and its contributors. 26 * 4. Neither the name of The NetBSD Foundation nor the names of its 27 * contributors may be used to endorse or promote products derived 28 * from this software without specific prior written permission. | |
29 * 30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS --- 56 unchanged lines hidden (view full) --- 93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 94 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 95 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 96 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 97 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 98 * SUCH DAMAGE. 99 */ 100 | 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS --- 56 unchanged lines hidden (view full) --- 87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 92 * SUCH DAMAGE. 93 */ 94 |
95#include "tnftp.h" 96 97#if 0 /* tnftp */ 98 |
|
101#include <sys/cdefs.h> 102#ifndef lint 103#if 0 104static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; 105#else | 99#include <sys/cdefs.h> 100#ifndef lint 101#if 0 102static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; 103#else |
106__RCSID("$NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $"); | 104__RCSID(" NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp "); |
107#endif 108#endif /* not lint */ 109 110/* 111 * FTP User Program -- Command Routines. 112 */ 113#include <sys/types.h> 114#include <sys/socket.h> 115#include <sys/stat.h> 116#include <sys/wait.h> 117#include <arpa/ftp.h> 118 119#include <ctype.h> 120#include <err.h> 121#include <glob.h> 122#include <limits.h> 123#include <netdb.h> 124#include <paths.h> | 105#endif 106#endif /* not lint */ 107 108/* 109 * FTP User Program -- Command Routines. 110 */ 111#include <sys/types.h> 112#include <sys/socket.h> 113#include <sys/stat.h> 114#include <sys/wait.h> 115#include <arpa/ftp.h> 116 117#include <ctype.h> 118#include <err.h> 119#include <glob.h> 120#include <limits.h> 121#include <netdb.h> 122#include <paths.h> |
123#include <stddef.h> |
|
125#include <stdio.h> 126#include <stdlib.h> 127#include <string.h> 128#include <time.h> 129#include <unistd.h> | 124#include <stdio.h> 125#include <stdlib.h> 126#include <string.h> 127#include <time.h> 128#include <unistd.h> |
130#include <libutil.h> | |
131 | 129 |
130#endif /* tnftp */ 131 |
|
132#include "ftp_var.h" 133#include "version.h" 134 | 132#include "ftp_var.h" 133#include "version.h" 134 |
135struct types { 136 char *t_name; 137 char *t_mode; 138 int t_type; 139 char *t_arg; | 135static struct types { 136 const char *t_name; 137 const char *t_mode; 138 int t_type; 139 const char *t_arg; |
140} types[] = { 141 { "ascii", "A", TYPE_A, 0 }, 142 { "binary", "I", TYPE_I, 0 }, 143 { "image", "I", TYPE_I, 0 }, 144 { "ebcdic", "E", TYPE_E, 0 }, 145 { "tenex", "L", TYPE_L, bytename }, | 140} types[] = { 141 { "ascii", "A", TYPE_A, 0 }, 142 { "binary", "I", TYPE_I, 0 }, 143 { "image", "I", TYPE_I, 0 }, 144 { "ebcdic", "E", TYPE_E, 0 }, 145 { "tenex", "L", TYPE_L, bytename }, |
146 { NULL } | 146 { NULL, NULL, 0, NULL } |
147}; 148 | 147}; 148 |
149sigjmp_buf jabort; 150const char *mname; | 149static sigjmp_buf jabort; |
151 152static int confirm(const char *, const char *); | 150 151static int confirm(const char *, const char *); |
152static void mintr(int); 153static void mabort(const char *); 154static void set_type(const char *); |
|
153 154static const char *doprocess(char *, size_t, const char *, int, int, int); 155static const char *domap(char *, size_t, const char *); 156static const char *docase(char *, size_t, const char *); 157static const char *dotrans(char *, size_t, const char *); 158 | 155 156static const char *doprocess(char *, size_t, const char *, int, int, int); 157static const char *domap(char *, size_t, const char *); 158static const char *docase(char *, size_t, const char *); 159static const char *dotrans(char *, size_t, const char *); 160 |
161/* 162 * Confirm if "cmd" is to be performed upon "file". 163 * If "file" is NULL, generate a "Continue with" prompt instead. 164 */ |
|
159static int 160confirm(const char *cmd, const char *file) 161{ | 165static int 166confirm(const char *cmd, const char *file) 167{ |
162 char line[BUFSIZ]; | 168 const char *errormsg; 169 char cline[BUFSIZ]; 170 const char *promptleft, *promptright; |
163 164 if (!interactive || confirmrest) 165 return (1); | 171 172 if (!interactive || confirmrest) 173 return (1); |
174 if (file == NULL) { 175 promptleft = "Continue with"; 176 promptright = cmd; 177 } else { 178 promptleft = cmd; 179 promptright = file; 180 } |
|
166 while (1) { | 181 while (1) { |
167 fprintf(ttyout, "%s %s [anpqy?]? ", cmd, file); | 182 fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright); |
168 (void)fflush(ttyout); | 183 (void)fflush(ttyout); |
169 if (fgets(line, sizeof(line), stdin) == NULL) { | 184 if (get_line(stdin, cline, sizeof(cline), &errormsg) < 0) { |
170 mflag = 0; | 185 mflag = 0; |
171 fprintf(ttyout, "\nEOF received; %s aborted\n", mname); 172 clearerr(stdin); | 186 fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd); |
173 return (0); 174 } | 187 return (0); 188 } |
175 switch (tolower((unsigned char)*line)) { | 189 switch (tolower((unsigned char)*cline)) { |
176 case 'a': 177 confirmrest = 1; 178 fprintf(ttyout, 179 "Prompting off for duration of %s.\n", cmd); 180 break; 181 case 'p': 182 interactive = 0; 183 fputs("Interactive mode: off.\n", ttyout); 184 break; 185 case 'q': 186 mflag = 0; | 190 case 'a': 191 confirmrest = 1; 192 fprintf(ttyout, 193 "Prompting off for duration of %s.\n", cmd); 194 break; 195 case 'p': 196 interactive = 0; 197 fputs("Interactive mode: off.\n", ttyout); 198 break; 199 case 'q': 200 mflag = 0; |
187 fprintf(ttyout, "%s aborted.\n", mname); | 201 fprintf(ttyout, "%s aborted.\n", cmd); |
188 /* FALLTHROUGH */ 189 case 'n': 190 return (0); 191 case '?': 192 fprintf(ttyout, 193 " confirmation options:\n" 194 "\ta answer `yes' for the duration of %s\n" 195 "\tn answer `no' for this file\n" --- 11 unchanged lines hidden (view full) --- 207 208/* 209 * Set transfer type. 210 */ 211void 212settype(int argc, char *argv[]) 213{ 214 struct types *p; | 202 /* FALLTHROUGH */ 203 case 'n': 204 return (0); 205 case '?': 206 fprintf(ttyout, 207 " confirmation options:\n" 208 "\ta answer `yes' for the duration of %s\n" 209 "\tn answer `no' for this file\n" --- 11 unchanged lines hidden (view full) --- 221 222/* 223 * Set transfer type. 224 */ 225void 226settype(int argc, char *argv[]) 227{ 228 struct types *p; |
215 int comret; | |
216 217 if (argc == 0 || argc > 2) { | 229 230 if (argc == 0 || argc > 2) { |
218 char *sep; | 231 const char *sep; |
219 | 232 |
220 fprintf(ttyout, "usage: %s [", argv[0]); | 233 UPRINTF("usage: %s [", argv[0]); |
221 sep = " "; 222 for (p = types; p->t_name; p++) { 223 fprintf(ttyout, "%s%s", sep, p->t_name); 224 sep = " | "; 225 } 226 fputs(" ]\n", ttyout); 227 code = -1; 228 return; 229 } 230 if (argc < 2) { 231 fprintf(ttyout, "Using %s mode to transfer files.\n", typename); 232 code = 0; 233 return; 234 } | 234 sep = " "; 235 for (p = types; p->t_name; p++) { 236 fprintf(ttyout, "%s%s", sep, p->t_name); 237 sep = " | "; 238 } 239 fputs(" ]\n", ttyout); 240 code = -1; 241 return; 242 } 243 if (argc < 2) { 244 fprintf(ttyout, "Using %s mode to transfer files.\n", typename); 245 code = 0; 246 return; 247 } |
248 set_type(argv[1]); 249} 250 251void 252set_type(const char *ttype) 253{ 254 struct types *p; 255 int comret; 256 |
|
235 for (p = types; p->t_name; p++) | 257 for (p = types; p->t_name; p++) |
236 if (strcmp(argv[1], p->t_name) == 0) | 258 if (strcmp(ttype, p->t_name) == 0) |
237 break; 238 if (p->t_name == 0) { | 259 break; 260 if (p->t_name == 0) { |
239 fprintf(ttyout, "%s: unknown mode.\n", argv[1]); | 261 fprintf(ttyout, "%s: unknown mode.\n", ttype); |
240 code = -1; 241 return; 242 } 243 if ((p->t_arg != NULL) && (*(p->t_arg) != '\0')) 244 comret = command("TYPE %s %s", p->t_mode, p->t_arg); 245 else 246 comret = command("TYPE %s", p->t_mode); 247 if (comret == COMPLETE) { --- 12 unchanged lines hidden (view full) --- 260{ 261 struct types *p; 262 int comret, oldverbose = verbose; 263 264 if (newtype == 0) 265 newtype = TYPE_I; 266 if (newtype == curtype) 267 return; | 262 code = -1; 263 return; 264 } 265 if ((p->t_arg != NULL) && (*(p->t_arg) != '\0')) 266 comret = command("TYPE %s %s", p->t_mode, p->t_arg); 267 else 268 comret = command("TYPE %s", p->t_mode); 269 if (comret == COMPLETE) { --- 12 unchanged lines hidden (view full) --- 282{ 283 struct types *p; 284 int comret, oldverbose = verbose; 285 286 if (newtype == 0) 287 newtype = TYPE_I; 288 if (newtype == curtype) 289 return; |
268 if (debug == 0 && show == 0) | 290 if (ftp_debug == 0 && show == 0) |
269 verbose = 0; 270 for (p = types; p->t_name; p++) 271 if (newtype == p->t_type) 272 break; 273 if (p->t_name == 0) { | 291 verbose = 0; 292 for (p = types; p->t_name; p++) 293 if (newtype == p->t_type) 294 break; 295 if (p->t_name == 0) { |
274 warnx("internal error: unknown type %d.", newtype); 275 return; | 296 errx(1, "changetype: unknown type %d", newtype); |
276 } 277 if (newtype == TYPE_L && bytename[0] != '\0') 278 comret = command("TYPE %s %s", p->t_mode, bytename); 279 else 280 comret = command("TYPE %s", p->t_mode); 281 if (comret == COMPLETE) 282 curtype = newtype; 283 verbose = oldverbose; 284} 285 | 297 } 298 if (newtype == TYPE_L && bytename[0] != '\0') 299 comret = command("TYPE %s %s", p->t_mode, bytename); 300 else 301 comret = command("TYPE %s", p->t_mode); 302 if (comret == COMPLETE) 303 curtype = newtype; 304 verbose = oldverbose; 305} 306 |
286char *stype[] = { 287 "type", 288 "", 289 0 290}; 291 | |
292/* 293 * Set binary transfer type. 294 */ 295/*VARARGS*/ 296void 297setbinary(int argc, char *argv[]) 298{ 299 300 if (argc == 0) { | 307/* 308 * Set binary transfer type. 309 */ 310/*VARARGS*/ 311void 312setbinary(int argc, char *argv[]) 313{ 314 315 if (argc == 0) { |
301 fprintf(ttyout, "usage: %s\n", argv[0]); | 316 UPRINTF("usage: %s\n", argv[0]); |
302 code = -1; 303 return; 304 } | 317 code = -1; 318 return; 319 } |
305 stype[1] = "binary"; 306 settype(2, stype); | 320 set_type("binary"); |
307} 308 309/* 310 * Set ascii transfer type. 311 */ 312/*VARARGS*/ 313void 314setascii(int argc, char *argv[]) 315{ 316 317 if (argc == 0) { | 321} 322 323/* 324 * Set ascii transfer type. 325 */ 326/*VARARGS*/ 327void 328setascii(int argc, char *argv[]) 329{ 330 331 if (argc == 0) { |
318 fprintf(ttyout, "usage: %s\n", argv[0]); | 332 UPRINTF("usage: %s\n", argv[0]); |
319 code = -1; 320 return; 321 } | 333 code = -1; 334 return; 335 } |
322 stype[1] = "ascii"; 323 settype(2, stype); | 336 set_type("ascii"); |
324} 325 326/* 327 * Set tenex transfer type. 328 */ 329/*VARARGS*/ 330void 331settenex(int argc, char *argv[]) 332{ 333 334 if (argc == 0) { | 337} 338 339/* 340 * Set tenex transfer type. 341 */ 342/*VARARGS*/ 343void 344settenex(int argc, char *argv[]) 345{ 346 347 if (argc == 0) { |
335 fprintf(ttyout, "usage: %s\n", argv[0]); | 348 UPRINTF("usage: %s\n", argv[0]); |
336 code = -1; 337 return; 338 } | 349 code = -1; 350 return; 351 } |
339 stype[1] = "tenex"; 340 settype(2, stype); | 352 set_type("tenex"); |
341} 342 343/* 344 * Set file transfer mode. 345 */ 346/*ARGSUSED*/ 347void 348setftmode(int argc, char *argv[]) 349{ 350 351 if (argc != 2) { | 353} 354 355/* 356 * Set file transfer mode. 357 */ 358/*ARGSUSED*/ 359void 360setftmode(int argc, char *argv[]) 361{ 362 363 if (argc != 2) { |
352 fprintf(ttyout, "usage: %s mode-name\n", argv[0]); | 364 UPRINTF("usage: %s mode-name\n", argv[0]); |
353 code = -1; 354 return; 355 } 356 fprintf(ttyout, "We only support %s mode, sorry.\n", modename); 357 code = -1; 358} 359 360/* 361 * Set file transfer format. 362 */ 363/*ARGSUSED*/ 364void 365setform(int argc, char *argv[]) 366{ 367 368 if (argc != 2) { | 365 code = -1; 366 return; 367 } 368 fprintf(ttyout, "We only support %s mode, sorry.\n", modename); 369 code = -1; 370} 371 372/* 373 * Set file transfer format. 374 */ 375/*ARGSUSED*/ 376void 377setform(int argc, char *argv[]) 378{ 379 380 if (argc != 2) { |
369 fprintf(ttyout, "usage: %s format\n", argv[0]); | 381 UPRINTF("usage: %s format\n", argv[0]); |
370 code = -1; 371 return; 372 } 373 fprintf(ttyout, "We only support %s format, sorry.\n", formname); 374 code = -1; 375} 376 377/* 378 * Set file transfer structure. 379 */ 380/*ARGSUSED*/ 381void 382setstruct(int argc, char *argv[]) 383{ 384 385 if (argc != 2) { | 382 code = -1; 383 return; 384 } 385 fprintf(ttyout, "We only support %s format, sorry.\n", formname); 386 code = -1; 387} 388 389/* 390 * Set file transfer structure. 391 */ 392/*ARGSUSED*/ 393void 394setstruct(int argc, char *argv[]) 395{ 396 397 if (argc != 2) { |
386 fprintf(ttyout, "usage: %s struct-mode\n", argv[0]); | 398 UPRINTF("usage: %s struct-mode\n", argv[0]); |
387 code = -1; 388 return; 389 } 390 fprintf(ttyout, "We only support %s structure, sorry.\n", structname); 391 code = -1; 392} 393 394/* 395 * Send a single file. 396 */ 397void 398put(int argc, char *argv[]) 399{ 400 char buf[MAXPATHLEN]; | 399 code = -1; 400 return; 401 } 402 fprintf(ttyout, "We only support %s structure, sorry.\n", structname); 403 code = -1; 404} 405 406/* 407 * Send a single file. 408 */ 409void 410put(int argc, char *argv[]) 411{ 412 char buf[MAXPATHLEN]; |
401 char *cmd; | 413 const char *cmd; |
402 int loc = 0; 403 char *locfile; 404 const char *remfile; 405 406 if (argc == 2) { 407 argc++; 408 argv[2] = argv[1]; 409 loc++; 410 } 411 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file"))) 412 goto usage; 413 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) { 414 usage: | 414 int loc = 0; 415 char *locfile; 416 const char *remfile; 417 418 if (argc == 2) { 419 argc++; 420 argv[2] = argv[1]; 421 loc++; 422 } 423 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file"))) 424 goto usage; 425 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) { 426 usage: |
415 fprintf(ttyout, "usage: %s local-file [remote-file]\n", 416 argv[0]); | 427 UPRINTF("usage: %s local-file [remote-file]\n", argv[0]); |
417 code = -1; 418 return; 419 } 420 if ((locfile = globulize(argv[1])) == NULL) { 421 code = -1; 422 return; 423 } 424 remfile = argv[2]; --- 27 unchanged lines hidden (view full) --- 452mput(int argc, char *argv[]) 453{ 454 int i; 455 sigfunc oldintr; 456 int ointer; 457 const char *tp; 458 459 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) { | 428 code = -1; 429 return; 430 } 431 if ((locfile = globulize(argv[1])) == NULL) { 432 code = -1; 433 return; 434 } 435 remfile = argv[2]; --- 27 unchanged lines hidden (view full) --- 463mput(int argc, char *argv[]) 464{ 465 int i; 466 sigfunc oldintr; 467 int ointer; 468 const char *tp; 469 470 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) { |
460 fprintf(ttyout, "usage: %s local-files\n", argv[0]); | 471 UPRINTF("usage: %s local-files\n", argv[0]); |
461 code = -1; 462 return; 463 } | 472 code = -1; 473 return; 474 } |
464 mname = argv[0]; | |
465 mflag = 1; 466 oldintr = xsignal(SIGINT, mintr); 467 if (sigsetjmp(jabort, 1)) | 475 mflag = 1; 476 oldintr = xsignal(SIGINT, mintr); 477 if (sigsetjmp(jabort, 1)) |
468 mabort(); | 478 mabort(argv[0]); |
469 if (proxy) { 470 char *cp; 471 472 while ((cp = remglob(argv, 0, NULL)) != NULL) { 473 if (*cp == '\0' || !connected) { 474 mflag = 0; 475 continue; 476 } 477 if (mflag && confirm(argv[0], cp)) { 478 char buf[MAXPATHLEN]; 479 tp = doprocess(buf, sizeof(buf), cp, 480 mcase, ntflag, mapflag); 481 sendrequest((sunique) ? "STOU" : "STOR", 482 cp, tp, cp != tp || !interactive); 483 if (!mflag && fromatty) { 484 ointer = interactive; 485 interactive = 1; | 479 if (proxy) { 480 char *cp; 481 482 while ((cp = remglob(argv, 0, NULL)) != NULL) { 483 if (*cp == '\0' || !connected) { 484 mflag = 0; 485 continue; 486 } 487 if (mflag && confirm(argv[0], cp)) { 488 char buf[MAXPATHLEN]; 489 tp = doprocess(buf, sizeof(buf), cp, 490 mcase, ntflag, mapflag); 491 sendrequest((sunique) ? "STOU" : "STOR", 492 cp, tp, cp != tp || !interactive); 493 if (!mflag && fromatty) { 494 ointer = interactive; 495 interactive = 1; |
486 if (confirm("Continue with", "mput")) { | 496 if (confirm(argv[0], NULL)) { |
487 mflag++; 488 } 489 interactive = ointer; 490 } 491 } 492 } 493 goto cleanupmput; 494 } --- 7 unchanged lines hidden (view full) --- 502 char buf[MAXPATHLEN]; 503 tp = doprocess(buf, sizeof(buf), argv[i], 504 0, ntflag, mapflag); 505 sendrequest((sunique) ? "STOU" : "STOR", 506 argv[i], tp, tp != argv[i] || !interactive); 507 if (!mflag && fromatty) { 508 ointer = interactive; 509 interactive = 1; | 497 mflag++; 498 } 499 interactive = ointer; 500 } 501 } 502 } 503 goto cleanupmput; 504 } --- 7 unchanged lines hidden (view full) --- 512 char buf[MAXPATHLEN]; 513 tp = doprocess(buf, sizeof(buf), argv[i], 514 0, ntflag, mapflag); 515 sendrequest((sunique) ? "STOU" : "STOR", 516 argv[i], tp, tp != argv[i] || !interactive); 517 if (!mflag && fromatty) { 518 ointer = interactive; 519 interactive = 1; |
510 if (confirm("Continue with", "mput")) { | 520 if (confirm(argv[0], NULL)) { |
511 mflag++; 512 } 513 interactive = ointer; 514 } 515 } 516 continue; 517 } 518 519 memset(&gl, 0, sizeof(gl)); 520 flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE; 521 if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) { | 521 mflag++; 522 } 523 interactive = ointer; 524 } 525 } 526 continue; 527 } 528 529 memset(&gl, 0, sizeof(gl)); 530 flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE; 531 if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) { |
522 warnx("%s: not found", argv[i]); | 532 warnx("Glob pattern `%s' not found", argv[i]); |
523 globfree(&gl); 524 continue; 525 } 526 for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected; 527 cpp++) { 528 if (mflag && confirm(argv[0], *cpp)) { 529 char buf[MAXPATHLEN]; 530 tp = *cpp; 531 tp = doprocess(buf, sizeof(buf), *cpp, 532 0, ntflag, mapflag); 533 sendrequest((sunique) ? "STOU" : "STOR", 534 *cpp, tp, *cpp != tp || !interactive); 535 if (!mflag && fromatty) { 536 ointer = interactive; 537 interactive = 1; | 533 globfree(&gl); 534 continue; 535 } 536 for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected; 537 cpp++) { 538 if (mflag && confirm(argv[0], *cpp)) { 539 char buf[MAXPATHLEN]; 540 tp = *cpp; 541 tp = doprocess(buf, sizeof(buf), *cpp, 542 0, ntflag, mapflag); 543 sendrequest((sunique) ? "STOU" : "STOR", 544 *cpp, tp, *cpp != tp || !interactive); 545 if (!mflag && fromatty) { 546 ointer = interactive; 547 interactive = 1; |
538 if (confirm("Continue with", "mput")) { | 548 if (confirm(argv[0], NULL)) { |
539 mflag++; 540 } 541 interactive = ointer; 542 } 543 } 544 } 545 globfree(&gl); 546 } --- 17 unchanged lines hidden (view full) --- 564} 565 566/* 567 * Receive one file. 568 * If restartit is 1, restart the xfer always. 569 * If restartit is -1, restart the xfer only if the remote file is newer. 570 */ 571int | 549 mflag++; 550 } 551 interactive = ointer; 552 } 553 } 554 } 555 globfree(&gl); 556 } --- 17 unchanged lines hidden (view full) --- 574} 575 576/* 577 * Receive one file. 578 * If restartit is 1, restart the xfer always. 579 * If restartit is -1, restart the xfer only if the remote file is newer. 580 */ 581int |
572getit(int argc, char *argv[], int restartit, const char *mode) | 582getit(int argc, char *argv[], int restartit, const char *gmode) |
573{ 574 int loc, rval; 575 char *remfile, *olocfile; 576 const char *locfile; 577 char buf[MAXPATHLEN]; 578 579 loc = rval = 0; 580 if (argc == 2) { 581 argc++; 582 argv[2] = argv[1]; 583 loc++; 584 } 585 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file"))) 586 goto usage; 587 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) { 588 usage: | 583{ 584 int loc, rval; 585 char *remfile, *olocfile; 586 const char *locfile; 587 char buf[MAXPATHLEN]; 588 589 loc = rval = 0; 590 if (argc == 2) { 591 argc++; 592 argv[2] = argv[1]; 593 loc++; 594 } 595 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file"))) 596 goto usage; 597 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) { 598 usage: |
589 fprintf(ttyout, "usage: %s remote-file [local-file]\n", 590 argv[0]); | 599 UPRINTF("usage: %s remote-file [local-file]\n", argv[0]); |
591 code = -1; 592 return (0); 593 } 594 remfile = argv[1]; 595 if ((olocfile = globulize(argv[2])) == NULL) { 596 code = -1; 597 return (0); 598 } --- 6 unchanged lines hidden (view full) --- 605 if (! features[FEAT_REST_STREAM]) { 606 fprintf(ttyout, 607 "Restart is not supported by the remote server.\n"); 608 return (0); 609 } 610 ret = stat(locfile, &stbuf); 611 if (restartit == 1) { 612 if (ret < 0) { | 600 code = -1; 601 return (0); 602 } 603 remfile = argv[1]; 604 if ((olocfile = globulize(argv[2])) == NULL) { 605 code = -1; 606 return (0); 607 } --- 6 unchanged lines hidden (view full) --- 614 if (! features[FEAT_REST_STREAM]) { 615 fprintf(ttyout, 616 "Restart is not supported by the remote server.\n"); 617 return (0); 618 } 619 ret = stat(locfile, &stbuf); 620 if (restartit == 1) { 621 if (ret < 0) { |
613 warn("local: %s", locfile); | 622 warn("Can't stat `%s'", locfile); |
614 goto freegetit; 615 } 616 restart_point = stbuf.st_size; 617 } else { 618 if (ret == 0) { 619 time_t mtime; 620 621 mtime = remotemodtime(argv[1], 0); 622 if (mtime == -1) 623 goto freegetit; 624 if (stbuf.st_mtime >= mtime) { 625 rval = 1; 626 goto freegetit; 627 } 628 } 629 } 630 } 631 | 623 goto freegetit; 624 } 625 restart_point = stbuf.st_size; 626 } else { 627 if (ret == 0) { 628 time_t mtime; 629 630 mtime = remotemodtime(argv[1], 0); 631 if (mtime == -1) 632 goto freegetit; 633 if (stbuf.st_mtime >= mtime) { 634 rval = 1; 635 goto freegetit; 636 } 637 } 638 } 639 } 640 |
632 recvrequest("RETR", locfile, remfile, mode, | 641 recvrequest("RETR", locfile, remfile, gmode, |
633 remfile != argv[1] || locfile != argv[2], loc); 634 restart_point = 0; 635 freegetit: 636 (void)free(olocfile); 637 return (rval); 638} 639 640/* ARGSUSED */ | 642 remfile != argv[1] || locfile != argv[2], loc); 643 restart_point = 0; 644 freegetit: 645 (void)free(olocfile); 646 return (rval); 647} 648 649/* ARGSUSED */ |
641void | 650static void |
642mintr(int signo) 643{ 644 645 alarmtimer(0); 646 if (fromatty) 647 write(fileno(ttyout), "\n", 1); 648 siglongjmp(jabort, 1); 649} 650 | 651mintr(int signo) 652{ 653 654 alarmtimer(0); 655 if (fromatty) 656 write(fileno(ttyout), "\n", 1); 657 siglongjmp(jabort, 1); 658} 659 |
651void 652mabort(void) | 660static void 661mabort(const char *cmd) |
653{ 654 int ointer, oconf; 655 656 if (mflag && fromatty) { 657 ointer = interactive; 658 oconf = confirmrest; 659 interactive = 1; 660 confirmrest = 0; | 662{ 663 int ointer, oconf; 664 665 if (mflag && fromatty) { 666 ointer = interactive; 667 oconf = confirmrest; 668 interactive = 1; 669 confirmrest = 0; |
661 if (confirm("Continue with", mname)) { | 670 if (confirm(cmd, NULL)) { |
662 interactive = ointer; 663 confirmrest = oconf; 664 return; 665 } 666 interactive = ointer; 667 confirmrest = oconf; 668 } 669 mflag = 0; --- 4 unchanged lines hidden (view full) --- 674 */ 675void 676mget(int argc, char *argv[]) 677{ 678 sigfunc oldintr; 679 int ointer; 680 char *cp; 681 const char *tp; | 671 interactive = ointer; 672 confirmrest = oconf; 673 return; 674 } 675 interactive = ointer; 676 confirmrest = oconf; 677 } 678 mflag = 0; --- 4 unchanged lines hidden (view full) --- 683 */ 684void 685mget(int argc, char *argv[]) 686{ 687 sigfunc oldintr; 688 int ointer; 689 char *cp; 690 const char *tp; |
682 int restartit; | 691 int volatile restartit; |
683 684 if (argc == 0 || 685 (argc == 1 && !another(&argc, &argv, "remote-files"))) { | 692 693 if (argc == 0 || 694 (argc == 1 && !another(&argc, &argv, "remote-files"))) { |
686 fprintf(ttyout, "usage: %s remote-files\n", argv[0]); | 695 UPRINTF("usage: %s remote-files\n", argv[0]); |
687 code = -1; 688 return; 689 } | 696 code = -1; 697 return; 698 } |
690 mname = argv[0]; | |
691 mflag = 1; 692 restart_point = 0; 693 restartit = 0; 694 if (strcmp(argv[0], "mreget") == 0) { 695 if (! features[FEAT_REST_STREAM]) { 696 fprintf(ttyout, 697 "Restart is not supported by the remote server.\n"); 698 return; 699 } 700 restartit = 1; 701 } 702 oldintr = xsignal(SIGINT, mintr); 703 if (sigsetjmp(jabort, 1)) | 699 mflag = 1; 700 restart_point = 0; 701 restartit = 0; 702 if (strcmp(argv[0], "mreget") == 0) { 703 if (! features[FEAT_REST_STREAM]) { 704 fprintf(ttyout, 705 "Restart is not supported by the remote server.\n"); 706 return; 707 } 708 restartit = 1; 709 } 710 oldintr = xsignal(SIGINT, mintr); 711 if (sigsetjmp(jabort, 1)) |
704 mabort(); | 712 mabort(argv[0]); |
705 while ((cp = remglob(argv, proxy, NULL)) != NULL) { 706 char buf[MAXPATHLEN]; 707 if (*cp == '\0' || !connected) { 708 mflag = 0; 709 continue; 710 } 711 if (! mflag) 712 continue; --- 6 unchanged lines hidden (view full) --- 719 continue; 720 tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag); 721 if (restartit) { 722 struct stat stbuf; 723 724 if (stat(tp, &stbuf) == 0) 725 restart_point = stbuf.st_size; 726 else | 713 while ((cp = remglob(argv, proxy, NULL)) != NULL) { 714 char buf[MAXPATHLEN]; 715 if (*cp == '\0' || !connected) { 716 mflag = 0; 717 continue; 718 } 719 if (! mflag) 720 continue; --- 6 unchanged lines hidden (view full) --- 727 continue; 728 tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag); 729 if (restartit) { 730 struct stat stbuf; 731 732 if (stat(tp, &stbuf) == 0) 733 restart_point = stbuf.st_size; 734 else |
727 warn("stat %s", tp); | 735 warn("Can't stat `%s'", tp); |
728 } 729 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w", 730 tp != cp || !interactive, 1); 731 restart_point = 0; 732 if (!mflag && fromatty) { 733 ointer = interactive; 734 interactive = 1; | 736 } 737 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w", 738 tp != cp || !interactive, 1); 739 restart_point = 0; 740 if (!mflag && fromatty) { 741 ointer = interactive; 742 interactive = 1; |
735 if (confirm("Continue with", "mget")) | 743 if (confirm(argv[0], NULL)) |
736 mflag++; 737 interactive = ointer; 738 } 739 } 740 (void)xsignal(SIGINT, oldintr); 741 mflag = 0; 742} 743 744/* 745 * Read list of filenames from a local file and get those 746 */ 747void 748fget(int argc, char *argv[]) 749{ | 744 mflag++; 745 interactive = ointer; 746 } 747 } 748 (void)xsignal(SIGINT, oldintr); 749 mflag = 0; 750} 751 752/* 753 * Read list of filenames from a local file and get those 754 */ 755void 756fget(int argc, char *argv[]) 757{ |
750 char *buf, *mode; | 758 const char *gmode; |
751 FILE *fp; | 759 FILE *fp; |
760 char buf[MAXPATHLEN], cmdbuf[MAX_C_NAME]; |
|
752 753 if (argc != 2) { | 761 762 if (argc != 2) { |
754 fprintf(ttyout, "usage: %s localfile\n", argv[0]); | 763 UPRINTF("usage: %s localfile\n", argv[0]); |
755 code = -1; 756 return; 757 } 758 759 fp = fopen(argv[1], "r"); 760 if (fp == NULL) { | 764 code = -1; 765 return; 766 } 767 768 fp = fopen(argv[1], "r"); 769 if (fp == NULL) { |
761 fprintf(ttyout, "Cannot open source file %s\n", argv[1]); | 770 fprintf(ttyout, "Can't open source file %s\n", argv[1]); |
762 code = -1; 763 return; 764 } 765 | 771 code = -1; 772 return; 773 } 774 |
766 argv[0] = "get"; 767 mode = restart_point ? "r+" : "w"; | 775 (void)strlcpy(cmdbuf, "get", sizeof(cmdbuf)); 776 argv[0] = cmdbuf; 777 gmode = restart_point ? "r+" : "w"; |
768 | 778 |
769 for (; 770 (buf = fparseln(fp, NULL, NULL, "\0\0\0", 0)) != NULL; 771 free(buf)) { | 779 while (get_line(fp, buf, sizeof(buf), NULL) >= 0) { |
772 if (buf[0] == '\0') 773 continue; 774 argv[1] = buf; | 780 if (buf[0] == '\0') 781 continue; 782 argv[1] = buf; |
775 (void)getit(argc, argv, 0, mode); | 783 (void)getit(argc, argv, 0, gmode); |
776 } 777 fclose(fp); 778} 779 | 784 } 785 fclose(fp); 786} 787 |
780char * 781onoff(int bool) | 788const char * 789onoff(int val) |
782{ 783 | 790{ 791 |
784 return (bool ? "on" : "off"); | 792 return (val ? "on" : "off"); |
785} 786 787/* 788 * Show status. 789 */ 790/*ARGSUSED*/ 791void 792status(int argc, char *argv[]) 793{ 794 795 if (argc == 0) { | 793} 794 795/* 796 * Show status. 797 */ 798/*ARGSUSED*/ 799void 800status(int argc, char *argv[]) 801{ 802 803 if (argc == 0) { |
796 fprintf(ttyout, "usage: %s\n", argv[0]); | 804 UPRINTF("usage: %s\n", argv[0]); |
797 code = -1; 798 return; 799 } 800#ifndef NO_STATUS 801 if (connected) 802 fprintf(ttyout, "Connected %sto %s.\n", 803 connected == -1 ? "and logged in" : "", hostname); 804 else --- 44 unchanged lines hidden (view full) --- 849 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n", 850 onoff(rate_put), rate_put, rate_put_incr); 851 fprintf(ttyout, 852 "Socket buffer sizes: send %d, receive %d.\n", 853 sndbuf_size, rcvbuf_size); 854 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport)); 855 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4), 856 epsv4bad ? " (disabled for this connection)" : ""); | 805 code = -1; 806 return; 807 } 808#ifndef NO_STATUS 809 if (connected) 810 fprintf(ttyout, "Connected %sto %s.\n", 811 connected == -1 ? "and logged in" : "", hostname); 812 else --- 44 unchanged lines hidden (view full) --- 857 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n", 858 onoff(rate_put), rate_put, rate_put_incr); 859 fprintf(ttyout, 860 "Socket buffer sizes: send %d, receive %d.\n", 861 sndbuf_size, rcvbuf_size); 862 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport)); 863 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4), 864 epsv4bad ? " (disabled for this connection)" : ""); |
865 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv6: %s%s.\n", onoff(epsv6), 866 epsv6bad ? " (disabled for this connection)" : ""); |
|
857 fprintf(ttyout, "Command line editing: %s.\n", 858#ifdef NO_EDITCOMPLETE 859 "support not compiled in" 860#else /* !def NO_EDITCOMPLETE */ 861 onoff(editing) 862#endif /* !def NO_EDITCOMPLETE */ 863 ); 864 if (macnum > 0) { --- 17 unchanged lines hidden (view full) --- 882{ 883 if (argc == 1) { 884 *var = !*var; 885 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) { 886 *var = 1; 887 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) { 888 *var = 0; 889 } else { | 867 fprintf(ttyout, "Command line editing: %s.\n", 868#ifdef NO_EDITCOMPLETE 869 "support not compiled in" 870#else /* !def NO_EDITCOMPLETE */ 871 onoff(editing) 872#endif /* !def NO_EDITCOMPLETE */ 873 ); 874 if (macnum > 0) { --- 17 unchanged lines hidden (view full) --- 892{ 893 if (argc == 1) { 894 *var = !*var; 895 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) { 896 *var = 1; 897 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) { 898 *var = 0; 899 } else { |
890 fprintf(ttyout, "usage: %s [ on | off ]\n", argv[0]); | 900 UPRINTF("usage: %s [ on | off ]\n", argv[0]); |
891 return (-1); 892 } 893 if (mesg) 894 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var)); 895 return (*var); 896} 897 898/* --- 12 unchanged lines hidden (view full) --- 911 */ 912/*VARARGS*/ 913void 914setedit(int argc, char *argv[]) 915{ 916 917#ifdef NO_EDITCOMPLETE 918 if (argc == 0) { | 901 return (-1); 902 } 903 if (mesg) 904 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var)); 905 return (*var); 906} 907 908/* --- 12 unchanged lines hidden (view full) --- 921 */ 922/*VARARGS*/ 923void 924setedit(int argc, char *argv[]) 925{ 926 927#ifdef NO_EDITCOMPLETE 928 if (argc == 0) { |
919 fprintf(ttyout, "usage: %s\n", argv[0]); | 929 UPRINTF("usage: %s\n", argv[0]); |
920 code = -1; 921 return; 922 } 923 if (verbose) 924 fputs("Editing support not compiled in; ignoring command.\n", 925 ttyout); 926#else /* !def NO_EDITCOMPLETE */ 927 code = togglevar(argc, argv, &editing, "Editing mode"); --- 17 unchanged lines hidden (view full) --- 945 */ 946/*VARARGS*/ 947void 948sethash(int argc, char *argv[]) 949{ 950 if (argc == 1) 951 hash = !hash; 952 else if (argc != 2) { | 930 code = -1; 931 return; 932 } 933 if (verbose) 934 fputs("Editing support not compiled in; ignoring command.\n", 935 ttyout); 936#else /* !def NO_EDITCOMPLETE */ 937 code = togglevar(argc, argv, &editing, "Editing mode"); --- 17 unchanged lines hidden (view full) --- 955 */ 956/*VARARGS*/ 957void 958sethash(int argc, char *argv[]) 959{ 960 if (argc == 1) 961 hash = !hash; 962 else if (argc != 2) { |
953 fprintf(ttyout, "usage: %s [ on | off | bytecount ]\n", | 963 UPRINTF("usage: %s [ on | off | bytecount ]\n", |
954 argv[0]); 955 code = -1; 956 return; 957 } else if (strcasecmp(argv[1], "on") == 0) 958 hash = 1; 959 else if (strcasecmp(argv[1], "off") == 0) 960 hash = 0; 961 else { --- 69 unchanged lines hidden (view full) --- 1031 */ 1032/*VARARGS*/ 1033void 1034setgate(int argc, char *argv[]) 1035{ 1036 static char gsbuf[MAXHOSTNAMELEN]; 1037 1038 if (argc == 0 || argc > 3) { | 964 argv[0]); 965 code = -1; 966 return; 967 } else if (strcasecmp(argv[1], "on") == 0) 968 hash = 1; 969 else if (strcasecmp(argv[1], "off") == 0) 970 hash = 0; 971 else { --- 69 unchanged lines hidden (view full) --- 1041 */ 1042/*VARARGS*/ 1043void 1044setgate(int argc, char *argv[]) 1045{ 1046 static char gsbuf[MAXHOSTNAMELEN]; 1047 1048 if (argc == 0 || argc > 3) { |
1039 fprintf(ttyout, | 1049 UPRINTF( |
1040 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]); 1041 code = -1; 1042 return; 1043 } else if (argc < 2) { 1044 gatemode = !gatemode; 1045 } else { 1046 if (argc == 2 && strcasecmp(argv[1], "on") == 0) 1047 gatemode = 1; 1048 else if (argc == 2 && strcasecmp(argv[1], "off") == 0) 1049 gatemode = 0; 1050 else { 1051 if (argc == 3) | 1050 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]); 1051 code = -1; 1052 return; 1053 } else if (argc < 2) { 1054 gatemode = !gatemode; 1055 } else { 1056 if (argc == 2 && strcasecmp(argv[1], "on") == 0) 1057 gatemode = 1; 1058 else if (argc == 2 && strcasecmp(argv[1], "off") == 0) 1059 gatemode = 0; 1060 else { 1061 if (argc == 3) |
1052 gateport = xstrdup(argv[2]); | 1062 gateport = ftp_strdup(argv[2]); |
1053 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf)); 1054 gateserver = gsbuf; 1055 gatemode = 1; 1056 } 1057 } 1058 if (gatemode && (gateserver == NULL || *gateserver == '\0')) { 1059 fprintf(ttyout, 1060 "Disabling gate-ftp mode - no gate-ftp server defined.\n"); --- 31 unchanged lines hidden (view full) --- 1092/* 1093 * Set debugging mode on/off and/or set level of debugging. 1094 */ 1095/*VARARGS*/ 1096void 1097setdebug(int argc, char *argv[]) 1098{ 1099 if (argc == 0 || argc > 2) { | 1063 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf)); 1064 gateserver = gsbuf; 1065 gatemode = 1; 1066 } 1067 } 1068 if (gatemode && (gateserver == NULL || *gateserver == '\0')) { 1069 fprintf(ttyout, 1070 "Disabling gate-ftp mode - no gate-ftp server defined.\n"); --- 31 unchanged lines hidden (view full) --- 1102/* 1103 * Set debugging mode on/off and/or set level of debugging. 1104 */ 1105/*VARARGS*/ 1106void 1107setdebug(int argc, char *argv[]) 1108{ 1109 if (argc == 0 || argc > 2) { |
1100 fprintf(ttyout, "usage: %s [ on | off | debuglevel ]\n", 1101 argv[0]); | 1110 UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]); |
1102 code = -1; 1103 return; 1104 } else if (argc == 2) { 1105 if (strcasecmp(argv[1], "on") == 0) | 1111 code = -1; 1112 return; 1113 } else if (argc == 2) { 1114 if (strcasecmp(argv[1], "on") == 0) |
1106 debug = 1; | 1115 ftp_debug = 1; |
1107 else if (strcasecmp(argv[1], "off") == 0) | 1116 else if (strcasecmp(argv[1], "off") == 0) |
1108 debug = 0; | 1117 ftp_debug = 0; |
1109 else { 1110 int val; 1111 1112 val = strsuftoi(argv[1]); 1113 if (val < 0) { 1114 fprintf(ttyout, "%s: bad debugging value.\n", 1115 argv[1]); 1116 code = -1; 1117 return; 1118 } | 1118 else { 1119 int val; 1120 1121 val = strsuftoi(argv[1]); 1122 if (val < 0) { 1123 fprintf(ttyout, "%s: bad debugging value.\n", 1124 argv[1]); 1125 code = -1; 1126 return; 1127 } |
1119 debug = val; | 1128 ftp_debug = val; |
1120 } 1121 } else | 1129 } 1130 } else |
1122 debug = !debug; 1123 if (debug) | 1131 ftp_debug = !ftp_debug; 1132 if (ftp_debug) |
1124 options |= SO_DEBUG; 1125 else 1126 options &= ~SO_DEBUG; | 1133 options |= SO_DEBUG; 1134 else 1135 options &= ~SO_DEBUG; |
1127 fprintf(ttyout, "Debugging %s (debug=%d).\n", onoff(debug), debug); 1128 code = debug > 0; | 1136 fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug); 1137 code = ftp_debug > 0; |
1129} 1130 1131/* 1132 * Set current working directory on remote machine. 1133 */ 1134void 1135cd(int argc, char *argv[]) 1136{ 1137 int r; 1138 1139 if (argc == 0 || argc > 2 || 1140 (argc == 1 && !another(&argc, &argv, "remote-directory"))) { | 1138} 1139 1140/* 1141 * Set current working directory on remote machine. 1142 */ 1143void 1144cd(int argc, char *argv[]) 1145{ 1146 int r; 1147 1148 if (argc == 0 || argc > 2 || 1149 (argc == 1 && !another(&argc, &argv, "remote-directory"))) { |
1141 fprintf(ttyout, "usage: %s remote-directory\n", argv[0]); | 1150 UPRINTF("usage: %s remote-directory\n", argv[0]); |
1142 code = -1; 1143 return; 1144 } 1145 r = command("CWD %s", argv[1]); 1146 if (r == ERROR && code == 500) { 1147 if (verbose) 1148 fputs("CWD command not recognized, trying XCWD.\n", 1149 ttyout); --- 14 unchanged lines hidden (view full) --- 1164 char *locdir; 1165 1166 code = -1; 1167 if (argc == 1) { 1168 argc++; 1169 argv[1] = localhome; 1170 } 1171 if (argc != 2) { | 1151 code = -1; 1152 return; 1153 } 1154 r = command("CWD %s", argv[1]); 1155 if (r == ERROR && code == 500) { 1156 if (verbose) 1157 fputs("CWD command not recognized, trying XCWD.\n", 1158 ttyout); --- 14 unchanged lines hidden (view full) --- 1173 char *locdir; 1174 1175 code = -1; 1176 if (argc == 1) { 1177 argc++; 1178 argv[1] = localhome; 1179 } 1180 if (argc != 2) { |
1172 fprintf(ttyout, "usage: %s [local-directory]\n", argv[0]); | 1181 UPRINTF("usage: %s [local-directory]\n", argv[0]); |
1173 return; 1174 } 1175 if ((locdir = globulize(argv[1])) == NULL) 1176 return; 1177 if (chdir(locdir) == -1) | 1182 return; 1183 } 1184 if ((locdir = globulize(argv[1])) == NULL) 1185 return; 1186 if (chdir(locdir) == -1) |
1178 warn("lcd %s", locdir); | 1187 warn("Can't chdir `%s'", locdir); |
1179 else { 1180 updatelocalcwd(); 1181 if (localcwd[0]) { 1182 fprintf(ttyout, "Local directory now: %s\n", localcwd); 1183 code = 0; 1184 } else { 1185 fprintf(ttyout, "Unable to determine local directory\n"); 1186 } --- 5 unchanged lines hidden (view full) --- 1192 * Delete a single file. 1193 */ 1194void 1195delete(int argc, char *argv[]) 1196{ 1197 1198 if (argc == 0 || argc > 2 || 1199 (argc == 1 && !another(&argc, &argv, "remote-file"))) { | 1188 else { 1189 updatelocalcwd(); 1190 if (localcwd[0]) { 1191 fprintf(ttyout, "Local directory now: %s\n", localcwd); 1192 code = 0; 1193 } else { 1194 fprintf(ttyout, "Unable to determine local directory\n"); 1195 } --- 5 unchanged lines hidden (view full) --- 1201 * Delete a single file. 1202 */ 1203void 1204delete(int argc, char *argv[]) 1205{ 1206 1207 if (argc == 0 || argc > 2 || 1208 (argc == 1 && !another(&argc, &argv, "remote-file"))) { |
1200 fprintf(ttyout, "usage: %s remote-file\n", argv[0]); | 1209 UPRINTF("usage: %s remote-file\n", argv[0]); |
1201 code = -1; 1202 return; 1203 } 1204 if (command("DELE %s", argv[1]) == COMPLETE) 1205 dirchange = 1; 1206} 1207 1208/* 1209 * Delete multiple files. 1210 */ 1211void 1212mdelete(int argc, char *argv[]) 1213{ 1214 sigfunc oldintr; 1215 int ointer; 1216 char *cp; 1217 1218 if (argc == 0 || 1219 (argc == 1 && !another(&argc, &argv, "remote-files"))) { | 1210 code = -1; 1211 return; 1212 } 1213 if (command("DELE %s", argv[1]) == COMPLETE) 1214 dirchange = 1; 1215} 1216 1217/* 1218 * Delete multiple files. 1219 */ 1220void 1221mdelete(int argc, char *argv[]) 1222{ 1223 sigfunc oldintr; 1224 int ointer; 1225 char *cp; 1226 1227 if (argc == 0 || 1228 (argc == 1 && !another(&argc, &argv, "remote-files"))) { |
1220 fprintf(ttyout, "usage: %s [remote-files]\n", argv[0]); | 1229 UPRINTF("usage: %s [remote-files]\n", argv[0]); |
1221 code = -1; 1222 return; 1223 } | 1230 code = -1; 1231 return; 1232 } |
1224 mname = argv[0]; | |
1225 mflag = 1; 1226 oldintr = xsignal(SIGINT, mintr); 1227 if (sigsetjmp(jabort, 1)) | 1233 mflag = 1; 1234 oldintr = xsignal(SIGINT, mintr); 1235 if (sigsetjmp(jabort, 1)) |
1228 mabort(); | 1236 mabort(argv[0]); |
1229 while ((cp = remglob(argv, 0, NULL)) != NULL) { 1230 if (*cp == '\0') { 1231 mflag = 0; 1232 continue; 1233 } 1234 if (mflag && confirm(argv[0], cp)) { 1235 if (command("DELE %s", cp) == COMPLETE) 1236 dirchange = 1; 1237 if (!mflag && fromatty) { 1238 ointer = interactive; 1239 interactive = 1; | 1237 while ((cp = remglob(argv, 0, NULL)) != NULL) { 1238 if (*cp == '\0') { 1239 mflag = 0; 1240 continue; 1241 } 1242 if (mflag && confirm(argv[0], cp)) { 1243 if (command("DELE %s", cp) == COMPLETE) 1244 dirchange = 1; 1245 if (!mflag && fromatty) { 1246 ointer = interactive; 1247 interactive = 1; |
1240 if (confirm("Continue with", "mdelete")) { | 1248 if (confirm(argv[0], NULL)) { |
1241 mflag++; 1242 } 1243 interactive = ointer; 1244 } 1245 } 1246 } 1247 (void)xsignal(SIGINT, oldintr); 1248 mflag = 0; --- 5 unchanged lines hidden (view full) --- 1254void 1255renamefile(int argc, char *argv[]) 1256{ 1257 1258 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name"))) 1259 goto usage; 1260 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) { 1261 usage: | 1249 mflag++; 1250 } 1251 interactive = ointer; 1252 } 1253 } 1254 } 1255 (void)xsignal(SIGINT, oldintr); 1256 mflag = 0; --- 5 unchanged lines hidden (view full) --- 1262void 1263renamefile(int argc, char *argv[]) 1264{ 1265 1266 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name"))) 1267 goto usage; 1268 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) { 1269 usage: |
1262 fprintf(ttyout, "usage: %s from-name to-name\n", argv[0]); | 1270 UPRINTF("usage: %s from-name to-name\n", argv[0]); |
1263 code = -1; 1264 return; 1265 } 1266 if (command("RNFR %s", argv[1]) == CONTINUE && 1267 command("RNTO %s", argv[2]) == COMPLETE) 1268 dirchange = 1; 1269} 1270 1271/* 1272 * Get a directory listing of remote files. 1273 * Supports being invoked as: 1274 * cmd runs 1275 * --- ---- 1276 * dir, ls LIST 1277 * mlsd MLSD 1278 * nlist NLST 1279 * pdir, pls LIST |$PAGER | 1271 code = -1; 1272 return; 1273 } 1274 if (command("RNFR %s", argv[1]) == CONTINUE && 1275 command("RNTO %s", argv[2]) == COMPLETE) 1276 dirchange = 1; 1277} 1278 1279/* 1280 * Get a directory listing of remote files. 1281 * Supports being invoked as: 1282 * cmd runs 1283 * --- ---- 1284 * dir, ls LIST 1285 * mlsd MLSD 1286 * nlist NLST 1287 * pdir, pls LIST |$PAGER |
1280 * mmlsd MLSD |$PAGER | 1288 * pmlsd MLSD |$PAGER |
1281 */ 1282void 1283ls(int argc, char *argv[]) 1284{ 1285 const char *cmd; | 1289 */ 1290void 1291ls(int argc, char *argv[]) 1292{ 1293 const char *cmd; |
1286 char *remdir, *locfile; 1287 int freelocfile, pagecmd, mlsdcmd; | 1294 char *remdir, *locbuf; 1295 const char *locfile; 1296 int pagecmd, mlsdcmd; |
1288 1289 remdir = NULL; | 1297 1298 remdir = NULL; |
1299 locbuf = NULL; |
|
1290 locfile = "-"; | 1300 locfile = "-"; |
1291 freelocfile = pagecmd = mlsdcmd = 0; | 1301 pagecmd = mlsdcmd = 0; |
1292 /* 1293 * the only commands that start with `p' are 1294 * the `pager' versions. 1295 */ 1296 if (argv[0][0] == 'p') 1297 pagecmd = 1; 1298 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) { 1299 if (! features[FEAT_MLST]) { --- 15 unchanged lines hidden (view full) --- 1315 1316 if (argc > 1) 1317 remdir = argv[1]; 1318 if (argc > 2) 1319 locfile = argv[2]; 1320 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) { 1321 usage: 1322 if (pagecmd || mlsdcmd) | 1302 /* 1303 * the only commands that start with `p' are 1304 * the `pager' versions. 1305 */ 1306 if (argv[0][0] == 'p') 1307 pagecmd = 1; 1308 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) { 1309 if (! features[FEAT_MLST]) { --- 15 unchanged lines hidden (view full) --- 1325 1326 if (argc > 1) 1327 remdir = argv[1]; 1328 if (argc > 2) 1329 locfile = argv[2]; 1330 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) { 1331 usage: 1332 if (pagecmd || mlsdcmd) |
1323 fprintf(ttyout, 1324 "usage: %s [remote-path]\n", argv[0]); | 1333 UPRINTF("usage: %s [remote-path]\n", argv[0]); |
1325 else | 1334 else |
1326 fprintf(ttyout, 1327 "usage: %s [remote-path [local-file]]\n", | 1335 UPRINTF("usage: %s [remote-path [local-file]]\n", |
1328 argv[0]); 1329 code = -1; 1330 goto freels; 1331 } 1332 1333 if (pagecmd) { | 1336 argv[0]); 1337 code = -1; 1338 goto freels; 1339 } 1340 1341 if (pagecmd) { |
1334 char *p; 1335 int len; | 1342 const char *p; 1343 size_t len; |
1336 1337 p = getoptionvalue("pager"); 1338 if (EMPTYSTRING(p)) 1339 p = DEFAULTPAGER; 1340 len = strlen(p) + 2; | 1344 1345 p = getoptionvalue("pager"); 1346 if (EMPTYSTRING(p)) 1347 p = DEFAULTPAGER; 1348 len = strlen(p) + 2; |
1341 locfile = xmalloc(len); 1342 locfile[0] = '|'; 1343 (void)strlcpy(locfile + 1, p, len - 1); 1344 freelocfile = 1; | 1349 locbuf = ftp_malloc(len); 1350 locbuf[0] = '|'; 1351 (void)strlcpy(locbuf + 1, p, len - 1); 1352 locfile = locbuf; |
1345 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') { | 1353 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') { |
1346 mname = argv[0]; 1347 if ((locfile = globulize(locfile)) == NULL || 1348 !confirm("output to local-file:", locfile)) { | 1354 if ((locbuf = globulize(locfile)) == NULL || 1355 !confirm("output to local-file:", locbuf)) { |
1349 code = -1; 1350 goto freels; 1351 } | 1356 code = -1; 1357 goto freels; 1358 } |
1352 freelocfile = 1; | 1359 locfile = locbuf; |
1353 } 1354 recvrequest(cmd, locfile, remdir, "w", 0, 0); 1355 freels: | 1360 } 1361 recvrequest(cmd, locfile, remdir, "w", 0, 0); 1362 freels: |
1356 if (freelocfile && locfile) 1357 (void)free(locfile); | 1363 if (locbuf) 1364 (void)free(locbuf); |
1358} 1359 1360/* 1361 * Get a directory listing of multiple remote files. 1362 */ 1363void 1364mls(int argc, char *argv[]) 1365{ 1366 sigfunc oldintr; 1367 int ointer, i; | 1365} 1366 1367/* 1368 * Get a directory listing of multiple remote files. 1369 */ 1370void 1371mls(int argc, char *argv[]) 1372{ 1373 sigfunc oldintr; 1374 int ointer, i; |
1368 int dolist; 1369 char *mode, *dest, *odest; | 1375 int volatile dolist; 1376 char * volatile dest, *odest; 1377 const char *lmode; |
1370 1371 if (argc == 0) 1372 goto usage; 1373 if (argc < 2 && !another(&argc, &argv, "remote-files")) 1374 goto usage; 1375 if (argc < 3 && !another(&argc, &argv, "local-file")) { 1376 usage: | 1378 1379 if (argc == 0) 1380 goto usage; 1381 if (argc < 2 && !another(&argc, &argv, "remote-files")) 1382 goto usage; 1383 if (argc < 3 && !another(&argc, &argv, "local-file")) { 1384 usage: |
1377 fprintf(ttyout, "usage: %s remote-files local-file\n", argv[0]); | 1385 UPRINTF("usage: %s remote-files local-file\n", argv[0]); |
1378 code = -1; 1379 return; 1380 } 1381 odest = dest = argv[argc - 1]; 1382 argv[argc - 1] = NULL; | 1386 code = -1; 1387 return; 1388 } 1389 odest = dest = argv[argc - 1]; 1390 argv[argc - 1] = NULL; |
1383 mname = argv[0]; | |
1384 if (strcmp(dest, "-") && *dest != '|') 1385 if (((dest = globulize(dest)) == NULL) || 1386 !confirm("output to local-file:", dest)) { 1387 code = -1; 1388 return; 1389 } 1390 dolist = strcmp(argv[0], "mls"); 1391 mflag = 1; 1392 oldintr = xsignal(SIGINT, mintr); 1393 if (sigsetjmp(jabort, 1)) | 1391 if (strcmp(dest, "-") && *dest != '|') 1392 if (((dest = globulize(dest)) == NULL) || 1393 !confirm("output to local-file:", dest)) { 1394 code = -1; 1395 return; 1396 } 1397 dolist = strcmp(argv[0], "mls"); 1398 mflag = 1; 1399 oldintr = xsignal(SIGINT, mintr); 1400 if (sigsetjmp(jabort, 1)) |
1394 mabort(); | 1401 mabort(argv[0]); |
1395 for (i = 1; mflag && i < argc-1 && connected; i++) { | 1402 for (i = 1; mflag && i < argc-1 && connected; i++) { |
1396 mode = (i == 1) ? "w" : "a"; 1397 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode, | 1403 lmode = (i == 1) ? "w" : "a"; 1404 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], lmode, |
1398 0, 0); 1399 if (!mflag && fromatty) { 1400 ointer = interactive; 1401 interactive = 1; | 1405 0, 0); 1406 if (!mflag && fromatty) { 1407 ointer = interactive; 1408 interactive = 1; |
1402 if (confirm("Continue with", argv[0])) { | 1409 if (confirm(argv[0], NULL)) { |
1403 mflag++; 1404 } 1405 interactive = ointer; 1406 } 1407 } 1408 (void)xsignal(SIGINT, oldintr); 1409 mflag = 0; 1410 if (dest != odest) /* free up after globulize() */ --- 4 unchanged lines hidden (view full) --- 1415 * Do a shell escape 1416 */ 1417/*ARGSUSED*/ 1418void 1419shell(int argc, char *argv[]) 1420{ 1421 pid_t pid; 1422 sigfunc oldintr; | 1410 mflag++; 1411 } 1412 interactive = ointer; 1413 } 1414 } 1415 (void)xsignal(SIGINT, oldintr); 1416 mflag = 0; 1417 if (dest != odest) /* free up after globulize() */ --- 4 unchanged lines hidden (view full) --- 1422 * Do a shell escape 1423 */ 1424/*ARGSUSED*/ 1425void 1426shell(int argc, char *argv[]) 1427{ 1428 pid_t pid; 1429 sigfunc oldintr; |
1423 char shellnam[MAXPATHLEN], *shell, *namep; | 1430 char shellnam[MAXPATHLEN]; 1431 const char *shellp, *namep; |
1424 int wait_status; 1425 1426 if (argc == 0) { | 1432 int wait_status; 1433 1434 if (argc == 0) { |
1427 fprintf(ttyout, "usage: %s [command [args]]\n", argv[0]); | 1435 UPRINTF("usage: %s [command [args]]\n", argv[0]); |
1428 code = -1; 1429 return; 1430 } 1431 oldintr = xsignal(SIGINT, SIG_IGN); 1432 if ((pid = fork()) == 0) { 1433 for (pid = 3; pid < 20; pid++) 1434 (void)close(pid); 1435 (void)xsignal(SIGINT, SIG_DFL); | 1436 code = -1; 1437 return; 1438 } 1439 oldintr = xsignal(SIGINT, SIG_IGN); 1440 if ((pid = fork()) == 0) { 1441 for (pid = 3; pid < 20; pid++) 1442 (void)close(pid); 1443 (void)xsignal(SIGINT, SIG_DFL); |
1436 shell = getenv("SHELL"); 1437 if (shell == NULL) 1438 shell = _PATH_BSHELL; 1439 namep = strrchr(shell, '/'); | 1444 shellp = getenv("SHELL"); 1445 if (shellp == NULL) 1446 shellp = _PATH_BSHELL; 1447 namep = strrchr(shellp, '/'); |
1440 if (namep == NULL) | 1448 if (namep == NULL) |
1441 namep = shell; | 1449 namep = shellp; |
1442 else 1443 namep++; 1444 (void)strlcpy(shellnam, namep, sizeof(shellnam)); | 1450 else 1451 namep++; 1452 (void)strlcpy(shellnam, namep, sizeof(shellnam)); |
1445 if (debug) { 1446 fputs(shell, ttyout); | 1453 if (ftp_debug) { 1454 fputs(shellp, ttyout); |
1447 putc('\n', ttyout); 1448 } 1449 if (argc > 1) { | 1455 putc('\n', ttyout); 1456 } 1457 if (argc > 1) { |
1450 execl(shell, shellnam, "-c", altarg, (char *)0); | 1458 execl(shellp, shellnam, "-c", altarg, (char *)0); |
1451 } 1452 else { | 1459 } 1460 else { |
1453 execl(shell, shellnam, (char *)0); | 1461 execl(shellp, shellnam, (char *)0); |
1454 } | 1462 } |
1455 warn("%s", shell); | 1463 warn("Can't execute `%s'", shellp); |
1456 code = -1; 1457 exit(1); 1458 } 1459 if (pid > 0) 1460 while (wait(&wait_status) != pid) 1461 ; 1462 (void)xsignal(SIGINT, oldintr); 1463 if (pid == -1) { | 1464 code = -1; 1465 exit(1); 1466 } 1467 if (pid > 0) 1468 while (wait(&wait_status) != pid) 1469 ; 1470 (void)xsignal(SIGINT, oldintr); 1471 if (pid == -1) { |
1464 warn("Try again later"); | 1472 warn("Can't fork a subshell; try again later"); |
1465 code = -1; 1466 } else 1467 code = 0; 1468} 1469 1470/* 1471 * Send new user information (re-login) 1472 */ 1473void 1474user(int argc, char *argv[]) 1475{ | 1473 code = -1; 1474 } else 1475 code = 0; 1476} 1477 1478/* 1479 * Send new user information (re-login) 1480 */ 1481void 1482user(int argc, char *argv[]) 1483{ |
1476 char acct[80]; | 1484 char *password; 1485 char emptypass[] = ""; |
1477 int n, aflag = 0; 1478 1479 if (argc == 0) 1480 goto usage; 1481 if (argc < 2) 1482 (void)another(&argc, &argv, "username"); 1483 if (argc < 2 || argc > 4) { 1484 usage: | 1486 int n, aflag = 0; 1487 1488 if (argc == 0) 1489 goto usage; 1490 if (argc < 2) 1491 (void)another(&argc, &argv, "username"); 1492 if (argc < 2 || argc > 4) { 1493 usage: |
1485 fprintf(ttyout, "usage: %s username [password [account]]\n", | 1494 UPRINTF("usage: %s username [password [account]]\n", |
1486 argv[0]); 1487 code = -1; 1488 return; 1489 } 1490 n = command("USER %s", argv[1]); 1491 if (n == CONTINUE) { 1492 if (argc < 3) { | 1495 argv[0]); 1496 code = -1; 1497 return; 1498 } 1499 n = command("USER %s", argv[1]); 1500 if (n == CONTINUE) { 1501 if (argc < 3) { |
1493 argv[2] = getpass("Password: "); 1494 argc++; | 1502 password = getpass("Password: "); 1503 if (password == NULL) 1504 password = emptypass; 1505 } else { 1506 password = argv[2]; |
1495 } | 1507 } |
1496 n = command("PASS %s", argv[2]); | 1508 n = command("PASS %s", password); 1509 memset(password, 0, strlen(password)); |
1497 } 1498 if (n == CONTINUE) { | 1510 } 1511 if (n == CONTINUE) { |
1512 aflag++; |
|
1499 if (argc < 4) { | 1513 if (argc < 4) { |
1500 (void)fputs("Account: ", ttyout); 1501 (void)fflush(ttyout); 1502 if (fgets(acct, sizeof(acct) - 1, stdin) == NULL) { 1503 fprintf(ttyout, 1504 "\nEOF received; login aborted.\n"); 1505 clearerr(stdin); 1506 code = -1; 1507 return; 1508 } 1509 acct[strlen(acct) - 1] = '\0'; 1510 argv[3] = acct; argc++; | 1514 password = getpass("Account: "); 1515 if (password == NULL) 1516 password = emptypass; 1517 } else { 1518 password = argv[3]; |
1511 } | 1519 } |
1512 n = command("ACCT %s", argv[3]); 1513 aflag++; | 1520 n = command("ACCT %s", password); 1521 memset(password, 0, strlen(password)); |
1514 } 1515 if (n != COMPLETE) { 1516 fputs("Login failed.\n", ttyout); 1517 return; 1518 } 1519 if (!aflag && argc == 4) { | 1522 } 1523 if (n != COMPLETE) { 1524 fputs("Login failed.\n", ttyout); 1525 return; 1526 } 1527 if (!aflag && argc == 4) { |
1520 (void)command("ACCT %s", argv[3]); | 1528 password = argv[3]; 1529 (void)command("ACCT %s", password); 1530 memset(password, 0, strlen(password)); |
1521 } 1522 connected = -1; 1523 getremoteinfo(); 1524} 1525 1526/* 1527 * Print working directory on remote machine. 1528 */ 1529/*VARARGS*/ 1530void 1531pwd(int argc, char *argv[]) 1532{ 1533 1534 code = -1; 1535 if (argc != 1) { | 1531 } 1532 connected = -1; 1533 getremoteinfo(); 1534} 1535 1536/* 1537 * Print working directory on remote machine. 1538 */ 1539/*VARARGS*/ 1540void 1541pwd(int argc, char *argv[]) 1542{ 1543 1544 code = -1; 1545 if (argc != 1) { |
1536 fprintf(ttyout, "usage: %s\n", argv[0]); | 1546 UPRINTF("usage: %s\n", argv[0]); |
1537 return; 1538 } 1539 if (! remotecwd[0]) 1540 updateremotecwd(); 1541 if (! remotecwd[0]) 1542 fprintf(ttyout, "Unable to determine remote directory\n"); 1543 else { 1544 fprintf(ttyout, "Remote directory: %s\n", remotecwd); --- 5 unchanged lines hidden (view full) --- 1550 * Print working directory on local machine. 1551 */ 1552void 1553lpwd(int argc, char *argv[]) 1554{ 1555 1556 code = -1; 1557 if (argc != 1) { | 1547 return; 1548 } 1549 if (! remotecwd[0]) 1550 updateremotecwd(); 1551 if (! remotecwd[0]) 1552 fprintf(ttyout, "Unable to determine remote directory\n"); 1553 else { 1554 fprintf(ttyout, "Remote directory: %s\n", remotecwd); --- 5 unchanged lines hidden (view full) --- 1560 * Print working directory on local machine. 1561 */ 1562void 1563lpwd(int argc, char *argv[]) 1564{ 1565 1566 code = -1; 1567 if (argc != 1) { |
1558 fprintf(ttyout, "usage: %s\n", argv[0]); | 1568 UPRINTF("usage: %s\n", argv[0]); |
1559 return; 1560 } 1561 if (! localcwd[0]) 1562 updatelocalcwd(); 1563 if (! localcwd[0]) 1564 fprintf(ttyout, "Unable to determine local directory\n"); 1565 else { 1566 fprintf(ttyout, "Local directory: %s\n", localcwd); --- 6 unchanged lines hidden (view full) --- 1573 */ 1574void 1575makedir(int argc, char *argv[]) 1576{ 1577 int r; 1578 1579 if (argc == 0 || argc > 2 || 1580 (argc == 1 && !another(&argc, &argv, "directory-name"))) { | 1569 return; 1570 } 1571 if (! localcwd[0]) 1572 updatelocalcwd(); 1573 if (! localcwd[0]) 1574 fprintf(ttyout, "Unable to determine local directory\n"); 1575 else { 1576 fprintf(ttyout, "Local directory: %s\n", localcwd); --- 6 unchanged lines hidden (view full) --- 1583 */ 1584void 1585makedir(int argc, char *argv[]) 1586{ 1587 int r; 1588 1589 if (argc == 0 || argc > 2 || 1590 (argc == 1 && !another(&argc, &argv, "directory-name"))) { |
1581 fprintf(ttyout, "usage: %s directory-name\n", argv[0]); | 1591 UPRINTF("usage: %s directory-name\n", argv[0]); |
1582 code = -1; 1583 return; 1584 } 1585 r = command("MKD %s", argv[1]); 1586 if (r == ERROR && code == 500) { 1587 if (verbose) 1588 fputs("MKD command not recognized, trying XMKD.\n", 1589 ttyout); --- 8 unchanged lines hidden (view full) --- 1598 */ 1599void 1600removedir(int argc, char *argv[]) 1601{ 1602 int r; 1603 1604 if (argc == 0 || argc > 2 || 1605 (argc == 1 && !another(&argc, &argv, "directory-name"))) { | 1592 code = -1; 1593 return; 1594 } 1595 r = command("MKD %s", argv[1]); 1596 if (r == ERROR && code == 500) { 1597 if (verbose) 1598 fputs("MKD command not recognized, trying XMKD.\n", 1599 ttyout); --- 8 unchanged lines hidden (view full) --- 1608 */ 1609void 1610removedir(int argc, char *argv[]) 1611{ 1612 int r; 1613 1614 if (argc == 0 || argc > 2 || 1615 (argc == 1 && !another(&argc, &argv, "directory-name"))) { |
1606 fprintf(ttyout, "usage: %s directory-name\n", argv[0]); | 1616 UPRINTF("usage: %s directory-name\n", argv[0]); |
1607 code = -1; 1608 return; 1609 } 1610 r = command("RMD %s", argv[1]); 1611 if (r == ERROR && code == 500) { 1612 if (verbose) 1613 fputs("RMD command not recognized, trying XRMD.\n", 1614 ttyout); --- 7 unchanged lines hidden (view full) --- 1622 * Send a line, verbatim, to the remote machine. 1623 */ 1624void 1625quote(int argc, char *argv[]) 1626{ 1627 1628 if (argc == 0 || 1629 (argc == 1 && !another(&argc, &argv, "command line to send"))) { | 1617 code = -1; 1618 return; 1619 } 1620 r = command("RMD %s", argv[1]); 1621 if (r == ERROR && code == 500) { 1622 if (verbose) 1623 fputs("RMD command not recognized, trying XRMD.\n", 1624 ttyout); --- 7 unchanged lines hidden (view full) --- 1632 * Send a line, verbatim, to the remote machine. 1633 */ 1634void 1635quote(int argc, char *argv[]) 1636{ 1637 1638 if (argc == 0 || 1639 (argc == 1 && !another(&argc, &argv, "command line to send"))) { |
1630 fprintf(ttyout, "usage: %s line-to-send\n", argv[0]); | 1640 UPRINTF("usage: %s line-to-send\n", argv[0]); |
1631 code = -1; 1632 return; 1633 } 1634 quote1("", argc, argv); 1635} 1636 1637/* 1638 * Send a SITE command to the remote machine. The line 1639 * is sent verbatim to the remote machine, except that the 1640 * word "SITE" is added at the front. 1641 */ 1642void 1643site(int argc, char *argv[]) 1644{ 1645 1646 if (argc == 0 || 1647 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){ | 1641 code = -1; 1642 return; 1643 } 1644 quote1("", argc, argv); 1645} 1646 1647/* 1648 * Send a SITE command to the remote machine. The line 1649 * is sent verbatim to the remote machine, except that the 1650 * word "SITE" is added at the front. 1651 */ 1652void 1653site(int argc, char *argv[]) 1654{ 1655 1656 if (argc == 0 || 1657 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){ |
1648 fprintf(ttyout, "usage: %s line-to-send\n", argv[0]); | 1658 UPRINTF("usage: %s line-to-send\n", argv[0]); |
1649 code = -1; 1650 return; 1651 } 1652 quote1("SITE ", argc, argv); 1653} 1654 1655/* 1656 * Turn argv[1..argc) into a space-separated string, then prepend initial text. --- 21 unchanged lines hidden (view full) --- 1678void 1679do_chmod(int argc, char *argv[]) 1680{ 1681 1682 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode"))) 1683 goto usage; 1684 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) { 1685 usage: | 1659 code = -1; 1660 return; 1661 } 1662 quote1("SITE ", argc, argv); 1663} 1664 1665/* 1666 * Turn argv[1..argc) into a space-separated string, then prepend initial text. --- 21 unchanged lines hidden (view full) --- 1688void 1689do_chmod(int argc, char *argv[]) 1690{ 1691 1692 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode"))) 1693 goto usage; 1694 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) { 1695 usage: |
1686 fprintf(ttyout, "usage: %s mode remote-file\n", argv[0]); | 1696 UPRINTF("usage: %s mode remote-file\n", argv[0]); |
1687 code = -1; 1688 return; 1689 } 1690 (void)command("SITE CHMOD %s %s", argv[1], argv[2]); 1691} 1692 1693#define COMMAND_1ARG(argc, argv, cmd) \ 1694 if (argc == 1) \ 1695 command(cmd); \ 1696 else \ 1697 command(cmd " %s", argv[1]) 1698 1699void 1700do_umask(int argc, char *argv[]) 1701{ 1702 int oldverbose = verbose; 1703 1704 if (argc == 0) { | 1697 code = -1; 1698 return; 1699 } 1700 (void)command("SITE CHMOD %s %s", argv[1], argv[2]); 1701} 1702 1703#define COMMAND_1ARG(argc, argv, cmd) \ 1704 if (argc == 1) \ 1705 command(cmd); \ 1706 else \ 1707 command(cmd " %s", argv[1]) 1708 1709void 1710do_umask(int argc, char *argv[]) 1711{ 1712 int oldverbose = verbose; 1713 1714 if (argc == 0) { |
1705 fprintf(ttyout, "usage: %s [umask]\n", argv[0]); | 1715 UPRINTF("usage: %s [umask]\n", argv[0]); |
1706 code = -1; 1707 return; 1708 } 1709 verbose = 1; 1710 COMMAND_1ARG(argc, argv, "SITE UMASK"); 1711 verbose = oldverbose; 1712} 1713 1714void 1715idlecmd(int argc, char *argv[]) 1716{ 1717 int oldverbose = verbose; 1718 1719 if (argc < 1 || argc > 2) { | 1716 code = -1; 1717 return; 1718 } 1719 verbose = 1; 1720 COMMAND_1ARG(argc, argv, "SITE UMASK"); 1721 verbose = oldverbose; 1722} 1723 1724void 1725idlecmd(int argc, char *argv[]) 1726{ 1727 int oldverbose = verbose; 1728 1729 if (argc < 1 || argc > 2) { |
1720 fprintf(ttyout, "usage: %s [seconds]\n", argv[0]); | 1730 UPRINTF("usage: %s [seconds]\n", argv[0]); |
1721 code = -1; 1722 return; 1723 } 1724 verbose = 1; 1725 COMMAND_1ARG(argc, argv, "SITE IDLE"); 1726 verbose = oldverbose; 1727} 1728 1729/* 1730 * Ask the other side for help. 1731 */ 1732void 1733rmthelp(int argc, char *argv[]) 1734{ 1735 int oldverbose = verbose; 1736 1737 if (argc == 0) { | 1731 code = -1; 1732 return; 1733 } 1734 verbose = 1; 1735 COMMAND_1ARG(argc, argv, "SITE IDLE"); 1736 verbose = oldverbose; 1737} 1738 1739/* 1740 * Ask the other side for help. 1741 */ 1742void 1743rmthelp(int argc, char *argv[]) 1744{ 1745 int oldverbose = verbose; 1746 1747 if (argc == 0) { |
1738 fprintf(ttyout, "usage: %s\n", argv[0]); | 1748 UPRINTF("usage: %s\n", argv[0]); |
1739 code = -1; 1740 return; 1741 } 1742 verbose = 1; 1743 COMMAND_1ARG(argc, argv, "HELP"); 1744 verbose = oldverbose; 1745} 1746 1747/* 1748 * Terminate session and exit. 1749 * May be called with 0, NULL. 1750 */ 1751/*VARARGS*/ 1752void 1753quit(int argc, char *argv[]) 1754{ 1755 1756 /* this may be called with argc == 0, argv == NULL */ 1757 if (argc == 0 && argv != NULL) { | 1749 code = -1; 1750 return; 1751 } 1752 verbose = 1; 1753 COMMAND_1ARG(argc, argv, "HELP"); 1754 verbose = oldverbose; 1755} 1756 1757/* 1758 * Terminate session and exit. 1759 * May be called with 0, NULL. 1760 */ 1761/*VARARGS*/ 1762void 1763quit(int argc, char *argv[]) 1764{ 1765 1766 /* this may be called with argc == 0, argv == NULL */ 1767 if (argc == 0 && argv != NULL) { |
1758 fprintf(ttyout, "usage: %s\n", argv[0]); | 1768 UPRINTF("usage: %s\n", argv[0]); |
1759 code = -1; 1760 return; 1761 } 1762 if (connected) 1763 disconnect(0, NULL); 1764 pswitch(1); 1765 if (connected) 1766 disconnect(0, NULL); --- 5 unchanged lines hidden (view full) --- 1772 * May be called with 0, NULL. 1773 */ 1774void 1775disconnect(int argc, char *argv[]) 1776{ 1777 1778 /* this may be called with argc == 0, argv == NULL */ 1779 if (argc == 0 && argv != NULL) { | 1769 code = -1; 1770 return; 1771 } 1772 if (connected) 1773 disconnect(0, NULL); 1774 pswitch(1); 1775 if (connected) 1776 disconnect(0, NULL); --- 5 unchanged lines hidden (view full) --- 1782 * May be called with 0, NULL. 1783 */ 1784void 1785disconnect(int argc, char *argv[]) 1786{ 1787 1788 /* this may be called with argc == 0, argv == NULL */ 1789 if (argc == 0 && argv != NULL) { |
1780 fprintf(ttyout, "usage: %s\n", argv[0]); | 1790 UPRINTF("usage: %s\n", argv[0]); |
1781 code = -1; 1782 return; 1783 } 1784 if (!connected) 1785 return; 1786 (void)command("QUIT"); 1787 cleanuppeer(); 1788} 1789 1790void 1791account(int argc, char *argv[]) 1792{ 1793 char *ap; | 1791 code = -1; 1792 return; 1793 } 1794 if (!connected) 1795 return; 1796 (void)command("QUIT"); 1797 cleanuppeer(); 1798} 1799 1800void 1801account(int argc, char *argv[]) 1802{ 1803 char *ap; |
1804 char emptypass[] = ""; |
|
1794 1795 if (argc == 0 || argc > 2) { | 1805 1806 if (argc == 0 || argc > 2) { |
1796 fprintf(ttyout, "usage: %s [password]\n", argv[0]); | 1807 UPRINTF("usage: %s [password]\n", argv[0]); |
1797 code = -1; 1798 return; 1799 } 1800 else if (argc == 2) 1801 ap = argv[1]; | 1808 code = -1; 1809 return; 1810 } 1811 else if (argc == 2) 1812 ap = argv[1]; |
1802 else | 1813 else { |
1803 ap = getpass("Account:"); | 1814 ap = getpass("Account:"); |
1815 if (ap == NULL) 1816 ap = emptypass; 1817 } |
|
1804 (void)command("ACCT %s", ap); | 1818 (void)command("ACCT %s", ap); |
1819 memset(ap, 0, strlen(ap)); |
|
1805} 1806 1807sigjmp_buf abortprox; 1808 1809void 1810proxabort(int notused) 1811{ 1812 --- 13 unchanged lines hidden (view full) --- 1826} 1827 1828void 1829doproxy(int argc, char *argv[]) 1830{ 1831 struct cmd *c; 1832 int cmdpos; 1833 sigfunc oldintr; | 1820} 1821 1822sigjmp_buf abortprox; 1823 1824void 1825proxabort(int notused) 1826{ 1827 --- 13 unchanged lines hidden (view full) --- 1841} 1842 1843void 1844doproxy(int argc, char *argv[]) 1845{ 1846 struct cmd *c; 1847 int cmdpos; 1848 sigfunc oldintr; |
1849 char cmdbuf[MAX_C_NAME]; |
|
1834 1835 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) { | 1850 1851 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) { |
1836 fprintf(ttyout, "usage: %s command\n", argv[0]); | 1852 UPRINTF("usage: %s command\n", argv[0]); |
1837 code = -1; 1838 return; 1839 } 1840 c = getcmd(argv[1]); 1841 if (c == (struct cmd *) -1) { 1842 fputs("?Ambiguous command.\n", ttyout); 1843 code = -1; 1844 return; --- 19 unchanged lines hidden (view full) --- 1864 pswitch(0); 1865 (void)xsignal(SIGINT, oldintr); 1866 code = -1; 1867 return; 1868 } 1869 cmdpos = strcspn(line, " \t"); 1870 if (cmdpos > 0) /* remove leading "proxy " from input buffer */ 1871 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1); | 1853 code = -1; 1854 return; 1855 } 1856 c = getcmd(argv[1]); 1857 if (c == (struct cmd *) -1) { 1858 fputs("?Ambiguous command.\n", ttyout); 1859 code = -1; 1860 return; --- 19 unchanged lines hidden (view full) --- 1880 pswitch(0); 1881 (void)xsignal(SIGINT, oldintr); 1882 code = -1; 1883 return; 1884 } 1885 cmdpos = strcspn(line, " \t"); 1886 if (cmdpos > 0) /* remove leading "proxy " from input buffer */ 1887 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1); |
1872 argv[1] = c->c_name; | 1888 (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf)); 1889 argv[1] = cmdbuf; |
1873 (*c->c_handler)(argc-1, argv+1); 1874 if (connected) { 1875 proxflag = 1; 1876 } 1877 else { 1878 proxflag = 0; 1879 } 1880 pswitch(0); --- 39 unchanged lines hidden (view full) --- 1920 code = togglevar(argc, argv, &crflag, "Carriage Return stripping"); 1921} 1922 1923void 1924setntrans(int argc, char *argv[]) 1925{ 1926 1927 if (argc == 0 || argc > 3) { | 1890 (*c->c_handler)(argc-1, argv+1); 1891 if (connected) { 1892 proxflag = 1; 1893 } 1894 else { 1895 proxflag = 0; 1896 } 1897 pswitch(0); --- 39 unchanged lines hidden (view full) --- 1937 code = togglevar(argc, argv, &crflag, "Carriage Return stripping"); 1938} 1939 1940void 1941setntrans(int argc, char *argv[]) 1942{ 1943 1944 if (argc == 0 || argc > 3) { |
1928 fprintf(ttyout, "usage: %s [inchars [outchars]]\n", argv[0]); | 1945 UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]); |
1929 code = -1; 1930 return; 1931 } 1932 if (argc == 1) { 1933 ntflag = 0; 1934 fputs("Ntrans off.\n", ttyout); 1935 code = ntflag; 1936 return; --- 19 unchanged lines hidden (view full) --- 1956 continue; 1957 for (cp1 = src; *cp1; cp1++) { 1958 int found = 0; 1959 for (i = 0; *(ntin + i) && i < 16; i++) { 1960 if (*cp1 == *(ntin + i)) { 1961 found++; 1962 if (i < ostop) { 1963 *cp2++ = *(ntout + i); | 1946 code = -1; 1947 return; 1948 } 1949 if (argc == 1) { 1950 ntflag = 0; 1951 fputs("Ntrans off.\n", ttyout); 1952 code = ntflag; 1953 return; --- 19 unchanged lines hidden (view full) --- 1973 continue; 1974 for (cp1 = src; *cp1; cp1++) { 1975 int found = 0; 1976 for (i = 0; *(ntin + i) && i < 16; i++) { 1977 if (*cp1 == *(ntin + i)) { 1978 found++; 1979 if (i < ostop) { 1980 *cp2++ = *(ntout + i); |
1964 if (cp2 - dst >= dlen - 1) | 1981 if (cp2 - dst >= (ptrdiff_t)(dlen - 1)) |
1965 goto out; 1966 } 1967 break; 1968 } 1969 } 1970 if (!found) { 1971 *cp2++ = *cp1; 1972 } --- 11 unchanged lines hidden (view full) --- 1984 if (argc == 1) { 1985 mapflag = 0; 1986 fputs("Nmap off.\n", ttyout); 1987 code = mapflag; 1988 return; 1989 } 1990 if (argc == 0 || 1991 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) { | 1982 goto out; 1983 } 1984 break; 1985 } 1986 } 1987 if (!found) { 1988 *cp2++ = *cp1; 1989 } --- 11 unchanged lines hidden (view full) --- 2001 if (argc == 1) { 2002 mapflag = 0; 2003 fputs("Nmap off.\n", ttyout); 2004 code = mapflag; 2005 return; 2006 } 2007 if (argc == 0 || 2008 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) { |
1992 fprintf(ttyout, "usage: %s [mapin mapout]\n", argv[0]); | 2009 UPRINTF("usage: %s [mapin mapout]\n", argv[0]); |
1993 code = -1; 1994 return; 1995 } 1996 mapflag = 1; 1997 code = 1; 1998 cp = strchr(altarg, ' '); 1999 if (proxy) { 2000 while(*++cp == ' ') --- 183 unchanged lines hidden (view full) --- 2184setpassive(int argc, char *argv[]) 2185{ 2186 2187 if (argc == 1) { 2188 passivemode = !passivemode; 2189 activefallback = passivemode; 2190 } else if (argc != 2) { 2191 passiveusage: | 2010 code = -1; 2011 return; 2012 } 2013 mapflag = 1; 2014 code = 1; 2015 cp = strchr(altarg, ' '); 2016 if (proxy) { 2017 while(*++cp == ' ') --- 183 unchanged lines hidden (view full) --- 2201setpassive(int argc, char *argv[]) 2202{ 2203 2204 if (argc == 1) { 2205 passivemode = !passivemode; 2206 activefallback = passivemode; 2207 } else if (argc != 2) { 2208 passiveusage: |
2192 fprintf(ttyout, "usage: %s [ on | off | auto ]\n", argv[0]); | 2209 UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]); |
2193 code = -1; 2194 return; 2195 } else if (strcasecmp(argv[1], "on") == 0) { 2196 passivemode = 1; 2197 activefallback = 0; 2198 } else if (strcasecmp(argv[1], "off") == 0) { 2199 passivemode = 0; 2200 activefallback = 0; 2201 } else if (strcasecmp(argv[1], "auto") == 0) { 2202 passivemode = 1; 2203 activefallback = 1; 2204 } else 2205 goto passiveusage; 2206 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n", 2207 onoff(passivemode), onoff(activefallback)); 2208 code = passivemode; 2209} 2210 | 2210 code = -1; 2211 return; 2212 } else if (strcasecmp(argv[1], "on") == 0) { 2213 passivemode = 1; 2214 activefallback = 0; 2215 } else if (strcasecmp(argv[1], "off") == 0) { 2216 passivemode = 0; 2217 activefallback = 0; 2218 } else if (strcasecmp(argv[1], "auto") == 0) { 2219 passivemode = 1; 2220 activefallback = 1; 2221 } else 2222 goto passiveusage; 2223 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n", 2224 onoff(passivemode), onoff(activefallback)); 2225 code = passivemode; 2226} 2227 |
2228 |
|
2211void 2212setepsv4(int argc, char *argv[]) 2213{ | 2229void 2230setepsv4(int argc, char *argv[]) 2231{ |
2214 | |
2215 code = togglevar(argc, argv, &epsv4, 2216 verbose ? "EPSV/EPRT on IPv4" : NULL); 2217 epsv4bad = 0; 2218} 2219 2220void | 2232 code = togglevar(argc, argv, &epsv4, 2233 verbose ? "EPSV/EPRT on IPv4" : NULL); 2234 epsv4bad = 0; 2235} 2236 2237void |
2238setepsv6(int argc, char *argv[]) 2239{ 2240 code = togglevar(argc, argv, &epsv6, 2241 verbose ? "EPSV/EPRT on IPv6" : NULL); 2242 epsv6bad = 0; 2243} 2244 2245void 2246setepsv(int argc, char*argv[]) 2247{ 2248 setepsv4(argc,argv); 2249 setepsv6(argc,argv); 2250} 2251 2252void |
|
2221setsunique(int argc, char *argv[]) 2222{ 2223 2224 code = togglevar(argc, argv, &sunique, "Store unique"); 2225} 2226 2227void 2228setrunique(int argc, char *argv[]) --- 6 unchanged lines hidden (view full) --- 2235parserate(int argc, char *argv[], int cmdlineopt) 2236{ 2237 int dir, max, incr, showonly; 2238 sigfunc oldusr1, oldusr2; 2239 2240 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) { 2241 usage: 2242 if (cmdlineopt) | 2253setsunique(int argc, char *argv[]) 2254{ 2255 2256 code = togglevar(argc, argv, &sunique, "Store unique"); 2257} 2258 2259void 2260setrunique(int argc, char *argv[]) --- 6 unchanged lines hidden (view full) --- 2267parserate(int argc, char *argv[], int cmdlineopt) 2268{ 2269 int dir, max, incr, showonly; 2270 sigfunc oldusr1, oldusr2; 2271 2272 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) { 2273 usage: 2274 if (cmdlineopt) |
2243 fprintf(ttyout, | 2275 UPRINTF( |
2244 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n", 2245 argv[0]); 2246 else | 2276 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n", 2277 argv[0]); 2278 else |
2247 fprintf(ttyout, | 2279 UPRINTF( |
2248 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n", 2249 argv[0]); 2250 return -1; 2251 } 2252 dir = max = incr = showonly = 0; 2253#define RATE_GET 1 2254#define RATE_PUT 2 2255#define RATE_ALL (RATE_GET | RATE_PUT) --- 55 unchanged lines hidden (view full) --- 2311 2312/* change directory to parent directory */ 2313void 2314cdup(int argc, char *argv[]) 2315{ 2316 int r; 2317 2318 if (argc == 0) { | 2280 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n", 2281 argv[0]); 2282 return -1; 2283 } 2284 dir = max = incr = showonly = 0; 2285#define RATE_GET 1 2286#define RATE_PUT 2 2287#define RATE_ALL (RATE_GET | RATE_PUT) --- 55 unchanged lines hidden (view full) --- 2343 2344/* change directory to parent directory */ 2345void 2346cdup(int argc, char *argv[]) 2347{ 2348 int r; 2349 2350 if (argc == 0) { |
2319 fprintf(ttyout, "usage: %s\n", argv[0]); | 2351 UPRINTF("usage: %s\n", argv[0]); |
2320 code = -1; 2321 return; 2322 } 2323 r = command("CDUP"); 2324 if (r == ERROR && code == 500) { 2325 if (verbose) 2326 fputs("CDUP command not recognized, trying XCUP.\n", 2327 ttyout); --- 8 unchanged lines hidden (view full) --- 2336/* 2337 * Restart transfer at specific point 2338 */ 2339void 2340restart(int argc, char *argv[]) 2341{ 2342 2343 if (argc == 0 || argc > 2) { | 2352 code = -1; 2353 return; 2354 } 2355 r = command("CDUP"); 2356 if (r == ERROR && code == 500) { 2357 if (verbose) 2358 fputs("CDUP command not recognized, trying XCUP.\n", 2359 ttyout); --- 8 unchanged lines hidden (view full) --- 2368/* 2369 * Restart transfer at specific point 2370 */ 2371void 2372restart(int argc, char *argv[]) 2373{ 2374 2375 if (argc == 0 || argc > 2) { |
2344 fprintf(ttyout, "usage: %s [restart-point]\n", argv[0]); | 2376 UPRINTF("usage: %s [restart-point]\n", argv[0]); |
2345 code = -1; 2346 return; 2347 } 2348 if (! features[FEAT_REST_STREAM]) { 2349 fprintf(ttyout, 2350 "Restart is not supported by the remote server.\n"); 2351 return; 2352 } --- 20 unchanged lines hidden (view full) --- 2373 * Show remote system type 2374 */ 2375void 2376syst(int argc, char *argv[]) 2377{ 2378 int oldverbose = verbose; 2379 2380 if (argc == 0) { | 2377 code = -1; 2378 return; 2379 } 2380 if (! features[FEAT_REST_STREAM]) { 2381 fprintf(ttyout, 2382 "Restart is not supported by the remote server.\n"); 2383 return; 2384 } --- 20 unchanged lines hidden (view full) --- 2405 * Show remote system type 2406 */ 2407void 2408syst(int argc, char *argv[]) 2409{ 2410 int oldverbose = verbose; 2411 2412 if (argc == 0) { |
2381 fprintf(ttyout, "usage: %s\n", argv[0]); | 2413 UPRINTF("usage: %s\n", argv[0]); |
2382 code = -1; 2383 return; 2384 } 2385 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2386 (void)command("SYST"); 2387 verbose = oldverbose; 2388} 2389 --- 8 unchanged lines hidden (view full) --- 2398 if (macnum == 16) { 2399 fputs("Limit of 16 macros have already been defined.\n", 2400 ttyout); 2401 code = -1; 2402 return; 2403 } 2404 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) { 2405 usage: | 2414 code = -1; 2415 return; 2416 } 2417 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2418 (void)command("SYST"); 2419 verbose = oldverbose; 2420} 2421 --- 8 unchanged lines hidden (view full) --- 2430 if (macnum == 16) { 2431 fputs("Limit of 16 macros have already been defined.\n", 2432 ttyout); 2433 code = -1; 2434 return; 2435 } 2436 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) { 2437 usage: |
2406 fprintf(ttyout, "usage: %s macro_name\n", argv[0]); | 2438 UPRINTF("usage: %s macro_name\n", argv[0]); |
2407 code = -1; 2408 return; 2409 } 2410 if (interactive) 2411 fputs( 2412 "Enter macro line by line, terminating it with a null line.\n", 2413 ttyout); 2414 (void)strlcpy(macros[macnum].mac_name, argv[1], --- 41 unchanged lines hidden (view full) --- 2456 */ 2457void 2458sizecmd(int argc, char *argv[]) 2459{ 2460 off_t size; 2461 2462 if (argc == 0 || argc > 2 || 2463 (argc == 1 && !another(&argc, &argv, "remote-file"))) { | 2439 code = -1; 2440 return; 2441 } 2442 if (interactive) 2443 fputs( 2444 "Enter macro line by line, terminating it with a null line.\n", 2445 ttyout); 2446 (void)strlcpy(macros[macnum].mac_name, argv[1], --- 41 unchanged lines hidden (view full) --- 2488 */ 2489void 2490sizecmd(int argc, char *argv[]) 2491{ 2492 off_t size; 2493 2494 if (argc == 0 || argc > 2 || 2495 (argc == 1 && !another(&argc, &argv, "remote-file"))) { |
2464 fprintf(ttyout, "usage: %s remote-file\n", argv[0]); | 2496 UPRINTF("usage: %s remote-file\n", argv[0]); |
2465 code = -1; 2466 return; 2467 } 2468 size = remotesize(argv[1], 1); 2469 if (size != -1) 2470 fprintf(ttyout, 2471 "%s\t" LLF "\n", argv[1], (LLT)size); 2472 code = (size > 0); --- 4 unchanged lines hidden (view full) --- 2477 */ 2478void 2479modtime(int argc, char *argv[]) 2480{ 2481 time_t mtime; 2482 2483 if (argc == 0 || argc > 2 || 2484 (argc == 1 && !another(&argc, &argv, "remote-file"))) { | 2497 code = -1; 2498 return; 2499 } 2500 size = remotesize(argv[1], 1); 2501 if (size != -1) 2502 fprintf(ttyout, 2503 "%s\t" LLF "\n", argv[1], (LLT)size); 2504 code = (size > 0); --- 4 unchanged lines hidden (view full) --- 2509 */ 2510void 2511modtime(int argc, char *argv[]) 2512{ 2513 time_t mtime; 2514 2515 if (argc == 0 || argc > 2 || 2516 (argc == 1 && !another(&argc, &argv, "remote-file"))) { |
2485 fprintf(ttyout, "usage: %s remote-file\n", argv[0]); | 2517 UPRINTF("usage: %s remote-file\n", argv[0]); |
2486 code = -1; 2487 return; 2488 } 2489 mtime = remotemodtime(argv[1], 1); 2490 if (mtime != -1) | 2518 code = -1; 2519 return; 2520 } 2521 mtime = remotemodtime(argv[1], 1); 2522 if (mtime != -1) |
2491 fprintf(ttyout, "%s\t%s", argv[1], asctime(localtime(&mtime))); | 2523 fprintf(ttyout, "%s\t%s", argv[1], 2524 rfc2822time(localtime(&mtime))); |
2492 code = (mtime > 0); 2493} 2494 2495/* 2496 * Show status on remote machine 2497 */ 2498void 2499rmtstatus(int argc, char *argv[]) 2500{ 2501 2502 if (argc == 0) { | 2525 code = (mtime > 0); 2526} 2527 2528/* 2529 * Show status on remote machine 2530 */ 2531void 2532rmtstatus(int argc, char *argv[]) 2533{ 2534 2535 if (argc == 0) { |
2503 fprintf(ttyout, "usage: %s [remote-file]\n", argv[0]); | 2536 UPRINTF("usage: %s [remote-file]\n", argv[0]); |
2504 code = -1; 2505 return; 2506 } 2507 COMMAND_1ARG(argc, argv, "STAT"); 2508} 2509 2510/* 2511 * Get file if modtime is more recent than current file --- 9 unchanged lines hidden (view full) --- 2521} 2522 2523/* 2524 * Display one local file through $PAGER. 2525 */ 2526void 2527lpage(int argc, char *argv[]) 2528{ | 2537 code = -1; 2538 return; 2539 } 2540 COMMAND_1ARG(argc, argv, "STAT"); 2541} 2542 2543/* 2544 * Get file if modtime is more recent than current file --- 9 unchanged lines hidden (view full) --- 2554} 2555 2556/* 2557 * Display one local file through $PAGER. 2558 */ 2559void 2560lpage(int argc, char *argv[]) 2561{ |
2529 int len; 2530 char *p, *pager, *locfile; | 2562 size_t len; 2563 const char *p; 2564 char *pager, *locfile; |
2531 2532 if (argc == 0 || argc > 2 || 2533 (argc == 1 && !another(&argc, &argv, "local-file"))) { | 2565 2566 if (argc == 0 || argc > 2 || 2567 (argc == 1 && !another(&argc, &argv, "local-file"))) { |
2534 fprintf(ttyout, "usage: %s local-file\n", argv[0]); | 2568 UPRINTF("usage: %s local-file\n", argv[0]); |
2535 code = -1; 2536 return; 2537 } 2538 if ((locfile = globulize(argv[1])) == NULL) { 2539 code = -1; 2540 return; 2541 } 2542 p = getoptionvalue("pager"); 2543 if (EMPTYSTRING(p)) 2544 p = DEFAULTPAGER; 2545 len = strlen(p) + strlen(locfile) + 2; | 2569 code = -1; 2570 return; 2571 } 2572 if ((locfile = globulize(argv[1])) == NULL) { 2573 code = -1; 2574 return; 2575 } 2576 p = getoptionvalue("pager"); 2577 if (EMPTYSTRING(p)) 2578 p = DEFAULTPAGER; 2579 len = strlen(p) + strlen(locfile) + 2; |
2546 pager = xmalloc(len); | 2580 pager = ftp_malloc(len); |
2547 (void)strlcpy(pager, p, len); 2548 (void)strlcat(pager, " ", len); 2549 (void)strlcat(pager, locfile, len); 2550 system(pager); 2551 code = 0; 2552 (void)free(pager); 2553 (void)free(locfile); 2554} 2555 2556/* 2557 * Display one remote file through $PAGER. 2558 */ 2559void 2560page(int argc, char *argv[]) 2561{ | 2581 (void)strlcpy(pager, p, len); 2582 (void)strlcat(pager, " ", len); 2583 (void)strlcat(pager, locfile, len); 2584 system(pager); 2585 code = 0; 2586 (void)free(pager); 2587 (void)free(locfile); 2588} 2589 2590/* 2591 * Display one remote file through $PAGER. 2592 */ 2593void 2594page(int argc, char *argv[]) 2595{ |
2562 int ohash, orestart_point, overbose, len; 2563 char *p, *pager; | 2596 int ohash, orestart_point, overbose; 2597 size_t len; 2598 const char *p; 2599 char *pager; |
2564 2565 if (argc == 0 || argc > 2 || 2566 (argc == 1 && !another(&argc, &argv, "remote-file"))) { | 2600 2601 if (argc == 0 || argc > 2 || 2602 (argc == 1 && !another(&argc, &argv, "remote-file"))) { |
2567 fprintf(ttyout, "usage: %s remote-file\n", argv[0]); | 2603 UPRINTF("usage: %s remote-file\n", argv[0]); |
2568 code = -1; 2569 return; 2570 } 2571 p = getoptionvalue("pager"); 2572 if (EMPTYSTRING(p)) 2573 p = DEFAULTPAGER; 2574 len = strlen(p) + 2; | 2604 code = -1; 2605 return; 2606 } 2607 p = getoptionvalue("pager"); 2608 if (EMPTYSTRING(p)) 2609 p = DEFAULTPAGER; 2610 len = strlen(p) + 2; |
2575 pager = xmalloc(len); | 2611 pager = ftp_malloc(len); |
2576 pager[0] = '|'; 2577 (void)strlcpy(pager + 1, p, len - 1); 2578 2579 ohash = hash; 2580 orestart_point = restart_point; 2581 overbose = verbose; 2582 hash = restart_point = verbose = 0; 2583 recvrequest("RETR", pager, argv[1], "r+", 1, 0); --- 8 unchanged lines hidden (view full) --- 2592 */ 2593void 2594setxferbuf(int argc, char *argv[]) 2595{ 2596 int size, dir; 2597 2598 if (argc != 2) { 2599 usage: | 2612 pager[0] = '|'; 2613 (void)strlcpy(pager + 1, p, len - 1); 2614 2615 ohash = hash; 2616 orestart_point = restart_point; 2617 overbose = verbose; 2618 hash = restart_point = verbose = 0; 2619 recvrequest("RETR", pager, argv[1], "r+", 1, 0); --- 8 unchanged lines hidden (view full) --- 2628 */ 2629void 2630setxferbuf(int argc, char *argv[]) 2631{ 2632 int size, dir; 2633 2634 if (argc != 2) { 2635 usage: |
2600 fprintf(ttyout, "usage: %s size\n", argv[0]); | 2636 UPRINTF("usage: %s size\n", argv[0]); |
2601 code = -1; 2602 return; 2603 } 2604 if (strcasecmp(argv[0], "sndbuf") == 0) 2605 dir = RATE_PUT; 2606 else if (strcasecmp(argv[0], "rcvbuf") == 0) 2607 dir = RATE_GET; 2608 else if (strcasecmp(argv[0], "xferbuf") == 0) --- 23 unchanged lines hidden (view full) --- 2632 */ 2633void 2634setoption(int argc, char *argv[]) 2635{ 2636 struct option *o; 2637 2638 code = -1; 2639 if (argc == 0 || (argc != 1 && argc != 3)) { | 2637 code = -1; 2638 return; 2639 } 2640 if (strcasecmp(argv[0], "sndbuf") == 0) 2641 dir = RATE_PUT; 2642 else if (strcasecmp(argv[0], "rcvbuf") == 0) 2643 dir = RATE_GET; 2644 else if (strcasecmp(argv[0], "xferbuf") == 0) --- 23 unchanged lines hidden (view full) --- 2668 */ 2669void 2670setoption(int argc, char *argv[]) 2671{ 2672 struct option *o; 2673 2674 code = -1; 2675 if (argc == 0 || (argc != 1 && argc != 3)) { |
2640 fprintf(ttyout, "usage: %s [option value]\n", argv[0]); | 2676 UPRINTF("usage: %s [option value]\n", argv[0]); |
2641 return; 2642 } 2643 2644#define OPTIONINDENT ((int) sizeof("http_proxy")) 2645 if (argc == 1) { 2646 for (o = optiontab; o->name != NULL; o++) { 2647 fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT, 2648 o->name, o->value ? o->value : ""); 2649 } 2650 } else { | 2677 return; 2678 } 2679 2680#define OPTIONINDENT ((int) sizeof("http_proxy")) 2681 if (argc == 1) { 2682 for (o = optiontab; o->name != NULL; o++) { 2683 fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT, 2684 o->name, o->value ? o->value : ""); 2685 } 2686 } else { |
2651 o = getoption(argv[1]); 2652 if (o == NULL) { 2653 fprintf(ttyout, "No such option `%s'.\n", argv[1]); 2654 return; 2655 } 2656 FREEPTR(o->value); 2657 o->value = xstrdup(argv[2]); 2658 if (verbose) 2659 fprintf(ttyout, "Setting `%s' to `%s'.\n", 2660 o->name, o->value); | 2687 set_option(argv[1], argv[2], 1); |
2661 } 2662 code = 0; 2663} 2664 | 2688 } 2689 code = 0; 2690} 2691 |
2692void 2693set_option(const char * option, const char * value, int doverbose) 2694{ 2695 struct option *o; 2696 2697 o = getoption(option); 2698 if (o == NULL) { 2699 fprintf(ttyout, "No such option `%s'.\n", option); 2700 return; 2701 } 2702 FREEPTR(o->value); 2703 o->value = ftp_strdup(value); 2704 if (verbose && doverbose) 2705 fprintf(ttyout, "Setting `%s' to `%s'.\n", 2706 o->name, o->value); 2707} 2708 |
|
2665/* 2666 * Unset an option 2667 */ 2668void 2669unsetoption(int argc, char *argv[]) 2670{ 2671 struct option *o; 2672 2673 code = -1; 2674 if (argc == 0 || argc != 2) { | 2709/* 2710 * Unset an option 2711 */ 2712void 2713unsetoption(int argc, char *argv[]) 2714{ 2715 struct option *o; 2716 2717 code = -1; 2718 if (argc == 0 || argc != 2) { |
2675 fprintf(ttyout, "usage: %s option\n", argv[0]); | 2719 UPRINTF("usage: %s option\n", argv[0]); |
2676 return; 2677 } 2678 2679 o = getoption(argv[1]); 2680 if (o == NULL) { 2681 fprintf(ttyout, "No such option `%s'.\n", argv[1]); 2682 return; 2683 } --- 6 unchanged lines hidden (view full) --- 2690 * Display features supported by the remote host. 2691 */ 2692void 2693feat(int argc, char *argv[]) 2694{ 2695 int oldverbose = verbose; 2696 2697 if (argc == 0) { | 2720 return; 2721 } 2722 2723 o = getoption(argv[1]); 2724 if (o == NULL) { 2725 fprintf(ttyout, "No such option `%s'.\n", argv[1]); 2726 return; 2727 } --- 6 unchanged lines hidden (view full) --- 2734 * Display features supported by the remote host. 2735 */ 2736void 2737feat(int argc, char *argv[]) 2738{ 2739 int oldverbose = verbose; 2740 2741 if (argc == 0) { |
2698 fprintf(ttyout, "usage: %s\n", argv[0]); | 2742 UPRINTF("usage: %s\n", argv[0]); |
2699 code = -1; 2700 return; 2701 } 2702 if (! features[FEAT_FEAT]) { 2703 fprintf(ttyout, 2704 "FEAT is not supported by the remote server.\n"); 2705 return; 2706 } 2707 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2708 (void)command("FEAT"); 2709 verbose = oldverbose; 2710} 2711 2712void 2713mlst(int argc, char *argv[]) 2714{ 2715 int oldverbose = verbose; 2716 2717 if (argc < 1 || argc > 2) { | 2743 code = -1; 2744 return; 2745 } 2746 if (! features[FEAT_FEAT]) { 2747 fprintf(ttyout, 2748 "FEAT is not supported by the remote server.\n"); 2749 return; 2750 } 2751 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2752 (void)command("FEAT"); 2753 verbose = oldverbose; 2754} 2755 2756void 2757mlst(int argc, char *argv[]) 2758{ 2759 int oldverbose = verbose; 2760 2761 if (argc < 1 || argc > 2) { |
2718 fprintf(ttyout, "usage: %s [remote-path]\n", argv[0]); | 2762 UPRINTF("usage: %s [remote-path]\n", argv[0]); |
2719 code = -1; 2720 return; 2721 } 2722 if (! features[FEAT_MLST]) { 2723 fprintf(ttyout, 2724 "MLST is not supported by the remote server.\n"); 2725 return; 2726 } 2727 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2728 COMMAND_1ARG(argc, argv, "MLST"); 2729 verbose = oldverbose; 2730} 2731 2732void 2733opts(int argc, char *argv[]) 2734{ 2735 int oldverbose = verbose; 2736 2737 if (argc < 2 || argc > 3) { | 2763 code = -1; 2764 return; 2765 } 2766 if (! features[FEAT_MLST]) { 2767 fprintf(ttyout, 2768 "MLST is not supported by the remote server.\n"); 2769 return; 2770 } 2771 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2772 COMMAND_1ARG(argc, argv, "MLST"); 2773 verbose = oldverbose; 2774} 2775 2776void 2777opts(int argc, char *argv[]) 2778{ 2779 int oldverbose = verbose; 2780 2781 if (argc < 2 || argc > 3) { |
2738 fprintf(ttyout, "usage: %s command [options]\n", argv[0]); | 2782 UPRINTF("usage: %s command [options]\n", argv[0]); |
2739 code = -1; 2740 return; 2741 } 2742 if (! features[FEAT_FEAT]) { 2743 fprintf(ttyout, 2744 "OPTS is not supported by the remote server.\n"); 2745 return; 2746 } 2747 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2748 if (argc == 2) 2749 command("OPTS %s", argv[1]); 2750 else 2751 command("OPTS %s %s", argv[1], argv[2]); 2752 verbose = oldverbose; 2753} | 2783 code = -1; 2784 return; 2785 } 2786 if (! features[FEAT_FEAT]) { 2787 fprintf(ttyout, 2788 "OPTS is not supported by the remote server.\n"); 2789 return; 2790 } 2791 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ 2792 if (argc == 2) 2793 command("OPTS %s", argv[1]); 2794 else 2795 command("OPTS %s %s", argv[1], argv[2]); 2796 verbose = oldverbose; 2797} |