10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*2321Ssp149894 * Common Development and Distribution License (the "License").
6*2321Ssp149894 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*2321Ssp149894 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate * The Regents of the University of California
320Sstevel@tonic-gate * All Rights Reserved
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate * contributors.
370Sstevel@tonic-gate */
380Sstevel@tonic-gate
390Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
400Sstevel@tonic-gate
410Sstevel@tonic-gate
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate * FTP User Program -- Command Routines.
440Sstevel@tonic-gate */
450Sstevel@tonic-gate #define FTP_NAMES
460Sstevel@tonic-gate #include "ftp_var.h"
470Sstevel@tonic-gate
480Sstevel@tonic-gate FILE *tmp_nlst = NULL; /* tmp file; holds NLST results for mget, etc */
490Sstevel@tonic-gate
500Sstevel@tonic-gate static char *mname;
510Sstevel@tonic-gate static jmp_buf jabort;
520Sstevel@tonic-gate static jmp_buf abortprox;
530Sstevel@tonic-gate
540Sstevel@tonic-gate static char *remglob(char *argv[], int doswitch);
550Sstevel@tonic-gate static char *onoff(int bool);
560Sstevel@tonic-gate static int confirm(char *cmd, char *file);
570Sstevel@tonic-gate static int globulize(char **cpp);
580Sstevel@tonic-gate static void proxabort(int sig);
590Sstevel@tonic-gate static void mabort(int sig);
600Sstevel@tonic-gate static char *dotrans(char *name);
610Sstevel@tonic-gate static char *domap(char *name);
620Sstevel@tonic-gate static void getit(int argc, char *argv[], int restartit, char *mode);
630Sstevel@tonic-gate
640Sstevel@tonic-gate static char *getlevel(int);
650Sstevel@tonic-gate
660Sstevel@tonic-gate /* Prompt for command argument, add to buffer with space separator */
670Sstevel@tonic-gate static int
prompt_for_arg(char * buffer,int buffer_size,char * prompt)680Sstevel@tonic-gate prompt_for_arg(char *buffer, int buffer_size, char *prompt)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate if (strlen(buffer) > buffer_size - 2) {
710Sstevel@tonic-gate (void) printf("Line too long\n");
720Sstevel@tonic-gate return (-1);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate strcat(buffer, " ");
750Sstevel@tonic-gate stop_timer();
760Sstevel@tonic-gate (void) printf("(%s) ", prompt);
770Sstevel@tonic-gate if (fgets(buffer + strlen(buffer), buffer_size - strlen(buffer), stdin)
780Sstevel@tonic-gate == NULL) {
790Sstevel@tonic-gate reset_timer();
800Sstevel@tonic-gate return (-1);
810Sstevel@tonic-gate }
820Sstevel@tonic-gate
830Sstevel@tonic-gate /* Flush what didn't fit in the buffer */
840Sstevel@tonic-gate if (buffer[strlen(buffer)-1] != '\n') {
850Sstevel@tonic-gate while (fgetc(stdin) != '\n' && !ferror(stdin) && !feof(stdin))
860Sstevel@tonic-gate ;
870Sstevel@tonic-gate (void) printf("Line too long\n");
880Sstevel@tonic-gate reset_timer();
890Sstevel@tonic-gate return (-1);
900Sstevel@tonic-gate } else
910Sstevel@tonic-gate buffer[strlen(buffer)-1] = 0;
920Sstevel@tonic-gate
930Sstevel@tonic-gate reset_timer();
940Sstevel@tonic-gate return (0);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate
970Sstevel@tonic-gate
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate * Connect to peer server and
1000Sstevel@tonic-gate * auto-login, if possible.
1010Sstevel@tonic-gate */
1020Sstevel@tonic-gate void
setpeer(int argc,char * argv[])1030Sstevel@tonic-gate setpeer(int argc, char *argv[])
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate char *host;
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate if (connected) {
1080Sstevel@tonic-gate (void) printf("Already connected to %s, use close first.\n",
1090Sstevel@tonic-gate hostname);
1100Sstevel@tonic-gate code = -1;
1110Sstevel@tonic-gate return;
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate if (argc < 2) {
1140Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "to") == -1) {
1150Sstevel@tonic-gate code = -1;
1160Sstevel@tonic-gate return;
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate makeargv();
1190Sstevel@tonic-gate argc = margc;
1200Sstevel@tonic-gate argv = margv;
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate if (argc > 3 || argc < 2) {
1230Sstevel@tonic-gate (void) printf("usage: %s host-name [port]\n", argv[0]);
1240Sstevel@tonic-gate code = -1;
1250Sstevel@tonic-gate return;
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate strcpy(typename, "ascii");
1280Sstevel@tonic-gate host = hookup(argv[1], (argc > 2 ? argv[2] : "ftp"));
1290Sstevel@tonic-gate if (host) {
1300Sstevel@tonic-gate int overbose;
1310Sstevel@tonic-gate extern char reply_string[];
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate connected = 1;
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate * Set up defaults for FTP.
1360Sstevel@tonic-gate */
1370Sstevel@tonic-gate clevel = dlevel = PROT_C;
1380Sstevel@tonic-gate if (autoauth) {
1390Sstevel@tonic-gate if (do_auth() && autoencrypt) {
1400Sstevel@tonic-gate clevel = PROT_P;
1410Sstevel@tonic-gate setpbsz(1<<20);
1420Sstevel@tonic-gate if (command("PROT P") == COMPLETE)
1430Sstevel@tonic-gate dlevel = PROT_P;
1440Sstevel@tonic-gate else {
1450Sstevel@tonic-gate (void) fprintf(stderr,
1460Sstevel@tonic-gate "%s: couldn't enable encryption\n",
1470Sstevel@tonic-gate argv[0]);
1480Sstevel@tonic-gate /* unable to encrypt command channel, too! */
1490Sstevel@tonic-gate dlevel = clevel = PROT_C;
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate if ((auth_type != AUTHTYPE_NONE) && (clevel == PROT_C))
1530Sstevel@tonic-gate clevel = PROT_S;
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate if (autologin)
1570Sstevel@tonic-gate (void) login(argv[1]);
158*2321Ssp149894 /* if skipsyst is enabled, then don't send SYST command */
159*2321Ssp149894 if (skipsyst)
160*2321Ssp149894 return;
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate overbose = verbose;
1630Sstevel@tonic-gate if (debug == 0)
1640Sstevel@tonic-gate verbose = -1;
1650Sstevel@tonic-gate if (command("SYST") == COMPLETE && overbose) {
1660Sstevel@tonic-gate char *cp, c;
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate cp = index(reply_string+4, ' ');
1690Sstevel@tonic-gate if (cp == NULL)
1700Sstevel@tonic-gate cp = index(reply_string+4, '\r');
1710Sstevel@tonic-gate if (cp) {
1720Sstevel@tonic-gate if (cp[-1] == '.')
1730Sstevel@tonic-gate cp--;
1740Sstevel@tonic-gate c = *cp;
1750Sstevel@tonic-gate *cp = '\0';
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate (void) printf("Remote system type is %s.\n",
1790Sstevel@tonic-gate reply_string+4);
1800Sstevel@tonic-gate if (cp)
1810Sstevel@tonic-gate *cp = c;
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate if (strncmp(reply_string, "215 UNIX Type: L8", 17) == 0) {
1840Sstevel@tonic-gate setbinary(0, NULL);
1850Sstevel@tonic-gate if (overbose)
1860Sstevel@tonic-gate (void) printf(
1870Sstevel@tonic-gate "Using %s mode to transfer files.\n",
1880Sstevel@tonic-gate typename);
1890Sstevel@tonic-gate } else if (overbose &&
1900Sstevel@tonic-gate strncmp(reply_string, "215 TOPS20", 10) == 0) {
1910Sstevel@tonic-gate (void) printf(
1920Sstevel@tonic-gate "Remember to set tenex mode when transfering "
1930Sstevel@tonic-gate "binary files from this machine.\n");
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate verbose = overbose;
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate static struct types {
2000Sstevel@tonic-gate char *t_name;
2010Sstevel@tonic-gate char *t_mode;
2020Sstevel@tonic-gate int t_type;
2030Sstevel@tonic-gate char *t_arg;
2040Sstevel@tonic-gate } types[] = {
2050Sstevel@tonic-gate { "ascii", "A", TYPE_A, 0 },
2060Sstevel@tonic-gate { "binary", "I", TYPE_I, 0 },
2070Sstevel@tonic-gate { "image", "I", TYPE_I, 0 },
2080Sstevel@tonic-gate { "ebcdic", "E", TYPE_E, 0 },
2090Sstevel@tonic-gate { "tenex", "L", TYPE_L, bytename },
2100Sstevel@tonic-gate 0
2110Sstevel@tonic-gate };
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate /*
2140Sstevel@tonic-gate * Set transfer type.
2150Sstevel@tonic-gate */
2160Sstevel@tonic-gate void
settype(int argc,char * argv[])2170Sstevel@tonic-gate settype(int argc, char *argv[])
2180Sstevel@tonic-gate {
2190Sstevel@tonic-gate struct types *p;
2200Sstevel@tonic-gate int comret;
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate if (argc > 2) {
2230Sstevel@tonic-gate char *sep;
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]);
2260Sstevel@tonic-gate sep = " ";
2270Sstevel@tonic-gate for (p = types; p->t_name; p++) {
2280Sstevel@tonic-gate (void) printf("%s%s", sep, p->t_name);
2290Sstevel@tonic-gate if (*sep == ' ')
2300Sstevel@tonic-gate sep = " | ";
2310Sstevel@tonic-gate }
2320Sstevel@tonic-gate (void) printf(" ]\n");
2330Sstevel@tonic-gate code = -1;
2340Sstevel@tonic-gate return;
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate if (argc < 2) {
2370Sstevel@tonic-gate (void) printf("Using %s mode to transfer files.\n", typename);
2380Sstevel@tonic-gate code = 0;
2390Sstevel@tonic-gate return;
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate for (p = types; p->t_name; p++)
2420Sstevel@tonic-gate if (strcmp(argv[1], p->t_name) == 0)
2430Sstevel@tonic-gate break;
2440Sstevel@tonic-gate if (p->t_name == 0) {
2450Sstevel@tonic-gate (void) printf("%s: unknown mode\n", argv[1]);
2460Sstevel@tonic-gate code = -1;
2470Sstevel@tonic-gate return;
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
2500Sstevel@tonic-gate comret = command("TYPE %s %s", p->t_mode, p->t_arg);
2510Sstevel@tonic-gate else
2520Sstevel@tonic-gate comret = command("TYPE %s", p->t_mode);
2530Sstevel@tonic-gate if (comret == COMPLETE) {
2540Sstevel@tonic-gate (void) strcpy(typename, p->t_name);
2550Sstevel@tonic-gate type = p->t_type;
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate * Set binary transfer type.
2610Sstevel@tonic-gate */
2620Sstevel@tonic-gate /*ARGSUSED*/
2630Sstevel@tonic-gate void
setbinary(int argc,char * argv[])2640Sstevel@tonic-gate setbinary(int argc, char *argv[])
2650Sstevel@tonic-gate {
2660Sstevel@tonic-gate call(settype, "type", "binary", 0);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate /*
2700Sstevel@tonic-gate * Set ascii transfer type.
2710Sstevel@tonic-gate */
2720Sstevel@tonic-gate /*ARGSUSED*/
2730Sstevel@tonic-gate void
setascii(int argc,char * argv[])2740Sstevel@tonic-gate setascii(int argc, char *argv[])
2750Sstevel@tonic-gate {
2760Sstevel@tonic-gate call(settype, "type", "ascii", 0);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate /*
2800Sstevel@tonic-gate * Set tenex transfer type.
2810Sstevel@tonic-gate */
2820Sstevel@tonic-gate /*ARGSUSED*/
2830Sstevel@tonic-gate void
settenex(int argc,char * argv[])2840Sstevel@tonic-gate settenex(int argc, char *argv[])
2850Sstevel@tonic-gate {
2860Sstevel@tonic-gate call(settype, "type", "tenex", 0);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate /*
2900Sstevel@tonic-gate * Set ebcdic transfer type.
2910Sstevel@tonic-gate */
2920Sstevel@tonic-gate /*ARGSUSED*/
2930Sstevel@tonic-gate void
setebcdic(int argc,char * argv[])2940Sstevel@tonic-gate setebcdic(int argc, char *argv[])
2950Sstevel@tonic-gate {
2960Sstevel@tonic-gate call(settype, "type", "ebcdic", 0);
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate * Set file transfer mode.
3010Sstevel@tonic-gate */
3020Sstevel@tonic-gate /*ARGSUSED*/
3030Sstevel@tonic-gate void
setmode(int argc,char * argv[])3040Sstevel@tonic-gate setmode(int argc, char *argv[])
3050Sstevel@tonic-gate {
3060Sstevel@tonic-gate (void) printf("We only support %s mode, sorry.\n", modename);
3070Sstevel@tonic-gate code = -1;
3080Sstevel@tonic-gate }
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate /*
3110Sstevel@tonic-gate * Set file transfer format.
3120Sstevel@tonic-gate */
3130Sstevel@tonic-gate /*ARGSUSED*/
3140Sstevel@tonic-gate void
setform(int argc,char * argv[])3150Sstevel@tonic-gate setform(int argc, char *argv[])
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate (void) printf("We only support %s format, sorry.\n", formname);
3180Sstevel@tonic-gate code = -1;
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate /*
3220Sstevel@tonic-gate * Set file transfer structure.
3230Sstevel@tonic-gate */
3240Sstevel@tonic-gate /*ARGSUSED*/
3250Sstevel@tonic-gate void
setstruct(int argc,char * argv[])3260Sstevel@tonic-gate setstruct(int argc, char *argv[])
3270Sstevel@tonic-gate {
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate (void) printf("We only support %s structure, sorry.\n", structname);
3300Sstevel@tonic-gate code = -1;
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate /*
3340Sstevel@tonic-gate * Send a single file.
3350Sstevel@tonic-gate */
3360Sstevel@tonic-gate void
put(int argc,char * argv[])3370Sstevel@tonic-gate put(int argc, char *argv[])
3380Sstevel@tonic-gate {
3390Sstevel@tonic-gate char *cmd;
3400Sstevel@tonic-gate int loc = 0;
3410Sstevel@tonic-gate char *oldargv1;
3420Sstevel@tonic-gate
3430Sstevel@tonic-gate if (argc == 2) {
3440Sstevel@tonic-gate argc++;
3450Sstevel@tonic-gate argv[2] = argv[1];
3460Sstevel@tonic-gate loc++;
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate if (argc < 2) {
3490Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") == -1) {
3500Sstevel@tonic-gate code = -1;
3510Sstevel@tonic-gate return;
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate makeargv();
3540Sstevel@tonic-gate argc = margc;
3550Sstevel@tonic-gate argv = margv;
3560Sstevel@tonic-gate }
3570Sstevel@tonic-gate if (argc < 2) {
3580Sstevel@tonic-gate usage:
3590Sstevel@tonic-gate (void) printf("usage: %s local-file remote-file\n", argv[0]);
3600Sstevel@tonic-gate code = -1;
3610Sstevel@tonic-gate return;
3620Sstevel@tonic-gate }
3630Sstevel@tonic-gate if (argc < 3) {
3640Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") == -1) {
3650Sstevel@tonic-gate code = -1;
3660Sstevel@tonic-gate return;
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate makeargv();
3690Sstevel@tonic-gate argc = margc;
3700Sstevel@tonic-gate argv = margv;
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate if (argc < 3)
3730Sstevel@tonic-gate goto usage;
3740Sstevel@tonic-gate oldargv1 = argv[1];
3750Sstevel@tonic-gate if (!globulize(&argv[1])) {
3760Sstevel@tonic-gate code = -1;
3770Sstevel@tonic-gate return;
3780Sstevel@tonic-gate }
3790Sstevel@tonic-gate /*
3800Sstevel@tonic-gate * If "globulize" modifies argv[1], and argv[2] is a copy of
3810Sstevel@tonic-gate * the old argv[1], make it a copy of the new argv[1].
3820Sstevel@tonic-gate */
3830Sstevel@tonic-gate if (argv[1] != oldargv1 && argv[2] == oldargv1) {
3840Sstevel@tonic-gate argv[2] = argv[1];
3850Sstevel@tonic-gate }
3860Sstevel@tonic-gate cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
3870Sstevel@tonic-gate if (loc && ntflag) {
3880Sstevel@tonic-gate argv[2] = dotrans(argv[2]);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate if (loc && mapflag) {
3910Sstevel@tonic-gate argv[2] = domap(argv[2]);
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate sendrequest(cmd, argv[1], argv[2], 1);
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate /*ARGSUSED*/
3970Sstevel@tonic-gate static void
mabort(int sig)3980Sstevel@tonic-gate mabort(int sig)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate int ointer;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate (void) printf("\n");
4030Sstevel@tonic-gate (void) fflush(stdout);
4040Sstevel@tonic-gate if (mflag && fromatty) {
4050Sstevel@tonic-gate ointer = interactive;
4060Sstevel@tonic-gate interactive = 1;
4070Sstevel@tonic-gate if (confirm("Continue with", mname)) {
4080Sstevel@tonic-gate interactive = ointer;
4090Sstevel@tonic-gate longjmp(jabort, 0);
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate interactive = ointer;
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate mflag = 0;
4140Sstevel@tonic-gate longjmp(jabort, 0);
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate /*
4180Sstevel@tonic-gate * Send multiple files.
4190Sstevel@tonic-gate */
4200Sstevel@tonic-gate void
mput(int argc,char * argv[])4210Sstevel@tonic-gate mput(int argc, char *argv[])
4220Sstevel@tonic-gate {
4230Sstevel@tonic-gate int i;
4240Sstevel@tonic-gate int ointer;
4250Sstevel@tonic-gate void (*oldintr)();
4260Sstevel@tonic-gate char *tp;
4270Sstevel@tonic-gate int len;
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate if (argc < 2) {
4300Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-files") == -1) {
4310Sstevel@tonic-gate code = -1;
4320Sstevel@tonic-gate return;
4330Sstevel@tonic-gate }
4340Sstevel@tonic-gate makeargv();
4350Sstevel@tonic-gate argc = margc;
4360Sstevel@tonic-gate argv = margv;
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate if (argc < 2) {
4390Sstevel@tonic-gate (void) printf("usage: %s local-files\n", argv[0]);
4400Sstevel@tonic-gate code = -1;
4410Sstevel@tonic-gate return;
4420Sstevel@tonic-gate }
4430Sstevel@tonic-gate mname = argv[0];
4440Sstevel@tonic-gate mflag = 1;
4450Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
4460Sstevel@tonic-gate (void) setjmp(jabort);
4470Sstevel@tonic-gate if (proxy) {
4480Sstevel@tonic-gate char *cp, *tp2, tmpbuf[MAXPATHLEN];
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate while ((cp = remglob(argv, 0)) != NULL) {
4510Sstevel@tonic-gate if (*cp == 0) {
4520Sstevel@tonic-gate mflag = 0;
4530Sstevel@tonic-gate continue;
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) {
4560Sstevel@tonic-gate tp = cp;
4570Sstevel@tonic-gate if (mcase) {
4580Sstevel@tonic-gate while (*tp) {
4590Sstevel@tonic-gate if ((len =
4600Sstevel@tonic-gate mblen(tp, MB_CUR_MAX)) <= 0)
4610Sstevel@tonic-gate len = 1;
4620Sstevel@tonic-gate if (islower(*tp))
4630Sstevel@tonic-gate break;
4640Sstevel@tonic-gate tp += len;
4650Sstevel@tonic-gate }
4660Sstevel@tonic-gate if (!*tp) {
4670Sstevel@tonic-gate tp = cp;
4680Sstevel@tonic-gate tp2 = tmpbuf;
4690Sstevel@tonic-gate while (*tp) {
4700Sstevel@tonic-gate if ((len = mblen(tp,
4710Sstevel@tonic-gate MB_CUR_MAX)) <= 0)
4720Sstevel@tonic-gate len = 1;
4730Sstevel@tonic-gate memcpy(tp2, tp, len);
4740Sstevel@tonic-gate if (isupper(*tp2)) {
4750Sstevel@tonic-gate *tp2 = 'a' +
4760Sstevel@tonic-gate *tp2 - 'A';
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate tp += len;
4790Sstevel@tonic-gate tp2 += len;
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate *tp2 = 0;
4820Sstevel@tonic-gate tp = tmpbuf;
4830Sstevel@tonic-gate }
4840Sstevel@tonic-gate }
4850Sstevel@tonic-gate if (ntflag) {
4860Sstevel@tonic-gate tp = dotrans(tp);
4870Sstevel@tonic-gate }
4880Sstevel@tonic-gate if (mapflag) {
4890Sstevel@tonic-gate tp = domap(tp);
4900Sstevel@tonic-gate }
4910Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR",
4920Sstevel@tonic-gate cp, tp, 0);
4930Sstevel@tonic-gate if (!mflag && fromatty) {
4940Sstevel@tonic-gate ointer = interactive;
4950Sstevel@tonic-gate interactive = 1;
4960Sstevel@tonic-gate if (confirm("Continue with", "mput")) {
4970Sstevel@tonic-gate mflag++;
4980Sstevel@tonic-gate }
4990Sstevel@tonic-gate interactive = ointer;
5000Sstevel@tonic-gate }
5010Sstevel@tonic-gate }
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
5040Sstevel@tonic-gate mflag = 0;
5050Sstevel@tonic-gate return;
5060Sstevel@tonic-gate }
5070Sstevel@tonic-gate for (i = 1; i < argc; i++) {
5080Sstevel@tonic-gate char **cpp, **gargs;
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate if (!doglob) {
5110Sstevel@tonic-gate if (mflag && confirm(argv[0], argv[i])) {
5120Sstevel@tonic-gate tp = (ntflag) ? dotrans(argv[i]) : argv[i];
5130Sstevel@tonic-gate tp = (mapflag) ? domap(tp) : tp;
5140Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR",
5150Sstevel@tonic-gate argv[i], tp, 1);
5160Sstevel@tonic-gate if (!mflag && fromatty) {
5170Sstevel@tonic-gate ointer = interactive;
5180Sstevel@tonic-gate interactive = 1;
5190Sstevel@tonic-gate if (confirm("Continue with", "mput")) {
5200Sstevel@tonic-gate mflag++;
5210Sstevel@tonic-gate }
5220Sstevel@tonic-gate interactive = ointer;
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate }
5250Sstevel@tonic-gate continue;
5260Sstevel@tonic-gate }
5270Sstevel@tonic-gate gargs = glob(argv[i]);
5280Sstevel@tonic-gate if (globerr != NULL) {
5290Sstevel@tonic-gate (void) printf("%s\n", globerr);
5300Sstevel@tonic-gate if (gargs)
5310Sstevel@tonic-gate blkfree(gargs);
5320Sstevel@tonic-gate continue;
5330Sstevel@tonic-gate }
5340Sstevel@tonic-gate for (cpp = gargs; cpp && *cpp != NULL; cpp++) {
5350Sstevel@tonic-gate if (mflag && confirm(argv[0], *cpp)) {
5360Sstevel@tonic-gate tp = (ntflag) ? dotrans(*cpp) : *cpp;
5370Sstevel@tonic-gate tp = (mapflag) ? domap(tp) : tp;
5380Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR",
5390Sstevel@tonic-gate *cpp, tp, 0);
5400Sstevel@tonic-gate if (!mflag && fromatty) {
5410Sstevel@tonic-gate ointer = interactive;
5420Sstevel@tonic-gate interactive = 1;
5430Sstevel@tonic-gate if (confirm("Continue with", "mput")) {
5440Sstevel@tonic-gate mflag++;
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate interactive = ointer;
5470Sstevel@tonic-gate }
5480Sstevel@tonic-gate }
5490Sstevel@tonic-gate }
5500Sstevel@tonic-gate if (gargs != NULL)
5510Sstevel@tonic-gate blkfree(gargs);
5520Sstevel@tonic-gate }
5530Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
5540Sstevel@tonic-gate mflag = 0;
5550Sstevel@tonic-gate }
5560Sstevel@tonic-gate
5570Sstevel@tonic-gate /*
5580Sstevel@tonic-gate * Restart transfer at a specific offset.
5590Sstevel@tonic-gate */
5600Sstevel@tonic-gate void
restart(int argc,char * argv[])5610Sstevel@tonic-gate restart(int argc, char *argv[])
5620Sstevel@tonic-gate {
5630Sstevel@tonic-gate off_t orestart_point = restart_point;
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate if (argc > 2) {
5660Sstevel@tonic-gate (void) printf("usage: %s [marker]\n", argv[0]);
5670Sstevel@tonic-gate code = -1;
5680Sstevel@tonic-gate return;
5690Sstevel@tonic-gate }
5700Sstevel@tonic-gate if (argc == 2) {
5710Sstevel@tonic-gate longlong_t rp;
5720Sstevel@tonic-gate char *endp;
5730Sstevel@tonic-gate
5740Sstevel@tonic-gate errno = 0;
5750Sstevel@tonic-gate rp = strtoll(argv[1], &endp, 10);
5760Sstevel@tonic-gate if (errno || rp < 0 || *endp != '\0')
5770Sstevel@tonic-gate (void) printf("%s: Invalid offset `%s'\n",
5780Sstevel@tonic-gate argv[0], argv[1]);
5790Sstevel@tonic-gate else
5800Sstevel@tonic-gate restart_point = rp;
5810Sstevel@tonic-gate }
5820Sstevel@tonic-gate if (restart_point == 0) {
5830Sstevel@tonic-gate if (orestart_point == 0)
5840Sstevel@tonic-gate (void) printf("No restart marker defined\n");
5850Sstevel@tonic-gate else
5860Sstevel@tonic-gate (void) printf("Restart marker cleared\n");
5870Sstevel@tonic-gate } else
5880Sstevel@tonic-gate (void) printf(
5890Sstevel@tonic-gate "Restarting at %lld for next get, put or append\n",
5900Sstevel@tonic-gate (longlong_t)restart_point);
5910Sstevel@tonic-gate }
5920Sstevel@tonic-gate
5930Sstevel@tonic-gate void
reget(int argc,char * argv[])5940Sstevel@tonic-gate reget(int argc, char *argv[])
5950Sstevel@tonic-gate {
5960Sstevel@tonic-gate getit(argc, argv, 1, "r+w");
5970Sstevel@tonic-gate }
5980Sstevel@tonic-gate
5990Sstevel@tonic-gate void
get(int argc,char * argv[])6000Sstevel@tonic-gate get(int argc, char *argv[])
6010Sstevel@tonic-gate {
6020Sstevel@tonic-gate getit(argc, argv, 0, restart_point ? "r+w" : "w");
6030Sstevel@tonic-gate }
6040Sstevel@tonic-gate
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate * Receive one file.
6070Sstevel@tonic-gate */
6080Sstevel@tonic-gate static void
getit(int argc,char * argv[],int restartit,char * mode)6090Sstevel@tonic-gate getit(int argc, char *argv[], int restartit, char *mode)
6100Sstevel@tonic-gate {
6110Sstevel@tonic-gate int loc = 0;
6120Sstevel@tonic-gate int len;
6130Sstevel@tonic-gate int allowpipe = 1;
6140Sstevel@tonic-gate
6150Sstevel@tonic-gate if (argc == 2) {
6160Sstevel@tonic-gate argc++;
6170Sstevel@tonic-gate argv[2] = argv[1];
6180Sstevel@tonic-gate /* Only permit !file if two arguments. */
6190Sstevel@tonic-gate allowpipe = 0;
6200Sstevel@tonic-gate loc++;
6210Sstevel@tonic-gate }
6220Sstevel@tonic-gate if (argc < 2) {
6230Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") == -1) {
6240Sstevel@tonic-gate code = -1;
6250Sstevel@tonic-gate return;
6260Sstevel@tonic-gate }
6270Sstevel@tonic-gate makeargv();
6280Sstevel@tonic-gate argc = margc;
6290Sstevel@tonic-gate argv = margv;
6300Sstevel@tonic-gate }
6310Sstevel@tonic-gate if (argc < 2) {
6320Sstevel@tonic-gate usage:
6330Sstevel@tonic-gate (void) printf("usage: %s remote-file [ local-file ]\n",
6340Sstevel@tonic-gate argv[0]);
6350Sstevel@tonic-gate code = -1;
6360Sstevel@tonic-gate return;
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate if (argc < 3) {
6390Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") == -1) {
6400Sstevel@tonic-gate code = -1;
6410Sstevel@tonic-gate return;
6420Sstevel@tonic-gate }
6430Sstevel@tonic-gate makeargv();
6440Sstevel@tonic-gate argc = margc;
6450Sstevel@tonic-gate argv = margv;
6460Sstevel@tonic-gate }
6470Sstevel@tonic-gate if (argc < 3)
6480Sstevel@tonic-gate goto usage;
6490Sstevel@tonic-gate if (!globulize(&argv[2])) {
6500Sstevel@tonic-gate code = -1;
6510Sstevel@tonic-gate return;
6520Sstevel@tonic-gate }
6530Sstevel@tonic-gate if (loc && mcase) {
6540Sstevel@tonic-gate char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
6550Sstevel@tonic-gate
6560Sstevel@tonic-gate while (*tp) {
6570Sstevel@tonic-gate if ((len = mblen(tp, MB_CUR_MAX)) <= 0)
6580Sstevel@tonic-gate len = 1;
6590Sstevel@tonic-gate if (islower(*tp))
6600Sstevel@tonic-gate break;
6610Sstevel@tonic-gate tp += len;
6620Sstevel@tonic-gate }
6630Sstevel@tonic-gate if (!*tp) {
6640Sstevel@tonic-gate tp = argv[2];
6650Sstevel@tonic-gate tp2 = tmpbuf;
6660Sstevel@tonic-gate while (*tp) {
6670Sstevel@tonic-gate if ((len = mblen(tp, MB_CUR_MAX)) <= 0)
6680Sstevel@tonic-gate len = 1;
6690Sstevel@tonic-gate memcpy(tp2, tp, len);
6700Sstevel@tonic-gate if (isupper(*tp2))
6710Sstevel@tonic-gate *tp2 = 'a' + *tp2 - 'A';
6720Sstevel@tonic-gate tp += len;
6730Sstevel@tonic-gate tp2 += len;
6740Sstevel@tonic-gate }
6750Sstevel@tonic-gate *tp2 = 0;
6760Sstevel@tonic-gate argv[2] = tmpbuf;
6770Sstevel@tonic-gate }
6780Sstevel@tonic-gate }
6790Sstevel@tonic-gate if (loc && ntflag) {
6800Sstevel@tonic-gate argv[2] = dotrans(argv[2]);
6810Sstevel@tonic-gate }
6820Sstevel@tonic-gate if (loc && mapflag) {
6830Sstevel@tonic-gate argv[2] = domap(argv[2]);
6840Sstevel@tonic-gate }
6850Sstevel@tonic-gate if (restartit) {
6860Sstevel@tonic-gate struct stat stbuf;
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate if (stat(argv[2], &stbuf) < 0) {
6890Sstevel@tonic-gate perror(argv[2]);
6900Sstevel@tonic-gate code = -1;
6910Sstevel@tonic-gate return;
6920Sstevel@tonic-gate }
6930Sstevel@tonic-gate restart_point = stbuf.st_size;
6940Sstevel@tonic-gate }
6950Sstevel@tonic-gate recvrequest("RETR", argv[2], argv[1], mode, allowpipe);
6960Sstevel@tonic-gate restart_point = 0;
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate
6990Sstevel@tonic-gate /*
7000Sstevel@tonic-gate * Get multiple files.
7010Sstevel@tonic-gate */
7020Sstevel@tonic-gate void
mget(int argc,char * argv[])7030Sstevel@tonic-gate mget(int argc, char *argv[])
7040Sstevel@tonic-gate {
7050Sstevel@tonic-gate char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN];
7060Sstevel@tonic-gate int ointer;
7070Sstevel@tonic-gate void (*oldintr)();
7080Sstevel@tonic-gate int need_convert;
7090Sstevel@tonic-gate int len;
7100Sstevel@tonic-gate
7110Sstevel@tonic-gate if (argc < 2) {
7120Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) {
7130Sstevel@tonic-gate code = -1;
7140Sstevel@tonic-gate return;
7150Sstevel@tonic-gate }
7160Sstevel@tonic-gate makeargv();
7170Sstevel@tonic-gate argc = margc;
7180Sstevel@tonic-gate argv = margv;
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate if (argc < 2) {
7210Sstevel@tonic-gate (void) printf("usage: %s remote-files\n", argv[0]);
7220Sstevel@tonic-gate code = -1;
7230Sstevel@tonic-gate return;
7240Sstevel@tonic-gate }
7250Sstevel@tonic-gate mname = argv[0];
7260Sstevel@tonic-gate mflag = 1;
7270Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
7280Sstevel@tonic-gate (void) setjmp(jabort);
7290Sstevel@tonic-gate while ((cp = remglob(argv, proxy)) != NULL) {
7300Sstevel@tonic-gate if (*cp == '\0') {
7310Sstevel@tonic-gate mflag = 0;
7320Sstevel@tonic-gate continue;
7330Sstevel@tonic-gate }
7340Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) {
7350Sstevel@tonic-gate strcpy(tmpbuf, cp);
7360Sstevel@tonic-gate tp = tmpbuf;
7370Sstevel@tonic-gate need_convert = 1;
7380Sstevel@tonic-gate if (mcase) {
7390Sstevel@tonic-gate tp2 = tp;
7400Sstevel@tonic-gate while (*tp2 && need_convert) {
7410Sstevel@tonic-gate /* Need any case convert? */
7420Sstevel@tonic-gate if (islower(*tp2))
7430Sstevel@tonic-gate need_convert = 0;
7440Sstevel@tonic-gate if ((len = mblen(tp2, MB_CUR_MAX)) <= 0)
7450Sstevel@tonic-gate len = 1;
7460Sstevel@tonic-gate tp2 += len;
7470Sstevel@tonic-gate }
7480Sstevel@tonic-gate tp2 = tp;
7490Sstevel@tonic-gate while (need_convert && *tp2) {
7500Sstevel@tonic-gate /* Convert to lower case */
7510Sstevel@tonic-gate if (isupper(*tp2))
7520Sstevel@tonic-gate *tp2 = tolower(*tp2);
7530Sstevel@tonic-gate if ((len = mblen(tp2, MB_CUR_MAX)) <= 0)
7540Sstevel@tonic-gate len = 1;
7550Sstevel@tonic-gate tp2 += len;
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate if (ntflag) {
7600Sstevel@tonic-gate tp = dotrans(tp);
7610Sstevel@tonic-gate }
7620Sstevel@tonic-gate if (mapflag) {
7630Sstevel@tonic-gate tp = domap(tp);
7640Sstevel@tonic-gate }
7650Sstevel@tonic-gate recvrequest("RETR", tp, cp, "w", 0);
7660Sstevel@tonic-gate restart_point = 0;
7670Sstevel@tonic-gate if (!mflag && fromatty) {
7680Sstevel@tonic-gate ointer = interactive;
7690Sstevel@tonic-gate interactive = 1;
7700Sstevel@tonic-gate if (confirm("Continue with", "mget")) {
7710Sstevel@tonic-gate mflag++;
7720Sstevel@tonic-gate }
7730Sstevel@tonic-gate interactive = ointer;
7740Sstevel@tonic-gate }
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate }
7770Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
7780Sstevel@tonic-gate mflag = 0;
7790Sstevel@tonic-gate }
7800Sstevel@tonic-gate
7810Sstevel@tonic-gate static char *
remglob(char * argv[],int doswitch)7820Sstevel@tonic-gate remglob(char *argv[], int doswitch)
7830Sstevel@tonic-gate {
7840Sstevel@tonic-gate static char buf[MAXPATHLEN];
7850Sstevel@tonic-gate static char **args;
7860Sstevel@tonic-gate int oldverbose, oldhash;
7870Sstevel@tonic-gate char *cp;
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate if (!mflag) {
7900Sstevel@tonic-gate if (!doglob) {
7910Sstevel@tonic-gate args = NULL;
7920Sstevel@tonic-gate } else {
7930Sstevel@tonic-gate if (tmp_nlst != NULL) {
7940Sstevel@tonic-gate (void) fclose(tmp_nlst);
7950Sstevel@tonic-gate tmp_nlst = NULL;
7960Sstevel@tonic-gate }
7970Sstevel@tonic-gate }
7980Sstevel@tonic-gate return (NULL);
7990Sstevel@tonic-gate }
8000Sstevel@tonic-gate if (!doglob) {
8010Sstevel@tonic-gate if (args == NULL)
8020Sstevel@tonic-gate args = argv;
8030Sstevel@tonic-gate if ((cp = *++args) == NULL)
8040Sstevel@tonic-gate args = NULL;
8050Sstevel@tonic-gate return (cp);
8060Sstevel@tonic-gate }
8070Sstevel@tonic-gate if (tmp_nlst == NULL) {
8080Sstevel@tonic-gate if ((tmp_nlst = tmpfile()) == NULL) {
8090Sstevel@tonic-gate (void) printf("%s\n", strerror(errno));
8100Sstevel@tonic-gate return (NULL);
8110Sstevel@tonic-gate }
8120Sstevel@tonic-gate oldverbose = verbose, verbose = 0;
8130Sstevel@tonic-gate oldhash = hash, hash = 0;
8140Sstevel@tonic-gate if (doswitch) {
8150Sstevel@tonic-gate pswitch(!proxy);
8160Sstevel@tonic-gate }
8170Sstevel@tonic-gate for (; *++argv != NULL; )
8180Sstevel@tonic-gate recvrequest("NLST", NULL, *argv, "", 0);
8190Sstevel@tonic-gate rewind(tmp_nlst);
8200Sstevel@tonic-gate if (doswitch) {
8210Sstevel@tonic-gate pswitch(!proxy);
8220Sstevel@tonic-gate }
8230Sstevel@tonic-gate verbose = oldverbose; hash = oldhash;
8240Sstevel@tonic-gate }
8250Sstevel@tonic-gate reset_timer();
8260Sstevel@tonic-gate if (fgets(buf, sizeof (buf), tmp_nlst) == NULL) {
8270Sstevel@tonic-gate (void) fclose(tmp_nlst), tmp_nlst = NULL;
8280Sstevel@tonic-gate return (NULL);
8290Sstevel@tonic-gate }
8300Sstevel@tonic-gate if ((cp = index(buf, '\n')) != NULL)
8310Sstevel@tonic-gate *cp = '\0';
8320Sstevel@tonic-gate return (buf);
8330Sstevel@tonic-gate }
8340Sstevel@tonic-gate
8350Sstevel@tonic-gate static char *
onoff(int bool)8360Sstevel@tonic-gate onoff(int bool)
8370Sstevel@tonic-gate {
8380Sstevel@tonic-gate return (bool ? "on" : "off");
8390Sstevel@tonic-gate }
8400Sstevel@tonic-gate
8410Sstevel@tonic-gate /*
8420Sstevel@tonic-gate * Show status.
8430Sstevel@tonic-gate */
8440Sstevel@tonic-gate /*ARGSUSED*/
8450Sstevel@tonic-gate void
status(int argc,char * argv[])8460Sstevel@tonic-gate status(int argc, char *argv[])
8470Sstevel@tonic-gate {
8480Sstevel@tonic-gate int i;
8490Sstevel@tonic-gate char *levelp;
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate if (connected)
8520Sstevel@tonic-gate (void) printf("Connected to %s.\n", hostname);
8530Sstevel@tonic-gate else
8540Sstevel@tonic-gate (void) printf("Not connected.\n");
8550Sstevel@tonic-gate if (!proxy) {
8560Sstevel@tonic-gate pswitch(1);
8570Sstevel@tonic-gate if (connected) {
8580Sstevel@tonic-gate (void) printf("Connected for proxy commands to %s.\n",
8590Sstevel@tonic-gate hostname);
8600Sstevel@tonic-gate } else {
8610Sstevel@tonic-gate (void) printf("No proxy connection.\n");
8620Sstevel@tonic-gate }
8630Sstevel@tonic-gate pswitch(0);
8640Sstevel@tonic-gate }
8650Sstevel@tonic-gate
8660Sstevel@tonic-gate if (auth_type != AUTHTYPE_NONE)
8670Sstevel@tonic-gate (void) printf("Authentication type: %s\n",
8680Sstevel@tonic-gate GSS_AUTHTYPE_NAME(auth_type));
8690Sstevel@tonic-gate else
8700Sstevel@tonic-gate (void) printf("Not authenticated.\n");
8710Sstevel@tonic-gate (void) printf("Mechanism: %s\n", mechstr);
8720Sstevel@tonic-gate (void) printf("Autoauth: %s; Autologin: %s\n",
8730Sstevel@tonic-gate onoff(autoauth), onoff(autologin));
8740Sstevel@tonic-gate levelp = getlevel(clevel);
8750Sstevel@tonic-gate (void) printf("Control Channel Protection Level: %s\n",
8760Sstevel@tonic-gate levelp ? levelp : "<unknown>");
8770Sstevel@tonic-gate levelp = getlevel(dlevel);
8780Sstevel@tonic-gate (void) printf("Data Channel Protection Level: %s\n",
8790Sstevel@tonic-gate levelp ? levelp : "<unknown>");
8800Sstevel@tonic-gate
8810Sstevel@tonic-gate (void) printf("Passive mode: %s.\n", onoff(passivemode));
8820Sstevel@tonic-gate (void) printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n",
8830Sstevel@tonic-gate modename, typename, formname, structname);
8840Sstevel@tonic-gate (void) printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n",
8850Sstevel@tonic-gate onoff(verbose), onoff(bell), onoff(interactive),
8860Sstevel@tonic-gate onoff(doglob));
8870Sstevel@tonic-gate (void) printf("Store unique: %s; Receive unique: %s\n", onoff(sunique),
8880Sstevel@tonic-gate onoff(runique));
8890Sstevel@tonic-gate (void) printf("Case: %s; CR stripping: %s\n",
8900Sstevel@tonic-gate onoff(mcase), onoff(crflag));
8910Sstevel@tonic-gate if (ntflag) {
8920Sstevel@tonic-gate (void) printf("Ntrans: (in) %s (out) %s\n", ntin, ntout);
8930Sstevel@tonic-gate } else {
8940Sstevel@tonic-gate (void) printf("Ntrans: off\n");
8950Sstevel@tonic-gate }
8960Sstevel@tonic-gate if (mapflag) {
8970Sstevel@tonic-gate (void) printf("Nmap: (in) %s (out) %s\n", mapin, mapout);
8980Sstevel@tonic-gate } else {
8990Sstevel@tonic-gate (void) printf("Nmap: off\n");
9000Sstevel@tonic-gate }
9010Sstevel@tonic-gate (void) printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
9020Sstevel@tonic-gate onoff(hash), onoff(sendport));
9030Sstevel@tonic-gate if (macnum > 0) {
9040Sstevel@tonic-gate (void) printf("Macros:\n");
9050Sstevel@tonic-gate for (i = 0; i < macnum; i++) {
9060Sstevel@tonic-gate (void) printf("\t%s\n", macros[i].mac_name);
9070Sstevel@tonic-gate }
9080Sstevel@tonic-gate }
9090Sstevel@tonic-gate code = 0;
9100Sstevel@tonic-gate }
9110Sstevel@tonic-gate
9120Sstevel@tonic-gate /*
9130Sstevel@tonic-gate * Set beep on cmd completed mode.
9140Sstevel@tonic-gate */
9150Sstevel@tonic-gate /*ARGSUSED*/
9160Sstevel@tonic-gate void
setbell(int argc,char * argv[])9170Sstevel@tonic-gate setbell(int argc, char *argv[])
9180Sstevel@tonic-gate {
9190Sstevel@tonic-gate bell = !bell;
9200Sstevel@tonic-gate (void) printf("Bell mode %s.\n", onoff(bell));
9210Sstevel@tonic-gate code = bell;
9220Sstevel@tonic-gate }
9230Sstevel@tonic-gate
9240Sstevel@tonic-gate /*
9250Sstevel@tonic-gate * Turn on packet tracing.
9260Sstevel@tonic-gate */
9270Sstevel@tonic-gate /*ARGSUSED*/
9280Sstevel@tonic-gate void
settrace(int argc,char * argv[])9290Sstevel@tonic-gate settrace(int argc, char *argv[])
9300Sstevel@tonic-gate {
9310Sstevel@tonic-gate trace = !trace;
9320Sstevel@tonic-gate (void) printf("Packet tracing %s.\n", onoff(trace));
9330Sstevel@tonic-gate code = trace;
9340Sstevel@tonic-gate }
9350Sstevel@tonic-gate
9360Sstevel@tonic-gate /*
9370Sstevel@tonic-gate * Toggle hash mark printing during transfers.
9380Sstevel@tonic-gate */
9390Sstevel@tonic-gate /*ARGSUSED*/
9400Sstevel@tonic-gate void
sethash(int argc,char * argv[])9410Sstevel@tonic-gate sethash(int argc, char *argv[])
9420Sstevel@tonic-gate {
9430Sstevel@tonic-gate hash = !hash;
9440Sstevel@tonic-gate (void) printf("Hash mark printing %s", onoff(hash));
9450Sstevel@tonic-gate code = hash;
9460Sstevel@tonic-gate if (hash)
9470Sstevel@tonic-gate (void) printf(" (%d bytes/hash mark)", HASHSIZ);
9480Sstevel@tonic-gate (void) printf(".\n");
9490Sstevel@tonic-gate }
9500Sstevel@tonic-gate
9510Sstevel@tonic-gate /*
9520Sstevel@tonic-gate * Turn on printing of server echo's.
9530Sstevel@tonic-gate */
9540Sstevel@tonic-gate /*ARGSUSED*/
9550Sstevel@tonic-gate void
setverbose(int argc,char * argv[])9560Sstevel@tonic-gate setverbose(int argc, char *argv[])
9570Sstevel@tonic-gate {
9580Sstevel@tonic-gate verbose = !verbose;
9590Sstevel@tonic-gate (void) printf("Verbose mode %s.\n", onoff(verbose));
9600Sstevel@tonic-gate code = verbose;
9610Sstevel@tonic-gate }
9620Sstevel@tonic-gate
9630Sstevel@tonic-gate /*
9640Sstevel@tonic-gate * Toggle PORT cmd use before each data connection.
9650Sstevel@tonic-gate */
9660Sstevel@tonic-gate /*ARGSUSED*/
9670Sstevel@tonic-gate void
setport(int argc,char * argv[])9680Sstevel@tonic-gate setport(int argc, char *argv[])
9690Sstevel@tonic-gate {
9700Sstevel@tonic-gate sendport = !sendport;
9710Sstevel@tonic-gate (void) printf("Use of PORT cmds %s.\n", onoff(sendport));
9720Sstevel@tonic-gate code = sendport;
9730Sstevel@tonic-gate }
9740Sstevel@tonic-gate
9750Sstevel@tonic-gate /*
9760Sstevel@tonic-gate * Turn on interactive prompting
9770Sstevel@tonic-gate * during mget, mput, and mdelete.
9780Sstevel@tonic-gate */
9790Sstevel@tonic-gate /*ARGSUSED*/
9800Sstevel@tonic-gate void
setprompt(int argc,char * argv[])9810Sstevel@tonic-gate setprompt(int argc, char *argv[])
9820Sstevel@tonic-gate {
9830Sstevel@tonic-gate interactive = !interactive;
9840Sstevel@tonic-gate (void) printf("Interactive mode %s.\n", onoff(interactive));
9850Sstevel@tonic-gate code = interactive;
9860Sstevel@tonic-gate }
9870Sstevel@tonic-gate
9880Sstevel@tonic-gate /*
9890Sstevel@tonic-gate * Toggle metacharacter interpretation
9900Sstevel@tonic-gate * on local file names.
9910Sstevel@tonic-gate */
9920Sstevel@tonic-gate /*ARGSUSED*/
9930Sstevel@tonic-gate void
setglob(int argc,char * argv[])9940Sstevel@tonic-gate setglob(int argc, char *argv[])
9950Sstevel@tonic-gate {
9960Sstevel@tonic-gate doglob = !doglob;
9970Sstevel@tonic-gate (void) printf("Globbing %s.\n", onoff(doglob));
9980Sstevel@tonic-gate code = doglob;
9990Sstevel@tonic-gate }
10000Sstevel@tonic-gate
10010Sstevel@tonic-gate /*
10020Sstevel@tonic-gate * Set debugging mode on/off and/or
10030Sstevel@tonic-gate * set level of debugging.
10040Sstevel@tonic-gate */
10050Sstevel@tonic-gate void
setdebug(int argc,char * argv[])10060Sstevel@tonic-gate setdebug(int argc, char *argv[])
10070Sstevel@tonic-gate {
10080Sstevel@tonic-gate int val;
10090Sstevel@tonic-gate
10100Sstevel@tonic-gate if (argc > 1) {
10110Sstevel@tonic-gate val = atoi(argv[1]);
10120Sstevel@tonic-gate if (val < 0) {
10130Sstevel@tonic-gate (void) printf("%s: bad debugging value.\n", argv[1]);
10140Sstevel@tonic-gate code = -1;
10150Sstevel@tonic-gate return;
10160Sstevel@tonic-gate }
10170Sstevel@tonic-gate } else
10180Sstevel@tonic-gate val = !debug;
10190Sstevel@tonic-gate debug = val;
10200Sstevel@tonic-gate if (debug)
10210Sstevel@tonic-gate options |= SO_DEBUG;
10220Sstevel@tonic-gate else
10230Sstevel@tonic-gate options &= ~SO_DEBUG;
10240Sstevel@tonic-gate (void) printf("Debugging %s (debug=%d).\n", onoff(debug), debug);
10250Sstevel@tonic-gate code = debug > 0;
10260Sstevel@tonic-gate }
10270Sstevel@tonic-gate
10280Sstevel@tonic-gate /*
10290Sstevel@tonic-gate * Set current working directory
10300Sstevel@tonic-gate * on remote machine.
10310Sstevel@tonic-gate */
10320Sstevel@tonic-gate void
cd(int argc,char * argv[])10330Sstevel@tonic-gate cd(int argc, char *argv[])
10340Sstevel@tonic-gate {
10350Sstevel@tonic-gate if (argc < 2) {
10360Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-directory") <
10370Sstevel@tonic-gate 0) {
10380Sstevel@tonic-gate code = -1;
10390Sstevel@tonic-gate return;
10400Sstevel@tonic-gate }
10410Sstevel@tonic-gate makeargv();
10420Sstevel@tonic-gate argc = margc;
10430Sstevel@tonic-gate argv = margv;
10440Sstevel@tonic-gate }
10450Sstevel@tonic-gate if (argc < 2) {
10460Sstevel@tonic-gate (void) printf("usage: %s remote-directory\n", argv[0]);
10470Sstevel@tonic-gate code = -1;
10480Sstevel@tonic-gate return;
10490Sstevel@tonic-gate }
10500Sstevel@tonic-gate (void) command("CWD %s", argv[1]);
10510Sstevel@tonic-gate }
10520Sstevel@tonic-gate
10530Sstevel@tonic-gate /*
10540Sstevel@tonic-gate * Set current working directory
10550Sstevel@tonic-gate * on local machine.
10560Sstevel@tonic-gate */
10570Sstevel@tonic-gate void
lcd(int argc,char * argv[])10580Sstevel@tonic-gate lcd(int argc, char *argv[])
10590Sstevel@tonic-gate {
10600Sstevel@tonic-gate char buf[MAXPATHLEN], *bufptr;
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate if (argc < 2)
10630Sstevel@tonic-gate argc++, argv[1] = home;
10640Sstevel@tonic-gate if (argc != 2) {
10650Sstevel@tonic-gate (void) printf("usage: %s local-directory\n", argv[0]);
10660Sstevel@tonic-gate code = -1;
10670Sstevel@tonic-gate return;
10680Sstevel@tonic-gate }
10690Sstevel@tonic-gate if (!globulize(&argv[1])) {
10700Sstevel@tonic-gate code = -1;
10710Sstevel@tonic-gate return;
10720Sstevel@tonic-gate }
10730Sstevel@tonic-gate if (chdir(argv[1]) < 0) {
10740Sstevel@tonic-gate perror(argv[1]);
10750Sstevel@tonic-gate code = -1;
10760Sstevel@tonic-gate return;
10770Sstevel@tonic-gate }
10780Sstevel@tonic-gate bufptr = getcwd(buf, MAXPATHLEN);
10790Sstevel@tonic-gate /*
10800Sstevel@tonic-gate * Even though chdir may succeed, getcwd may fail if a component
10810Sstevel@tonic-gate * of the pwd is unreadable. In this case, print the argument to
10820Sstevel@tonic-gate * chdir as the resultant directory, since we know it succeeded above.
10830Sstevel@tonic-gate */
10840Sstevel@tonic-gate (void) printf("Local directory now %s\n", (bufptr ? bufptr : argv[1]));
10850Sstevel@tonic-gate code = 0;
10860Sstevel@tonic-gate }
10870Sstevel@tonic-gate
10880Sstevel@tonic-gate /*
10890Sstevel@tonic-gate * Delete a single file.
10900Sstevel@tonic-gate */
10910Sstevel@tonic-gate void
delete(int argc,char * argv[])10920Sstevel@tonic-gate delete(int argc, char *argv[])
10930Sstevel@tonic-gate {
10940Sstevel@tonic-gate
10950Sstevel@tonic-gate if (argc < 2) {
10960Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") < 0) {
10970Sstevel@tonic-gate code = -1;
10980Sstevel@tonic-gate return;
10990Sstevel@tonic-gate }
11000Sstevel@tonic-gate makeargv();
11010Sstevel@tonic-gate argc = margc;
11020Sstevel@tonic-gate argv = margv;
11030Sstevel@tonic-gate }
11040Sstevel@tonic-gate if (argc < 2) {
11050Sstevel@tonic-gate (void) printf("usage: %s remote-file\n", argv[0]);
11060Sstevel@tonic-gate code = -1;
11070Sstevel@tonic-gate return;
11080Sstevel@tonic-gate }
11090Sstevel@tonic-gate (void) command("DELE %s", argv[1]);
11100Sstevel@tonic-gate }
11110Sstevel@tonic-gate
11120Sstevel@tonic-gate /*
11130Sstevel@tonic-gate * Delete multiple files.
11140Sstevel@tonic-gate */
11150Sstevel@tonic-gate void
mdelete(int argc,char * argv[])11160Sstevel@tonic-gate mdelete(int argc, char *argv[])
11170Sstevel@tonic-gate {
11180Sstevel@tonic-gate char *cp;
11190Sstevel@tonic-gate int ointer;
11200Sstevel@tonic-gate void (*oldintr)();
11210Sstevel@tonic-gate
11220Sstevel@tonic-gate if (argc < 2) {
11230Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) {
11240Sstevel@tonic-gate code = -1;
11250Sstevel@tonic-gate return;
11260Sstevel@tonic-gate }
11270Sstevel@tonic-gate makeargv();
11280Sstevel@tonic-gate argc = margc;
11290Sstevel@tonic-gate argv = margv;
11300Sstevel@tonic-gate }
11310Sstevel@tonic-gate if (argc < 2) {
11320Sstevel@tonic-gate (void) printf("usage: %s remote-files\n", argv[0]);
11330Sstevel@tonic-gate code = -1;
11340Sstevel@tonic-gate return;
11350Sstevel@tonic-gate }
11360Sstevel@tonic-gate mname = argv[0];
11370Sstevel@tonic-gate mflag = 1;
11380Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
11390Sstevel@tonic-gate (void) setjmp(jabort);
11400Sstevel@tonic-gate while ((cp = remglob(argv, 0)) != NULL) {
11410Sstevel@tonic-gate if (*cp == '\0') {
11420Sstevel@tonic-gate mflag = 0;
11430Sstevel@tonic-gate continue;
11440Sstevel@tonic-gate }
11450Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) {
11460Sstevel@tonic-gate (void) command("DELE %s", cp);
11470Sstevel@tonic-gate if (!mflag && fromatty) {
11480Sstevel@tonic-gate ointer = interactive;
11490Sstevel@tonic-gate interactive = 1;
11500Sstevel@tonic-gate if (confirm("Continue with", "mdelete")) {
11510Sstevel@tonic-gate mflag++;
11520Sstevel@tonic-gate }
11530Sstevel@tonic-gate interactive = ointer;
11540Sstevel@tonic-gate }
11550Sstevel@tonic-gate }
11560Sstevel@tonic-gate }
11570Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
11580Sstevel@tonic-gate mflag = 0;
11590Sstevel@tonic-gate }
11600Sstevel@tonic-gate
11610Sstevel@tonic-gate /*
11620Sstevel@tonic-gate * Rename a remote file.
11630Sstevel@tonic-gate */
11640Sstevel@tonic-gate void
renamefile(int argc,char * argv[])11650Sstevel@tonic-gate renamefile(int argc, char *argv[])
11660Sstevel@tonic-gate {
11670Sstevel@tonic-gate
11680Sstevel@tonic-gate if (argc < 2) {
11690Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "from-name") < 0) {
11700Sstevel@tonic-gate code = -1;
11710Sstevel@tonic-gate return;
11720Sstevel@tonic-gate }
11730Sstevel@tonic-gate makeargv();
11740Sstevel@tonic-gate argc = margc;
11750Sstevel@tonic-gate argv = margv;
11760Sstevel@tonic-gate }
11770Sstevel@tonic-gate if (argc < 2) {
11780Sstevel@tonic-gate usage:
11790Sstevel@tonic-gate (void) printf("%s from-name to-name\n", argv[0]);
11800Sstevel@tonic-gate code = -1;
11810Sstevel@tonic-gate return;
11820Sstevel@tonic-gate }
11830Sstevel@tonic-gate if (argc < 3) {
11840Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "to-name") < 0) {
11850Sstevel@tonic-gate code = -1;
11860Sstevel@tonic-gate return;
11870Sstevel@tonic-gate }
11880Sstevel@tonic-gate makeargv();
11890Sstevel@tonic-gate argc = margc;
11900Sstevel@tonic-gate argv = margv;
11910Sstevel@tonic-gate }
11920Sstevel@tonic-gate if (argc < 3)
11930Sstevel@tonic-gate goto usage;
11940Sstevel@tonic-gate if (command("RNFR %s", argv[1]) == CONTINUE)
11950Sstevel@tonic-gate (void) command("RNTO %s", argv[2]);
11960Sstevel@tonic-gate }
11970Sstevel@tonic-gate
11980Sstevel@tonic-gate /*
11990Sstevel@tonic-gate * Get a directory listing
12000Sstevel@tonic-gate * of remote files.
12010Sstevel@tonic-gate */
12020Sstevel@tonic-gate void
ls(int argc,char * argv[])12030Sstevel@tonic-gate ls(int argc, char *argv[])
12040Sstevel@tonic-gate {
12050Sstevel@tonic-gate char *cmd;
12060Sstevel@tonic-gate
12070Sstevel@tonic-gate if (argc < 2)
12080Sstevel@tonic-gate argc++, argv[1] = NULL;
12090Sstevel@tonic-gate if (argc < 3)
12100Sstevel@tonic-gate argc++, argv[2] = "-";
12110Sstevel@tonic-gate if (argc > 3) {
12120Sstevel@tonic-gate (void) printf("usage: %s remote-directory local-file\n",
12130Sstevel@tonic-gate argv[0]);
12140Sstevel@tonic-gate code = -1;
12150Sstevel@tonic-gate return;
12160Sstevel@tonic-gate }
12170Sstevel@tonic-gate if (ls_invokes_NLST) {
12180Sstevel@tonic-gate cmd = ((argv[0][0] == 'l' || argv[0][0] == 'n') ?
12190Sstevel@tonic-gate "NLST" : "LIST");
12200Sstevel@tonic-gate } else {
12210Sstevel@tonic-gate cmd = ((argv[0][0] == 'n') ? "NLST" : "LIST");
12220Sstevel@tonic-gate }
12230Sstevel@tonic-gate if (strcmp(argv[2], "-") && !globulize(&argv[2])) {
12240Sstevel@tonic-gate code = -1;
12250Sstevel@tonic-gate return;
12260Sstevel@tonic-gate }
12270Sstevel@tonic-gate recvrequest(cmd, argv[2], argv[1], "w", 1);
12280Sstevel@tonic-gate }
12290Sstevel@tonic-gate
12300Sstevel@tonic-gate /*
12310Sstevel@tonic-gate * Get a directory listing
12320Sstevel@tonic-gate * of multiple remote files.
12330Sstevel@tonic-gate */
12340Sstevel@tonic-gate void
mls(int argc,char * argv[])12350Sstevel@tonic-gate mls(int argc, char *argv[])
12360Sstevel@tonic-gate {
12370Sstevel@tonic-gate char *cmd, mode[1], *dest;
12380Sstevel@tonic-gate int ointer, i;
12390Sstevel@tonic-gate void (*oldintr)();
12400Sstevel@tonic-gate
12410Sstevel@tonic-gate if (argc < 2) {
12420Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) {
12430Sstevel@tonic-gate code = -1;
12440Sstevel@tonic-gate return;
12450Sstevel@tonic-gate }
12460Sstevel@tonic-gate makeargv();
12470Sstevel@tonic-gate argc = margc;
12480Sstevel@tonic-gate argv = margv;
12490Sstevel@tonic-gate }
12500Sstevel@tonic-gate if (argc < 3) {
12510Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") < 0) {
12520Sstevel@tonic-gate code = -1;
12530Sstevel@tonic-gate return;
12540Sstevel@tonic-gate }
12550Sstevel@tonic-gate makeargv();
12560Sstevel@tonic-gate argc = margc;
12570Sstevel@tonic-gate argv = margv;
12580Sstevel@tonic-gate }
12590Sstevel@tonic-gate if (argc < 3) {
12600Sstevel@tonic-gate (void) printf("usage: %s remote-files local-file\n", argv[0]);
12610Sstevel@tonic-gate code = -1;
12620Sstevel@tonic-gate return;
12630Sstevel@tonic-gate }
12640Sstevel@tonic-gate dest = argv[argc - 1];
12650Sstevel@tonic-gate argv[argc - 1] = NULL;
12660Sstevel@tonic-gate if (strcmp(dest, "-") && *dest != '|')
12670Sstevel@tonic-gate if (!globulize(&dest) ||
12680Sstevel@tonic-gate !confirm("output to local-file:", dest)) {
12690Sstevel@tonic-gate code = -1;
12700Sstevel@tonic-gate return;
12710Sstevel@tonic-gate }
12720Sstevel@tonic-gate cmd = argv[0][1] == 'l' ? "NLST" : "LIST";
12730Sstevel@tonic-gate mname = argv[0];
12740Sstevel@tonic-gate mflag = 1;
12750Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
12760Sstevel@tonic-gate (void) setjmp(jabort);
12770Sstevel@tonic-gate for (i = 1; mflag && i < argc-1; ++i) {
12780Sstevel@tonic-gate *mode = (i == 1) ? 'w' : 'a';
12790Sstevel@tonic-gate recvrequest(cmd, dest, argv[i], mode, 1);
12800Sstevel@tonic-gate if (!mflag && fromatty) {
12810Sstevel@tonic-gate ointer = interactive;
12820Sstevel@tonic-gate interactive = 1;
12830Sstevel@tonic-gate if (confirm("Continue with", argv[0])) {
12840Sstevel@tonic-gate mflag ++;
12850Sstevel@tonic-gate }
12860Sstevel@tonic-gate interactive = ointer;
12870Sstevel@tonic-gate }
12880Sstevel@tonic-gate }
12890Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
12900Sstevel@tonic-gate mflag = 0;
12910Sstevel@tonic-gate }
12920Sstevel@tonic-gate
12930Sstevel@tonic-gate /*
12940Sstevel@tonic-gate * Do a shell escape
12950Sstevel@tonic-gate */
12960Sstevel@tonic-gate /*ARGSUSED*/
12970Sstevel@tonic-gate void
shell(int argc,char * argv[])12980Sstevel@tonic-gate shell(int argc, char *argv[])
12990Sstevel@tonic-gate {
13000Sstevel@tonic-gate pid_t pid;
13010Sstevel@tonic-gate void (*old1)(), (*old2)();
13020Sstevel@tonic-gate char *shellstring, *namep;
13030Sstevel@tonic-gate int status;
13040Sstevel@tonic-gate
13050Sstevel@tonic-gate stop_timer();
13060Sstevel@tonic-gate old1 = signal(SIGINT, SIG_IGN);
13070Sstevel@tonic-gate old2 = signal(SIGQUIT, SIG_IGN);
13080Sstevel@tonic-gate if ((pid = fork()) == 0) {
13090Sstevel@tonic-gate closefrom(STDERR_FILENO + 1);
13100Sstevel@tonic-gate (void) signal(SIGINT, SIG_DFL);
13110Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_DFL);
13120Sstevel@tonic-gate shellstring = getenv("SHELL");
13130Sstevel@tonic-gate if (shellstring == NULL)
13140Sstevel@tonic-gate shellstring = "/bin/sh";
13150Sstevel@tonic-gate namep = rindex(shellstring, '/');
13160Sstevel@tonic-gate if (namep == NULL)
13170Sstevel@tonic-gate namep = shellstring;
13180Sstevel@tonic-gate if (argc > 1) {
13190Sstevel@tonic-gate if (debug) {
13200Sstevel@tonic-gate (void) printf("%s -c %s\n", shellstring,
13210Sstevel@tonic-gate altarg);
13220Sstevel@tonic-gate (void) fflush(stdout);
13230Sstevel@tonic-gate }
13240Sstevel@tonic-gate execl(shellstring, namep, "-c", altarg, (char *)0);
13250Sstevel@tonic-gate } else {
13260Sstevel@tonic-gate if (debug) {
13270Sstevel@tonic-gate (void) printf("%s\n", shellstring);
13280Sstevel@tonic-gate (void) fflush(stdout);
13290Sstevel@tonic-gate }
13300Sstevel@tonic-gate execl(shellstring, namep, (char *)0);
13310Sstevel@tonic-gate }
13320Sstevel@tonic-gate perror(shellstring);
13330Sstevel@tonic-gate code = -1;
13340Sstevel@tonic-gate exit(1);
13350Sstevel@tonic-gate }
13360Sstevel@tonic-gate if (pid > 0)
13370Sstevel@tonic-gate while (wait(&status) != pid)
13380Sstevel@tonic-gate ;
13390Sstevel@tonic-gate (void) signal(SIGINT, old1);
13400Sstevel@tonic-gate (void) signal(SIGQUIT, old2);
13410Sstevel@tonic-gate reset_timer();
13420Sstevel@tonic-gate if (pid == (pid_t)-1) {
13430Sstevel@tonic-gate perror("Try again later");
13440Sstevel@tonic-gate code = -1;
13450Sstevel@tonic-gate } else {
13460Sstevel@tonic-gate code = 0;
13470Sstevel@tonic-gate }
13480Sstevel@tonic-gate }
13490Sstevel@tonic-gate
13500Sstevel@tonic-gate /*
13510Sstevel@tonic-gate * Send new user information (re-login)
13520Sstevel@tonic-gate */
13530Sstevel@tonic-gate void
user(int argc,char * argv[])13540Sstevel@tonic-gate user(int argc, char *argv[])
13550Sstevel@tonic-gate {
13560Sstevel@tonic-gate char acct[80];
13570Sstevel@tonic-gate int n, aflag = 0;
13580Sstevel@tonic-gate
13590Sstevel@tonic-gate if (argc < 2) {
13600Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "username") < 0) {
13610Sstevel@tonic-gate code = -1;
13620Sstevel@tonic-gate return;
13630Sstevel@tonic-gate }
13640Sstevel@tonic-gate makeargv();
13650Sstevel@tonic-gate argc = margc;
13660Sstevel@tonic-gate argv = margv;
13670Sstevel@tonic-gate }
13680Sstevel@tonic-gate if (argc > 4) {
13690Sstevel@tonic-gate (void) printf("usage: %s username [password] [account]\n",
13700Sstevel@tonic-gate argv[0]);
13710Sstevel@tonic-gate code = -1;
13720Sstevel@tonic-gate return;
13730Sstevel@tonic-gate }
13740Sstevel@tonic-gate if (argv[1] == 0) {
13750Sstevel@tonic-gate (void) printf("access for user (nil) denied\n");
13760Sstevel@tonic-gate code = -1;
13770Sstevel@tonic-gate return;
13780Sstevel@tonic-gate }
13790Sstevel@tonic-gate n = command("USER %s", argv[1]);
13800Sstevel@tonic-gate if (n == CONTINUE) {
13810Sstevel@tonic-gate int oldclevel;
13820Sstevel@tonic-gate if (argc < 3)
13830Sstevel@tonic-gate argv[2] = mygetpass("Password: "), argc++;
13840Sstevel@tonic-gate if ((oldclevel = clevel) == PROT_S)
13850Sstevel@tonic-gate clevel = PROT_P;
13860Sstevel@tonic-gate n = command("PASS %s", argv[2]);
13870Sstevel@tonic-gate /* level may have changed */
13880Sstevel@tonic-gate if (clevel == PROT_P)
13890Sstevel@tonic-gate clevel = oldclevel;
13900Sstevel@tonic-gate }
13910Sstevel@tonic-gate if (n == CONTINUE) {
13920Sstevel@tonic-gate if (argc < 4) {
13930Sstevel@tonic-gate (void) printf("Account: "); (void) fflush(stdout);
13940Sstevel@tonic-gate stop_timer();
13950Sstevel@tonic-gate (void) fgets(acct, sizeof (acct) - 1, stdin);
13960Sstevel@tonic-gate reset_timer();
13970Sstevel@tonic-gate acct[strlen(acct) - 1] = '\0';
13980Sstevel@tonic-gate argv[3] = acct; argc++;
13990Sstevel@tonic-gate }
14000Sstevel@tonic-gate n = command("ACCT %s", argv[3]);
14010Sstevel@tonic-gate aflag++;
14020Sstevel@tonic-gate }
14030Sstevel@tonic-gate if (n != COMPLETE) {
14040Sstevel@tonic-gate (void) fprintf(stdout, "Login failed.\n");
14050Sstevel@tonic-gate return;
14060Sstevel@tonic-gate }
14070Sstevel@tonic-gate if (!aflag && argc == 4) {
14080Sstevel@tonic-gate (void) command("ACCT %s", argv[3]);
14090Sstevel@tonic-gate }
14100Sstevel@tonic-gate }
14110Sstevel@tonic-gate
14120Sstevel@tonic-gate /*
14130Sstevel@tonic-gate * Print working directory.
14140Sstevel@tonic-gate */
14150Sstevel@tonic-gate /*ARGSUSED*/
14160Sstevel@tonic-gate void
pwd(int argc,char * argv[])14170Sstevel@tonic-gate pwd(int argc, char *argv[])
14180Sstevel@tonic-gate {
14190Sstevel@tonic-gate (void) command("PWD");
14200Sstevel@tonic-gate }
14210Sstevel@tonic-gate
14220Sstevel@tonic-gate /*
14230Sstevel@tonic-gate * Make a directory.
14240Sstevel@tonic-gate */
14250Sstevel@tonic-gate void
makedir(int argc,char * argv[])14260Sstevel@tonic-gate makedir(int argc, char *argv[])
14270Sstevel@tonic-gate {
14280Sstevel@tonic-gate if (argc < 2) {
14290Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "directory-name") <
14300Sstevel@tonic-gate 0) {
14310Sstevel@tonic-gate code = -1;
14320Sstevel@tonic-gate return;
14330Sstevel@tonic-gate }
14340Sstevel@tonic-gate makeargv();
14350Sstevel@tonic-gate argc = margc;
14360Sstevel@tonic-gate argv = margv;
14370Sstevel@tonic-gate }
14380Sstevel@tonic-gate if (argc < 2) {
14390Sstevel@tonic-gate (void) printf("usage: %s directory-name\n", argv[0]);
14400Sstevel@tonic-gate code = -1;
14410Sstevel@tonic-gate return;
14420Sstevel@tonic-gate }
14430Sstevel@tonic-gate (void) command("MKD %s", argv[1]);
14440Sstevel@tonic-gate }
14450Sstevel@tonic-gate
14460Sstevel@tonic-gate /*
14470Sstevel@tonic-gate * Remove a directory.
14480Sstevel@tonic-gate */
14490Sstevel@tonic-gate void
removedir(int argc,char * argv[])14500Sstevel@tonic-gate removedir(int argc, char *argv[])
14510Sstevel@tonic-gate {
14520Sstevel@tonic-gate if (argc < 2) {
14530Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "directory-name") <
14540Sstevel@tonic-gate 0) {
14550Sstevel@tonic-gate code = -1;
14560Sstevel@tonic-gate return;
14570Sstevel@tonic-gate }
14580Sstevel@tonic-gate makeargv();
14590Sstevel@tonic-gate argc = margc;
14600Sstevel@tonic-gate argv = margv;
14610Sstevel@tonic-gate }
14620Sstevel@tonic-gate if (argc < 2) {
14630Sstevel@tonic-gate (void) printf("usage: %s directory-name\n", argv[0]);
14640Sstevel@tonic-gate code = -1;
14650Sstevel@tonic-gate return;
14660Sstevel@tonic-gate }
14670Sstevel@tonic-gate (void) command("RMD %s", argv[1]);
14680Sstevel@tonic-gate }
14690Sstevel@tonic-gate
14700Sstevel@tonic-gate /*
14710Sstevel@tonic-gate * Send a line, verbatim, to the remote machine.
14720Sstevel@tonic-gate */
14730Sstevel@tonic-gate void
quote(int argc,char * argv[])14740Sstevel@tonic-gate quote(int argc, char *argv[])
14750Sstevel@tonic-gate {
14760Sstevel@tonic-gate int i, n, len;
14770Sstevel@tonic-gate char buf[FTPBUFSIZ];
14780Sstevel@tonic-gate
14790Sstevel@tonic-gate if (argc < 2) {
14800Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line),
14810Sstevel@tonic-gate "command line to send") == -1) {
14820Sstevel@tonic-gate code = -1;
14830Sstevel@tonic-gate return;
14840Sstevel@tonic-gate }
14850Sstevel@tonic-gate makeargv();
14860Sstevel@tonic-gate argc = margc;
14870Sstevel@tonic-gate argv = margv;
14880Sstevel@tonic-gate }
14890Sstevel@tonic-gate if (argc < 2) {
14900Sstevel@tonic-gate (void) printf("usage: %s line-to-send\n", argv[0]);
14910Sstevel@tonic-gate code = -1;
14920Sstevel@tonic-gate return;
14930Sstevel@tonic-gate }
14940Sstevel@tonic-gate len = snprintf(buf, sizeof (buf), "%s", argv[1]);
14950Sstevel@tonic-gate if (len >= 0 && len < sizeof (buf) - 1) {
14960Sstevel@tonic-gate for (i = 2; i < argc; i++) {
14970Sstevel@tonic-gate n = snprintf(&buf[len], sizeof (buf) - len, " %s",
14980Sstevel@tonic-gate argv[i]);
14990Sstevel@tonic-gate if (n < 0 || n >= sizeof (buf) - len)
15000Sstevel@tonic-gate break;
15010Sstevel@tonic-gate len += n;
15020Sstevel@tonic-gate }
15030Sstevel@tonic-gate }
15040Sstevel@tonic-gate if (command("%s", buf) == PRELIM) {
15050Sstevel@tonic-gate while (getreply(0) == PRELIM)
15060Sstevel@tonic-gate ;
15070Sstevel@tonic-gate }
15080Sstevel@tonic-gate }
15090Sstevel@tonic-gate
15100Sstevel@tonic-gate /*
15110Sstevel@tonic-gate * Send a line, verbatim, to the remote machine as a SITE command.
15120Sstevel@tonic-gate */
15130Sstevel@tonic-gate void
site(int argc,char * argv[])15140Sstevel@tonic-gate site(int argc, char *argv[])
15150Sstevel@tonic-gate {
15160Sstevel@tonic-gate int i, n, len;
15170Sstevel@tonic-gate char buf[FTPBUFSIZ];
15180Sstevel@tonic-gate
15190Sstevel@tonic-gate if (argc < 2) {
15200Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line),
15210Sstevel@tonic-gate "arguments to SITE command") == -1) {
15220Sstevel@tonic-gate code = -1;
15230Sstevel@tonic-gate return;
15240Sstevel@tonic-gate }
15250Sstevel@tonic-gate makeargv();
15260Sstevel@tonic-gate argc = margc;
15270Sstevel@tonic-gate argv = margv;
15280Sstevel@tonic-gate }
15290Sstevel@tonic-gate if (argc < 2) {
15300Sstevel@tonic-gate (void) printf("usage: %s arg1 [arg2] ...\n", argv[0]);
15310Sstevel@tonic-gate code = -1;
15320Sstevel@tonic-gate return;
15330Sstevel@tonic-gate }
15340Sstevel@tonic-gate len = snprintf(buf, sizeof (buf), "%s", argv[1]);
15350Sstevel@tonic-gate if (len >= 0 && len < sizeof (buf) - 1) {
15360Sstevel@tonic-gate for (i = 2; i < argc; i++) {
15370Sstevel@tonic-gate n = snprintf(&buf[len], sizeof (buf) - len, " %s",
15380Sstevel@tonic-gate argv[i]);
15390Sstevel@tonic-gate if (n < 0 || n >= sizeof (buf) - len)
15400Sstevel@tonic-gate break;
15410Sstevel@tonic-gate len += n;
15420Sstevel@tonic-gate }
15430Sstevel@tonic-gate }
15440Sstevel@tonic-gate if (command("SITE %s", buf) == PRELIM) {
15450Sstevel@tonic-gate while (getreply(0) == PRELIM)
15460Sstevel@tonic-gate ;
15470Sstevel@tonic-gate }
15480Sstevel@tonic-gate }
15490Sstevel@tonic-gate
15500Sstevel@tonic-gate /*
15510Sstevel@tonic-gate * Ask the other side for help.
15520Sstevel@tonic-gate */
15530Sstevel@tonic-gate void
rmthelp(int argc,char * argv[])15540Sstevel@tonic-gate rmthelp(int argc, char *argv[])
15550Sstevel@tonic-gate {
15560Sstevel@tonic-gate int oldverbose = verbose;
15570Sstevel@tonic-gate
15580Sstevel@tonic-gate verbose = 1;
15590Sstevel@tonic-gate (void) command(argc == 1 ? "HELP" : "HELP %s", argv[1]);
15600Sstevel@tonic-gate verbose = oldverbose;
15610Sstevel@tonic-gate }
15620Sstevel@tonic-gate
15630Sstevel@tonic-gate /*
15640Sstevel@tonic-gate * Terminate session and exit.
15650Sstevel@tonic-gate */
15660Sstevel@tonic-gate /*ARGSUSED*/
15670Sstevel@tonic-gate void
quit(int argc,char * argv[])15680Sstevel@tonic-gate quit(int argc, char *argv[])
15690Sstevel@tonic-gate {
15700Sstevel@tonic-gate if (connected)
15710Sstevel@tonic-gate disconnect(0, NULL);
15720Sstevel@tonic-gate pswitch(1);
15730Sstevel@tonic-gate if (connected) {
15740Sstevel@tonic-gate disconnect(0, NULL);
15750Sstevel@tonic-gate }
15760Sstevel@tonic-gate exit(0);
15770Sstevel@tonic-gate }
15780Sstevel@tonic-gate
15790Sstevel@tonic-gate /*
15800Sstevel@tonic-gate * Terminate session, but don't exit.
15810Sstevel@tonic-gate */
15820Sstevel@tonic-gate /*ARGSUSED*/
15830Sstevel@tonic-gate void
disconnect(int argc,char * argv[])15840Sstevel@tonic-gate disconnect(int argc, char *argv[])
15850Sstevel@tonic-gate {
15860Sstevel@tonic-gate extern FILE *ctrl_in, *ctrl_out;
15870Sstevel@tonic-gate extern int data;
15880Sstevel@tonic-gate
15890Sstevel@tonic-gate if (!connected)
15900Sstevel@tonic-gate return;
15910Sstevel@tonic-gate (void) command("QUIT");
15920Sstevel@tonic-gate if (ctrl_in) {
15930Sstevel@tonic-gate reset_timer();
15940Sstevel@tonic-gate (void) fclose(ctrl_in);
15950Sstevel@tonic-gate }
15960Sstevel@tonic-gate if (ctrl_out) {
15970Sstevel@tonic-gate reset_timer();
15980Sstevel@tonic-gate (void) fclose(ctrl_out);
15990Sstevel@tonic-gate }
16000Sstevel@tonic-gate ctrl_out = ctrl_in = NULL;
16010Sstevel@tonic-gate connected = 0;
16020Sstevel@tonic-gate data = -1;
16030Sstevel@tonic-gate if (!proxy) {
16040Sstevel@tonic-gate macnum = 0;
16050Sstevel@tonic-gate }
16060Sstevel@tonic-gate
16070Sstevel@tonic-gate auth_type = AUTHTYPE_NONE;
16080Sstevel@tonic-gate clevel = dlevel = PROT_C;
16090Sstevel@tonic-gate goteof = 0;
16100Sstevel@tonic-gate }
16110Sstevel@tonic-gate
16120Sstevel@tonic-gate static int
confirm(char * cmd,char * file)16130Sstevel@tonic-gate confirm(char *cmd, char *file)
16140Sstevel@tonic-gate {
16150Sstevel@tonic-gate char line[FTPBUFSIZ];
16160Sstevel@tonic-gate
16170Sstevel@tonic-gate if (!interactive)
16180Sstevel@tonic-gate return (1);
16190Sstevel@tonic-gate stop_timer();
16200Sstevel@tonic-gate (void) printf("%s %s? ", cmd, file);
16210Sstevel@tonic-gate (void) fflush(stdout);
16220Sstevel@tonic-gate *line = '\0';
16230Sstevel@tonic-gate (void) fgets(line, sizeof (line), stdin);
16240Sstevel@tonic-gate reset_timer();
16250Sstevel@tonic-gate return (*line != 'n' && *line != 'N');
16260Sstevel@tonic-gate }
16270Sstevel@tonic-gate
16280Sstevel@tonic-gate void
fatal(char * msg)16290Sstevel@tonic-gate fatal(char *msg)
16300Sstevel@tonic-gate {
16310Sstevel@tonic-gate (void) fprintf(stderr, "ftp: %s\n", msg);
16320Sstevel@tonic-gate exit(1);
16330Sstevel@tonic-gate }
16340Sstevel@tonic-gate
16350Sstevel@tonic-gate /*
16360Sstevel@tonic-gate * Glob a local file name specification with
16370Sstevel@tonic-gate * the expectation of a single return value.
16380Sstevel@tonic-gate * Can't control multiple values being expanded
16390Sstevel@tonic-gate * from the expression, we return only the first.
16400Sstevel@tonic-gate */
16410Sstevel@tonic-gate static int
globulize(char ** cpp)16420Sstevel@tonic-gate globulize(char **cpp)
16430Sstevel@tonic-gate {
16440Sstevel@tonic-gate char **globbed;
16450Sstevel@tonic-gate
16460Sstevel@tonic-gate if (!doglob)
16470Sstevel@tonic-gate return (1);
16480Sstevel@tonic-gate globbed = glob(*cpp);
16490Sstevel@tonic-gate if (globbed != NULL && *globbed == NULL && globerr == NULL)
16500Sstevel@tonic-gate globerr = "No match";
16510Sstevel@tonic-gate if (globerr != NULL) {
16520Sstevel@tonic-gate (void) printf("%s: %s\n", *cpp, globerr);
16530Sstevel@tonic-gate if (globbed)
16540Sstevel@tonic-gate blkfree(globbed);
16550Sstevel@tonic-gate return (0);
16560Sstevel@tonic-gate }
16570Sstevel@tonic-gate if (globbed) {
16580Sstevel@tonic-gate *cpp = strdup(*globbed);
16590Sstevel@tonic-gate blkfree(globbed);
16600Sstevel@tonic-gate if (!*cpp)
16610Sstevel@tonic-gate return (0);
16620Sstevel@tonic-gate }
16630Sstevel@tonic-gate return (1);
16640Sstevel@tonic-gate }
16650Sstevel@tonic-gate
16660Sstevel@tonic-gate void
account(int argc,char * argv[])16670Sstevel@tonic-gate account(int argc, char *argv[])
16680Sstevel@tonic-gate {
16690Sstevel@tonic-gate char acct[50], *ap;
16700Sstevel@tonic-gate
16710Sstevel@tonic-gate if (argc > 1) {
16720Sstevel@tonic-gate ++argv;
16730Sstevel@tonic-gate --argc;
16740Sstevel@tonic-gate (void) strncpy(acct, *argv, 49);
16750Sstevel@tonic-gate acct[49] = '\0';
16760Sstevel@tonic-gate while (argc > 1) {
16770Sstevel@tonic-gate --argc;
16780Sstevel@tonic-gate ++argv;
16790Sstevel@tonic-gate (void) strncat(acct, *argv, 49 - strlen(acct));
16800Sstevel@tonic-gate }
16810Sstevel@tonic-gate ap = acct;
16820Sstevel@tonic-gate } else {
16830Sstevel@tonic-gate ap = mygetpass("Account:");
16840Sstevel@tonic-gate }
16850Sstevel@tonic-gate (void) command("ACCT %s", ap);
16860Sstevel@tonic-gate }
16870Sstevel@tonic-gate
16880Sstevel@tonic-gate /*ARGSUSED*/
16890Sstevel@tonic-gate static void
proxabort(int sig)16900Sstevel@tonic-gate proxabort(int sig)
16910Sstevel@tonic-gate {
16920Sstevel@tonic-gate extern int proxy;
16930Sstevel@tonic-gate
16940Sstevel@tonic-gate if (!proxy) {
16950Sstevel@tonic-gate pswitch(1);
16960Sstevel@tonic-gate }
16970Sstevel@tonic-gate if (connected) {
16980Sstevel@tonic-gate proxflag = 1;
16990Sstevel@tonic-gate } else {
17000Sstevel@tonic-gate proxflag = 0;
17010Sstevel@tonic-gate }
17020Sstevel@tonic-gate pswitch(0);
17030Sstevel@tonic-gate longjmp(abortprox, 1);
17040Sstevel@tonic-gate }
17050Sstevel@tonic-gate
17060Sstevel@tonic-gate void
doproxy(int argc,char * argv[])17070Sstevel@tonic-gate doproxy(int argc, char *argv[])
17080Sstevel@tonic-gate {
17090Sstevel@tonic-gate void (*oldintr)();
17100Sstevel@tonic-gate struct cmd *c;
17110Sstevel@tonic-gate
17120Sstevel@tonic-gate if (argc < 2) {
17130Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "command") == -1) {
17140Sstevel@tonic-gate code = -1;
17150Sstevel@tonic-gate return;
17160Sstevel@tonic-gate }
17170Sstevel@tonic-gate makeargv();
17180Sstevel@tonic-gate argc = margc;
17190Sstevel@tonic-gate argv = margv;
17200Sstevel@tonic-gate }
17210Sstevel@tonic-gate if (argc < 2) {
17220Sstevel@tonic-gate (void) printf("usage: %s command\n", argv[0]);
17230Sstevel@tonic-gate code = -1;
17240Sstevel@tonic-gate return;
17250Sstevel@tonic-gate }
17260Sstevel@tonic-gate c = getcmd(argv[1]);
17270Sstevel@tonic-gate if (c == (struct cmd *)-1) {
17280Sstevel@tonic-gate (void) printf("?Ambiguous command\n");
17290Sstevel@tonic-gate (void) fflush(stdout);
17300Sstevel@tonic-gate code = -1;
17310Sstevel@tonic-gate return;
17320Sstevel@tonic-gate }
17330Sstevel@tonic-gate if (c == 0) {
17340Sstevel@tonic-gate (void) printf("?Invalid command\n");
17350Sstevel@tonic-gate (void) fflush(stdout);
17360Sstevel@tonic-gate code = -1;
17370Sstevel@tonic-gate return;
17380Sstevel@tonic-gate }
17390Sstevel@tonic-gate if (!c->c_proxy) {
17400Sstevel@tonic-gate (void) printf("?Invalid proxy command\n");
17410Sstevel@tonic-gate (void) fflush(stdout);
17420Sstevel@tonic-gate code = -1;
17430Sstevel@tonic-gate return;
17440Sstevel@tonic-gate }
17450Sstevel@tonic-gate if (setjmp(abortprox)) {
17460Sstevel@tonic-gate code = -1;
17470Sstevel@tonic-gate return;
17480Sstevel@tonic-gate }
17490Sstevel@tonic-gate oldintr = signal(SIGINT, (void (*)())proxabort);
17500Sstevel@tonic-gate pswitch(1);
17510Sstevel@tonic-gate if (c->c_conn && !connected) {
17520Sstevel@tonic-gate (void) printf("Not connected\n");
17530Sstevel@tonic-gate (void) fflush(stdout);
17540Sstevel@tonic-gate pswitch(0);
17550Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
17560Sstevel@tonic-gate code = -1;
17570Sstevel@tonic-gate return;
17580Sstevel@tonic-gate }
17590Sstevel@tonic-gate (*c->c_handler)(argc-1, argv+1);
17600Sstevel@tonic-gate if (connected) {
17610Sstevel@tonic-gate proxflag = 1;
17620Sstevel@tonic-gate } else {
17630Sstevel@tonic-gate proxflag = 0;
17640Sstevel@tonic-gate }
17650Sstevel@tonic-gate pswitch(0);
17660Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
17670Sstevel@tonic-gate }
17680Sstevel@tonic-gate
17690Sstevel@tonic-gate /*ARGSUSED*/
17700Sstevel@tonic-gate void
setcase(int argc,char * argv[])17710Sstevel@tonic-gate setcase(int argc, char *argv[])
17720Sstevel@tonic-gate {
17730Sstevel@tonic-gate mcase = !mcase;
17740Sstevel@tonic-gate (void) printf("Case mapping %s.\n", onoff(mcase));
17750Sstevel@tonic-gate code = mcase;
17760Sstevel@tonic-gate }
17770Sstevel@tonic-gate
17780Sstevel@tonic-gate /*ARGSUSED*/
17790Sstevel@tonic-gate void
setcr(int argc,char * argv[])17800Sstevel@tonic-gate setcr(int argc, char *argv[])
17810Sstevel@tonic-gate {
17820Sstevel@tonic-gate crflag = !crflag;
17830Sstevel@tonic-gate (void) printf("Carriage Return stripping %s.\n", onoff(crflag));
17840Sstevel@tonic-gate code = crflag;
17850Sstevel@tonic-gate }
17860Sstevel@tonic-gate
17870Sstevel@tonic-gate void
setntrans(int argc,char * argv[])17880Sstevel@tonic-gate setntrans(int argc, char *argv[])
17890Sstevel@tonic-gate {
17900Sstevel@tonic-gate if (argc == 1) {
17910Sstevel@tonic-gate ntflag = 0;
17920Sstevel@tonic-gate (void) printf("Ntrans off.\n");
17930Sstevel@tonic-gate code = ntflag;
17940Sstevel@tonic-gate return;
17950Sstevel@tonic-gate }
17960Sstevel@tonic-gate ntflag++;
17970Sstevel@tonic-gate code = ntflag;
17980Sstevel@tonic-gate (void) strncpy(ntin, argv[1], 16);
17990Sstevel@tonic-gate ntin[16] = '\0';
18000Sstevel@tonic-gate if (argc == 2) {
18010Sstevel@tonic-gate ntout[0] = '\0';
18020Sstevel@tonic-gate return;
18030Sstevel@tonic-gate }
18040Sstevel@tonic-gate (void) strncpy(ntout, argv[2], 16);
18050Sstevel@tonic-gate ntout[16] = '\0';
18060Sstevel@tonic-gate }
18070Sstevel@tonic-gate
18080Sstevel@tonic-gate static char *
dotrans(char * name)18090Sstevel@tonic-gate dotrans(char *name)
18100Sstevel@tonic-gate {
18110Sstevel@tonic-gate static char new[MAXPATHLEN];
18120Sstevel@tonic-gate char *cp1, *cp2 = new;
18130Sstevel@tonic-gate int i, ostop, found;
18140Sstevel@tonic-gate
18150Sstevel@tonic-gate for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
18160Sstevel@tonic-gate ;
18170Sstevel@tonic-gate for (cp1 = name; *cp1; cp1++) {
18180Sstevel@tonic-gate found = 0;
18190Sstevel@tonic-gate for (i = 0; *(ntin + i) && i < 16; i++) {
18200Sstevel@tonic-gate if (*cp1 == *(ntin + i)) {
18210Sstevel@tonic-gate found++;
18220Sstevel@tonic-gate if (i < ostop) {
18230Sstevel@tonic-gate *cp2++ = *(ntout + i);
18240Sstevel@tonic-gate }
18250Sstevel@tonic-gate break;
18260Sstevel@tonic-gate }
18270Sstevel@tonic-gate }
18280Sstevel@tonic-gate if (!found) {
18290Sstevel@tonic-gate *cp2++ = *cp1;
18300Sstevel@tonic-gate }
18310Sstevel@tonic-gate }
18320Sstevel@tonic-gate *cp2 = '\0';
18330Sstevel@tonic-gate return (new);
18340Sstevel@tonic-gate }
18350Sstevel@tonic-gate
18360Sstevel@tonic-gate void
setnmap(int argc,char * argv[])18370Sstevel@tonic-gate setnmap(int argc, char *argv[])
18380Sstevel@tonic-gate {
18390Sstevel@tonic-gate char *cp;
18400Sstevel@tonic-gate
18410Sstevel@tonic-gate if (argc == 1) {
18420Sstevel@tonic-gate mapflag = 0;
18430Sstevel@tonic-gate (void) printf("Nmap off.\n");
18440Sstevel@tonic-gate code = mapflag;
18450Sstevel@tonic-gate return;
18460Sstevel@tonic-gate }
18470Sstevel@tonic-gate if (argc < 3) {
18480Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "mapout") == -1) {
18490Sstevel@tonic-gate code = -1;
18500Sstevel@tonic-gate return;
18510Sstevel@tonic-gate }
18520Sstevel@tonic-gate makeargv();
18530Sstevel@tonic-gate argc = margc;
18540Sstevel@tonic-gate argv = margv;
18550Sstevel@tonic-gate }
18560Sstevel@tonic-gate if (argc < 3) {
18570Sstevel@tonic-gate (void) printf("Usage: %s [mapin mapout]\n", argv[0]);
18580Sstevel@tonic-gate code = -1;
18590Sstevel@tonic-gate return;
18600Sstevel@tonic-gate }
18610Sstevel@tonic-gate mapflag = 1;
18620Sstevel@tonic-gate code = 1;
18630Sstevel@tonic-gate cp = index(altarg, ' ');
18640Sstevel@tonic-gate if (proxy) {
18650Sstevel@tonic-gate while (*++cp == ' ')
18660Sstevel@tonic-gate /* NULL */;
18670Sstevel@tonic-gate altarg = cp;
18680Sstevel@tonic-gate cp = index(altarg, ' ');
18690Sstevel@tonic-gate }
18700Sstevel@tonic-gate *cp = '\0';
18710Sstevel@tonic-gate (void) strncpy(mapin, altarg, MAXPATHLEN - 1);
18720Sstevel@tonic-gate while (*++cp == ' ')
18730Sstevel@tonic-gate /* NULL */;
18740Sstevel@tonic-gate (void) strncpy(mapout, cp, MAXPATHLEN - 1);
18750Sstevel@tonic-gate }
18760Sstevel@tonic-gate
18770Sstevel@tonic-gate static char *
domap(char * name)18780Sstevel@tonic-gate domap(char *name)
18790Sstevel@tonic-gate {
18800Sstevel@tonic-gate static char new[MAXPATHLEN];
18810Sstevel@tonic-gate char *cp1 = name, *cp2 = mapin;
18820Sstevel@tonic-gate char *tp[9], *te[9];
18830Sstevel@tonic-gate int i, toks[9], toknum, match = 1;
18840Sstevel@tonic-gate wchar_t wc1, wc2;
18850Sstevel@tonic-gate int len1, len2;
18860Sstevel@tonic-gate
18870Sstevel@tonic-gate for (i = 0; i < 9; ++i) {
18880Sstevel@tonic-gate toks[i] = 0;
18890Sstevel@tonic-gate }
18900Sstevel@tonic-gate while (match && *cp1 && *cp2) {
18910Sstevel@tonic-gate if ((len1 = mbtowc(&wc1, cp1, MB_CUR_MAX)) <= 0) {
18920Sstevel@tonic-gate wc1 = (unsigned char)*cp1;
18930Sstevel@tonic-gate len1 = 1;
18940Sstevel@tonic-gate }
18950Sstevel@tonic-gate cp1 += len1;
18960Sstevel@tonic-gate if ((len2 = mbtowc(&wc2, cp2, MB_CUR_MAX)) <= 0) {
18970Sstevel@tonic-gate wc2 = (unsigned char)*cp2;
18980Sstevel@tonic-gate len2 = 1;
18990Sstevel@tonic-gate }
19000Sstevel@tonic-gate cp2 += len2;
19010Sstevel@tonic-gate
19020Sstevel@tonic-gate switch (wc2) {
19030Sstevel@tonic-gate case '\\':
19040Sstevel@tonic-gate if ((len2 = mbtowc(&wc2, cp2, MB_CUR_MAX)) <= 0) {
19050Sstevel@tonic-gate wc2 = (unsigned char)*cp2;
19060Sstevel@tonic-gate len2 = 1;
19070Sstevel@tonic-gate }
19080Sstevel@tonic-gate cp2 += len2;
19090Sstevel@tonic-gate if (wc2 != wc1)
19100Sstevel@tonic-gate match = 0;
19110Sstevel@tonic-gate break;
19120Sstevel@tonic-gate
19130Sstevel@tonic-gate case '$':
19140Sstevel@tonic-gate if (*cp2 >= '1' && *cp2 <= '9') {
19150Sstevel@tonic-gate if ((len2 =
19160Sstevel@tonic-gate mbtowc(&wc2, cp2 + 1, MB_CUR_MAX)) <= 0) {
19170Sstevel@tonic-gate wc2 = (unsigned char)*(cp2 + 1);
19180Sstevel@tonic-gate len2 = 1;
19190Sstevel@tonic-gate }
19200Sstevel@tonic-gate if (wc1 != wc2) {
19210Sstevel@tonic-gate toks[toknum = *cp2 - '1']++;
19220Sstevel@tonic-gate tp[toknum] = cp1 - len1;
19230Sstevel@tonic-gate while (*cp1) {
19240Sstevel@tonic-gate if ((len1 = mbtowc(&wc1,
19250Sstevel@tonic-gate cp1, MB_CUR_MAX)) <= 0) {
19260Sstevel@tonic-gate wc1 =
19270Sstevel@tonic-gate (unsigned char)*cp1;
19280Sstevel@tonic-gate len1 = 1;
19290Sstevel@tonic-gate }
19300Sstevel@tonic-gate cp1 += len1;
19310Sstevel@tonic-gate if (wc2 == wc1)
19320Sstevel@tonic-gate break;
19330Sstevel@tonic-gate }
19340Sstevel@tonic-gate if (*cp1 == 0 && wc2 != wc1)
19350Sstevel@tonic-gate te[toknum] = cp1;
19360Sstevel@tonic-gate else
19370Sstevel@tonic-gate te[toknum] = cp1 - len1;
19380Sstevel@tonic-gate }
19390Sstevel@tonic-gate cp2++; /* Consume the digit */
19400Sstevel@tonic-gate if (wc2)
19410Sstevel@tonic-gate cp2 += len2; /* Consume wide char */
19420Sstevel@tonic-gate break;
19430Sstevel@tonic-gate }
19440Sstevel@tonic-gate /* intentional drop through */
19450Sstevel@tonic-gate default:
19460Sstevel@tonic-gate if (wc2 != wc1)
19470Sstevel@tonic-gate match = 0;
19480Sstevel@tonic-gate break;
19490Sstevel@tonic-gate }
19500Sstevel@tonic-gate }
19510Sstevel@tonic-gate
19520Sstevel@tonic-gate cp1 = new;
19530Sstevel@tonic-gate *cp1 = '\0';
19540Sstevel@tonic-gate cp2 = mapout;
19550Sstevel@tonic-gate while (*cp2) {
19560Sstevel@tonic-gate match = 0;
19570Sstevel@tonic-gate switch (*cp2) {
19580Sstevel@tonic-gate case '\\':
19590Sstevel@tonic-gate cp2++;
19600Sstevel@tonic-gate if (*cp2) {
19610Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 0)
19620Sstevel@tonic-gate len2 = 1;
19630Sstevel@tonic-gate memcpy(cp1, cp2, len2);
19640Sstevel@tonic-gate cp1 += len2;
19650Sstevel@tonic-gate cp2 += len2;
19660Sstevel@tonic-gate }
19670Sstevel@tonic-gate break;
19680Sstevel@tonic-gate
19690Sstevel@tonic-gate case '[':
19700Sstevel@tonic-gate LOOP:
19710Sstevel@tonic-gate cp2++;
19720Sstevel@tonic-gate if (*cp2 == '$' && isdigit(*(cp2+1))) {
19730Sstevel@tonic-gate if (*++cp2 == '0') {
19740Sstevel@tonic-gate char *cp3 = name;
19750Sstevel@tonic-gate
19760Sstevel@tonic-gate while (*cp3) {
19770Sstevel@tonic-gate *cp1++ = *cp3++;
19780Sstevel@tonic-gate }
19790Sstevel@tonic-gate match = 1;
19800Sstevel@tonic-gate } else if (toks[toknum = *cp2 - '1']) {
19810Sstevel@tonic-gate char *cp3 = tp[toknum];
19820Sstevel@tonic-gate
19830Sstevel@tonic-gate while (cp3 != te[toknum]) {
19840Sstevel@tonic-gate *cp1++ = *cp3++;
19850Sstevel@tonic-gate }
19860Sstevel@tonic-gate match = 1;
19870Sstevel@tonic-gate }
19880Sstevel@tonic-gate } else {
19890Sstevel@tonic-gate while (*cp2 && *cp2 != ',' && *cp2 != ']') {
19900Sstevel@tonic-gate if (*cp2 == '\\') {
19910Sstevel@tonic-gate cp2++;
19920Sstevel@tonic-gate continue;
19930Sstevel@tonic-gate }
19940Sstevel@tonic-gate
19950Sstevel@tonic-gate if (*cp2 == '$' && isdigit(*(cp2+1))) {
19960Sstevel@tonic-gate if (*++cp2 == '0') {
19970Sstevel@tonic-gate char *cp3 = name;
19980Sstevel@tonic-gate
19990Sstevel@tonic-gate while (*cp3)
20000Sstevel@tonic-gate *cp1++ = *cp3++;
20010Sstevel@tonic-gate continue;
20020Sstevel@tonic-gate }
20030Sstevel@tonic-gate if (toks[toknum = *cp2 - '1']) {
20040Sstevel@tonic-gate char *cp3 = tp[toknum];
20050Sstevel@tonic-gate
20060Sstevel@tonic-gate while (cp3 !=
20070Sstevel@tonic-gate te[toknum])
20080Sstevel@tonic-gate *cp1++ = *cp3++;
20090Sstevel@tonic-gate }
20100Sstevel@tonic-gate continue;
20110Sstevel@tonic-gate }
20120Sstevel@tonic-gate if (*cp2) {
20130Sstevel@tonic-gate if ((len2 =
20140Sstevel@tonic-gate mblen(cp2, MB_CUR_MAX)) <=
20150Sstevel@tonic-gate 0) {
20160Sstevel@tonic-gate len2 = 1;
20170Sstevel@tonic-gate }
20180Sstevel@tonic-gate memcpy(cp1, cp2, len2);
20190Sstevel@tonic-gate cp1 += len2;
20200Sstevel@tonic-gate cp2 += len2;
20210Sstevel@tonic-gate }
20220Sstevel@tonic-gate }
20230Sstevel@tonic-gate if (!*cp2) {
20240Sstevel@tonic-gate (void) printf(
20250Sstevel@tonic-gate "nmap: unbalanced brackets\n");
20260Sstevel@tonic-gate return (name);
20270Sstevel@tonic-gate }
20280Sstevel@tonic-gate match = 1;
20290Sstevel@tonic-gate }
20300Sstevel@tonic-gate if (match) {
20310Sstevel@tonic-gate while (*cp2 && *cp2 != ']') {
20320Sstevel@tonic-gate if (*cp2 == '\\' && *(cp2 + 1)) {
20330Sstevel@tonic-gate cp2++;
20340Sstevel@tonic-gate }
20350Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <=
20360Sstevel@tonic-gate 0)
20370Sstevel@tonic-gate len2 = 1;
20380Sstevel@tonic-gate cp2 += len2;
20390Sstevel@tonic-gate }
20400Sstevel@tonic-gate if (!*cp2) {
20410Sstevel@tonic-gate (void) printf(
20420Sstevel@tonic-gate "nmap: unbalanced brackets\n");
20430Sstevel@tonic-gate return (name);
20440Sstevel@tonic-gate }
20450Sstevel@tonic-gate cp2++;
20460Sstevel@tonic-gate break;
20470Sstevel@tonic-gate }
20480Sstevel@tonic-gate switch (*++cp2) {
20490Sstevel@tonic-gate case ',':
20500Sstevel@tonic-gate goto LOOP;
20510Sstevel@tonic-gate case ']':
20520Sstevel@tonic-gate break;
20530Sstevel@tonic-gate default:
20540Sstevel@tonic-gate cp2--;
20550Sstevel@tonic-gate goto LOOP;
20560Sstevel@tonic-gate }
20570Sstevel@tonic-gate cp2++;
20580Sstevel@tonic-gate break;
20590Sstevel@tonic-gate case '$':
20600Sstevel@tonic-gate if (isdigit(*(cp2 + 1))) {
20610Sstevel@tonic-gate if (*++cp2 == '0') {
20620Sstevel@tonic-gate char *cp3 = name;
20630Sstevel@tonic-gate
20640Sstevel@tonic-gate while (*cp3) {
20650Sstevel@tonic-gate *cp1++ = *cp3++;
20660Sstevel@tonic-gate }
20670Sstevel@tonic-gate } else if (toks[toknum = *cp2 - '1']) {
20680Sstevel@tonic-gate char *cp3 = tp[toknum];
20690Sstevel@tonic-gate
20700Sstevel@tonic-gate while (cp3 != te[toknum]) {
20710Sstevel@tonic-gate *cp1++ = *cp3++;
20720Sstevel@tonic-gate }
20730Sstevel@tonic-gate }
20740Sstevel@tonic-gate cp2++;
20750Sstevel@tonic-gate break;
20760Sstevel@tonic-gate }
20770Sstevel@tonic-gate /* intentional drop through */
20780Sstevel@tonic-gate default:
20790Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 0)
20800Sstevel@tonic-gate len2 = 1;
20810Sstevel@tonic-gate memcpy(cp1, cp2, len2);
20820Sstevel@tonic-gate cp1 += len2;
20830Sstevel@tonic-gate cp2 += len2;
20840Sstevel@tonic-gate break;
20850Sstevel@tonic-gate }
20860Sstevel@tonic-gate }
20870Sstevel@tonic-gate *cp1 = '\0';
20880Sstevel@tonic-gate if (!*new) {
20890Sstevel@tonic-gate return (name);
20900Sstevel@tonic-gate }
20910Sstevel@tonic-gate return (new);
20920Sstevel@tonic-gate }
20930Sstevel@tonic-gate
20940Sstevel@tonic-gate /*ARGSUSED*/
20950Sstevel@tonic-gate void
setsunique(int argc,char * argv[])20960Sstevel@tonic-gate setsunique(int argc, char *argv[])
20970Sstevel@tonic-gate {
20980Sstevel@tonic-gate sunique = !sunique;
20990Sstevel@tonic-gate (void) printf("Store unique %s.\n", onoff(sunique));
21000Sstevel@tonic-gate code = sunique;
21010Sstevel@tonic-gate }
21020Sstevel@tonic-gate
21030Sstevel@tonic-gate /*ARGSUSED*/
21040Sstevel@tonic-gate void
setrunique(int argc,char * argv[])21050Sstevel@tonic-gate setrunique(int argc, char *argv[])
21060Sstevel@tonic-gate {
21070Sstevel@tonic-gate runique = !runique;
21080Sstevel@tonic-gate (void) printf("Receive unique %s.\n", onoff(runique));
21090Sstevel@tonic-gate code = runique;
21100Sstevel@tonic-gate }
21110Sstevel@tonic-gate
21120Sstevel@tonic-gate /*ARGSUSED*/
21130Sstevel@tonic-gate void
setpassive(int argc,char * argv[])21140Sstevel@tonic-gate setpassive(int argc, char *argv[])
21150Sstevel@tonic-gate {
21160Sstevel@tonic-gate passivemode = !passivemode;
21170Sstevel@tonic-gate (void) printf("Passive mode %s.\n", onoff(passivemode));
21180Sstevel@tonic-gate code = passivemode;
21190Sstevel@tonic-gate }
21200Sstevel@tonic-gate
21210Sstevel@tonic-gate void
settcpwindow(int argc,char * argv[])21220Sstevel@tonic-gate settcpwindow(int argc, char *argv[])
21230Sstevel@tonic-gate {
21240Sstevel@tonic-gate int owindowsize = tcpwindowsize;
21250Sstevel@tonic-gate
21260Sstevel@tonic-gate if (argc > 2) {
21270Sstevel@tonic-gate (void) printf("usage: %s [size]\n", argv[0]);
21280Sstevel@tonic-gate code = -1;
21290Sstevel@tonic-gate return;
21300Sstevel@tonic-gate }
21310Sstevel@tonic-gate if (argc == 2) {
21320Sstevel@tonic-gate int window;
21330Sstevel@tonic-gate char *endp;
21340Sstevel@tonic-gate
21350Sstevel@tonic-gate errno = 0;
21360Sstevel@tonic-gate window = (int)strtol(argv[1], &endp, 10);
21370Sstevel@tonic-gate if (errno || window < 0 || *endp != '\0')
21380Sstevel@tonic-gate (void) printf("%s: Invalid size `%s'\n",
21390Sstevel@tonic-gate argv[0], argv[1]);
21400Sstevel@tonic-gate else
21410Sstevel@tonic-gate tcpwindowsize = window;
21420Sstevel@tonic-gate }
21430Sstevel@tonic-gate if (tcpwindowsize == 0) {
21440Sstevel@tonic-gate if (owindowsize == 0)
21450Sstevel@tonic-gate (void) printf("No TCP window size defined\n");
21460Sstevel@tonic-gate else
21470Sstevel@tonic-gate (void) printf("TCP window size cleared\n");
21480Sstevel@tonic-gate } else
21490Sstevel@tonic-gate (void) printf("TCP window size is set to %d\n", tcpwindowsize);
21500Sstevel@tonic-gate }
21510Sstevel@tonic-gate
21520Sstevel@tonic-gate /* change directory to parent directory */
21530Sstevel@tonic-gate /*ARGSUSED*/
21540Sstevel@tonic-gate void
cdup(int argc,char * argv[])21550Sstevel@tonic-gate cdup(int argc, char *argv[])
21560Sstevel@tonic-gate {
21570Sstevel@tonic-gate (void) command("CDUP");
21580Sstevel@tonic-gate }
21590Sstevel@tonic-gate
21600Sstevel@tonic-gate void
macdef(int argc,char * argv[])21610Sstevel@tonic-gate macdef(int argc, char *argv[])
21620Sstevel@tonic-gate {
21630Sstevel@tonic-gate char *tmp;
21640Sstevel@tonic-gate int c;
21650Sstevel@tonic-gate
21660Sstevel@tonic-gate if (macnum == 16) {
21670Sstevel@tonic-gate (void) printf("Limit of 16 macros have already been defined\n");
21680Sstevel@tonic-gate code = -1;
21690Sstevel@tonic-gate return;
21700Sstevel@tonic-gate }
21710Sstevel@tonic-gate if (argc < 2) {
21720Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "macro name") == -1) {
21730Sstevel@tonic-gate code = -1;
21740Sstevel@tonic-gate return;
21750Sstevel@tonic-gate }
21760Sstevel@tonic-gate makeargv();
21770Sstevel@tonic-gate argc = margc;
21780Sstevel@tonic-gate argv = margv;
21790Sstevel@tonic-gate }
21800Sstevel@tonic-gate if (argc != 2) {
21810Sstevel@tonic-gate (void) printf("Usage: %s macro_name\n", argv[0]);
21820Sstevel@tonic-gate code = -1;
21830Sstevel@tonic-gate return;
21840Sstevel@tonic-gate }
21850Sstevel@tonic-gate if (interactive) {
21860Sstevel@tonic-gate (void) printf("Enter macro line by line, terminating "
21870Sstevel@tonic-gate "it with a null line\n");
21880Sstevel@tonic-gate }
21890Sstevel@tonic-gate (void) strncpy(macros[macnum].mac_name, argv[1], 8);
21900Sstevel@tonic-gate if (macnum == 0) {
21910Sstevel@tonic-gate macros[macnum].mac_start = macbuf;
21920Sstevel@tonic-gate } else {
21930Sstevel@tonic-gate macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
21940Sstevel@tonic-gate }
21950Sstevel@tonic-gate tmp = macros[macnum].mac_start;
21960Sstevel@tonic-gate while (tmp != macbuf+4096) {
21970Sstevel@tonic-gate if ((c = getchar()) == EOF) {
21980Sstevel@tonic-gate (void) printf("macdef:end of file encountered\n");
21990Sstevel@tonic-gate code = -1;
22000Sstevel@tonic-gate return;
22010Sstevel@tonic-gate }
22020Sstevel@tonic-gate if ((*tmp = c) == '\n') {
22030Sstevel@tonic-gate if (tmp == macros[macnum].mac_start) {
22040Sstevel@tonic-gate macros[macnum++].mac_end = tmp;
22050Sstevel@tonic-gate code = 0;
22060Sstevel@tonic-gate return;
22070Sstevel@tonic-gate }
22080Sstevel@tonic-gate if (*(tmp-1) == '\0') {
22090Sstevel@tonic-gate macros[macnum++].mac_end = tmp - 1;
22100Sstevel@tonic-gate code = 0;
22110Sstevel@tonic-gate return;
22120Sstevel@tonic-gate }
22130Sstevel@tonic-gate *tmp = '\0';
22140Sstevel@tonic-gate }
22150Sstevel@tonic-gate tmp++;
22160Sstevel@tonic-gate }
22170Sstevel@tonic-gate for (;;) {
22180Sstevel@tonic-gate while ((c = getchar()) != '\n' && c != EOF)
22190Sstevel@tonic-gate /* NULL */;
22200Sstevel@tonic-gate if (c == EOF || getchar() == '\n') {
22210Sstevel@tonic-gate (void) printf(
22220Sstevel@tonic-gate "Macro not defined - 4k buffer exceeded\n");
22230Sstevel@tonic-gate code = -1;
22240Sstevel@tonic-gate return;
22250Sstevel@tonic-gate }
22260Sstevel@tonic-gate }
22270Sstevel@tonic-gate }
22280Sstevel@tonic-gate
22290Sstevel@tonic-gate /*
22300Sstevel@tonic-gate * The p_name strings are for the getlevel and setlevel commands.
22310Sstevel@tonic-gate * The name strings for printing are in the arpa/ftp.h file in the
22320Sstevel@tonic-gate * protnames[] array of strings.
22330Sstevel@tonic-gate */
22340Sstevel@tonic-gate static struct levels {
22350Sstevel@tonic-gate char *p_name;
22360Sstevel@tonic-gate char *p_mode;
22370Sstevel@tonic-gate int p_level;
22380Sstevel@tonic-gate } levels[] = {
22390Sstevel@tonic-gate { "clear", "C", PROT_C },
22400Sstevel@tonic-gate { "safe", "S", PROT_S },
22410Sstevel@tonic-gate { "private", "P", PROT_P },
22420Sstevel@tonic-gate NULL
22430Sstevel@tonic-gate };
22440Sstevel@tonic-gate
22450Sstevel@tonic-gate /*
22460Sstevel@tonic-gate * Return a pointer to a string which is the readable version of the
22470Sstevel@tonic-gate * protection level, or NULL if the input level is not found.
22480Sstevel@tonic-gate */
22490Sstevel@tonic-gate static char *
getlevel(int level)22500Sstevel@tonic-gate getlevel(int level)
22510Sstevel@tonic-gate {
22520Sstevel@tonic-gate struct levels *p;
22530Sstevel@tonic-gate
22540Sstevel@tonic-gate for (p = levels; (p != NULL) && (p->p_level != level); p++)
22550Sstevel@tonic-gate ;
22560Sstevel@tonic-gate return (p ? p->p_name : NULL);
22570Sstevel@tonic-gate }
22580Sstevel@tonic-gate
22590Sstevel@tonic-gate static char *plevel[] = {
22600Sstevel@tonic-gate "protect",
22610Sstevel@tonic-gate "",
22620Sstevel@tonic-gate NULL
22630Sstevel@tonic-gate };
22640Sstevel@tonic-gate
22650Sstevel@tonic-gate /*
22660Sstevel@tonic-gate * Set control channel protection level.
22670Sstevel@tonic-gate */
22680Sstevel@tonic-gate void
setclevel(int argc,char * argv[])22690Sstevel@tonic-gate setclevel(int argc, char *argv[])
22700Sstevel@tonic-gate {
22710Sstevel@tonic-gate struct levels *p;
22720Sstevel@tonic-gate char *levelp;
22730Sstevel@tonic-gate int comret;
22740Sstevel@tonic-gate
22750Sstevel@tonic-gate if (argc > 2) {
22760Sstevel@tonic-gate char *sep;
22770Sstevel@tonic-gate
22780Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]);
22790Sstevel@tonic-gate sep = " ";
22800Sstevel@tonic-gate for (p = levels; p->p_name; p++) {
22810Sstevel@tonic-gate (void) printf("%s%s", sep, p->p_name);
22820Sstevel@tonic-gate if (*sep == ' ')
22830Sstevel@tonic-gate sep = " | ";
22840Sstevel@tonic-gate }
22850Sstevel@tonic-gate (void) printf(" ]\n");
22860Sstevel@tonic-gate code = -1;
22870Sstevel@tonic-gate return;
22880Sstevel@tonic-gate }
22890Sstevel@tonic-gate if (argc < 2) {
22900Sstevel@tonic-gate levelp = getlevel(clevel);
22910Sstevel@tonic-gate (void) printf("Using %s protection level for commands.\n",
22920Sstevel@tonic-gate levelp ? levelp : "<unknown>");
22930Sstevel@tonic-gate code = 0;
22940Sstevel@tonic-gate return;
22950Sstevel@tonic-gate }
22960Sstevel@tonic-gate for (p = levels; (p != NULL) && (p->p_name); p++)
22970Sstevel@tonic-gate if (strcmp(argv[1], p->p_name) == 0)
22980Sstevel@tonic-gate break;
22990Sstevel@tonic-gate if (p->p_name == 0) {
23000Sstevel@tonic-gate (void) printf("%s: unknown protection level\n", argv[1]);
23010Sstevel@tonic-gate code = -1;
23020Sstevel@tonic-gate return;
23030Sstevel@tonic-gate }
23040Sstevel@tonic-gate if (auth_type == AUTHTYPE_NONE) {
23050Sstevel@tonic-gate if (strcmp(p->p_name, "clear"))
23060Sstevel@tonic-gate (void) printf("Cannot set protection level to %s\n",
23070Sstevel@tonic-gate argv[1]);
23080Sstevel@tonic-gate return;
23090Sstevel@tonic-gate }
23100Sstevel@tonic-gate if (strcmp(p->p_name, "clear") == 0) {
23110Sstevel@tonic-gate comret = command("CCC");
23120Sstevel@tonic-gate if (comret == COMPLETE)
23130Sstevel@tonic-gate clevel = PROT_C;
23140Sstevel@tonic-gate return;
23150Sstevel@tonic-gate }
23160Sstevel@tonic-gate clevel = p->p_level;
23170Sstevel@tonic-gate (void) printf("Control channel protection level set to %s.\n",
23180Sstevel@tonic-gate p->p_name);
23190Sstevel@tonic-gate }
23200Sstevel@tonic-gate
23210Sstevel@tonic-gate /*
23220Sstevel@tonic-gate * Set data channel protection level.
23230Sstevel@tonic-gate */
23240Sstevel@tonic-gate void
setdlevel(int argc,char * argv[])23250Sstevel@tonic-gate setdlevel(int argc, char *argv[])
23260Sstevel@tonic-gate {
23270Sstevel@tonic-gate struct levels *p;
23280Sstevel@tonic-gate int comret;
23290Sstevel@tonic-gate
23300Sstevel@tonic-gate if (argc != 2) {
23310Sstevel@tonic-gate char *sep;
23320Sstevel@tonic-gate
23330Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]);
23340Sstevel@tonic-gate sep = " ";
23350Sstevel@tonic-gate for (p = levels; p->p_name; p++) {
23360Sstevel@tonic-gate (void) printf("%s%s", sep, p->p_name);
23370Sstevel@tonic-gate if (*sep == ' ')
23380Sstevel@tonic-gate sep = " | ";
23390Sstevel@tonic-gate }
23400Sstevel@tonic-gate (void) printf(" ]\n");
23410Sstevel@tonic-gate code = -1;
23420Sstevel@tonic-gate return;
23430Sstevel@tonic-gate }
23440Sstevel@tonic-gate for (p = levels; p->p_name; p++)
23450Sstevel@tonic-gate if (strcmp(argv[1], p->p_name) == 0)
23460Sstevel@tonic-gate break;
23470Sstevel@tonic-gate if (p->p_name == 0) {
23480Sstevel@tonic-gate (void) printf("%s: unknown protection level\n", argv[1]);
23490Sstevel@tonic-gate code = -1;
23500Sstevel@tonic-gate return;
23510Sstevel@tonic-gate }
23520Sstevel@tonic-gate if (auth_type == AUTHTYPE_NONE) {
23530Sstevel@tonic-gate if (strcmp(p->p_name, "clear"))
23540Sstevel@tonic-gate (void) printf("Cannot set protection level to %s\n",
23550Sstevel@tonic-gate argv[1]);
23560Sstevel@tonic-gate return;
23570Sstevel@tonic-gate }
23580Sstevel@tonic-gate /* Start with a PBSZ of 1 meg */
23590Sstevel@tonic-gate if (p->p_level != PROT_C)
23600Sstevel@tonic-gate setpbsz(1<<20);
23610Sstevel@tonic-gate comret = command("PROT %s", p->p_mode);
23620Sstevel@tonic-gate if (comret == COMPLETE)
23630Sstevel@tonic-gate dlevel = p->p_level;
23640Sstevel@tonic-gate }
23650Sstevel@tonic-gate
23660Sstevel@tonic-gate /*
23670Sstevel@tonic-gate * Set clear command protection level.
23680Sstevel@tonic-gate */
23690Sstevel@tonic-gate /* VARARGS */
23700Sstevel@tonic-gate void
ccc(int argc,char * argv[])23710Sstevel@tonic-gate ccc(int argc, char *argv[])
23720Sstevel@tonic-gate {
23730Sstevel@tonic-gate plevel[1] = "clear";
23740Sstevel@tonic-gate setclevel(2, plevel);
23750Sstevel@tonic-gate }
23760Sstevel@tonic-gate
23770Sstevel@tonic-gate /*
23780Sstevel@tonic-gate * Set clear data protection level.
23790Sstevel@tonic-gate */
23800Sstevel@tonic-gate /* VARARGS */
23810Sstevel@tonic-gate void
setclear(int argc,char * argv[])23820Sstevel@tonic-gate setclear(int argc, char *argv[])
23830Sstevel@tonic-gate {
23840Sstevel@tonic-gate plevel[1] = "clear";
23850Sstevel@tonic-gate setdlevel(2, plevel);
23860Sstevel@tonic-gate }
23870Sstevel@tonic-gate
23880Sstevel@tonic-gate /*
23890Sstevel@tonic-gate * Set safe data protection level.
23900Sstevel@tonic-gate */
23910Sstevel@tonic-gate /* VARARGS */
23920Sstevel@tonic-gate void
setsafe(int argc,char * argv[])23930Sstevel@tonic-gate setsafe(int argc, char *argv[])
23940Sstevel@tonic-gate {
23950Sstevel@tonic-gate plevel[1] = "safe";
23960Sstevel@tonic-gate setdlevel(2, plevel);
23970Sstevel@tonic-gate }
23980Sstevel@tonic-gate
23990Sstevel@tonic-gate /*
24000Sstevel@tonic-gate * Set private data protection level.
24010Sstevel@tonic-gate */
24020Sstevel@tonic-gate /* VARARGS */
24030Sstevel@tonic-gate void
setprivate(int argc,char * argv[])24040Sstevel@tonic-gate setprivate(int argc, char *argv[])
24050Sstevel@tonic-gate {
24060Sstevel@tonic-gate plevel[1] = "private";
24070Sstevel@tonic-gate setdlevel(2, plevel);
24080Sstevel@tonic-gate }
24090Sstevel@tonic-gate
24100Sstevel@tonic-gate /*
24110Sstevel@tonic-gate * Set mechanism type
24120Sstevel@tonic-gate */
24130Sstevel@tonic-gate void
setmech(int argc,char * argv[])24140Sstevel@tonic-gate setmech(int argc, char *argv[])
24150Sstevel@tonic-gate {
24160Sstevel@tonic-gate char tempmech[MECH_SZ];
24170Sstevel@tonic-gate
24180Sstevel@tonic-gate if (argc < 2) {
24190Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "mech-type") == -1) {
24200Sstevel@tonic-gate code = -1;
24210Sstevel@tonic-gate return;
24220Sstevel@tonic-gate }
24230Sstevel@tonic-gate makeargv();
24240Sstevel@tonic-gate argc = margc;
24250Sstevel@tonic-gate argv = margv;
24260Sstevel@tonic-gate }
24270Sstevel@tonic-gate
24280Sstevel@tonic-gate if (argc != 2) {
24290Sstevel@tonic-gate (void) printf("usage: %s [ mechanism type ]\n", argv[0]);
24300Sstevel@tonic-gate code = -1;
24310Sstevel@tonic-gate return;
24320Sstevel@tonic-gate }
24330Sstevel@tonic-gate
24340Sstevel@tonic-gate if ((strlcpy(tempmech, argv[1], MECH_SZ) >= MECH_SZ) ||
24350Sstevel@tonic-gate __gss_mech_to_oid(tempmech, (gss_OID*)&mechoid) !=
24360Sstevel@tonic-gate GSS_S_COMPLETE) {
24370Sstevel@tonic-gate (void) printf("%s: %s: not a valid security mechanism\n",
24380Sstevel@tonic-gate argv[0], tempmech);
24390Sstevel@tonic-gate code = -1;
24400Sstevel@tonic-gate return;
24410Sstevel@tonic-gate } else {
24420Sstevel@tonic-gate (void) strlcpy(mechstr, tempmech, MECH_SZ);
24430Sstevel@tonic-gate (void) printf("Using %s mechanism type\n", mechstr);
24440Sstevel@tonic-gate code = 0;
24450Sstevel@tonic-gate return;
24460Sstevel@tonic-gate }
24470Sstevel@tonic-gate }
2448