1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate /* 31*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*0Sstevel@tonic-gate * The Regents of the University of California 33*0Sstevel@tonic-gate * All Rights Reserved 34*0Sstevel@tonic-gate * 35*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*0Sstevel@tonic-gate * contributors. 38*0Sstevel@tonic-gate */ 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate /* 44*0Sstevel@tonic-gate * FTP User Program -- Command Routines. 45*0Sstevel@tonic-gate */ 46*0Sstevel@tonic-gate #define FTP_NAMES 47*0Sstevel@tonic-gate #include "ftp_var.h" 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate FILE *tmp_nlst = NULL; /* tmp file; holds NLST results for mget, etc */ 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate static char *mname; 52*0Sstevel@tonic-gate static jmp_buf jabort; 53*0Sstevel@tonic-gate static jmp_buf abortprox; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate static char *remglob(char *argv[], int doswitch); 56*0Sstevel@tonic-gate static char *onoff(int bool); 57*0Sstevel@tonic-gate static int confirm(char *cmd, char *file); 58*0Sstevel@tonic-gate static int globulize(char **cpp); 59*0Sstevel@tonic-gate static void proxabort(int sig); 60*0Sstevel@tonic-gate static void mabort(int sig); 61*0Sstevel@tonic-gate static char *dotrans(char *name); 62*0Sstevel@tonic-gate static char *domap(char *name); 63*0Sstevel@tonic-gate static void getit(int argc, char *argv[], int restartit, char *mode); 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate static char *getlevel(int); 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate /* Prompt for command argument, add to buffer with space separator */ 68*0Sstevel@tonic-gate static int 69*0Sstevel@tonic-gate prompt_for_arg(char *buffer, int buffer_size, char *prompt) 70*0Sstevel@tonic-gate { 71*0Sstevel@tonic-gate if (strlen(buffer) > buffer_size - 2) { 72*0Sstevel@tonic-gate (void) printf("Line too long\n"); 73*0Sstevel@tonic-gate return (-1); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate strcat(buffer, " "); 76*0Sstevel@tonic-gate stop_timer(); 77*0Sstevel@tonic-gate (void) printf("(%s) ", prompt); 78*0Sstevel@tonic-gate if (fgets(buffer + strlen(buffer), buffer_size - strlen(buffer), stdin) 79*0Sstevel@tonic-gate == NULL) { 80*0Sstevel@tonic-gate reset_timer(); 81*0Sstevel@tonic-gate return (-1); 82*0Sstevel@tonic-gate } 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate /* Flush what didn't fit in the buffer */ 85*0Sstevel@tonic-gate if (buffer[strlen(buffer)-1] != '\n') { 86*0Sstevel@tonic-gate while (fgetc(stdin) != '\n' && !ferror(stdin) && !feof(stdin)) 87*0Sstevel@tonic-gate ; 88*0Sstevel@tonic-gate (void) printf("Line too long\n"); 89*0Sstevel@tonic-gate reset_timer(); 90*0Sstevel@tonic-gate return (-1); 91*0Sstevel@tonic-gate } else 92*0Sstevel@tonic-gate buffer[strlen(buffer)-1] = 0; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate reset_timer(); 95*0Sstevel@tonic-gate return (0); 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate /* 100*0Sstevel@tonic-gate * Connect to peer server and 101*0Sstevel@tonic-gate * auto-login, if possible. 102*0Sstevel@tonic-gate */ 103*0Sstevel@tonic-gate void 104*0Sstevel@tonic-gate setpeer(int argc, char *argv[]) 105*0Sstevel@tonic-gate { 106*0Sstevel@tonic-gate char *host; 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate if (connected) { 109*0Sstevel@tonic-gate (void) printf("Already connected to %s, use close first.\n", 110*0Sstevel@tonic-gate hostname); 111*0Sstevel@tonic-gate code = -1; 112*0Sstevel@tonic-gate return; 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate if (argc < 2) { 115*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "to") == -1) { 116*0Sstevel@tonic-gate code = -1; 117*0Sstevel@tonic-gate return; 118*0Sstevel@tonic-gate } 119*0Sstevel@tonic-gate makeargv(); 120*0Sstevel@tonic-gate argc = margc; 121*0Sstevel@tonic-gate argv = margv; 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate if (argc > 3 || argc < 2) { 124*0Sstevel@tonic-gate (void) printf("usage: %s host-name [port]\n", argv[0]); 125*0Sstevel@tonic-gate code = -1; 126*0Sstevel@tonic-gate return; 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate strcpy(typename, "ascii"); 129*0Sstevel@tonic-gate host = hookup(argv[1], (argc > 2 ? argv[2] : "ftp")); 130*0Sstevel@tonic-gate if (host) { 131*0Sstevel@tonic-gate int overbose; 132*0Sstevel@tonic-gate extern char reply_string[]; 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate connected = 1; 135*0Sstevel@tonic-gate /* 136*0Sstevel@tonic-gate * Set up defaults for FTP. 137*0Sstevel@tonic-gate */ 138*0Sstevel@tonic-gate clevel = dlevel = PROT_C; 139*0Sstevel@tonic-gate if (autoauth) { 140*0Sstevel@tonic-gate if (do_auth() && autoencrypt) { 141*0Sstevel@tonic-gate clevel = PROT_P; 142*0Sstevel@tonic-gate setpbsz(1<<20); 143*0Sstevel@tonic-gate if (command("PROT P") == COMPLETE) 144*0Sstevel@tonic-gate dlevel = PROT_P; 145*0Sstevel@tonic-gate else { 146*0Sstevel@tonic-gate (void) fprintf(stderr, 147*0Sstevel@tonic-gate "%s: couldn't enable encryption\n", 148*0Sstevel@tonic-gate argv[0]); 149*0Sstevel@tonic-gate /* unable to encrypt command channel, too! */ 150*0Sstevel@tonic-gate dlevel = clevel = PROT_C; 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate if ((auth_type != AUTHTYPE_NONE) && (clevel == PROT_C)) 154*0Sstevel@tonic-gate clevel = PROT_S; 155*0Sstevel@tonic-gate } 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate if (autologin) 158*0Sstevel@tonic-gate (void) login(argv[1]); 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate overbose = verbose; 161*0Sstevel@tonic-gate if (debug == 0) 162*0Sstevel@tonic-gate verbose = -1; 163*0Sstevel@tonic-gate if (command("SYST") == COMPLETE && overbose) { 164*0Sstevel@tonic-gate char *cp, c; 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate cp = index(reply_string+4, ' '); 167*0Sstevel@tonic-gate if (cp == NULL) 168*0Sstevel@tonic-gate cp = index(reply_string+4, '\r'); 169*0Sstevel@tonic-gate if (cp) { 170*0Sstevel@tonic-gate if (cp[-1] == '.') 171*0Sstevel@tonic-gate cp--; 172*0Sstevel@tonic-gate c = *cp; 173*0Sstevel@tonic-gate *cp = '\0'; 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate (void) printf("Remote system type is %s.\n", 177*0Sstevel@tonic-gate reply_string+4); 178*0Sstevel@tonic-gate if (cp) 179*0Sstevel@tonic-gate *cp = c; 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate if (strncmp(reply_string, "215 UNIX Type: L8", 17) == 0) { 182*0Sstevel@tonic-gate setbinary(0, NULL); 183*0Sstevel@tonic-gate if (overbose) 184*0Sstevel@tonic-gate (void) printf( 185*0Sstevel@tonic-gate "Using %s mode to transfer files.\n", 186*0Sstevel@tonic-gate typename); 187*0Sstevel@tonic-gate } else if (overbose && 188*0Sstevel@tonic-gate strncmp(reply_string, "215 TOPS20", 10) == 0) { 189*0Sstevel@tonic-gate (void) printf( 190*0Sstevel@tonic-gate "Remember to set tenex mode when transfering " 191*0Sstevel@tonic-gate "binary files from this machine.\n"); 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate verbose = overbose; 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate } 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate static struct types { 198*0Sstevel@tonic-gate char *t_name; 199*0Sstevel@tonic-gate char *t_mode; 200*0Sstevel@tonic-gate int t_type; 201*0Sstevel@tonic-gate char *t_arg; 202*0Sstevel@tonic-gate } types[] = { 203*0Sstevel@tonic-gate { "ascii", "A", TYPE_A, 0 }, 204*0Sstevel@tonic-gate { "binary", "I", TYPE_I, 0 }, 205*0Sstevel@tonic-gate { "image", "I", TYPE_I, 0 }, 206*0Sstevel@tonic-gate { "ebcdic", "E", TYPE_E, 0 }, 207*0Sstevel@tonic-gate { "tenex", "L", TYPE_L, bytename }, 208*0Sstevel@tonic-gate 0 209*0Sstevel@tonic-gate }; 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate /* 212*0Sstevel@tonic-gate * Set transfer type. 213*0Sstevel@tonic-gate */ 214*0Sstevel@tonic-gate void 215*0Sstevel@tonic-gate settype(int argc, char *argv[]) 216*0Sstevel@tonic-gate { 217*0Sstevel@tonic-gate struct types *p; 218*0Sstevel@tonic-gate int comret; 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate if (argc > 2) { 221*0Sstevel@tonic-gate char *sep; 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]); 224*0Sstevel@tonic-gate sep = " "; 225*0Sstevel@tonic-gate for (p = types; p->t_name; p++) { 226*0Sstevel@tonic-gate (void) printf("%s%s", sep, p->t_name); 227*0Sstevel@tonic-gate if (*sep == ' ') 228*0Sstevel@tonic-gate sep = " | "; 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate (void) printf(" ]\n"); 231*0Sstevel@tonic-gate code = -1; 232*0Sstevel@tonic-gate return; 233*0Sstevel@tonic-gate } 234*0Sstevel@tonic-gate if (argc < 2) { 235*0Sstevel@tonic-gate (void) printf("Using %s mode to transfer files.\n", typename); 236*0Sstevel@tonic-gate code = 0; 237*0Sstevel@tonic-gate return; 238*0Sstevel@tonic-gate } 239*0Sstevel@tonic-gate for (p = types; p->t_name; p++) 240*0Sstevel@tonic-gate if (strcmp(argv[1], p->t_name) == 0) 241*0Sstevel@tonic-gate break; 242*0Sstevel@tonic-gate if (p->t_name == 0) { 243*0Sstevel@tonic-gate (void) printf("%s: unknown mode\n", argv[1]); 244*0Sstevel@tonic-gate code = -1; 245*0Sstevel@tonic-gate return; 246*0Sstevel@tonic-gate } 247*0Sstevel@tonic-gate if ((p->t_arg != NULL) && (*(p->t_arg) != '\0')) 248*0Sstevel@tonic-gate comret = command("TYPE %s %s", p->t_mode, p->t_arg); 249*0Sstevel@tonic-gate else 250*0Sstevel@tonic-gate comret = command("TYPE %s", p->t_mode); 251*0Sstevel@tonic-gate if (comret == COMPLETE) { 252*0Sstevel@tonic-gate (void) strcpy(typename, p->t_name); 253*0Sstevel@tonic-gate type = p->t_type; 254*0Sstevel@tonic-gate } 255*0Sstevel@tonic-gate } 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate /* 258*0Sstevel@tonic-gate * Set binary transfer type. 259*0Sstevel@tonic-gate */ 260*0Sstevel@tonic-gate /*ARGSUSED*/ 261*0Sstevel@tonic-gate void 262*0Sstevel@tonic-gate setbinary(int argc, char *argv[]) 263*0Sstevel@tonic-gate { 264*0Sstevel@tonic-gate call(settype, "type", "binary", 0); 265*0Sstevel@tonic-gate } 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate /* 268*0Sstevel@tonic-gate * Set ascii transfer type. 269*0Sstevel@tonic-gate */ 270*0Sstevel@tonic-gate /*ARGSUSED*/ 271*0Sstevel@tonic-gate void 272*0Sstevel@tonic-gate setascii(int argc, char *argv[]) 273*0Sstevel@tonic-gate { 274*0Sstevel@tonic-gate call(settype, "type", "ascii", 0); 275*0Sstevel@tonic-gate } 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate /* 278*0Sstevel@tonic-gate * Set tenex transfer type. 279*0Sstevel@tonic-gate */ 280*0Sstevel@tonic-gate /*ARGSUSED*/ 281*0Sstevel@tonic-gate void 282*0Sstevel@tonic-gate settenex(int argc, char *argv[]) 283*0Sstevel@tonic-gate { 284*0Sstevel@tonic-gate call(settype, "type", "tenex", 0); 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate /* 288*0Sstevel@tonic-gate * Set ebcdic transfer type. 289*0Sstevel@tonic-gate */ 290*0Sstevel@tonic-gate /*ARGSUSED*/ 291*0Sstevel@tonic-gate void 292*0Sstevel@tonic-gate setebcdic(int argc, char *argv[]) 293*0Sstevel@tonic-gate { 294*0Sstevel@tonic-gate call(settype, "type", "ebcdic", 0); 295*0Sstevel@tonic-gate } 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate /* 298*0Sstevel@tonic-gate * Set file transfer mode. 299*0Sstevel@tonic-gate */ 300*0Sstevel@tonic-gate /*ARGSUSED*/ 301*0Sstevel@tonic-gate void 302*0Sstevel@tonic-gate setmode(int argc, char *argv[]) 303*0Sstevel@tonic-gate { 304*0Sstevel@tonic-gate (void) printf("We only support %s mode, sorry.\n", modename); 305*0Sstevel@tonic-gate code = -1; 306*0Sstevel@tonic-gate } 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gate /* 309*0Sstevel@tonic-gate * Set file transfer format. 310*0Sstevel@tonic-gate */ 311*0Sstevel@tonic-gate /*ARGSUSED*/ 312*0Sstevel@tonic-gate void 313*0Sstevel@tonic-gate setform(int argc, char *argv[]) 314*0Sstevel@tonic-gate { 315*0Sstevel@tonic-gate (void) printf("We only support %s format, sorry.\n", formname); 316*0Sstevel@tonic-gate code = -1; 317*0Sstevel@tonic-gate } 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gate /* 320*0Sstevel@tonic-gate * Set file transfer structure. 321*0Sstevel@tonic-gate */ 322*0Sstevel@tonic-gate /*ARGSUSED*/ 323*0Sstevel@tonic-gate void 324*0Sstevel@tonic-gate setstruct(int argc, char *argv[]) 325*0Sstevel@tonic-gate { 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate (void) printf("We only support %s structure, sorry.\n", structname); 328*0Sstevel@tonic-gate code = -1; 329*0Sstevel@tonic-gate } 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate /* 332*0Sstevel@tonic-gate * Send a single file. 333*0Sstevel@tonic-gate */ 334*0Sstevel@tonic-gate void 335*0Sstevel@tonic-gate put(int argc, char *argv[]) 336*0Sstevel@tonic-gate { 337*0Sstevel@tonic-gate char *cmd; 338*0Sstevel@tonic-gate int loc = 0; 339*0Sstevel@tonic-gate char *oldargv1; 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate if (argc == 2) { 342*0Sstevel@tonic-gate argc++; 343*0Sstevel@tonic-gate argv[2] = argv[1]; 344*0Sstevel@tonic-gate loc++; 345*0Sstevel@tonic-gate } 346*0Sstevel@tonic-gate if (argc < 2) { 347*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") == -1) { 348*0Sstevel@tonic-gate code = -1; 349*0Sstevel@tonic-gate return; 350*0Sstevel@tonic-gate } 351*0Sstevel@tonic-gate makeargv(); 352*0Sstevel@tonic-gate argc = margc; 353*0Sstevel@tonic-gate argv = margv; 354*0Sstevel@tonic-gate } 355*0Sstevel@tonic-gate if (argc < 2) { 356*0Sstevel@tonic-gate usage: 357*0Sstevel@tonic-gate (void) printf("usage: %s local-file remote-file\n", argv[0]); 358*0Sstevel@tonic-gate code = -1; 359*0Sstevel@tonic-gate return; 360*0Sstevel@tonic-gate } 361*0Sstevel@tonic-gate if (argc < 3) { 362*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") == -1) { 363*0Sstevel@tonic-gate code = -1; 364*0Sstevel@tonic-gate return; 365*0Sstevel@tonic-gate } 366*0Sstevel@tonic-gate makeargv(); 367*0Sstevel@tonic-gate argc = margc; 368*0Sstevel@tonic-gate argv = margv; 369*0Sstevel@tonic-gate } 370*0Sstevel@tonic-gate if (argc < 3) 371*0Sstevel@tonic-gate goto usage; 372*0Sstevel@tonic-gate oldargv1 = argv[1]; 373*0Sstevel@tonic-gate if (!globulize(&argv[1])) { 374*0Sstevel@tonic-gate code = -1; 375*0Sstevel@tonic-gate return; 376*0Sstevel@tonic-gate } 377*0Sstevel@tonic-gate /* 378*0Sstevel@tonic-gate * If "globulize" modifies argv[1], and argv[2] is a copy of 379*0Sstevel@tonic-gate * the old argv[1], make it a copy of the new argv[1]. 380*0Sstevel@tonic-gate */ 381*0Sstevel@tonic-gate if (argv[1] != oldargv1 && argv[2] == oldargv1) { 382*0Sstevel@tonic-gate argv[2] = argv[1]; 383*0Sstevel@tonic-gate } 384*0Sstevel@tonic-gate cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR"); 385*0Sstevel@tonic-gate if (loc && ntflag) { 386*0Sstevel@tonic-gate argv[2] = dotrans(argv[2]); 387*0Sstevel@tonic-gate } 388*0Sstevel@tonic-gate if (loc && mapflag) { 389*0Sstevel@tonic-gate argv[2] = domap(argv[2]); 390*0Sstevel@tonic-gate } 391*0Sstevel@tonic-gate sendrequest(cmd, argv[1], argv[2], 1); 392*0Sstevel@tonic-gate } 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate /*ARGSUSED*/ 395*0Sstevel@tonic-gate static void 396*0Sstevel@tonic-gate mabort(int sig) 397*0Sstevel@tonic-gate { 398*0Sstevel@tonic-gate int ointer; 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gate (void) printf("\n"); 401*0Sstevel@tonic-gate (void) fflush(stdout); 402*0Sstevel@tonic-gate if (mflag && fromatty) { 403*0Sstevel@tonic-gate ointer = interactive; 404*0Sstevel@tonic-gate interactive = 1; 405*0Sstevel@tonic-gate if (confirm("Continue with", mname)) { 406*0Sstevel@tonic-gate interactive = ointer; 407*0Sstevel@tonic-gate longjmp(jabort, 0); 408*0Sstevel@tonic-gate } 409*0Sstevel@tonic-gate interactive = ointer; 410*0Sstevel@tonic-gate } 411*0Sstevel@tonic-gate mflag = 0; 412*0Sstevel@tonic-gate longjmp(jabort, 0); 413*0Sstevel@tonic-gate } 414*0Sstevel@tonic-gate 415*0Sstevel@tonic-gate /* 416*0Sstevel@tonic-gate * Send multiple files. 417*0Sstevel@tonic-gate */ 418*0Sstevel@tonic-gate void 419*0Sstevel@tonic-gate mput(int argc, char *argv[]) 420*0Sstevel@tonic-gate { 421*0Sstevel@tonic-gate int i; 422*0Sstevel@tonic-gate int ointer; 423*0Sstevel@tonic-gate void (*oldintr)(); 424*0Sstevel@tonic-gate char *tp; 425*0Sstevel@tonic-gate int len; 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate if (argc < 2) { 428*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-files") == -1) { 429*0Sstevel@tonic-gate code = -1; 430*0Sstevel@tonic-gate return; 431*0Sstevel@tonic-gate } 432*0Sstevel@tonic-gate makeargv(); 433*0Sstevel@tonic-gate argc = margc; 434*0Sstevel@tonic-gate argv = margv; 435*0Sstevel@tonic-gate } 436*0Sstevel@tonic-gate if (argc < 2) { 437*0Sstevel@tonic-gate (void) printf("usage: %s local-files\n", argv[0]); 438*0Sstevel@tonic-gate code = -1; 439*0Sstevel@tonic-gate return; 440*0Sstevel@tonic-gate } 441*0Sstevel@tonic-gate mname = argv[0]; 442*0Sstevel@tonic-gate mflag = 1; 443*0Sstevel@tonic-gate oldintr = signal(SIGINT, mabort); 444*0Sstevel@tonic-gate (void) setjmp(jabort); 445*0Sstevel@tonic-gate if (proxy) { 446*0Sstevel@tonic-gate char *cp, *tp2, tmpbuf[MAXPATHLEN]; 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate while ((cp = remglob(argv, 0)) != NULL) { 449*0Sstevel@tonic-gate if (*cp == 0) { 450*0Sstevel@tonic-gate mflag = 0; 451*0Sstevel@tonic-gate continue; 452*0Sstevel@tonic-gate } 453*0Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) { 454*0Sstevel@tonic-gate tp = cp; 455*0Sstevel@tonic-gate if (mcase) { 456*0Sstevel@tonic-gate while (*tp) { 457*0Sstevel@tonic-gate if ((len = 458*0Sstevel@tonic-gate mblen(tp, MB_CUR_MAX)) <= 0) 459*0Sstevel@tonic-gate len = 1; 460*0Sstevel@tonic-gate if (islower(*tp)) 461*0Sstevel@tonic-gate break; 462*0Sstevel@tonic-gate tp += len; 463*0Sstevel@tonic-gate } 464*0Sstevel@tonic-gate if (!*tp) { 465*0Sstevel@tonic-gate tp = cp; 466*0Sstevel@tonic-gate tp2 = tmpbuf; 467*0Sstevel@tonic-gate while (*tp) { 468*0Sstevel@tonic-gate if ((len = mblen(tp, 469*0Sstevel@tonic-gate MB_CUR_MAX)) <= 0) 470*0Sstevel@tonic-gate len = 1; 471*0Sstevel@tonic-gate memcpy(tp2, tp, len); 472*0Sstevel@tonic-gate if (isupper(*tp2)) { 473*0Sstevel@tonic-gate *tp2 = 'a' + 474*0Sstevel@tonic-gate *tp2 - 'A'; 475*0Sstevel@tonic-gate } 476*0Sstevel@tonic-gate tp += len; 477*0Sstevel@tonic-gate tp2 += len; 478*0Sstevel@tonic-gate } 479*0Sstevel@tonic-gate *tp2 = 0; 480*0Sstevel@tonic-gate tp = tmpbuf; 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate } 483*0Sstevel@tonic-gate if (ntflag) { 484*0Sstevel@tonic-gate tp = dotrans(tp); 485*0Sstevel@tonic-gate } 486*0Sstevel@tonic-gate if (mapflag) { 487*0Sstevel@tonic-gate tp = domap(tp); 488*0Sstevel@tonic-gate } 489*0Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR", 490*0Sstevel@tonic-gate cp, tp, 0); 491*0Sstevel@tonic-gate if (!mflag && fromatty) { 492*0Sstevel@tonic-gate ointer = interactive; 493*0Sstevel@tonic-gate interactive = 1; 494*0Sstevel@tonic-gate if (confirm("Continue with", "mput")) { 495*0Sstevel@tonic-gate mflag++; 496*0Sstevel@tonic-gate } 497*0Sstevel@tonic-gate interactive = ointer; 498*0Sstevel@tonic-gate } 499*0Sstevel@tonic-gate } 500*0Sstevel@tonic-gate } 501*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 502*0Sstevel@tonic-gate mflag = 0; 503*0Sstevel@tonic-gate return; 504*0Sstevel@tonic-gate } 505*0Sstevel@tonic-gate for (i = 1; i < argc; i++) { 506*0Sstevel@tonic-gate char **cpp, **gargs; 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gate if (!doglob) { 509*0Sstevel@tonic-gate if (mflag && confirm(argv[0], argv[i])) { 510*0Sstevel@tonic-gate tp = (ntflag) ? dotrans(argv[i]) : argv[i]; 511*0Sstevel@tonic-gate tp = (mapflag) ? domap(tp) : tp; 512*0Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR", 513*0Sstevel@tonic-gate argv[i], tp, 1); 514*0Sstevel@tonic-gate if (!mflag && fromatty) { 515*0Sstevel@tonic-gate ointer = interactive; 516*0Sstevel@tonic-gate interactive = 1; 517*0Sstevel@tonic-gate if (confirm("Continue with", "mput")) { 518*0Sstevel@tonic-gate mflag++; 519*0Sstevel@tonic-gate } 520*0Sstevel@tonic-gate interactive = ointer; 521*0Sstevel@tonic-gate } 522*0Sstevel@tonic-gate } 523*0Sstevel@tonic-gate continue; 524*0Sstevel@tonic-gate } 525*0Sstevel@tonic-gate gargs = glob(argv[i]); 526*0Sstevel@tonic-gate if (globerr != NULL) { 527*0Sstevel@tonic-gate (void) printf("%s\n", globerr); 528*0Sstevel@tonic-gate if (gargs) 529*0Sstevel@tonic-gate blkfree(gargs); 530*0Sstevel@tonic-gate continue; 531*0Sstevel@tonic-gate } 532*0Sstevel@tonic-gate for (cpp = gargs; cpp && *cpp != NULL; cpp++) { 533*0Sstevel@tonic-gate if (mflag && confirm(argv[0], *cpp)) { 534*0Sstevel@tonic-gate tp = (ntflag) ? dotrans(*cpp) : *cpp; 535*0Sstevel@tonic-gate tp = (mapflag) ? domap(tp) : tp; 536*0Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR", 537*0Sstevel@tonic-gate *cpp, tp, 0); 538*0Sstevel@tonic-gate if (!mflag && fromatty) { 539*0Sstevel@tonic-gate ointer = interactive; 540*0Sstevel@tonic-gate interactive = 1; 541*0Sstevel@tonic-gate if (confirm("Continue with", "mput")) { 542*0Sstevel@tonic-gate mflag++; 543*0Sstevel@tonic-gate } 544*0Sstevel@tonic-gate interactive = ointer; 545*0Sstevel@tonic-gate } 546*0Sstevel@tonic-gate } 547*0Sstevel@tonic-gate } 548*0Sstevel@tonic-gate if (gargs != NULL) 549*0Sstevel@tonic-gate blkfree(gargs); 550*0Sstevel@tonic-gate } 551*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 552*0Sstevel@tonic-gate mflag = 0; 553*0Sstevel@tonic-gate } 554*0Sstevel@tonic-gate 555*0Sstevel@tonic-gate /* 556*0Sstevel@tonic-gate * Restart transfer at a specific offset. 557*0Sstevel@tonic-gate */ 558*0Sstevel@tonic-gate void 559*0Sstevel@tonic-gate restart(int argc, char *argv[]) 560*0Sstevel@tonic-gate { 561*0Sstevel@tonic-gate off_t orestart_point = restart_point; 562*0Sstevel@tonic-gate 563*0Sstevel@tonic-gate if (argc > 2) { 564*0Sstevel@tonic-gate (void) printf("usage: %s [marker]\n", argv[0]); 565*0Sstevel@tonic-gate code = -1; 566*0Sstevel@tonic-gate return; 567*0Sstevel@tonic-gate } 568*0Sstevel@tonic-gate if (argc == 2) { 569*0Sstevel@tonic-gate longlong_t rp; 570*0Sstevel@tonic-gate char *endp; 571*0Sstevel@tonic-gate 572*0Sstevel@tonic-gate errno = 0; 573*0Sstevel@tonic-gate rp = strtoll(argv[1], &endp, 10); 574*0Sstevel@tonic-gate if (errno || rp < 0 || *endp != '\0') 575*0Sstevel@tonic-gate (void) printf("%s: Invalid offset `%s'\n", 576*0Sstevel@tonic-gate argv[0], argv[1]); 577*0Sstevel@tonic-gate else 578*0Sstevel@tonic-gate restart_point = rp; 579*0Sstevel@tonic-gate } 580*0Sstevel@tonic-gate if (restart_point == 0) { 581*0Sstevel@tonic-gate if (orestart_point == 0) 582*0Sstevel@tonic-gate (void) printf("No restart marker defined\n"); 583*0Sstevel@tonic-gate else 584*0Sstevel@tonic-gate (void) printf("Restart marker cleared\n"); 585*0Sstevel@tonic-gate } else 586*0Sstevel@tonic-gate (void) printf( 587*0Sstevel@tonic-gate "Restarting at %lld for next get, put or append\n", 588*0Sstevel@tonic-gate (longlong_t)restart_point); 589*0Sstevel@tonic-gate } 590*0Sstevel@tonic-gate 591*0Sstevel@tonic-gate void 592*0Sstevel@tonic-gate reget(int argc, char *argv[]) 593*0Sstevel@tonic-gate { 594*0Sstevel@tonic-gate getit(argc, argv, 1, "r+w"); 595*0Sstevel@tonic-gate } 596*0Sstevel@tonic-gate 597*0Sstevel@tonic-gate void 598*0Sstevel@tonic-gate get(int argc, char *argv[]) 599*0Sstevel@tonic-gate { 600*0Sstevel@tonic-gate getit(argc, argv, 0, restart_point ? "r+w" : "w"); 601*0Sstevel@tonic-gate } 602*0Sstevel@tonic-gate 603*0Sstevel@tonic-gate /* 604*0Sstevel@tonic-gate * Receive one file. 605*0Sstevel@tonic-gate */ 606*0Sstevel@tonic-gate static void 607*0Sstevel@tonic-gate getit(int argc, char *argv[], int restartit, char *mode) 608*0Sstevel@tonic-gate { 609*0Sstevel@tonic-gate int loc = 0; 610*0Sstevel@tonic-gate int len; 611*0Sstevel@tonic-gate int allowpipe = 1; 612*0Sstevel@tonic-gate 613*0Sstevel@tonic-gate if (argc == 2) { 614*0Sstevel@tonic-gate argc++; 615*0Sstevel@tonic-gate argv[2] = argv[1]; 616*0Sstevel@tonic-gate /* Only permit !file if two arguments. */ 617*0Sstevel@tonic-gate allowpipe = 0; 618*0Sstevel@tonic-gate loc++; 619*0Sstevel@tonic-gate } 620*0Sstevel@tonic-gate if (argc < 2) { 621*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") == -1) { 622*0Sstevel@tonic-gate code = -1; 623*0Sstevel@tonic-gate return; 624*0Sstevel@tonic-gate } 625*0Sstevel@tonic-gate makeargv(); 626*0Sstevel@tonic-gate argc = margc; 627*0Sstevel@tonic-gate argv = margv; 628*0Sstevel@tonic-gate } 629*0Sstevel@tonic-gate if (argc < 2) { 630*0Sstevel@tonic-gate usage: 631*0Sstevel@tonic-gate (void) printf("usage: %s remote-file [ local-file ]\n", 632*0Sstevel@tonic-gate argv[0]); 633*0Sstevel@tonic-gate code = -1; 634*0Sstevel@tonic-gate return; 635*0Sstevel@tonic-gate } 636*0Sstevel@tonic-gate if (argc < 3) { 637*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") == -1) { 638*0Sstevel@tonic-gate code = -1; 639*0Sstevel@tonic-gate return; 640*0Sstevel@tonic-gate } 641*0Sstevel@tonic-gate makeargv(); 642*0Sstevel@tonic-gate argc = margc; 643*0Sstevel@tonic-gate argv = margv; 644*0Sstevel@tonic-gate } 645*0Sstevel@tonic-gate if (argc < 3) 646*0Sstevel@tonic-gate goto usage; 647*0Sstevel@tonic-gate if (!globulize(&argv[2])) { 648*0Sstevel@tonic-gate code = -1; 649*0Sstevel@tonic-gate return; 650*0Sstevel@tonic-gate } 651*0Sstevel@tonic-gate if (loc && mcase) { 652*0Sstevel@tonic-gate char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN]; 653*0Sstevel@tonic-gate 654*0Sstevel@tonic-gate while (*tp) { 655*0Sstevel@tonic-gate if ((len = mblen(tp, MB_CUR_MAX)) <= 0) 656*0Sstevel@tonic-gate len = 1; 657*0Sstevel@tonic-gate if (islower(*tp)) 658*0Sstevel@tonic-gate break; 659*0Sstevel@tonic-gate tp += len; 660*0Sstevel@tonic-gate } 661*0Sstevel@tonic-gate if (!*tp) { 662*0Sstevel@tonic-gate tp = argv[2]; 663*0Sstevel@tonic-gate tp2 = tmpbuf; 664*0Sstevel@tonic-gate while (*tp) { 665*0Sstevel@tonic-gate if ((len = mblen(tp, MB_CUR_MAX)) <= 0) 666*0Sstevel@tonic-gate len = 1; 667*0Sstevel@tonic-gate memcpy(tp2, tp, len); 668*0Sstevel@tonic-gate if (isupper(*tp2)) 669*0Sstevel@tonic-gate *tp2 = 'a' + *tp2 - 'A'; 670*0Sstevel@tonic-gate tp += len; 671*0Sstevel@tonic-gate tp2 += len; 672*0Sstevel@tonic-gate } 673*0Sstevel@tonic-gate *tp2 = 0; 674*0Sstevel@tonic-gate argv[2] = tmpbuf; 675*0Sstevel@tonic-gate } 676*0Sstevel@tonic-gate } 677*0Sstevel@tonic-gate if (loc && ntflag) { 678*0Sstevel@tonic-gate argv[2] = dotrans(argv[2]); 679*0Sstevel@tonic-gate } 680*0Sstevel@tonic-gate if (loc && mapflag) { 681*0Sstevel@tonic-gate argv[2] = domap(argv[2]); 682*0Sstevel@tonic-gate } 683*0Sstevel@tonic-gate if (restartit) { 684*0Sstevel@tonic-gate struct stat stbuf; 685*0Sstevel@tonic-gate 686*0Sstevel@tonic-gate if (stat(argv[2], &stbuf) < 0) { 687*0Sstevel@tonic-gate perror(argv[2]); 688*0Sstevel@tonic-gate code = -1; 689*0Sstevel@tonic-gate return; 690*0Sstevel@tonic-gate } 691*0Sstevel@tonic-gate restart_point = stbuf.st_size; 692*0Sstevel@tonic-gate } 693*0Sstevel@tonic-gate recvrequest("RETR", argv[2], argv[1], mode, allowpipe); 694*0Sstevel@tonic-gate restart_point = 0; 695*0Sstevel@tonic-gate } 696*0Sstevel@tonic-gate 697*0Sstevel@tonic-gate /* 698*0Sstevel@tonic-gate * Get multiple files. 699*0Sstevel@tonic-gate */ 700*0Sstevel@tonic-gate void 701*0Sstevel@tonic-gate mget(int argc, char *argv[]) 702*0Sstevel@tonic-gate { 703*0Sstevel@tonic-gate char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN]; 704*0Sstevel@tonic-gate int ointer; 705*0Sstevel@tonic-gate void (*oldintr)(); 706*0Sstevel@tonic-gate int need_convert; 707*0Sstevel@tonic-gate int len; 708*0Sstevel@tonic-gate 709*0Sstevel@tonic-gate if (argc < 2) { 710*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) { 711*0Sstevel@tonic-gate code = -1; 712*0Sstevel@tonic-gate return; 713*0Sstevel@tonic-gate } 714*0Sstevel@tonic-gate makeargv(); 715*0Sstevel@tonic-gate argc = margc; 716*0Sstevel@tonic-gate argv = margv; 717*0Sstevel@tonic-gate } 718*0Sstevel@tonic-gate if (argc < 2) { 719*0Sstevel@tonic-gate (void) printf("usage: %s remote-files\n", argv[0]); 720*0Sstevel@tonic-gate code = -1; 721*0Sstevel@tonic-gate return; 722*0Sstevel@tonic-gate } 723*0Sstevel@tonic-gate mname = argv[0]; 724*0Sstevel@tonic-gate mflag = 1; 725*0Sstevel@tonic-gate oldintr = signal(SIGINT, mabort); 726*0Sstevel@tonic-gate (void) setjmp(jabort); 727*0Sstevel@tonic-gate while ((cp = remglob(argv, proxy)) != NULL) { 728*0Sstevel@tonic-gate if (*cp == '\0') { 729*0Sstevel@tonic-gate mflag = 0; 730*0Sstevel@tonic-gate continue; 731*0Sstevel@tonic-gate } 732*0Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) { 733*0Sstevel@tonic-gate strcpy(tmpbuf, cp); 734*0Sstevel@tonic-gate tp = tmpbuf; 735*0Sstevel@tonic-gate need_convert = 1; 736*0Sstevel@tonic-gate if (mcase) { 737*0Sstevel@tonic-gate tp2 = tp; 738*0Sstevel@tonic-gate while (*tp2 && need_convert) { 739*0Sstevel@tonic-gate /* Need any case convert? */ 740*0Sstevel@tonic-gate if (islower(*tp2)) 741*0Sstevel@tonic-gate need_convert = 0; 742*0Sstevel@tonic-gate if ((len = mblen(tp2, MB_CUR_MAX)) <= 0) 743*0Sstevel@tonic-gate len = 1; 744*0Sstevel@tonic-gate tp2 += len; 745*0Sstevel@tonic-gate } 746*0Sstevel@tonic-gate tp2 = tp; 747*0Sstevel@tonic-gate while (need_convert && *tp2) { 748*0Sstevel@tonic-gate /* Convert to lower case */ 749*0Sstevel@tonic-gate if (isupper(*tp2)) 750*0Sstevel@tonic-gate *tp2 = tolower(*tp2); 751*0Sstevel@tonic-gate if ((len = mblen(tp2, MB_CUR_MAX)) <= 0) 752*0Sstevel@tonic-gate len = 1; 753*0Sstevel@tonic-gate tp2 += len; 754*0Sstevel@tonic-gate } 755*0Sstevel@tonic-gate } 756*0Sstevel@tonic-gate 757*0Sstevel@tonic-gate if (ntflag) { 758*0Sstevel@tonic-gate tp = dotrans(tp); 759*0Sstevel@tonic-gate } 760*0Sstevel@tonic-gate if (mapflag) { 761*0Sstevel@tonic-gate tp = domap(tp); 762*0Sstevel@tonic-gate } 763*0Sstevel@tonic-gate recvrequest("RETR", tp, cp, "w", 0); 764*0Sstevel@tonic-gate restart_point = 0; 765*0Sstevel@tonic-gate if (!mflag && fromatty) { 766*0Sstevel@tonic-gate ointer = interactive; 767*0Sstevel@tonic-gate interactive = 1; 768*0Sstevel@tonic-gate if (confirm("Continue with", "mget")) { 769*0Sstevel@tonic-gate mflag++; 770*0Sstevel@tonic-gate } 771*0Sstevel@tonic-gate interactive = ointer; 772*0Sstevel@tonic-gate } 773*0Sstevel@tonic-gate } 774*0Sstevel@tonic-gate } 775*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 776*0Sstevel@tonic-gate mflag = 0; 777*0Sstevel@tonic-gate } 778*0Sstevel@tonic-gate 779*0Sstevel@tonic-gate static char * 780*0Sstevel@tonic-gate remglob(char *argv[], int doswitch) 781*0Sstevel@tonic-gate { 782*0Sstevel@tonic-gate static char buf[MAXPATHLEN]; 783*0Sstevel@tonic-gate static char **args; 784*0Sstevel@tonic-gate int oldverbose, oldhash; 785*0Sstevel@tonic-gate char *cp; 786*0Sstevel@tonic-gate 787*0Sstevel@tonic-gate if (!mflag) { 788*0Sstevel@tonic-gate if (!doglob) { 789*0Sstevel@tonic-gate args = NULL; 790*0Sstevel@tonic-gate } else { 791*0Sstevel@tonic-gate if (tmp_nlst != NULL) { 792*0Sstevel@tonic-gate (void) fclose(tmp_nlst); 793*0Sstevel@tonic-gate tmp_nlst = NULL; 794*0Sstevel@tonic-gate } 795*0Sstevel@tonic-gate } 796*0Sstevel@tonic-gate return (NULL); 797*0Sstevel@tonic-gate } 798*0Sstevel@tonic-gate if (!doglob) { 799*0Sstevel@tonic-gate if (args == NULL) 800*0Sstevel@tonic-gate args = argv; 801*0Sstevel@tonic-gate if ((cp = *++args) == NULL) 802*0Sstevel@tonic-gate args = NULL; 803*0Sstevel@tonic-gate return (cp); 804*0Sstevel@tonic-gate } 805*0Sstevel@tonic-gate if (tmp_nlst == NULL) { 806*0Sstevel@tonic-gate if ((tmp_nlst = tmpfile()) == NULL) { 807*0Sstevel@tonic-gate (void) printf("%s\n", strerror(errno)); 808*0Sstevel@tonic-gate return (NULL); 809*0Sstevel@tonic-gate } 810*0Sstevel@tonic-gate oldverbose = verbose, verbose = 0; 811*0Sstevel@tonic-gate oldhash = hash, hash = 0; 812*0Sstevel@tonic-gate if (doswitch) { 813*0Sstevel@tonic-gate pswitch(!proxy); 814*0Sstevel@tonic-gate } 815*0Sstevel@tonic-gate for (; *++argv != NULL; ) 816*0Sstevel@tonic-gate recvrequest("NLST", NULL, *argv, "", 0); 817*0Sstevel@tonic-gate rewind(tmp_nlst); 818*0Sstevel@tonic-gate if (doswitch) { 819*0Sstevel@tonic-gate pswitch(!proxy); 820*0Sstevel@tonic-gate } 821*0Sstevel@tonic-gate verbose = oldverbose; hash = oldhash; 822*0Sstevel@tonic-gate } 823*0Sstevel@tonic-gate reset_timer(); 824*0Sstevel@tonic-gate if (fgets(buf, sizeof (buf), tmp_nlst) == NULL) { 825*0Sstevel@tonic-gate (void) fclose(tmp_nlst), tmp_nlst = NULL; 826*0Sstevel@tonic-gate return (NULL); 827*0Sstevel@tonic-gate } 828*0Sstevel@tonic-gate if ((cp = index(buf, '\n')) != NULL) 829*0Sstevel@tonic-gate *cp = '\0'; 830*0Sstevel@tonic-gate return (buf); 831*0Sstevel@tonic-gate } 832*0Sstevel@tonic-gate 833*0Sstevel@tonic-gate static char * 834*0Sstevel@tonic-gate onoff(int bool) 835*0Sstevel@tonic-gate { 836*0Sstevel@tonic-gate return (bool ? "on" : "off"); 837*0Sstevel@tonic-gate } 838*0Sstevel@tonic-gate 839*0Sstevel@tonic-gate /* 840*0Sstevel@tonic-gate * Show status. 841*0Sstevel@tonic-gate */ 842*0Sstevel@tonic-gate /*ARGSUSED*/ 843*0Sstevel@tonic-gate void 844*0Sstevel@tonic-gate status(int argc, char *argv[]) 845*0Sstevel@tonic-gate { 846*0Sstevel@tonic-gate int i; 847*0Sstevel@tonic-gate char *levelp; 848*0Sstevel@tonic-gate 849*0Sstevel@tonic-gate if (connected) 850*0Sstevel@tonic-gate (void) printf("Connected to %s.\n", hostname); 851*0Sstevel@tonic-gate else 852*0Sstevel@tonic-gate (void) printf("Not connected.\n"); 853*0Sstevel@tonic-gate if (!proxy) { 854*0Sstevel@tonic-gate pswitch(1); 855*0Sstevel@tonic-gate if (connected) { 856*0Sstevel@tonic-gate (void) printf("Connected for proxy commands to %s.\n", 857*0Sstevel@tonic-gate hostname); 858*0Sstevel@tonic-gate } else { 859*0Sstevel@tonic-gate (void) printf("No proxy connection.\n"); 860*0Sstevel@tonic-gate } 861*0Sstevel@tonic-gate pswitch(0); 862*0Sstevel@tonic-gate } 863*0Sstevel@tonic-gate 864*0Sstevel@tonic-gate if (auth_type != AUTHTYPE_NONE) 865*0Sstevel@tonic-gate (void) printf("Authentication type: %s\n", 866*0Sstevel@tonic-gate GSS_AUTHTYPE_NAME(auth_type)); 867*0Sstevel@tonic-gate else 868*0Sstevel@tonic-gate (void) printf("Not authenticated.\n"); 869*0Sstevel@tonic-gate (void) printf("Mechanism: %s\n", mechstr); 870*0Sstevel@tonic-gate (void) printf("Autoauth: %s; Autologin: %s\n", 871*0Sstevel@tonic-gate onoff(autoauth), onoff(autologin)); 872*0Sstevel@tonic-gate levelp = getlevel(clevel); 873*0Sstevel@tonic-gate (void) printf("Control Channel Protection Level: %s\n", 874*0Sstevel@tonic-gate levelp ? levelp : "<unknown>"); 875*0Sstevel@tonic-gate levelp = getlevel(dlevel); 876*0Sstevel@tonic-gate (void) printf("Data Channel Protection Level: %s\n", 877*0Sstevel@tonic-gate levelp ? levelp : "<unknown>"); 878*0Sstevel@tonic-gate 879*0Sstevel@tonic-gate (void) printf("Passive mode: %s.\n", onoff(passivemode)); 880*0Sstevel@tonic-gate (void) printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n", 881*0Sstevel@tonic-gate modename, typename, formname, structname); 882*0Sstevel@tonic-gate (void) printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n", 883*0Sstevel@tonic-gate onoff(verbose), onoff(bell), onoff(interactive), 884*0Sstevel@tonic-gate onoff(doglob)); 885*0Sstevel@tonic-gate (void) printf("Store unique: %s; Receive unique: %s\n", onoff(sunique), 886*0Sstevel@tonic-gate onoff(runique)); 887*0Sstevel@tonic-gate (void) printf("Case: %s; CR stripping: %s\n", 888*0Sstevel@tonic-gate onoff(mcase), onoff(crflag)); 889*0Sstevel@tonic-gate if (ntflag) { 890*0Sstevel@tonic-gate (void) printf("Ntrans: (in) %s (out) %s\n", ntin, ntout); 891*0Sstevel@tonic-gate } else { 892*0Sstevel@tonic-gate (void) printf("Ntrans: off\n"); 893*0Sstevel@tonic-gate } 894*0Sstevel@tonic-gate if (mapflag) { 895*0Sstevel@tonic-gate (void) printf("Nmap: (in) %s (out) %s\n", mapin, mapout); 896*0Sstevel@tonic-gate } else { 897*0Sstevel@tonic-gate (void) printf("Nmap: off\n"); 898*0Sstevel@tonic-gate } 899*0Sstevel@tonic-gate (void) printf("Hash mark printing: %s; Use of PORT cmds: %s\n", 900*0Sstevel@tonic-gate onoff(hash), onoff(sendport)); 901*0Sstevel@tonic-gate if (macnum > 0) { 902*0Sstevel@tonic-gate (void) printf("Macros:\n"); 903*0Sstevel@tonic-gate for (i = 0; i < macnum; i++) { 904*0Sstevel@tonic-gate (void) printf("\t%s\n", macros[i].mac_name); 905*0Sstevel@tonic-gate } 906*0Sstevel@tonic-gate } 907*0Sstevel@tonic-gate code = 0; 908*0Sstevel@tonic-gate } 909*0Sstevel@tonic-gate 910*0Sstevel@tonic-gate /* 911*0Sstevel@tonic-gate * Set beep on cmd completed mode. 912*0Sstevel@tonic-gate */ 913*0Sstevel@tonic-gate /*ARGSUSED*/ 914*0Sstevel@tonic-gate void 915*0Sstevel@tonic-gate setbell(int argc, char *argv[]) 916*0Sstevel@tonic-gate { 917*0Sstevel@tonic-gate bell = !bell; 918*0Sstevel@tonic-gate (void) printf("Bell mode %s.\n", onoff(bell)); 919*0Sstevel@tonic-gate code = bell; 920*0Sstevel@tonic-gate } 921*0Sstevel@tonic-gate 922*0Sstevel@tonic-gate /* 923*0Sstevel@tonic-gate * Turn on packet tracing. 924*0Sstevel@tonic-gate */ 925*0Sstevel@tonic-gate /*ARGSUSED*/ 926*0Sstevel@tonic-gate void 927*0Sstevel@tonic-gate settrace(int argc, char *argv[]) 928*0Sstevel@tonic-gate { 929*0Sstevel@tonic-gate trace = !trace; 930*0Sstevel@tonic-gate (void) printf("Packet tracing %s.\n", onoff(trace)); 931*0Sstevel@tonic-gate code = trace; 932*0Sstevel@tonic-gate } 933*0Sstevel@tonic-gate 934*0Sstevel@tonic-gate /* 935*0Sstevel@tonic-gate * Toggle hash mark printing during transfers. 936*0Sstevel@tonic-gate */ 937*0Sstevel@tonic-gate /*ARGSUSED*/ 938*0Sstevel@tonic-gate void 939*0Sstevel@tonic-gate sethash(int argc, char *argv[]) 940*0Sstevel@tonic-gate { 941*0Sstevel@tonic-gate hash = !hash; 942*0Sstevel@tonic-gate (void) printf("Hash mark printing %s", onoff(hash)); 943*0Sstevel@tonic-gate code = hash; 944*0Sstevel@tonic-gate if (hash) 945*0Sstevel@tonic-gate (void) printf(" (%d bytes/hash mark)", HASHSIZ); 946*0Sstevel@tonic-gate (void) printf(".\n"); 947*0Sstevel@tonic-gate } 948*0Sstevel@tonic-gate 949*0Sstevel@tonic-gate /* 950*0Sstevel@tonic-gate * Turn on printing of server echo's. 951*0Sstevel@tonic-gate */ 952*0Sstevel@tonic-gate /*ARGSUSED*/ 953*0Sstevel@tonic-gate void 954*0Sstevel@tonic-gate setverbose(int argc, char *argv[]) 955*0Sstevel@tonic-gate { 956*0Sstevel@tonic-gate verbose = !verbose; 957*0Sstevel@tonic-gate (void) printf("Verbose mode %s.\n", onoff(verbose)); 958*0Sstevel@tonic-gate code = verbose; 959*0Sstevel@tonic-gate } 960*0Sstevel@tonic-gate 961*0Sstevel@tonic-gate /* 962*0Sstevel@tonic-gate * Toggle PORT cmd use before each data connection. 963*0Sstevel@tonic-gate */ 964*0Sstevel@tonic-gate /*ARGSUSED*/ 965*0Sstevel@tonic-gate void 966*0Sstevel@tonic-gate setport(int argc, char *argv[]) 967*0Sstevel@tonic-gate { 968*0Sstevel@tonic-gate sendport = !sendport; 969*0Sstevel@tonic-gate (void) printf("Use of PORT cmds %s.\n", onoff(sendport)); 970*0Sstevel@tonic-gate code = sendport; 971*0Sstevel@tonic-gate } 972*0Sstevel@tonic-gate 973*0Sstevel@tonic-gate /* 974*0Sstevel@tonic-gate * Turn on interactive prompting 975*0Sstevel@tonic-gate * during mget, mput, and mdelete. 976*0Sstevel@tonic-gate */ 977*0Sstevel@tonic-gate /*ARGSUSED*/ 978*0Sstevel@tonic-gate void 979*0Sstevel@tonic-gate setprompt(int argc, char *argv[]) 980*0Sstevel@tonic-gate { 981*0Sstevel@tonic-gate interactive = !interactive; 982*0Sstevel@tonic-gate (void) printf("Interactive mode %s.\n", onoff(interactive)); 983*0Sstevel@tonic-gate code = interactive; 984*0Sstevel@tonic-gate } 985*0Sstevel@tonic-gate 986*0Sstevel@tonic-gate /* 987*0Sstevel@tonic-gate * Toggle metacharacter interpretation 988*0Sstevel@tonic-gate * on local file names. 989*0Sstevel@tonic-gate */ 990*0Sstevel@tonic-gate /*ARGSUSED*/ 991*0Sstevel@tonic-gate void 992*0Sstevel@tonic-gate setglob(int argc, char *argv[]) 993*0Sstevel@tonic-gate { 994*0Sstevel@tonic-gate doglob = !doglob; 995*0Sstevel@tonic-gate (void) printf("Globbing %s.\n", onoff(doglob)); 996*0Sstevel@tonic-gate code = doglob; 997*0Sstevel@tonic-gate } 998*0Sstevel@tonic-gate 999*0Sstevel@tonic-gate /* 1000*0Sstevel@tonic-gate * Set debugging mode on/off and/or 1001*0Sstevel@tonic-gate * set level of debugging. 1002*0Sstevel@tonic-gate */ 1003*0Sstevel@tonic-gate void 1004*0Sstevel@tonic-gate setdebug(int argc, char *argv[]) 1005*0Sstevel@tonic-gate { 1006*0Sstevel@tonic-gate int val; 1007*0Sstevel@tonic-gate 1008*0Sstevel@tonic-gate if (argc > 1) { 1009*0Sstevel@tonic-gate val = atoi(argv[1]); 1010*0Sstevel@tonic-gate if (val < 0) { 1011*0Sstevel@tonic-gate (void) printf("%s: bad debugging value.\n", argv[1]); 1012*0Sstevel@tonic-gate code = -1; 1013*0Sstevel@tonic-gate return; 1014*0Sstevel@tonic-gate } 1015*0Sstevel@tonic-gate } else 1016*0Sstevel@tonic-gate val = !debug; 1017*0Sstevel@tonic-gate debug = val; 1018*0Sstevel@tonic-gate if (debug) 1019*0Sstevel@tonic-gate options |= SO_DEBUG; 1020*0Sstevel@tonic-gate else 1021*0Sstevel@tonic-gate options &= ~SO_DEBUG; 1022*0Sstevel@tonic-gate (void) printf("Debugging %s (debug=%d).\n", onoff(debug), debug); 1023*0Sstevel@tonic-gate code = debug > 0; 1024*0Sstevel@tonic-gate } 1025*0Sstevel@tonic-gate 1026*0Sstevel@tonic-gate /* 1027*0Sstevel@tonic-gate * Set current working directory 1028*0Sstevel@tonic-gate * on remote machine. 1029*0Sstevel@tonic-gate */ 1030*0Sstevel@tonic-gate void 1031*0Sstevel@tonic-gate cd(int argc, char *argv[]) 1032*0Sstevel@tonic-gate { 1033*0Sstevel@tonic-gate if (argc < 2) { 1034*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-directory") < 1035*0Sstevel@tonic-gate 0) { 1036*0Sstevel@tonic-gate code = -1; 1037*0Sstevel@tonic-gate return; 1038*0Sstevel@tonic-gate } 1039*0Sstevel@tonic-gate makeargv(); 1040*0Sstevel@tonic-gate argc = margc; 1041*0Sstevel@tonic-gate argv = margv; 1042*0Sstevel@tonic-gate } 1043*0Sstevel@tonic-gate if (argc < 2) { 1044*0Sstevel@tonic-gate (void) printf("usage: %s remote-directory\n", argv[0]); 1045*0Sstevel@tonic-gate code = -1; 1046*0Sstevel@tonic-gate return; 1047*0Sstevel@tonic-gate } 1048*0Sstevel@tonic-gate (void) command("CWD %s", argv[1]); 1049*0Sstevel@tonic-gate } 1050*0Sstevel@tonic-gate 1051*0Sstevel@tonic-gate /* 1052*0Sstevel@tonic-gate * Set current working directory 1053*0Sstevel@tonic-gate * on local machine. 1054*0Sstevel@tonic-gate */ 1055*0Sstevel@tonic-gate void 1056*0Sstevel@tonic-gate lcd(int argc, char *argv[]) 1057*0Sstevel@tonic-gate { 1058*0Sstevel@tonic-gate char buf[MAXPATHLEN], *bufptr; 1059*0Sstevel@tonic-gate 1060*0Sstevel@tonic-gate if (argc < 2) 1061*0Sstevel@tonic-gate argc++, argv[1] = home; 1062*0Sstevel@tonic-gate if (argc != 2) { 1063*0Sstevel@tonic-gate (void) printf("usage: %s local-directory\n", argv[0]); 1064*0Sstevel@tonic-gate code = -1; 1065*0Sstevel@tonic-gate return; 1066*0Sstevel@tonic-gate } 1067*0Sstevel@tonic-gate if (!globulize(&argv[1])) { 1068*0Sstevel@tonic-gate code = -1; 1069*0Sstevel@tonic-gate return; 1070*0Sstevel@tonic-gate } 1071*0Sstevel@tonic-gate if (chdir(argv[1]) < 0) { 1072*0Sstevel@tonic-gate perror(argv[1]); 1073*0Sstevel@tonic-gate code = -1; 1074*0Sstevel@tonic-gate return; 1075*0Sstevel@tonic-gate } 1076*0Sstevel@tonic-gate bufptr = getcwd(buf, MAXPATHLEN); 1077*0Sstevel@tonic-gate /* 1078*0Sstevel@tonic-gate * Even though chdir may succeed, getcwd may fail if a component 1079*0Sstevel@tonic-gate * of the pwd is unreadable. In this case, print the argument to 1080*0Sstevel@tonic-gate * chdir as the resultant directory, since we know it succeeded above. 1081*0Sstevel@tonic-gate */ 1082*0Sstevel@tonic-gate (void) printf("Local directory now %s\n", (bufptr ? bufptr : argv[1])); 1083*0Sstevel@tonic-gate code = 0; 1084*0Sstevel@tonic-gate } 1085*0Sstevel@tonic-gate 1086*0Sstevel@tonic-gate /* 1087*0Sstevel@tonic-gate * Delete a single file. 1088*0Sstevel@tonic-gate */ 1089*0Sstevel@tonic-gate void 1090*0Sstevel@tonic-gate delete(int argc, char *argv[]) 1091*0Sstevel@tonic-gate { 1092*0Sstevel@tonic-gate 1093*0Sstevel@tonic-gate if (argc < 2) { 1094*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") < 0) { 1095*0Sstevel@tonic-gate code = -1; 1096*0Sstevel@tonic-gate return; 1097*0Sstevel@tonic-gate } 1098*0Sstevel@tonic-gate makeargv(); 1099*0Sstevel@tonic-gate argc = margc; 1100*0Sstevel@tonic-gate argv = margv; 1101*0Sstevel@tonic-gate } 1102*0Sstevel@tonic-gate if (argc < 2) { 1103*0Sstevel@tonic-gate (void) printf("usage: %s remote-file\n", argv[0]); 1104*0Sstevel@tonic-gate code = -1; 1105*0Sstevel@tonic-gate return; 1106*0Sstevel@tonic-gate } 1107*0Sstevel@tonic-gate (void) command("DELE %s", argv[1]); 1108*0Sstevel@tonic-gate } 1109*0Sstevel@tonic-gate 1110*0Sstevel@tonic-gate /* 1111*0Sstevel@tonic-gate * Delete multiple files. 1112*0Sstevel@tonic-gate */ 1113*0Sstevel@tonic-gate void 1114*0Sstevel@tonic-gate mdelete(int argc, char *argv[]) 1115*0Sstevel@tonic-gate { 1116*0Sstevel@tonic-gate char *cp; 1117*0Sstevel@tonic-gate int ointer; 1118*0Sstevel@tonic-gate void (*oldintr)(); 1119*0Sstevel@tonic-gate 1120*0Sstevel@tonic-gate if (argc < 2) { 1121*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) { 1122*0Sstevel@tonic-gate code = -1; 1123*0Sstevel@tonic-gate return; 1124*0Sstevel@tonic-gate } 1125*0Sstevel@tonic-gate makeargv(); 1126*0Sstevel@tonic-gate argc = margc; 1127*0Sstevel@tonic-gate argv = margv; 1128*0Sstevel@tonic-gate } 1129*0Sstevel@tonic-gate if (argc < 2) { 1130*0Sstevel@tonic-gate (void) printf("usage: %s remote-files\n", argv[0]); 1131*0Sstevel@tonic-gate code = -1; 1132*0Sstevel@tonic-gate return; 1133*0Sstevel@tonic-gate } 1134*0Sstevel@tonic-gate mname = argv[0]; 1135*0Sstevel@tonic-gate mflag = 1; 1136*0Sstevel@tonic-gate oldintr = signal(SIGINT, mabort); 1137*0Sstevel@tonic-gate (void) setjmp(jabort); 1138*0Sstevel@tonic-gate while ((cp = remglob(argv, 0)) != NULL) { 1139*0Sstevel@tonic-gate if (*cp == '\0') { 1140*0Sstevel@tonic-gate mflag = 0; 1141*0Sstevel@tonic-gate continue; 1142*0Sstevel@tonic-gate } 1143*0Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) { 1144*0Sstevel@tonic-gate (void) command("DELE %s", cp); 1145*0Sstevel@tonic-gate if (!mflag && fromatty) { 1146*0Sstevel@tonic-gate ointer = interactive; 1147*0Sstevel@tonic-gate interactive = 1; 1148*0Sstevel@tonic-gate if (confirm("Continue with", "mdelete")) { 1149*0Sstevel@tonic-gate mflag++; 1150*0Sstevel@tonic-gate } 1151*0Sstevel@tonic-gate interactive = ointer; 1152*0Sstevel@tonic-gate } 1153*0Sstevel@tonic-gate } 1154*0Sstevel@tonic-gate } 1155*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 1156*0Sstevel@tonic-gate mflag = 0; 1157*0Sstevel@tonic-gate } 1158*0Sstevel@tonic-gate 1159*0Sstevel@tonic-gate /* 1160*0Sstevel@tonic-gate * Rename a remote file. 1161*0Sstevel@tonic-gate */ 1162*0Sstevel@tonic-gate void 1163*0Sstevel@tonic-gate renamefile(int argc, char *argv[]) 1164*0Sstevel@tonic-gate { 1165*0Sstevel@tonic-gate 1166*0Sstevel@tonic-gate if (argc < 2) { 1167*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "from-name") < 0) { 1168*0Sstevel@tonic-gate code = -1; 1169*0Sstevel@tonic-gate return; 1170*0Sstevel@tonic-gate } 1171*0Sstevel@tonic-gate makeargv(); 1172*0Sstevel@tonic-gate argc = margc; 1173*0Sstevel@tonic-gate argv = margv; 1174*0Sstevel@tonic-gate } 1175*0Sstevel@tonic-gate if (argc < 2) { 1176*0Sstevel@tonic-gate usage: 1177*0Sstevel@tonic-gate (void) printf("%s from-name to-name\n", argv[0]); 1178*0Sstevel@tonic-gate code = -1; 1179*0Sstevel@tonic-gate return; 1180*0Sstevel@tonic-gate } 1181*0Sstevel@tonic-gate if (argc < 3) { 1182*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "to-name") < 0) { 1183*0Sstevel@tonic-gate code = -1; 1184*0Sstevel@tonic-gate return; 1185*0Sstevel@tonic-gate } 1186*0Sstevel@tonic-gate makeargv(); 1187*0Sstevel@tonic-gate argc = margc; 1188*0Sstevel@tonic-gate argv = margv; 1189*0Sstevel@tonic-gate } 1190*0Sstevel@tonic-gate if (argc < 3) 1191*0Sstevel@tonic-gate goto usage; 1192*0Sstevel@tonic-gate if (command("RNFR %s", argv[1]) == CONTINUE) 1193*0Sstevel@tonic-gate (void) command("RNTO %s", argv[2]); 1194*0Sstevel@tonic-gate } 1195*0Sstevel@tonic-gate 1196*0Sstevel@tonic-gate /* 1197*0Sstevel@tonic-gate * Get a directory listing 1198*0Sstevel@tonic-gate * of remote files. 1199*0Sstevel@tonic-gate */ 1200*0Sstevel@tonic-gate void 1201*0Sstevel@tonic-gate ls(int argc, char *argv[]) 1202*0Sstevel@tonic-gate { 1203*0Sstevel@tonic-gate char *cmd; 1204*0Sstevel@tonic-gate 1205*0Sstevel@tonic-gate if (argc < 2) 1206*0Sstevel@tonic-gate argc++, argv[1] = NULL; 1207*0Sstevel@tonic-gate if (argc < 3) 1208*0Sstevel@tonic-gate argc++, argv[2] = "-"; 1209*0Sstevel@tonic-gate if (argc > 3) { 1210*0Sstevel@tonic-gate (void) printf("usage: %s remote-directory local-file\n", 1211*0Sstevel@tonic-gate argv[0]); 1212*0Sstevel@tonic-gate code = -1; 1213*0Sstevel@tonic-gate return; 1214*0Sstevel@tonic-gate } 1215*0Sstevel@tonic-gate if (ls_invokes_NLST) { 1216*0Sstevel@tonic-gate cmd = ((argv[0][0] == 'l' || argv[0][0] == 'n') ? 1217*0Sstevel@tonic-gate "NLST" : "LIST"); 1218*0Sstevel@tonic-gate } else { 1219*0Sstevel@tonic-gate cmd = ((argv[0][0] == 'n') ? "NLST" : "LIST"); 1220*0Sstevel@tonic-gate } 1221*0Sstevel@tonic-gate if (strcmp(argv[2], "-") && !globulize(&argv[2])) { 1222*0Sstevel@tonic-gate code = -1; 1223*0Sstevel@tonic-gate return; 1224*0Sstevel@tonic-gate } 1225*0Sstevel@tonic-gate recvrequest(cmd, argv[2], argv[1], "w", 1); 1226*0Sstevel@tonic-gate } 1227*0Sstevel@tonic-gate 1228*0Sstevel@tonic-gate /* 1229*0Sstevel@tonic-gate * Get a directory listing 1230*0Sstevel@tonic-gate * of multiple remote files. 1231*0Sstevel@tonic-gate */ 1232*0Sstevel@tonic-gate void 1233*0Sstevel@tonic-gate mls(int argc, char *argv[]) 1234*0Sstevel@tonic-gate { 1235*0Sstevel@tonic-gate char *cmd, mode[1], *dest; 1236*0Sstevel@tonic-gate int ointer, i; 1237*0Sstevel@tonic-gate void (*oldintr)(); 1238*0Sstevel@tonic-gate 1239*0Sstevel@tonic-gate if (argc < 2) { 1240*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) { 1241*0Sstevel@tonic-gate code = -1; 1242*0Sstevel@tonic-gate return; 1243*0Sstevel@tonic-gate } 1244*0Sstevel@tonic-gate makeargv(); 1245*0Sstevel@tonic-gate argc = margc; 1246*0Sstevel@tonic-gate argv = margv; 1247*0Sstevel@tonic-gate } 1248*0Sstevel@tonic-gate if (argc < 3) { 1249*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") < 0) { 1250*0Sstevel@tonic-gate code = -1; 1251*0Sstevel@tonic-gate return; 1252*0Sstevel@tonic-gate } 1253*0Sstevel@tonic-gate makeargv(); 1254*0Sstevel@tonic-gate argc = margc; 1255*0Sstevel@tonic-gate argv = margv; 1256*0Sstevel@tonic-gate } 1257*0Sstevel@tonic-gate if (argc < 3) { 1258*0Sstevel@tonic-gate (void) printf("usage: %s remote-files local-file\n", argv[0]); 1259*0Sstevel@tonic-gate code = -1; 1260*0Sstevel@tonic-gate return; 1261*0Sstevel@tonic-gate } 1262*0Sstevel@tonic-gate dest = argv[argc - 1]; 1263*0Sstevel@tonic-gate argv[argc - 1] = NULL; 1264*0Sstevel@tonic-gate if (strcmp(dest, "-") && *dest != '|') 1265*0Sstevel@tonic-gate if (!globulize(&dest) || 1266*0Sstevel@tonic-gate !confirm("output to local-file:", dest)) { 1267*0Sstevel@tonic-gate code = -1; 1268*0Sstevel@tonic-gate return; 1269*0Sstevel@tonic-gate } 1270*0Sstevel@tonic-gate cmd = argv[0][1] == 'l' ? "NLST" : "LIST"; 1271*0Sstevel@tonic-gate mname = argv[0]; 1272*0Sstevel@tonic-gate mflag = 1; 1273*0Sstevel@tonic-gate oldintr = signal(SIGINT, mabort); 1274*0Sstevel@tonic-gate (void) setjmp(jabort); 1275*0Sstevel@tonic-gate for (i = 1; mflag && i < argc-1; ++i) { 1276*0Sstevel@tonic-gate *mode = (i == 1) ? 'w' : 'a'; 1277*0Sstevel@tonic-gate recvrequest(cmd, dest, argv[i], mode, 1); 1278*0Sstevel@tonic-gate if (!mflag && fromatty) { 1279*0Sstevel@tonic-gate ointer = interactive; 1280*0Sstevel@tonic-gate interactive = 1; 1281*0Sstevel@tonic-gate if (confirm("Continue with", argv[0])) { 1282*0Sstevel@tonic-gate mflag ++; 1283*0Sstevel@tonic-gate } 1284*0Sstevel@tonic-gate interactive = ointer; 1285*0Sstevel@tonic-gate } 1286*0Sstevel@tonic-gate } 1287*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 1288*0Sstevel@tonic-gate mflag = 0; 1289*0Sstevel@tonic-gate } 1290*0Sstevel@tonic-gate 1291*0Sstevel@tonic-gate /* 1292*0Sstevel@tonic-gate * Do a shell escape 1293*0Sstevel@tonic-gate */ 1294*0Sstevel@tonic-gate /*ARGSUSED*/ 1295*0Sstevel@tonic-gate void 1296*0Sstevel@tonic-gate shell(int argc, char *argv[]) 1297*0Sstevel@tonic-gate { 1298*0Sstevel@tonic-gate pid_t pid; 1299*0Sstevel@tonic-gate void (*old1)(), (*old2)(); 1300*0Sstevel@tonic-gate char *shellstring, *namep; 1301*0Sstevel@tonic-gate int status; 1302*0Sstevel@tonic-gate 1303*0Sstevel@tonic-gate stop_timer(); 1304*0Sstevel@tonic-gate old1 = signal(SIGINT, SIG_IGN); 1305*0Sstevel@tonic-gate old2 = signal(SIGQUIT, SIG_IGN); 1306*0Sstevel@tonic-gate if ((pid = fork()) == 0) { 1307*0Sstevel@tonic-gate closefrom(STDERR_FILENO + 1); 1308*0Sstevel@tonic-gate (void) signal(SIGINT, SIG_DFL); 1309*0Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_DFL); 1310*0Sstevel@tonic-gate shellstring = getenv("SHELL"); 1311*0Sstevel@tonic-gate if (shellstring == NULL) 1312*0Sstevel@tonic-gate shellstring = "/bin/sh"; 1313*0Sstevel@tonic-gate namep = rindex(shellstring, '/'); 1314*0Sstevel@tonic-gate if (namep == NULL) 1315*0Sstevel@tonic-gate namep = shellstring; 1316*0Sstevel@tonic-gate if (argc > 1) { 1317*0Sstevel@tonic-gate if (debug) { 1318*0Sstevel@tonic-gate (void) printf("%s -c %s\n", shellstring, 1319*0Sstevel@tonic-gate altarg); 1320*0Sstevel@tonic-gate (void) fflush(stdout); 1321*0Sstevel@tonic-gate } 1322*0Sstevel@tonic-gate execl(shellstring, namep, "-c", altarg, (char *)0); 1323*0Sstevel@tonic-gate } else { 1324*0Sstevel@tonic-gate if (debug) { 1325*0Sstevel@tonic-gate (void) printf("%s\n", shellstring); 1326*0Sstevel@tonic-gate (void) fflush(stdout); 1327*0Sstevel@tonic-gate } 1328*0Sstevel@tonic-gate execl(shellstring, namep, (char *)0); 1329*0Sstevel@tonic-gate } 1330*0Sstevel@tonic-gate perror(shellstring); 1331*0Sstevel@tonic-gate code = -1; 1332*0Sstevel@tonic-gate exit(1); 1333*0Sstevel@tonic-gate } 1334*0Sstevel@tonic-gate if (pid > 0) 1335*0Sstevel@tonic-gate while (wait(&status) != pid) 1336*0Sstevel@tonic-gate ; 1337*0Sstevel@tonic-gate (void) signal(SIGINT, old1); 1338*0Sstevel@tonic-gate (void) signal(SIGQUIT, old2); 1339*0Sstevel@tonic-gate reset_timer(); 1340*0Sstevel@tonic-gate if (pid == (pid_t)-1) { 1341*0Sstevel@tonic-gate perror("Try again later"); 1342*0Sstevel@tonic-gate code = -1; 1343*0Sstevel@tonic-gate } else { 1344*0Sstevel@tonic-gate code = 0; 1345*0Sstevel@tonic-gate } 1346*0Sstevel@tonic-gate } 1347*0Sstevel@tonic-gate 1348*0Sstevel@tonic-gate /* 1349*0Sstevel@tonic-gate * Send new user information (re-login) 1350*0Sstevel@tonic-gate */ 1351*0Sstevel@tonic-gate void 1352*0Sstevel@tonic-gate user(int argc, char *argv[]) 1353*0Sstevel@tonic-gate { 1354*0Sstevel@tonic-gate char acct[80]; 1355*0Sstevel@tonic-gate int n, aflag = 0; 1356*0Sstevel@tonic-gate 1357*0Sstevel@tonic-gate if (argc < 2) { 1358*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "username") < 0) { 1359*0Sstevel@tonic-gate code = -1; 1360*0Sstevel@tonic-gate return; 1361*0Sstevel@tonic-gate } 1362*0Sstevel@tonic-gate makeargv(); 1363*0Sstevel@tonic-gate argc = margc; 1364*0Sstevel@tonic-gate argv = margv; 1365*0Sstevel@tonic-gate } 1366*0Sstevel@tonic-gate if (argc > 4) { 1367*0Sstevel@tonic-gate (void) printf("usage: %s username [password] [account]\n", 1368*0Sstevel@tonic-gate argv[0]); 1369*0Sstevel@tonic-gate code = -1; 1370*0Sstevel@tonic-gate return; 1371*0Sstevel@tonic-gate } 1372*0Sstevel@tonic-gate if (argv[1] == 0) { 1373*0Sstevel@tonic-gate (void) printf("access for user (nil) denied\n"); 1374*0Sstevel@tonic-gate code = -1; 1375*0Sstevel@tonic-gate return; 1376*0Sstevel@tonic-gate } 1377*0Sstevel@tonic-gate n = command("USER %s", argv[1]); 1378*0Sstevel@tonic-gate if (n == CONTINUE) { 1379*0Sstevel@tonic-gate int oldclevel; 1380*0Sstevel@tonic-gate if (argc < 3) 1381*0Sstevel@tonic-gate argv[2] = mygetpass("Password: "), argc++; 1382*0Sstevel@tonic-gate if ((oldclevel = clevel) == PROT_S) 1383*0Sstevel@tonic-gate clevel = PROT_P; 1384*0Sstevel@tonic-gate n = command("PASS %s", argv[2]); 1385*0Sstevel@tonic-gate /* level may have changed */ 1386*0Sstevel@tonic-gate if (clevel == PROT_P) 1387*0Sstevel@tonic-gate clevel = oldclevel; 1388*0Sstevel@tonic-gate } 1389*0Sstevel@tonic-gate if (n == CONTINUE) { 1390*0Sstevel@tonic-gate if (argc < 4) { 1391*0Sstevel@tonic-gate (void) printf("Account: "); (void) fflush(stdout); 1392*0Sstevel@tonic-gate stop_timer(); 1393*0Sstevel@tonic-gate (void) fgets(acct, sizeof (acct) - 1, stdin); 1394*0Sstevel@tonic-gate reset_timer(); 1395*0Sstevel@tonic-gate acct[strlen(acct) - 1] = '\0'; 1396*0Sstevel@tonic-gate argv[3] = acct; argc++; 1397*0Sstevel@tonic-gate } 1398*0Sstevel@tonic-gate n = command("ACCT %s", argv[3]); 1399*0Sstevel@tonic-gate aflag++; 1400*0Sstevel@tonic-gate } 1401*0Sstevel@tonic-gate if (n != COMPLETE) { 1402*0Sstevel@tonic-gate (void) fprintf(stdout, "Login failed.\n"); 1403*0Sstevel@tonic-gate return; 1404*0Sstevel@tonic-gate } 1405*0Sstevel@tonic-gate if (!aflag && argc == 4) { 1406*0Sstevel@tonic-gate (void) command("ACCT %s", argv[3]); 1407*0Sstevel@tonic-gate } 1408*0Sstevel@tonic-gate } 1409*0Sstevel@tonic-gate 1410*0Sstevel@tonic-gate /* 1411*0Sstevel@tonic-gate * Print working directory. 1412*0Sstevel@tonic-gate */ 1413*0Sstevel@tonic-gate /*ARGSUSED*/ 1414*0Sstevel@tonic-gate void 1415*0Sstevel@tonic-gate pwd(int argc, char *argv[]) 1416*0Sstevel@tonic-gate { 1417*0Sstevel@tonic-gate (void) command("PWD"); 1418*0Sstevel@tonic-gate } 1419*0Sstevel@tonic-gate 1420*0Sstevel@tonic-gate /* 1421*0Sstevel@tonic-gate * Make a directory. 1422*0Sstevel@tonic-gate */ 1423*0Sstevel@tonic-gate void 1424*0Sstevel@tonic-gate makedir(int argc, char *argv[]) 1425*0Sstevel@tonic-gate { 1426*0Sstevel@tonic-gate if (argc < 2) { 1427*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "directory-name") < 1428*0Sstevel@tonic-gate 0) { 1429*0Sstevel@tonic-gate code = -1; 1430*0Sstevel@tonic-gate return; 1431*0Sstevel@tonic-gate } 1432*0Sstevel@tonic-gate makeargv(); 1433*0Sstevel@tonic-gate argc = margc; 1434*0Sstevel@tonic-gate argv = margv; 1435*0Sstevel@tonic-gate } 1436*0Sstevel@tonic-gate if (argc < 2) { 1437*0Sstevel@tonic-gate (void) printf("usage: %s directory-name\n", argv[0]); 1438*0Sstevel@tonic-gate code = -1; 1439*0Sstevel@tonic-gate return; 1440*0Sstevel@tonic-gate } 1441*0Sstevel@tonic-gate (void) command("MKD %s", argv[1]); 1442*0Sstevel@tonic-gate } 1443*0Sstevel@tonic-gate 1444*0Sstevel@tonic-gate /* 1445*0Sstevel@tonic-gate * Remove a directory. 1446*0Sstevel@tonic-gate */ 1447*0Sstevel@tonic-gate void 1448*0Sstevel@tonic-gate removedir(int argc, char *argv[]) 1449*0Sstevel@tonic-gate { 1450*0Sstevel@tonic-gate if (argc < 2) { 1451*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "directory-name") < 1452*0Sstevel@tonic-gate 0) { 1453*0Sstevel@tonic-gate code = -1; 1454*0Sstevel@tonic-gate return; 1455*0Sstevel@tonic-gate } 1456*0Sstevel@tonic-gate makeargv(); 1457*0Sstevel@tonic-gate argc = margc; 1458*0Sstevel@tonic-gate argv = margv; 1459*0Sstevel@tonic-gate } 1460*0Sstevel@tonic-gate if (argc < 2) { 1461*0Sstevel@tonic-gate (void) printf("usage: %s directory-name\n", argv[0]); 1462*0Sstevel@tonic-gate code = -1; 1463*0Sstevel@tonic-gate return; 1464*0Sstevel@tonic-gate } 1465*0Sstevel@tonic-gate (void) command("RMD %s", argv[1]); 1466*0Sstevel@tonic-gate } 1467*0Sstevel@tonic-gate 1468*0Sstevel@tonic-gate /* 1469*0Sstevel@tonic-gate * Send a line, verbatim, to the remote machine. 1470*0Sstevel@tonic-gate */ 1471*0Sstevel@tonic-gate void 1472*0Sstevel@tonic-gate quote(int argc, char *argv[]) 1473*0Sstevel@tonic-gate { 1474*0Sstevel@tonic-gate int i, n, len; 1475*0Sstevel@tonic-gate char buf[FTPBUFSIZ]; 1476*0Sstevel@tonic-gate 1477*0Sstevel@tonic-gate if (argc < 2) { 1478*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), 1479*0Sstevel@tonic-gate "command line to send") == -1) { 1480*0Sstevel@tonic-gate code = -1; 1481*0Sstevel@tonic-gate return; 1482*0Sstevel@tonic-gate } 1483*0Sstevel@tonic-gate makeargv(); 1484*0Sstevel@tonic-gate argc = margc; 1485*0Sstevel@tonic-gate argv = margv; 1486*0Sstevel@tonic-gate } 1487*0Sstevel@tonic-gate if (argc < 2) { 1488*0Sstevel@tonic-gate (void) printf("usage: %s line-to-send\n", argv[0]); 1489*0Sstevel@tonic-gate code = -1; 1490*0Sstevel@tonic-gate return; 1491*0Sstevel@tonic-gate } 1492*0Sstevel@tonic-gate len = snprintf(buf, sizeof (buf), "%s", argv[1]); 1493*0Sstevel@tonic-gate if (len >= 0 && len < sizeof (buf) - 1) { 1494*0Sstevel@tonic-gate for (i = 2; i < argc; i++) { 1495*0Sstevel@tonic-gate n = snprintf(&buf[len], sizeof (buf) - len, " %s", 1496*0Sstevel@tonic-gate argv[i]); 1497*0Sstevel@tonic-gate if (n < 0 || n >= sizeof (buf) - len) 1498*0Sstevel@tonic-gate break; 1499*0Sstevel@tonic-gate len += n; 1500*0Sstevel@tonic-gate } 1501*0Sstevel@tonic-gate } 1502*0Sstevel@tonic-gate if (command("%s", buf) == PRELIM) { 1503*0Sstevel@tonic-gate while (getreply(0) == PRELIM) 1504*0Sstevel@tonic-gate ; 1505*0Sstevel@tonic-gate } 1506*0Sstevel@tonic-gate } 1507*0Sstevel@tonic-gate 1508*0Sstevel@tonic-gate /* 1509*0Sstevel@tonic-gate * Send a line, verbatim, to the remote machine as a SITE command. 1510*0Sstevel@tonic-gate */ 1511*0Sstevel@tonic-gate void 1512*0Sstevel@tonic-gate site(int argc, char *argv[]) 1513*0Sstevel@tonic-gate { 1514*0Sstevel@tonic-gate int i, n, len; 1515*0Sstevel@tonic-gate char buf[FTPBUFSIZ]; 1516*0Sstevel@tonic-gate 1517*0Sstevel@tonic-gate if (argc < 2) { 1518*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), 1519*0Sstevel@tonic-gate "arguments to SITE command") == -1) { 1520*0Sstevel@tonic-gate code = -1; 1521*0Sstevel@tonic-gate return; 1522*0Sstevel@tonic-gate } 1523*0Sstevel@tonic-gate makeargv(); 1524*0Sstevel@tonic-gate argc = margc; 1525*0Sstevel@tonic-gate argv = margv; 1526*0Sstevel@tonic-gate } 1527*0Sstevel@tonic-gate if (argc < 2) { 1528*0Sstevel@tonic-gate (void) printf("usage: %s arg1 [arg2] ...\n", argv[0]); 1529*0Sstevel@tonic-gate code = -1; 1530*0Sstevel@tonic-gate return; 1531*0Sstevel@tonic-gate } 1532*0Sstevel@tonic-gate len = snprintf(buf, sizeof (buf), "%s", argv[1]); 1533*0Sstevel@tonic-gate if (len >= 0 && len < sizeof (buf) - 1) { 1534*0Sstevel@tonic-gate for (i = 2; i < argc; i++) { 1535*0Sstevel@tonic-gate n = snprintf(&buf[len], sizeof (buf) - len, " %s", 1536*0Sstevel@tonic-gate argv[i]); 1537*0Sstevel@tonic-gate if (n < 0 || n >= sizeof (buf) - len) 1538*0Sstevel@tonic-gate break; 1539*0Sstevel@tonic-gate len += n; 1540*0Sstevel@tonic-gate } 1541*0Sstevel@tonic-gate } 1542*0Sstevel@tonic-gate if (command("SITE %s", buf) == PRELIM) { 1543*0Sstevel@tonic-gate while (getreply(0) == PRELIM) 1544*0Sstevel@tonic-gate ; 1545*0Sstevel@tonic-gate } 1546*0Sstevel@tonic-gate } 1547*0Sstevel@tonic-gate 1548*0Sstevel@tonic-gate /* 1549*0Sstevel@tonic-gate * Ask the other side for help. 1550*0Sstevel@tonic-gate */ 1551*0Sstevel@tonic-gate void 1552*0Sstevel@tonic-gate rmthelp(int argc, char *argv[]) 1553*0Sstevel@tonic-gate { 1554*0Sstevel@tonic-gate int oldverbose = verbose; 1555*0Sstevel@tonic-gate 1556*0Sstevel@tonic-gate verbose = 1; 1557*0Sstevel@tonic-gate (void) command(argc == 1 ? "HELP" : "HELP %s", argv[1]); 1558*0Sstevel@tonic-gate verbose = oldverbose; 1559*0Sstevel@tonic-gate } 1560*0Sstevel@tonic-gate 1561*0Sstevel@tonic-gate /* 1562*0Sstevel@tonic-gate * Terminate session and exit. 1563*0Sstevel@tonic-gate */ 1564*0Sstevel@tonic-gate /*ARGSUSED*/ 1565*0Sstevel@tonic-gate void 1566*0Sstevel@tonic-gate quit(int argc, char *argv[]) 1567*0Sstevel@tonic-gate { 1568*0Sstevel@tonic-gate if (connected) 1569*0Sstevel@tonic-gate disconnect(0, NULL); 1570*0Sstevel@tonic-gate pswitch(1); 1571*0Sstevel@tonic-gate if (connected) { 1572*0Sstevel@tonic-gate disconnect(0, NULL); 1573*0Sstevel@tonic-gate } 1574*0Sstevel@tonic-gate exit(0); 1575*0Sstevel@tonic-gate } 1576*0Sstevel@tonic-gate 1577*0Sstevel@tonic-gate /* 1578*0Sstevel@tonic-gate * Terminate session, but don't exit. 1579*0Sstevel@tonic-gate */ 1580*0Sstevel@tonic-gate /*ARGSUSED*/ 1581*0Sstevel@tonic-gate void 1582*0Sstevel@tonic-gate disconnect(int argc, char *argv[]) 1583*0Sstevel@tonic-gate { 1584*0Sstevel@tonic-gate extern FILE *ctrl_in, *ctrl_out; 1585*0Sstevel@tonic-gate extern int data; 1586*0Sstevel@tonic-gate 1587*0Sstevel@tonic-gate if (!connected) 1588*0Sstevel@tonic-gate return; 1589*0Sstevel@tonic-gate (void) command("QUIT"); 1590*0Sstevel@tonic-gate if (ctrl_in) { 1591*0Sstevel@tonic-gate reset_timer(); 1592*0Sstevel@tonic-gate (void) fclose(ctrl_in); 1593*0Sstevel@tonic-gate } 1594*0Sstevel@tonic-gate if (ctrl_out) { 1595*0Sstevel@tonic-gate reset_timer(); 1596*0Sstevel@tonic-gate (void) fclose(ctrl_out); 1597*0Sstevel@tonic-gate } 1598*0Sstevel@tonic-gate ctrl_out = ctrl_in = NULL; 1599*0Sstevel@tonic-gate connected = 0; 1600*0Sstevel@tonic-gate data = -1; 1601*0Sstevel@tonic-gate if (!proxy) { 1602*0Sstevel@tonic-gate macnum = 0; 1603*0Sstevel@tonic-gate } 1604*0Sstevel@tonic-gate 1605*0Sstevel@tonic-gate auth_type = AUTHTYPE_NONE; 1606*0Sstevel@tonic-gate clevel = dlevel = PROT_C; 1607*0Sstevel@tonic-gate goteof = 0; 1608*0Sstevel@tonic-gate } 1609*0Sstevel@tonic-gate 1610*0Sstevel@tonic-gate static int 1611*0Sstevel@tonic-gate confirm(char *cmd, char *file) 1612*0Sstevel@tonic-gate { 1613*0Sstevel@tonic-gate char line[FTPBUFSIZ]; 1614*0Sstevel@tonic-gate 1615*0Sstevel@tonic-gate if (!interactive) 1616*0Sstevel@tonic-gate return (1); 1617*0Sstevel@tonic-gate stop_timer(); 1618*0Sstevel@tonic-gate (void) printf("%s %s? ", cmd, file); 1619*0Sstevel@tonic-gate (void) fflush(stdout); 1620*0Sstevel@tonic-gate *line = '\0'; 1621*0Sstevel@tonic-gate (void) fgets(line, sizeof (line), stdin); 1622*0Sstevel@tonic-gate reset_timer(); 1623*0Sstevel@tonic-gate return (*line != 'n' && *line != 'N'); 1624*0Sstevel@tonic-gate } 1625*0Sstevel@tonic-gate 1626*0Sstevel@tonic-gate void 1627*0Sstevel@tonic-gate fatal(char *msg) 1628*0Sstevel@tonic-gate { 1629*0Sstevel@tonic-gate (void) fprintf(stderr, "ftp: %s\n", msg); 1630*0Sstevel@tonic-gate exit(1); 1631*0Sstevel@tonic-gate } 1632*0Sstevel@tonic-gate 1633*0Sstevel@tonic-gate /* 1634*0Sstevel@tonic-gate * Glob a local file name specification with 1635*0Sstevel@tonic-gate * the expectation of a single return value. 1636*0Sstevel@tonic-gate * Can't control multiple values being expanded 1637*0Sstevel@tonic-gate * from the expression, we return only the first. 1638*0Sstevel@tonic-gate */ 1639*0Sstevel@tonic-gate static int 1640*0Sstevel@tonic-gate globulize(char **cpp) 1641*0Sstevel@tonic-gate { 1642*0Sstevel@tonic-gate char **globbed; 1643*0Sstevel@tonic-gate 1644*0Sstevel@tonic-gate if (!doglob) 1645*0Sstevel@tonic-gate return (1); 1646*0Sstevel@tonic-gate globbed = glob(*cpp); 1647*0Sstevel@tonic-gate if (globbed != NULL && *globbed == NULL && globerr == NULL) 1648*0Sstevel@tonic-gate globerr = "No match"; 1649*0Sstevel@tonic-gate if (globerr != NULL) { 1650*0Sstevel@tonic-gate (void) printf("%s: %s\n", *cpp, globerr); 1651*0Sstevel@tonic-gate if (globbed) 1652*0Sstevel@tonic-gate blkfree(globbed); 1653*0Sstevel@tonic-gate return (0); 1654*0Sstevel@tonic-gate } 1655*0Sstevel@tonic-gate if (globbed) { 1656*0Sstevel@tonic-gate *cpp = strdup(*globbed); 1657*0Sstevel@tonic-gate blkfree(globbed); 1658*0Sstevel@tonic-gate if (!*cpp) 1659*0Sstevel@tonic-gate return (0); 1660*0Sstevel@tonic-gate } 1661*0Sstevel@tonic-gate return (1); 1662*0Sstevel@tonic-gate } 1663*0Sstevel@tonic-gate 1664*0Sstevel@tonic-gate void 1665*0Sstevel@tonic-gate account(int argc, char *argv[]) 1666*0Sstevel@tonic-gate { 1667*0Sstevel@tonic-gate char acct[50], *ap; 1668*0Sstevel@tonic-gate 1669*0Sstevel@tonic-gate if (argc > 1) { 1670*0Sstevel@tonic-gate ++argv; 1671*0Sstevel@tonic-gate --argc; 1672*0Sstevel@tonic-gate (void) strncpy(acct, *argv, 49); 1673*0Sstevel@tonic-gate acct[49] = '\0'; 1674*0Sstevel@tonic-gate while (argc > 1) { 1675*0Sstevel@tonic-gate --argc; 1676*0Sstevel@tonic-gate ++argv; 1677*0Sstevel@tonic-gate (void) strncat(acct, *argv, 49 - strlen(acct)); 1678*0Sstevel@tonic-gate } 1679*0Sstevel@tonic-gate ap = acct; 1680*0Sstevel@tonic-gate } else { 1681*0Sstevel@tonic-gate ap = mygetpass("Account:"); 1682*0Sstevel@tonic-gate } 1683*0Sstevel@tonic-gate (void) command("ACCT %s", ap); 1684*0Sstevel@tonic-gate } 1685*0Sstevel@tonic-gate 1686*0Sstevel@tonic-gate /*ARGSUSED*/ 1687*0Sstevel@tonic-gate static void 1688*0Sstevel@tonic-gate proxabort(int sig) 1689*0Sstevel@tonic-gate { 1690*0Sstevel@tonic-gate extern int proxy; 1691*0Sstevel@tonic-gate 1692*0Sstevel@tonic-gate if (!proxy) { 1693*0Sstevel@tonic-gate pswitch(1); 1694*0Sstevel@tonic-gate } 1695*0Sstevel@tonic-gate if (connected) { 1696*0Sstevel@tonic-gate proxflag = 1; 1697*0Sstevel@tonic-gate } else { 1698*0Sstevel@tonic-gate proxflag = 0; 1699*0Sstevel@tonic-gate } 1700*0Sstevel@tonic-gate pswitch(0); 1701*0Sstevel@tonic-gate longjmp(abortprox, 1); 1702*0Sstevel@tonic-gate } 1703*0Sstevel@tonic-gate 1704*0Sstevel@tonic-gate void 1705*0Sstevel@tonic-gate doproxy(int argc, char *argv[]) 1706*0Sstevel@tonic-gate { 1707*0Sstevel@tonic-gate void (*oldintr)(); 1708*0Sstevel@tonic-gate struct cmd *c; 1709*0Sstevel@tonic-gate 1710*0Sstevel@tonic-gate if (argc < 2) { 1711*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "command") == -1) { 1712*0Sstevel@tonic-gate code = -1; 1713*0Sstevel@tonic-gate return; 1714*0Sstevel@tonic-gate } 1715*0Sstevel@tonic-gate makeargv(); 1716*0Sstevel@tonic-gate argc = margc; 1717*0Sstevel@tonic-gate argv = margv; 1718*0Sstevel@tonic-gate } 1719*0Sstevel@tonic-gate if (argc < 2) { 1720*0Sstevel@tonic-gate (void) printf("usage: %s command\n", argv[0]); 1721*0Sstevel@tonic-gate code = -1; 1722*0Sstevel@tonic-gate return; 1723*0Sstevel@tonic-gate } 1724*0Sstevel@tonic-gate c = getcmd(argv[1]); 1725*0Sstevel@tonic-gate if (c == (struct cmd *)-1) { 1726*0Sstevel@tonic-gate (void) printf("?Ambiguous command\n"); 1727*0Sstevel@tonic-gate (void) fflush(stdout); 1728*0Sstevel@tonic-gate code = -1; 1729*0Sstevel@tonic-gate return; 1730*0Sstevel@tonic-gate } 1731*0Sstevel@tonic-gate if (c == 0) { 1732*0Sstevel@tonic-gate (void) printf("?Invalid command\n"); 1733*0Sstevel@tonic-gate (void) fflush(stdout); 1734*0Sstevel@tonic-gate code = -1; 1735*0Sstevel@tonic-gate return; 1736*0Sstevel@tonic-gate } 1737*0Sstevel@tonic-gate if (!c->c_proxy) { 1738*0Sstevel@tonic-gate (void) printf("?Invalid proxy command\n"); 1739*0Sstevel@tonic-gate (void) fflush(stdout); 1740*0Sstevel@tonic-gate code = -1; 1741*0Sstevel@tonic-gate return; 1742*0Sstevel@tonic-gate } 1743*0Sstevel@tonic-gate if (setjmp(abortprox)) { 1744*0Sstevel@tonic-gate code = -1; 1745*0Sstevel@tonic-gate return; 1746*0Sstevel@tonic-gate } 1747*0Sstevel@tonic-gate oldintr = signal(SIGINT, (void (*)())proxabort); 1748*0Sstevel@tonic-gate pswitch(1); 1749*0Sstevel@tonic-gate if (c->c_conn && !connected) { 1750*0Sstevel@tonic-gate (void) printf("Not connected\n"); 1751*0Sstevel@tonic-gate (void) fflush(stdout); 1752*0Sstevel@tonic-gate pswitch(0); 1753*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 1754*0Sstevel@tonic-gate code = -1; 1755*0Sstevel@tonic-gate return; 1756*0Sstevel@tonic-gate } 1757*0Sstevel@tonic-gate (*c->c_handler)(argc-1, argv+1); 1758*0Sstevel@tonic-gate if (connected) { 1759*0Sstevel@tonic-gate proxflag = 1; 1760*0Sstevel@tonic-gate } else { 1761*0Sstevel@tonic-gate proxflag = 0; 1762*0Sstevel@tonic-gate } 1763*0Sstevel@tonic-gate pswitch(0); 1764*0Sstevel@tonic-gate (void) signal(SIGINT, oldintr); 1765*0Sstevel@tonic-gate } 1766*0Sstevel@tonic-gate 1767*0Sstevel@tonic-gate /*ARGSUSED*/ 1768*0Sstevel@tonic-gate void 1769*0Sstevel@tonic-gate setcase(int argc, char *argv[]) 1770*0Sstevel@tonic-gate { 1771*0Sstevel@tonic-gate mcase = !mcase; 1772*0Sstevel@tonic-gate (void) printf("Case mapping %s.\n", onoff(mcase)); 1773*0Sstevel@tonic-gate code = mcase; 1774*0Sstevel@tonic-gate } 1775*0Sstevel@tonic-gate 1776*0Sstevel@tonic-gate /*ARGSUSED*/ 1777*0Sstevel@tonic-gate void 1778*0Sstevel@tonic-gate setcr(int argc, char *argv[]) 1779*0Sstevel@tonic-gate { 1780*0Sstevel@tonic-gate crflag = !crflag; 1781*0Sstevel@tonic-gate (void) printf("Carriage Return stripping %s.\n", onoff(crflag)); 1782*0Sstevel@tonic-gate code = crflag; 1783*0Sstevel@tonic-gate } 1784*0Sstevel@tonic-gate 1785*0Sstevel@tonic-gate void 1786*0Sstevel@tonic-gate setntrans(int argc, char *argv[]) 1787*0Sstevel@tonic-gate { 1788*0Sstevel@tonic-gate if (argc == 1) { 1789*0Sstevel@tonic-gate ntflag = 0; 1790*0Sstevel@tonic-gate (void) printf("Ntrans off.\n"); 1791*0Sstevel@tonic-gate code = ntflag; 1792*0Sstevel@tonic-gate return; 1793*0Sstevel@tonic-gate } 1794*0Sstevel@tonic-gate ntflag++; 1795*0Sstevel@tonic-gate code = ntflag; 1796*0Sstevel@tonic-gate (void) strncpy(ntin, argv[1], 16); 1797*0Sstevel@tonic-gate ntin[16] = '\0'; 1798*0Sstevel@tonic-gate if (argc == 2) { 1799*0Sstevel@tonic-gate ntout[0] = '\0'; 1800*0Sstevel@tonic-gate return; 1801*0Sstevel@tonic-gate } 1802*0Sstevel@tonic-gate (void) strncpy(ntout, argv[2], 16); 1803*0Sstevel@tonic-gate ntout[16] = '\0'; 1804*0Sstevel@tonic-gate } 1805*0Sstevel@tonic-gate 1806*0Sstevel@tonic-gate static char * 1807*0Sstevel@tonic-gate dotrans(char *name) 1808*0Sstevel@tonic-gate { 1809*0Sstevel@tonic-gate static char new[MAXPATHLEN]; 1810*0Sstevel@tonic-gate char *cp1, *cp2 = new; 1811*0Sstevel@tonic-gate int i, ostop, found; 1812*0Sstevel@tonic-gate 1813*0Sstevel@tonic-gate for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++) 1814*0Sstevel@tonic-gate ; 1815*0Sstevel@tonic-gate for (cp1 = name; *cp1; cp1++) { 1816*0Sstevel@tonic-gate found = 0; 1817*0Sstevel@tonic-gate for (i = 0; *(ntin + i) && i < 16; i++) { 1818*0Sstevel@tonic-gate if (*cp1 == *(ntin + i)) { 1819*0Sstevel@tonic-gate found++; 1820*0Sstevel@tonic-gate if (i < ostop) { 1821*0Sstevel@tonic-gate *cp2++ = *(ntout + i); 1822*0Sstevel@tonic-gate } 1823*0Sstevel@tonic-gate break; 1824*0Sstevel@tonic-gate } 1825*0Sstevel@tonic-gate } 1826*0Sstevel@tonic-gate if (!found) { 1827*0Sstevel@tonic-gate *cp2++ = *cp1; 1828*0Sstevel@tonic-gate } 1829*0Sstevel@tonic-gate } 1830*0Sstevel@tonic-gate *cp2 = '\0'; 1831*0Sstevel@tonic-gate return (new); 1832*0Sstevel@tonic-gate } 1833*0Sstevel@tonic-gate 1834*0Sstevel@tonic-gate void 1835*0Sstevel@tonic-gate setnmap(int argc, char *argv[]) 1836*0Sstevel@tonic-gate { 1837*0Sstevel@tonic-gate char *cp; 1838*0Sstevel@tonic-gate 1839*0Sstevel@tonic-gate if (argc == 1) { 1840*0Sstevel@tonic-gate mapflag = 0; 1841*0Sstevel@tonic-gate (void) printf("Nmap off.\n"); 1842*0Sstevel@tonic-gate code = mapflag; 1843*0Sstevel@tonic-gate return; 1844*0Sstevel@tonic-gate } 1845*0Sstevel@tonic-gate if (argc < 3) { 1846*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "mapout") == -1) { 1847*0Sstevel@tonic-gate code = -1; 1848*0Sstevel@tonic-gate return; 1849*0Sstevel@tonic-gate } 1850*0Sstevel@tonic-gate makeargv(); 1851*0Sstevel@tonic-gate argc = margc; 1852*0Sstevel@tonic-gate argv = margv; 1853*0Sstevel@tonic-gate } 1854*0Sstevel@tonic-gate if (argc < 3) { 1855*0Sstevel@tonic-gate (void) printf("Usage: %s [mapin mapout]\n", argv[0]); 1856*0Sstevel@tonic-gate code = -1; 1857*0Sstevel@tonic-gate return; 1858*0Sstevel@tonic-gate } 1859*0Sstevel@tonic-gate mapflag = 1; 1860*0Sstevel@tonic-gate code = 1; 1861*0Sstevel@tonic-gate cp = index(altarg, ' '); 1862*0Sstevel@tonic-gate if (proxy) { 1863*0Sstevel@tonic-gate while (*++cp == ' ') 1864*0Sstevel@tonic-gate /* NULL */; 1865*0Sstevel@tonic-gate altarg = cp; 1866*0Sstevel@tonic-gate cp = index(altarg, ' '); 1867*0Sstevel@tonic-gate } 1868*0Sstevel@tonic-gate *cp = '\0'; 1869*0Sstevel@tonic-gate (void) strncpy(mapin, altarg, MAXPATHLEN - 1); 1870*0Sstevel@tonic-gate while (*++cp == ' ') 1871*0Sstevel@tonic-gate /* NULL */; 1872*0Sstevel@tonic-gate (void) strncpy(mapout, cp, MAXPATHLEN - 1); 1873*0Sstevel@tonic-gate } 1874*0Sstevel@tonic-gate 1875*0Sstevel@tonic-gate static char * 1876*0Sstevel@tonic-gate domap(char *name) 1877*0Sstevel@tonic-gate { 1878*0Sstevel@tonic-gate static char new[MAXPATHLEN]; 1879*0Sstevel@tonic-gate char *cp1 = name, *cp2 = mapin; 1880*0Sstevel@tonic-gate char *tp[9], *te[9]; 1881*0Sstevel@tonic-gate int i, toks[9], toknum, match = 1; 1882*0Sstevel@tonic-gate wchar_t wc1, wc2; 1883*0Sstevel@tonic-gate int len1, len2; 1884*0Sstevel@tonic-gate 1885*0Sstevel@tonic-gate for (i = 0; i < 9; ++i) { 1886*0Sstevel@tonic-gate toks[i] = 0; 1887*0Sstevel@tonic-gate } 1888*0Sstevel@tonic-gate while (match && *cp1 && *cp2) { 1889*0Sstevel@tonic-gate if ((len1 = mbtowc(&wc1, cp1, MB_CUR_MAX)) <= 0) { 1890*0Sstevel@tonic-gate wc1 = (unsigned char)*cp1; 1891*0Sstevel@tonic-gate len1 = 1; 1892*0Sstevel@tonic-gate } 1893*0Sstevel@tonic-gate cp1 += len1; 1894*0Sstevel@tonic-gate if ((len2 = mbtowc(&wc2, cp2, MB_CUR_MAX)) <= 0) { 1895*0Sstevel@tonic-gate wc2 = (unsigned char)*cp2; 1896*0Sstevel@tonic-gate len2 = 1; 1897*0Sstevel@tonic-gate } 1898*0Sstevel@tonic-gate cp2 += len2; 1899*0Sstevel@tonic-gate 1900*0Sstevel@tonic-gate switch (wc2) { 1901*0Sstevel@tonic-gate case '\\': 1902*0Sstevel@tonic-gate if ((len2 = mbtowc(&wc2, cp2, MB_CUR_MAX)) <= 0) { 1903*0Sstevel@tonic-gate wc2 = (unsigned char)*cp2; 1904*0Sstevel@tonic-gate len2 = 1; 1905*0Sstevel@tonic-gate } 1906*0Sstevel@tonic-gate cp2 += len2; 1907*0Sstevel@tonic-gate if (wc2 != wc1) 1908*0Sstevel@tonic-gate match = 0; 1909*0Sstevel@tonic-gate break; 1910*0Sstevel@tonic-gate 1911*0Sstevel@tonic-gate case '$': 1912*0Sstevel@tonic-gate if (*cp2 >= '1' && *cp2 <= '9') { 1913*0Sstevel@tonic-gate if ((len2 = 1914*0Sstevel@tonic-gate mbtowc(&wc2, cp2 + 1, MB_CUR_MAX)) <= 0) { 1915*0Sstevel@tonic-gate wc2 = (unsigned char)*(cp2 + 1); 1916*0Sstevel@tonic-gate len2 = 1; 1917*0Sstevel@tonic-gate } 1918*0Sstevel@tonic-gate if (wc1 != wc2) { 1919*0Sstevel@tonic-gate toks[toknum = *cp2 - '1']++; 1920*0Sstevel@tonic-gate tp[toknum] = cp1 - len1; 1921*0Sstevel@tonic-gate while (*cp1) { 1922*0Sstevel@tonic-gate if ((len1 = mbtowc(&wc1, 1923*0Sstevel@tonic-gate cp1, MB_CUR_MAX)) <= 0) { 1924*0Sstevel@tonic-gate wc1 = 1925*0Sstevel@tonic-gate (unsigned char)*cp1; 1926*0Sstevel@tonic-gate len1 = 1; 1927*0Sstevel@tonic-gate } 1928*0Sstevel@tonic-gate cp1 += len1; 1929*0Sstevel@tonic-gate if (wc2 == wc1) 1930*0Sstevel@tonic-gate break; 1931*0Sstevel@tonic-gate } 1932*0Sstevel@tonic-gate if (*cp1 == 0 && wc2 != wc1) 1933*0Sstevel@tonic-gate te[toknum] = cp1; 1934*0Sstevel@tonic-gate else 1935*0Sstevel@tonic-gate te[toknum] = cp1 - len1; 1936*0Sstevel@tonic-gate } 1937*0Sstevel@tonic-gate cp2++; /* Consume the digit */ 1938*0Sstevel@tonic-gate if (wc2) 1939*0Sstevel@tonic-gate cp2 += len2; /* Consume wide char */ 1940*0Sstevel@tonic-gate break; 1941*0Sstevel@tonic-gate } 1942*0Sstevel@tonic-gate /* intentional drop through */ 1943*0Sstevel@tonic-gate default: 1944*0Sstevel@tonic-gate if (wc2 != wc1) 1945*0Sstevel@tonic-gate match = 0; 1946*0Sstevel@tonic-gate break; 1947*0Sstevel@tonic-gate } 1948*0Sstevel@tonic-gate } 1949*0Sstevel@tonic-gate 1950*0Sstevel@tonic-gate cp1 = new; 1951*0Sstevel@tonic-gate *cp1 = '\0'; 1952*0Sstevel@tonic-gate cp2 = mapout; 1953*0Sstevel@tonic-gate while (*cp2) { 1954*0Sstevel@tonic-gate match = 0; 1955*0Sstevel@tonic-gate switch (*cp2) { 1956*0Sstevel@tonic-gate case '\\': 1957*0Sstevel@tonic-gate cp2++; 1958*0Sstevel@tonic-gate if (*cp2) { 1959*0Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 0) 1960*0Sstevel@tonic-gate len2 = 1; 1961*0Sstevel@tonic-gate memcpy(cp1, cp2, len2); 1962*0Sstevel@tonic-gate cp1 += len2; 1963*0Sstevel@tonic-gate cp2 += len2; 1964*0Sstevel@tonic-gate } 1965*0Sstevel@tonic-gate break; 1966*0Sstevel@tonic-gate 1967*0Sstevel@tonic-gate case '[': 1968*0Sstevel@tonic-gate LOOP: 1969*0Sstevel@tonic-gate cp2++; 1970*0Sstevel@tonic-gate if (*cp2 == '$' && isdigit(*(cp2+1))) { 1971*0Sstevel@tonic-gate if (*++cp2 == '0') { 1972*0Sstevel@tonic-gate char *cp3 = name; 1973*0Sstevel@tonic-gate 1974*0Sstevel@tonic-gate while (*cp3) { 1975*0Sstevel@tonic-gate *cp1++ = *cp3++; 1976*0Sstevel@tonic-gate } 1977*0Sstevel@tonic-gate match = 1; 1978*0Sstevel@tonic-gate } else if (toks[toknum = *cp2 - '1']) { 1979*0Sstevel@tonic-gate char *cp3 = tp[toknum]; 1980*0Sstevel@tonic-gate 1981*0Sstevel@tonic-gate while (cp3 != te[toknum]) { 1982*0Sstevel@tonic-gate *cp1++ = *cp3++; 1983*0Sstevel@tonic-gate } 1984*0Sstevel@tonic-gate match = 1; 1985*0Sstevel@tonic-gate } 1986*0Sstevel@tonic-gate } else { 1987*0Sstevel@tonic-gate while (*cp2 && *cp2 != ',' && *cp2 != ']') { 1988*0Sstevel@tonic-gate if (*cp2 == '\\') { 1989*0Sstevel@tonic-gate cp2++; 1990*0Sstevel@tonic-gate continue; 1991*0Sstevel@tonic-gate } 1992*0Sstevel@tonic-gate 1993*0Sstevel@tonic-gate if (*cp2 == '$' && isdigit(*(cp2+1))) { 1994*0Sstevel@tonic-gate if (*++cp2 == '0') { 1995*0Sstevel@tonic-gate char *cp3 = name; 1996*0Sstevel@tonic-gate 1997*0Sstevel@tonic-gate while (*cp3) 1998*0Sstevel@tonic-gate *cp1++ = *cp3++; 1999*0Sstevel@tonic-gate continue; 2000*0Sstevel@tonic-gate } 2001*0Sstevel@tonic-gate if (toks[toknum = *cp2 - '1']) { 2002*0Sstevel@tonic-gate char *cp3 = tp[toknum]; 2003*0Sstevel@tonic-gate 2004*0Sstevel@tonic-gate while (cp3 != 2005*0Sstevel@tonic-gate te[toknum]) 2006*0Sstevel@tonic-gate *cp1++ = *cp3++; 2007*0Sstevel@tonic-gate } 2008*0Sstevel@tonic-gate continue; 2009*0Sstevel@tonic-gate } 2010*0Sstevel@tonic-gate if (*cp2) { 2011*0Sstevel@tonic-gate if ((len2 = 2012*0Sstevel@tonic-gate mblen(cp2, MB_CUR_MAX)) <= 2013*0Sstevel@tonic-gate 0) { 2014*0Sstevel@tonic-gate len2 = 1; 2015*0Sstevel@tonic-gate } 2016*0Sstevel@tonic-gate memcpy(cp1, cp2, len2); 2017*0Sstevel@tonic-gate cp1 += len2; 2018*0Sstevel@tonic-gate cp2 += len2; 2019*0Sstevel@tonic-gate } 2020*0Sstevel@tonic-gate } 2021*0Sstevel@tonic-gate if (!*cp2) { 2022*0Sstevel@tonic-gate (void) printf( 2023*0Sstevel@tonic-gate "nmap: unbalanced brackets\n"); 2024*0Sstevel@tonic-gate return (name); 2025*0Sstevel@tonic-gate } 2026*0Sstevel@tonic-gate match = 1; 2027*0Sstevel@tonic-gate } 2028*0Sstevel@tonic-gate if (match) { 2029*0Sstevel@tonic-gate while (*cp2 && *cp2 != ']') { 2030*0Sstevel@tonic-gate if (*cp2 == '\\' && *(cp2 + 1)) { 2031*0Sstevel@tonic-gate cp2++; 2032*0Sstevel@tonic-gate } 2033*0Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 2034*0Sstevel@tonic-gate 0) 2035*0Sstevel@tonic-gate len2 = 1; 2036*0Sstevel@tonic-gate cp2 += len2; 2037*0Sstevel@tonic-gate } 2038*0Sstevel@tonic-gate if (!*cp2) { 2039*0Sstevel@tonic-gate (void) printf( 2040*0Sstevel@tonic-gate "nmap: unbalanced brackets\n"); 2041*0Sstevel@tonic-gate return (name); 2042*0Sstevel@tonic-gate } 2043*0Sstevel@tonic-gate cp2++; 2044*0Sstevel@tonic-gate break; 2045*0Sstevel@tonic-gate } 2046*0Sstevel@tonic-gate switch (*++cp2) { 2047*0Sstevel@tonic-gate case ',': 2048*0Sstevel@tonic-gate goto LOOP; 2049*0Sstevel@tonic-gate case ']': 2050*0Sstevel@tonic-gate break; 2051*0Sstevel@tonic-gate default: 2052*0Sstevel@tonic-gate cp2--; 2053*0Sstevel@tonic-gate goto LOOP; 2054*0Sstevel@tonic-gate } 2055*0Sstevel@tonic-gate cp2++; 2056*0Sstevel@tonic-gate break; 2057*0Sstevel@tonic-gate case '$': 2058*0Sstevel@tonic-gate if (isdigit(*(cp2 + 1))) { 2059*0Sstevel@tonic-gate if (*++cp2 == '0') { 2060*0Sstevel@tonic-gate char *cp3 = name; 2061*0Sstevel@tonic-gate 2062*0Sstevel@tonic-gate while (*cp3) { 2063*0Sstevel@tonic-gate *cp1++ = *cp3++; 2064*0Sstevel@tonic-gate } 2065*0Sstevel@tonic-gate } else if (toks[toknum = *cp2 - '1']) { 2066*0Sstevel@tonic-gate char *cp3 = tp[toknum]; 2067*0Sstevel@tonic-gate 2068*0Sstevel@tonic-gate while (cp3 != te[toknum]) { 2069*0Sstevel@tonic-gate *cp1++ = *cp3++; 2070*0Sstevel@tonic-gate } 2071*0Sstevel@tonic-gate } 2072*0Sstevel@tonic-gate cp2++; 2073*0Sstevel@tonic-gate break; 2074*0Sstevel@tonic-gate } 2075*0Sstevel@tonic-gate /* intentional drop through */ 2076*0Sstevel@tonic-gate default: 2077*0Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 0) 2078*0Sstevel@tonic-gate len2 = 1; 2079*0Sstevel@tonic-gate memcpy(cp1, cp2, len2); 2080*0Sstevel@tonic-gate cp1 += len2; 2081*0Sstevel@tonic-gate cp2 += len2; 2082*0Sstevel@tonic-gate break; 2083*0Sstevel@tonic-gate } 2084*0Sstevel@tonic-gate } 2085*0Sstevel@tonic-gate *cp1 = '\0'; 2086*0Sstevel@tonic-gate if (!*new) { 2087*0Sstevel@tonic-gate return (name); 2088*0Sstevel@tonic-gate } 2089*0Sstevel@tonic-gate return (new); 2090*0Sstevel@tonic-gate } 2091*0Sstevel@tonic-gate 2092*0Sstevel@tonic-gate /*ARGSUSED*/ 2093*0Sstevel@tonic-gate void 2094*0Sstevel@tonic-gate setsunique(int argc, char *argv[]) 2095*0Sstevel@tonic-gate { 2096*0Sstevel@tonic-gate sunique = !sunique; 2097*0Sstevel@tonic-gate (void) printf("Store unique %s.\n", onoff(sunique)); 2098*0Sstevel@tonic-gate code = sunique; 2099*0Sstevel@tonic-gate } 2100*0Sstevel@tonic-gate 2101*0Sstevel@tonic-gate /*ARGSUSED*/ 2102*0Sstevel@tonic-gate void 2103*0Sstevel@tonic-gate setrunique(int argc, char *argv[]) 2104*0Sstevel@tonic-gate { 2105*0Sstevel@tonic-gate runique = !runique; 2106*0Sstevel@tonic-gate (void) printf("Receive unique %s.\n", onoff(runique)); 2107*0Sstevel@tonic-gate code = runique; 2108*0Sstevel@tonic-gate } 2109*0Sstevel@tonic-gate 2110*0Sstevel@tonic-gate /*ARGSUSED*/ 2111*0Sstevel@tonic-gate void 2112*0Sstevel@tonic-gate setpassive(int argc, char *argv[]) 2113*0Sstevel@tonic-gate { 2114*0Sstevel@tonic-gate passivemode = !passivemode; 2115*0Sstevel@tonic-gate (void) printf("Passive mode %s.\n", onoff(passivemode)); 2116*0Sstevel@tonic-gate code = passivemode; 2117*0Sstevel@tonic-gate } 2118*0Sstevel@tonic-gate 2119*0Sstevel@tonic-gate void 2120*0Sstevel@tonic-gate settcpwindow(int argc, char *argv[]) 2121*0Sstevel@tonic-gate { 2122*0Sstevel@tonic-gate int owindowsize = tcpwindowsize; 2123*0Sstevel@tonic-gate 2124*0Sstevel@tonic-gate if (argc > 2) { 2125*0Sstevel@tonic-gate (void) printf("usage: %s [size]\n", argv[0]); 2126*0Sstevel@tonic-gate code = -1; 2127*0Sstevel@tonic-gate return; 2128*0Sstevel@tonic-gate } 2129*0Sstevel@tonic-gate if (argc == 2) { 2130*0Sstevel@tonic-gate int window; 2131*0Sstevel@tonic-gate char *endp; 2132*0Sstevel@tonic-gate 2133*0Sstevel@tonic-gate errno = 0; 2134*0Sstevel@tonic-gate window = (int)strtol(argv[1], &endp, 10); 2135*0Sstevel@tonic-gate if (errno || window < 0 || *endp != '\0') 2136*0Sstevel@tonic-gate (void) printf("%s: Invalid size `%s'\n", 2137*0Sstevel@tonic-gate argv[0], argv[1]); 2138*0Sstevel@tonic-gate else 2139*0Sstevel@tonic-gate tcpwindowsize = window; 2140*0Sstevel@tonic-gate } 2141*0Sstevel@tonic-gate if (tcpwindowsize == 0) { 2142*0Sstevel@tonic-gate if (owindowsize == 0) 2143*0Sstevel@tonic-gate (void) printf("No TCP window size defined\n"); 2144*0Sstevel@tonic-gate else 2145*0Sstevel@tonic-gate (void) printf("TCP window size cleared\n"); 2146*0Sstevel@tonic-gate } else 2147*0Sstevel@tonic-gate (void) printf("TCP window size is set to %d\n", tcpwindowsize); 2148*0Sstevel@tonic-gate } 2149*0Sstevel@tonic-gate 2150*0Sstevel@tonic-gate /* change directory to parent directory */ 2151*0Sstevel@tonic-gate /*ARGSUSED*/ 2152*0Sstevel@tonic-gate void 2153*0Sstevel@tonic-gate cdup(int argc, char *argv[]) 2154*0Sstevel@tonic-gate { 2155*0Sstevel@tonic-gate (void) command("CDUP"); 2156*0Sstevel@tonic-gate } 2157*0Sstevel@tonic-gate 2158*0Sstevel@tonic-gate void 2159*0Sstevel@tonic-gate macdef(int argc, char *argv[]) 2160*0Sstevel@tonic-gate { 2161*0Sstevel@tonic-gate char *tmp; 2162*0Sstevel@tonic-gate int c; 2163*0Sstevel@tonic-gate 2164*0Sstevel@tonic-gate if (macnum == 16) { 2165*0Sstevel@tonic-gate (void) printf("Limit of 16 macros have already been defined\n"); 2166*0Sstevel@tonic-gate code = -1; 2167*0Sstevel@tonic-gate return; 2168*0Sstevel@tonic-gate } 2169*0Sstevel@tonic-gate if (argc < 2) { 2170*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "macro name") == -1) { 2171*0Sstevel@tonic-gate code = -1; 2172*0Sstevel@tonic-gate return; 2173*0Sstevel@tonic-gate } 2174*0Sstevel@tonic-gate makeargv(); 2175*0Sstevel@tonic-gate argc = margc; 2176*0Sstevel@tonic-gate argv = margv; 2177*0Sstevel@tonic-gate } 2178*0Sstevel@tonic-gate if (argc != 2) { 2179*0Sstevel@tonic-gate (void) printf("Usage: %s macro_name\n", argv[0]); 2180*0Sstevel@tonic-gate code = -1; 2181*0Sstevel@tonic-gate return; 2182*0Sstevel@tonic-gate } 2183*0Sstevel@tonic-gate if (interactive) { 2184*0Sstevel@tonic-gate (void) printf("Enter macro line by line, terminating " 2185*0Sstevel@tonic-gate "it with a null line\n"); 2186*0Sstevel@tonic-gate } 2187*0Sstevel@tonic-gate (void) strncpy(macros[macnum].mac_name, argv[1], 8); 2188*0Sstevel@tonic-gate if (macnum == 0) { 2189*0Sstevel@tonic-gate macros[macnum].mac_start = macbuf; 2190*0Sstevel@tonic-gate } else { 2191*0Sstevel@tonic-gate macros[macnum].mac_start = macros[macnum - 1].mac_end + 1; 2192*0Sstevel@tonic-gate } 2193*0Sstevel@tonic-gate tmp = macros[macnum].mac_start; 2194*0Sstevel@tonic-gate while (tmp != macbuf+4096) { 2195*0Sstevel@tonic-gate if ((c = getchar()) == EOF) { 2196*0Sstevel@tonic-gate (void) printf("macdef:end of file encountered\n"); 2197*0Sstevel@tonic-gate code = -1; 2198*0Sstevel@tonic-gate return; 2199*0Sstevel@tonic-gate } 2200*0Sstevel@tonic-gate if ((*tmp = c) == '\n') { 2201*0Sstevel@tonic-gate if (tmp == macros[macnum].mac_start) { 2202*0Sstevel@tonic-gate macros[macnum++].mac_end = tmp; 2203*0Sstevel@tonic-gate code = 0; 2204*0Sstevel@tonic-gate return; 2205*0Sstevel@tonic-gate } 2206*0Sstevel@tonic-gate if (*(tmp-1) == '\0') { 2207*0Sstevel@tonic-gate macros[macnum++].mac_end = tmp - 1; 2208*0Sstevel@tonic-gate code = 0; 2209*0Sstevel@tonic-gate return; 2210*0Sstevel@tonic-gate } 2211*0Sstevel@tonic-gate *tmp = '\0'; 2212*0Sstevel@tonic-gate } 2213*0Sstevel@tonic-gate tmp++; 2214*0Sstevel@tonic-gate } 2215*0Sstevel@tonic-gate for (;;) { 2216*0Sstevel@tonic-gate while ((c = getchar()) != '\n' && c != EOF) 2217*0Sstevel@tonic-gate /* NULL */; 2218*0Sstevel@tonic-gate if (c == EOF || getchar() == '\n') { 2219*0Sstevel@tonic-gate (void) printf( 2220*0Sstevel@tonic-gate "Macro not defined - 4k buffer exceeded\n"); 2221*0Sstevel@tonic-gate code = -1; 2222*0Sstevel@tonic-gate return; 2223*0Sstevel@tonic-gate } 2224*0Sstevel@tonic-gate } 2225*0Sstevel@tonic-gate } 2226*0Sstevel@tonic-gate 2227*0Sstevel@tonic-gate /* 2228*0Sstevel@tonic-gate * The p_name strings are for the getlevel and setlevel commands. 2229*0Sstevel@tonic-gate * The name strings for printing are in the arpa/ftp.h file in the 2230*0Sstevel@tonic-gate * protnames[] array of strings. 2231*0Sstevel@tonic-gate */ 2232*0Sstevel@tonic-gate static struct levels { 2233*0Sstevel@tonic-gate char *p_name; 2234*0Sstevel@tonic-gate char *p_mode; 2235*0Sstevel@tonic-gate int p_level; 2236*0Sstevel@tonic-gate } levels[] = { 2237*0Sstevel@tonic-gate { "clear", "C", PROT_C }, 2238*0Sstevel@tonic-gate { "safe", "S", PROT_S }, 2239*0Sstevel@tonic-gate { "private", "P", PROT_P }, 2240*0Sstevel@tonic-gate NULL 2241*0Sstevel@tonic-gate }; 2242*0Sstevel@tonic-gate 2243*0Sstevel@tonic-gate /* 2244*0Sstevel@tonic-gate * Return a pointer to a string which is the readable version of the 2245*0Sstevel@tonic-gate * protection level, or NULL if the input level is not found. 2246*0Sstevel@tonic-gate */ 2247*0Sstevel@tonic-gate static char * 2248*0Sstevel@tonic-gate getlevel(int level) 2249*0Sstevel@tonic-gate { 2250*0Sstevel@tonic-gate struct levels *p; 2251*0Sstevel@tonic-gate 2252*0Sstevel@tonic-gate for (p = levels; (p != NULL) && (p->p_level != level); p++) 2253*0Sstevel@tonic-gate ; 2254*0Sstevel@tonic-gate return (p ? p->p_name : NULL); 2255*0Sstevel@tonic-gate } 2256*0Sstevel@tonic-gate 2257*0Sstevel@tonic-gate static char *plevel[] = { 2258*0Sstevel@tonic-gate "protect", 2259*0Sstevel@tonic-gate "", 2260*0Sstevel@tonic-gate NULL 2261*0Sstevel@tonic-gate }; 2262*0Sstevel@tonic-gate 2263*0Sstevel@tonic-gate /* 2264*0Sstevel@tonic-gate * Set control channel protection level. 2265*0Sstevel@tonic-gate */ 2266*0Sstevel@tonic-gate void 2267*0Sstevel@tonic-gate setclevel(int argc, char *argv[]) 2268*0Sstevel@tonic-gate { 2269*0Sstevel@tonic-gate struct levels *p; 2270*0Sstevel@tonic-gate char *levelp; 2271*0Sstevel@tonic-gate int comret; 2272*0Sstevel@tonic-gate 2273*0Sstevel@tonic-gate if (argc > 2) { 2274*0Sstevel@tonic-gate char *sep; 2275*0Sstevel@tonic-gate 2276*0Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]); 2277*0Sstevel@tonic-gate sep = " "; 2278*0Sstevel@tonic-gate for (p = levels; p->p_name; p++) { 2279*0Sstevel@tonic-gate (void) printf("%s%s", sep, p->p_name); 2280*0Sstevel@tonic-gate if (*sep == ' ') 2281*0Sstevel@tonic-gate sep = " | "; 2282*0Sstevel@tonic-gate } 2283*0Sstevel@tonic-gate (void) printf(" ]\n"); 2284*0Sstevel@tonic-gate code = -1; 2285*0Sstevel@tonic-gate return; 2286*0Sstevel@tonic-gate } 2287*0Sstevel@tonic-gate if (argc < 2) { 2288*0Sstevel@tonic-gate levelp = getlevel(clevel); 2289*0Sstevel@tonic-gate (void) printf("Using %s protection level for commands.\n", 2290*0Sstevel@tonic-gate levelp ? levelp : "<unknown>"); 2291*0Sstevel@tonic-gate code = 0; 2292*0Sstevel@tonic-gate return; 2293*0Sstevel@tonic-gate } 2294*0Sstevel@tonic-gate for (p = levels; (p != NULL) && (p->p_name); p++) 2295*0Sstevel@tonic-gate if (strcmp(argv[1], p->p_name) == 0) 2296*0Sstevel@tonic-gate break; 2297*0Sstevel@tonic-gate if (p->p_name == 0) { 2298*0Sstevel@tonic-gate (void) printf("%s: unknown protection level\n", argv[1]); 2299*0Sstevel@tonic-gate code = -1; 2300*0Sstevel@tonic-gate return; 2301*0Sstevel@tonic-gate } 2302*0Sstevel@tonic-gate if (auth_type == AUTHTYPE_NONE) { 2303*0Sstevel@tonic-gate if (strcmp(p->p_name, "clear")) 2304*0Sstevel@tonic-gate (void) printf("Cannot set protection level to %s\n", 2305*0Sstevel@tonic-gate argv[1]); 2306*0Sstevel@tonic-gate return; 2307*0Sstevel@tonic-gate } 2308*0Sstevel@tonic-gate if (strcmp(p->p_name, "clear") == 0) { 2309*0Sstevel@tonic-gate comret = command("CCC"); 2310*0Sstevel@tonic-gate if (comret == COMPLETE) 2311*0Sstevel@tonic-gate clevel = PROT_C; 2312*0Sstevel@tonic-gate return; 2313*0Sstevel@tonic-gate } 2314*0Sstevel@tonic-gate clevel = p->p_level; 2315*0Sstevel@tonic-gate (void) printf("Control channel protection level set to %s.\n", 2316*0Sstevel@tonic-gate p->p_name); 2317*0Sstevel@tonic-gate } 2318*0Sstevel@tonic-gate 2319*0Sstevel@tonic-gate /* 2320*0Sstevel@tonic-gate * Set data channel protection level. 2321*0Sstevel@tonic-gate */ 2322*0Sstevel@tonic-gate void 2323*0Sstevel@tonic-gate setdlevel(int argc, char *argv[]) 2324*0Sstevel@tonic-gate { 2325*0Sstevel@tonic-gate struct levels *p; 2326*0Sstevel@tonic-gate int comret; 2327*0Sstevel@tonic-gate 2328*0Sstevel@tonic-gate if (argc != 2) { 2329*0Sstevel@tonic-gate char *sep; 2330*0Sstevel@tonic-gate 2331*0Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]); 2332*0Sstevel@tonic-gate sep = " "; 2333*0Sstevel@tonic-gate for (p = levels; p->p_name; p++) { 2334*0Sstevel@tonic-gate (void) printf("%s%s", sep, p->p_name); 2335*0Sstevel@tonic-gate if (*sep == ' ') 2336*0Sstevel@tonic-gate sep = " | "; 2337*0Sstevel@tonic-gate } 2338*0Sstevel@tonic-gate (void) printf(" ]\n"); 2339*0Sstevel@tonic-gate code = -1; 2340*0Sstevel@tonic-gate return; 2341*0Sstevel@tonic-gate } 2342*0Sstevel@tonic-gate for (p = levels; p->p_name; p++) 2343*0Sstevel@tonic-gate if (strcmp(argv[1], p->p_name) == 0) 2344*0Sstevel@tonic-gate break; 2345*0Sstevel@tonic-gate if (p->p_name == 0) { 2346*0Sstevel@tonic-gate (void) printf("%s: unknown protection level\n", argv[1]); 2347*0Sstevel@tonic-gate code = -1; 2348*0Sstevel@tonic-gate return; 2349*0Sstevel@tonic-gate } 2350*0Sstevel@tonic-gate if (auth_type == AUTHTYPE_NONE) { 2351*0Sstevel@tonic-gate if (strcmp(p->p_name, "clear")) 2352*0Sstevel@tonic-gate (void) printf("Cannot set protection level to %s\n", 2353*0Sstevel@tonic-gate argv[1]); 2354*0Sstevel@tonic-gate return; 2355*0Sstevel@tonic-gate } 2356*0Sstevel@tonic-gate /* Start with a PBSZ of 1 meg */ 2357*0Sstevel@tonic-gate if (p->p_level != PROT_C) 2358*0Sstevel@tonic-gate setpbsz(1<<20); 2359*0Sstevel@tonic-gate comret = command("PROT %s", p->p_mode); 2360*0Sstevel@tonic-gate if (comret == COMPLETE) 2361*0Sstevel@tonic-gate dlevel = p->p_level; 2362*0Sstevel@tonic-gate } 2363*0Sstevel@tonic-gate 2364*0Sstevel@tonic-gate /* 2365*0Sstevel@tonic-gate * Set clear command protection level. 2366*0Sstevel@tonic-gate */ 2367*0Sstevel@tonic-gate /* VARARGS */ 2368*0Sstevel@tonic-gate void 2369*0Sstevel@tonic-gate ccc(int argc, char *argv[]) 2370*0Sstevel@tonic-gate { 2371*0Sstevel@tonic-gate plevel[1] = "clear"; 2372*0Sstevel@tonic-gate setclevel(2, plevel); 2373*0Sstevel@tonic-gate } 2374*0Sstevel@tonic-gate 2375*0Sstevel@tonic-gate /* 2376*0Sstevel@tonic-gate * Set clear data protection level. 2377*0Sstevel@tonic-gate */ 2378*0Sstevel@tonic-gate /* VARARGS */ 2379*0Sstevel@tonic-gate void 2380*0Sstevel@tonic-gate setclear(int argc, char *argv[]) 2381*0Sstevel@tonic-gate { 2382*0Sstevel@tonic-gate plevel[1] = "clear"; 2383*0Sstevel@tonic-gate setdlevel(2, plevel); 2384*0Sstevel@tonic-gate } 2385*0Sstevel@tonic-gate 2386*0Sstevel@tonic-gate /* 2387*0Sstevel@tonic-gate * Set safe data protection level. 2388*0Sstevel@tonic-gate */ 2389*0Sstevel@tonic-gate /* VARARGS */ 2390*0Sstevel@tonic-gate void 2391*0Sstevel@tonic-gate setsafe(int argc, char *argv[]) 2392*0Sstevel@tonic-gate { 2393*0Sstevel@tonic-gate plevel[1] = "safe"; 2394*0Sstevel@tonic-gate setdlevel(2, plevel); 2395*0Sstevel@tonic-gate } 2396*0Sstevel@tonic-gate 2397*0Sstevel@tonic-gate /* 2398*0Sstevel@tonic-gate * Set private data protection level. 2399*0Sstevel@tonic-gate */ 2400*0Sstevel@tonic-gate /* VARARGS */ 2401*0Sstevel@tonic-gate void 2402*0Sstevel@tonic-gate setprivate(int argc, char *argv[]) 2403*0Sstevel@tonic-gate { 2404*0Sstevel@tonic-gate plevel[1] = "private"; 2405*0Sstevel@tonic-gate setdlevel(2, plevel); 2406*0Sstevel@tonic-gate } 2407*0Sstevel@tonic-gate 2408*0Sstevel@tonic-gate /* 2409*0Sstevel@tonic-gate * Set mechanism type 2410*0Sstevel@tonic-gate */ 2411*0Sstevel@tonic-gate void 2412*0Sstevel@tonic-gate setmech(int argc, char *argv[]) 2413*0Sstevel@tonic-gate { 2414*0Sstevel@tonic-gate char tempmech[MECH_SZ]; 2415*0Sstevel@tonic-gate 2416*0Sstevel@tonic-gate if (argc < 2) { 2417*0Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "mech-type") == -1) { 2418*0Sstevel@tonic-gate code = -1; 2419*0Sstevel@tonic-gate return; 2420*0Sstevel@tonic-gate } 2421*0Sstevel@tonic-gate makeargv(); 2422*0Sstevel@tonic-gate argc = margc; 2423*0Sstevel@tonic-gate argv = margv; 2424*0Sstevel@tonic-gate } 2425*0Sstevel@tonic-gate 2426*0Sstevel@tonic-gate if (argc != 2) { 2427*0Sstevel@tonic-gate (void) printf("usage: %s [ mechanism type ]\n", argv[0]); 2428*0Sstevel@tonic-gate code = -1; 2429*0Sstevel@tonic-gate return; 2430*0Sstevel@tonic-gate } 2431*0Sstevel@tonic-gate 2432*0Sstevel@tonic-gate if ((strlcpy(tempmech, argv[1], MECH_SZ) >= MECH_SZ) || 2433*0Sstevel@tonic-gate __gss_mech_to_oid(tempmech, (gss_OID*)&mechoid) != 2434*0Sstevel@tonic-gate GSS_S_COMPLETE) { 2435*0Sstevel@tonic-gate (void) printf("%s: %s: not a valid security mechanism\n", 2436*0Sstevel@tonic-gate argv[0], tempmech); 2437*0Sstevel@tonic-gate code = -1; 2438*0Sstevel@tonic-gate return; 2439*0Sstevel@tonic-gate } else { 2440*0Sstevel@tonic-gate (void) strlcpy(mechstr, tempmech, MECH_SZ); 2441*0Sstevel@tonic-gate (void) printf("Using %s mechanism type\n", mechstr); 2442*0Sstevel@tonic-gate code = 0; 2443*0Sstevel@tonic-gate return; 2444*0Sstevel@tonic-gate } 2445*0Sstevel@tonic-gate } 2446