17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0b6880ccSsp149894 * Common Development and Distribution License (the "License").
6*0b6880ccSsp149894 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*0b6880ccSsp149894 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate * The Regents of the University of California
327c478bd9Sstevel@tonic-gate * All Rights Reserved
337c478bd9Sstevel@tonic-gate *
347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate * contributors.
377c478bd9Sstevel@tonic-gate */
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * FTP User Program -- Command Routines.
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate #define FTP_NAMES
467c478bd9Sstevel@tonic-gate #include "ftp_var.h"
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate FILE *tmp_nlst = NULL; /* tmp file; holds NLST results for mget, etc */
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate static char *mname;
517c478bd9Sstevel@tonic-gate static jmp_buf jabort;
527c478bd9Sstevel@tonic-gate static jmp_buf abortprox;
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate static char *remglob(char *argv[], int doswitch);
557c478bd9Sstevel@tonic-gate static char *onoff(int bool);
567c478bd9Sstevel@tonic-gate static int confirm(char *cmd, char *file);
577c478bd9Sstevel@tonic-gate static int globulize(char **cpp);
587c478bd9Sstevel@tonic-gate static void proxabort(int sig);
597c478bd9Sstevel@tonic-gate static void mabort(int sig);
607c478bd9Sstevel@tonic-gate static char *dotrans(char *name);
617c478bd9Sstevel@tonic-gate static char *domap(char *name);
627c478bd9Sstevel@tonic-gate static void getit(int argc, char *argv[], int restartit, char *mode);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate static char *getlevel(int);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /* Prompt for command argument, add to buffer with space separator */
677c478bd9Sstevel@tonic-gate static int
prompt_for_arg(char * buffer,int buffer_size,char * prompt)687c478bd9Sstevel@tonic-gate prompt_for_arg(char *buffer, int buffer_size, char *prompt)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate if (strlen(buffer) > buffer_size - 2) {
717c478bd9Sstevel@tonic-gate (void) printf("Line too long\n");
727c478bd9Sstevel@tonic-gate return (-1);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate strcat(buffer, " ");
757c478bd9Sstevel@tonic-gate stop_timer();
767c478bd9Sstevel@tonic-gate (void) printf("(%s) ", prompt);
777c478bd9Sstevel@tonic-gate if (fgets(buffer + strlen(buffer), buffer_size - strlen(buffer), stdin)
787c478bd9Sstevel@tonic-gate == NULL) {
797c478bd9Sstevel@tonic-gate reset_timer();
807c478bd9Sstevel@tonic-gate return (-1);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate /* Flush what didn't fit in the buffer */
847c478bd9Sstevel@tonic-gate if (buffer[strlen(buffer)-1] != '\n') {
857c478bd9Sstevel@tonic-gate while (fgetc(stdin) != '\n' && !ferror(stdin) && !feof(stdin))
867c478bd9Sstevel@tonic-gate ;
877c478bd9Sstevel@tonic-gate (void) printf("Line too long\n");
887c478bd9Sstevel@tonic-gate reset_timer();
897c478bd9Sstevel@tonic-gate return (-1);
907c478bd9Sstevel@tonic-gate } else
917c478bd9Sstevel@tonic-gate buffer[strlen(buffer)-1] = 0;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate reset_timer();
947c478bd9Sstevel@tonic-gate return (0);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate * Connect to peer server and
1007c478bd9Sstevel@tonic-gate * auto-login, if possible.
1017c478bd9Sstevel@tonic-gate */
1027c478bd9Sstevel@tonic-gate void
setpeer(int argc,char * argv[])1037c478bd9Sstevel@tonic-gate setpeer(int argc, char *argv[])
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate char *host;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate if (connected) {
1087c478bd9Sstevel@tonic-gate (void) printf("Already connected to %s, use close first.\n",
1097c478bd9Sstevel@tonic-gate hostname);
1107c478bd9Sstevel@tonic-gate code = -1;
1117c478bd9Sstevel@tonic-gate return;
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate if (argc < 2) {
1147c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "to") == -1) {
1157c478bd9Sstevel@tonic-gate code = -1;
1167c478bd9Sstevel@tonic-gate return;
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate makeargv();
1197c478bd9Sstevel@tonic-gate argc = margc;
1207c478bd9Sstevel@tonic-gate argv = margv;
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate if (argc > 3 || argc < 2) {
1237c478bd9Sstevel@tonic-gate (void) printf("usage: %s host-name [port]\n", argv[0]);
1247c478bd9Sstevel@tonic-gate code = -1;
1257c478bd9Sstevel@tonic-gate return;
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate strcpy(typename, "ascii");
1287c478bd9Sstevel@tonic-gate host = hookup(argv[1], (argc > 2 ? argv[2] : "ftp"));
1297c478bd9Sstevel@tonic-gate if (host) {
1307c478bd9Sstevel@tonic-gate int overbose;
1317c478bd9Sstevel@tonic-gate extern char reply_string[];
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate connected = 1;
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate * Set up defaults for FTP.
1367c478bd9Sstevel@tonic-gate */
1377c478bd9Sstevel@tonic-gate clevel = dlevel = PROT_C;
1387c478bd9Sstevel@tonic-gate if (autoauth) {
1397c478bd9Sstevel@tonic-gate if (do_auth() && autoencrypt) {
1407c478bd9Sstevel@tonic-gate clevel = PROT_P;
1417c478bd9Sstevel@tonic-gate setpbsz(1<<20);
1427c478bd9Sstevel@tonic-gate if (command("PROT P") == COMPLETE)
1437c478bd9Sstevel@tonic-gate dlevel = PROT_P;
1447c478bd9Sstevel@tonic-gate else {
1457c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
1467c478bd9Sstevel@tonic-gate "%s: couldn't enable encryption\n",
1477c478bd9Sstevel@tonic-gate argv[0]);
1487c478bd9Sstevel@tonic-gate /* unable to encrypt command channel, too! */
1497c478bd9Sstevel@tonic-gate dlevel = clevel = PROT_C;
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate if ((auth_type != AUTHTYPE_NONE) && (clevel == PROT_C))
1537c478bd9Sstevel@tonic-gate clevel = PROT_S;
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate if (autologin)
1577c478bd9Sstevel@tonic-gate (void) login(argv[1]);
158*0b6880ccSsp149894 /* if skipsyst is enabled, then don't send SYST command */
159*0b6880ccSsp149894 if (skipsyst)
160*0b6880ccSsp149894 return;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate overbose = verbose;
1637c478bd9Sstevel@tonic-gate if (debug == 0)
1647c478bd9Sstevel@tonic-gate verbose = -1;
1657c478bd9Sstevel@tonic-gate if (command("SYST") == COMPLETE && overbose) {
1667c478bd9Sstevel@tonic-gate char *cp, c;
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate cp = index(reply_string+4, ' ');
1697c478bd9Sstevel@tonic-gate if (cp == NULL)
1707c478bd9Sstevel@tonic-gate cp = index(reply_string+4, '\r');
1717c478bd9Sstevel@tonic-gate if (cp) {
1727c478bd9Sstevel@tonic-gate if (cp[-1] == '.')
1737c478bd9Sstevel@tonic-gate cp--;
1747c478bd9Sstevel@tonic-gate c = *cp;
1757c478bd9Sstevel@tonic-gate *cp = '\0';
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate (void) printf("Remote system type is %s.\n",
1797c478bd9Sstevel@tonic-gate reply_string+4);
1807c478bd9Sstevel@tonic-gate if (cp)
1817c478bd9Sstevel@tonic-gate *cp = c;
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate if (strncmp(reply_string, "215 UNIX Type: L8", 17) == 0) {
1847c478bd9Sstevel@tonic-gate setbinary(0, NULL);
1857c478bd9Sstevel@tonic-gate if (overbose)
1867c478bd9Sstevel@tonic-gate (void) printf(
1877c478bd9Sstevel@tonic-gate "Using %s mode to transfer files.\n",
1887c478bd9Sstevel@tonic-gate typename);
1897c478bd9Sstevel@tonic-gate } else if (overbose &&
1907c478bd9Sstevel@tonic-gate strncmp(reply_string, "215 TOPS20", 10) == 0) {
1917c478bd9Sstevel@tonic-gate (void) printf(
1927c478bd9Sstevel@tonic-gate "Remember to set tenex mode when transfering "
1937c478bd9Sstevel@tonic-gate "binary files from this machine.\n");
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate verbose = overbose;
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate static struct types {
2007c478bd9Sstevel@tonic-gate char *t_name;
2017c478bd9Sstevel@tonic-gate char *t_mode;
2027c478bd9Sstevel@tonic-gate int t_type;
2037c478bd9Sstevel@tonic-gate char *t_arg;
2047c478bd9Sstevel@tonic-gate } types[] = {
2057c478bd9Sstevel@tonic-gate { "ascii", "A", TYPE_A, 0 },
2067c478bd9Sstevel@tonic-gate { "binary", "I", TYPE_I, 0 },
2077c478bd9Sstevel@tonic-gate { "image", "I", TYPE_I, 0 },
2087c478bd9Sstevel@tonic-gate { "ebcdic", "E", TYPE_E, 0 },
2097c478bd9Sstevel@tonic-gate { "tenex", "L", TYPE_L, bytename },
2107c478bd9Sstevel@tonic-gate 0
2117c478bd9Sstevel@tonic-gate };
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate * Set transfer type.
2157c478bd9Sstevel@tonic-gate */
2167c478bd9Sstevel@tonic-gate void
settype(int argc,char * argv[])2177c478bd9Sstevel@tonic-gate settype(int argc, char *argv[])
2187c478bd9Sstevel@tonic-gate {
2197c478bd9Sstevel@tonic-gate struct types *p;
2207c478bd9Sstevel@tonic-gate int comret;
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate if (argc > 2) {
2237c478bd9Sstevel@tonic-gate char *sep;
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]);
2267c478bd9Sstevel@tonic-gate sep = " ";
2277c478bd9Sstevel@tonic-gate for (p = types; p->t_name; p++) {
2287c478bd9Sstevel@tonic-gate (void) printf("%s%s", sep, p->t_name);
2297c478bd9Sstevel@tonic-gate if (*sep == ' ')
2307c478bd9Sstevel@tonic-gate sep = " | ";
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate (void) printf(" ]\n");
2337c478bd9Sstevel@tonic-gate code = -1;
2347c478bd9Sstevel@tonic-gate return;
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate if (argc < 2) {
2377c478bd9Sstevel@tonic-gate (void) printf("Using %s mode to transfer files.\n", typename);
2387c478bd9Sstevel@tonic-gate code = 0;
2397c478bd9Sstevel@tonic-gate return;
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate for (p = types; p->t_name; p++)
2427c478bd9Sstevel@tonic-gate if (strcmp(argv[1], p->t_name) == 0)
2437c478bd9Sstevel@tonic-gate break;
2447c478bd9Sstevel@tonic-gate if (p->t_name == 0) {
2457c478bd9Sstevel@tonic-gate (void) printf("%s: unknown mode\n", argv[1]);
2467c478bd9Sstevel@tonic-gate code = -1;
2477c478bd9Sstevel@tonic-gate return;
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
2507c478bd9Sstevel@tonic-gate comret = command("TYPE %s %s", p->t_mode, p->t_arg);
2517c478bd9Sstevel@tonic-gate else
2527c478bd9Sstevel@tonic-gate comret = command("TYPE %s", p->t_mode);
2537c478bd9Sstevel@tonic-gate if (comret == COMPLETE) {
2547c478bd9Sstevel@tonic-gate (void) strcpy(typename, p->t_name);
2557c478bd9Sstevel@tonic-gate type = p->t_type;
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate * Set binary transfer type.
2617c478bd9Sstevel@tonic-gate */
2627c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2637c478bd9Sstevel@tonic-gate void
setbinary(int argc,char * argv[])2647c478bd9Sstevel@tonic-gate setbinary(int argc, char *argv[])
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate call(settype, "type", "binary", 0);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate * Set ascii transfer type.
2717c478bd9Sstevel@tonic-gate */
2727c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2737c478bd9Sstevel@tonic-gate void
setascii(int argc,char * argv[])2747c478bd9Sstevel@tonic-gate setascii(int argc, char *argv[])
2757c478bd9Sstevel@tonic-gate {
2767c478bd9Sstevel@tonic-gate call(settype, "type", "ascii", 0);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate * Set tenex transfer type.
2817c478bd9Sstevel@tonic-gate */
2827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2837c478bd9Sstevel@tonic-gate void
settenex(int argc,char * argv[])2847c478bd9Sstevel@tonic-gate settenex(int argc, char *argv[])
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate call(settype, "type", "tenex", 0);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate * Set ebcdic transfer type.
2917c478bd9Sstevel@tonic-gate */
2927c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2937c478bd9Sstevel@tonic-gate void
setebcdic(int argc,char * argv[])2947c478bd9Sstevel@tonic-gate setebcdic(int argc, char *argv[])
2957c478bd9Sstevel@tonic-gate {
2967c478bd9Sstevel@tonic-gate call(settype, "type", "ebcdic", 0);
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate * Set file transfer mode.
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3037c478bd9Sstevel@tonic-gate void
setmode(int argc,char * argv[])3047c478bd9Sstevel@tonic-gate setmode(int argc, char *argv[])
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate (void) printf("We only support %s mode, sorry.\n", modename);
3077c478bd9Sstevel@tonic-gate code = -1;
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate * Set file transfer format.
3127c478bd9Sstevel@tonic-gate */
3137c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3147c478bd9Sstevel@tonic-gate void
setform(int argc,char * argv[])3157c478bd9Sstevel@tonic-gate setform(int argc, char *argv[])
3167c478bd9Sstevel@tonic-gate {
3177c478bd9Sstevel@tonic-gate (void) printf("We only support %s format, sorry.\n", formname);
3187c478bd9Sstevel@tonic-gate code = -1;
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate * Set file transfer structure.
3237c478bd9Sstevel@tonic-gate */
3247c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3257c478bd9Sstevel@tonic-gate void
setstruct(int argc,char * argv[])3267c478bd9Sstevel@tonic-gate setstruct(int argc, char *argv[])
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate (void) printf("We only support %s structure, sorry.\n", structname);
3307c478bd9Sstevel@tonic-gate code = -1;
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate * Send a single file.
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate void
put(int argc,char * argv[])3377c478bd9Sstevel@tonic-gate put(int argc, char *argv[])
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate char *cmd;
3407c478bd9Sstevel@tonic-gate int loc = 0;
3417c478bd9Sstevel@tonic-gate char *oldargv1;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate if (argc == 2) {
3447c478bd9Sstevel@tonic-gate argc++;
3457c478bd9Sstevel@tonic-gate argv[2] = argv[1];
3467c478bd9Sstevel@tonic-gate loc++;
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate if (argc < 2) {
3497c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") == -1) {
3507c478bd9Sstevel@tonic-gate code = -1;
3517c478bd9Sstevel@tonic-gate return;
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate makeargv();
3547c478bd9Sstevel@tonic-gate argc = margc;
3557c478bd9Sstevel@tonic-gate argv = margv;
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate if (argc < 2) {
3587c478bd9Sstevel@tonic-gate usage:
3597c478bd9Sstevel@tonic-gate (void) printf("usage: %s local-file remote-file\n", argv[0]);
3607c478bd9Sstevel@tonic-gate code = -1;
3617c478bd9Sstevel@tonic-gate return;
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate if (argc < 3) {
3647c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") == -1) {
3657c478bd9Sstevel@tonic-gate code = -1;
3667c478bd9Sstevel@tonic-gate return;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate makeargv();
3697c478bd9Sstevel@tonic-gate argc = margc;
3707c478bd9Sstevel@tonic-gate argv = margv;
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate if (argc < 3)
3737c478bd9Sstevel@tonic-gate goto usage;
3747c478bd9Sstevel@tonic-gate oldargv1 = argv[1];
3757c478bd9Sstevel@tonic-gate if (!globulize(&argv[1])) {
3767c478bd9Sstevel@tonic-gate code = -1;
3777c478bd9Sstevel@tonic-gate return;
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate * If "globulize" modifies argv[1], and argv[2] is a copy of
3817c478bd9Sstevel@tonic-gate * the old argv[1], make it a copy of the new argv[1].
3827c478bd9Sstevel@tonic-gate */
3837c478bd9Sstevel@tonic-gate if (argv[1] != oldargv1 && argv[2] == oldargv1) {
3847c478bd9Sstevel@tonic-gate argv[2] = argv[1];
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
3877c478bd9Sstevel@tonic-gate if (loc && ntflag) {
3887c478bd9Sstevel@tonic-gate argv[2] = dotrans(argv[2]);
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate if (loc && mapflag) {
3917c478bd9Sstevel@tonic-gate argv[2] = domap(argv[2]);
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate sendrequest(cmd, argv[1], argv[2], 1);
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3977c478bd9Sstevel@tonic-gate static void
mabort(int sig)3987c478bd9Sstevel@tonic-gate mabort(int sig)
3997c478bd9Sstevel@tonic-gate {
4007c478bd9Sstevel@tonic-gate int ointer;
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate (void) printf("\n");
4037c478bd9Sstevel@tonic-gate (void) fflush(stdout);
4047c478bd9Sstevel@tonic-gate if (mflag && fromatty) {
4057c478bd9Sstevel@tonic-gate ointer = interactive;
4067c478bd9Sstevel@tonic-gate interactive = 1;
4077c478bd9Sstevel@tonic-gate if (confirm("Continue with", mname)) {
4087c478bd9Sstevel@tonic-gate interactive = ointer;
4097c478bd9Sstevel@tonic-gate longjmp(jabort, 0);
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate interactive = ointer;
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate mflag = 0;
4147c478bd9Sstevel@tonic-gate longjmp(jabort, 0);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate * Send multiple files.
4197c478bd9Sstevel@tonic-gate */
4207c478bd9Sstevel@tonic-gate void
mput(int argc,char * argv[])4217c478bd9Sstevel@tonic-gate mput(int argc, char *argv[])
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate int i;
4247c478bd9Sstevel@tonic-gate int ointer;
4257c478bd9Sstevel@tonic-gate void (*oldintr)();
4267c478bd9Sstevel@tonic-gate char *tp;
4277c478bd9Sstevel@tonic-gate int len;
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate if (argc < 2) {
4307c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-files") == -1) {
4317c478bd9Sstevel@tonic-gate code = -1;
4327c478bd9Sstevel@tonic-gate return;
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate makeargv();
4357c478bd9Sstevel@tonic-gate argc = margc;
4367c478bd9Sstevel@tonic-gate argv = margv;
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate if (argc < 2) {
4397c478bd9Sstevel@tonic-gate (void) printf("usage: %s local-files\n", argv[0]);
4407c478bd9Sstevel@tonic-gate code = -1;
4417c478bd9Sstevel@tonic-gate return;
4427c478bd9Sstevel@tonic-gate }
4437c478bd9Sstevel@tonic-gate mname = argv[0];
4447c478bd9Sstevel@tonic-gate mflag = 1;
4457c478bd9Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
4467c478bd9Sstevel@tonic-gate (void) setjmp(jabort);
4477c478bd9Sstevel@tonic-gate if (proxy) {
4487c478bd9Sstevel@tonic-gate char *cp, *tp2, tmpbuf[MAXPATHLEN];
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate while ((cp = remglob(argv, 0)) != NULL) {
4517c478bd9Sstevel@tonic-gate if (*cp == 0) {
4527c478bd9Sstevel@tonic-gate mflag = 0;
4537c478bd9Sstevel@tonic-gate continue;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) {
4567c478bd9Sstevel@tonic-gate tp = cp;
4577c478bd9Sstevel@tonic-gate if (mcase) {
4587c478bd9Sstevel@tonic-gate while (*tp) {
4597c478bd9Sstevel@tonic-gate if ((len =
4607c478bd9Sstevel@tonic-gate mblen(tp, MB_CUR_MAX)) <= 0)
4617c478bd9Sstevel@tonic-gate len = 1;
4627c478bd9Sstevel@tonic-gate if (islower(*tp))
4637c478bd9Sstevel@tonic-gate break;
4647c478bd9Sstevel@tonic-gate tp += len;
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate if (!*tp) {
4677c478bd9Sstevel@tonic-gate tp = cp;
4687c478bd9Sstevel@tonic-gate tp2 = tmpbuf;
4697c478bd9Sstevel@tonic-gate while (*tp) {
4707c478bd9Sstevel@tonic-gate if ((len = mblen(tp,
4717c478bd9Sstevel@tonic-gate MB_CUR_MAX)) <= 0)
4727c478bd9Sstevel@tonic-gate len = 1;
4737c478bd9Sstevel@tonic-gate memcpy(tp2, tp, len);
4747c478bd9Sstevel@tonic-gate if (isupper(*tp2)) {
4757c478bd9Sstevel@tonic-gate *tp2 = 'a' +
4767c478bd9Sstevel@tonic-gate *tp2 - 'A';
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate tp += len;
4797c478bd9Sstevel@tonic-gate tp2 += len;
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate *tp2 = 0;
4827c478bd9Sstevel@tonic-gate tp = tmpbuf;
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate if (ntflag) {
4867c478bd9Sstevel@tonic-gate tp = dotrans(tp);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate if (mapflag) {
4897c478bd9Sstevel@tonic-gate tp = domap(tp);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR",
4927c478bd9Sstevel@tonic-gate cp, tp, 0);
4937c478bd9Sstevel@tonic-gate if (!mflag && fromatty) {
4947c478bd9Sstevel@tonic-gate ointer = interactive;
4957c478bd9Sstevel@tonic-gate interactive = 1;
4967c478bd9Sstevel@tonic-gate if (confirm("Continue with", "mput")) {
4977c478bd9Sstevel@tonic-gate mflag++;
4987c478bd9Sstevel@tonic-gate }
4997c478bd9Sstevel@tonic-gate interactive = ointer;
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate }
5037c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
5047c478bd9Sstevel@tonic-gate mflag = 0;
5057c478bd9Sstevel@tonic-gate return;
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) {
5087c478bd9Sstevel@tonic-gate char **cpp, **gargs;
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate if (!doglob) {
5117c478bd9Sstevel@tonic-gate if (mflag && confirm(argv[0], argv[i])) {
5127c478bd9Sstevel@tonic-gate tp = (ntflag) ? dotrans(argv[i]) : argv[i];
5137c478bd9Sstevel@tonic-gate tp = (mapflag) ? domap(tp) : tp;
5147c478bd9Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR",
5157c478bd9Sstevel@tonic-gate argv[i], tp, 1);
5167c478bd9Sstevel@tonic-gate if (!mflag && fromatty) {
5177c478bd9Sstevel@tonic-gate ointer = interactive;
5187c478bd9Sstevel@tonic-gate interactive = 1;
5197c478bd9Sstevel@tonic-gate if (confirm("Continue with", "mput")) {
5207c478bd9Sstevel@tonic-gate mflag++;
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate interactive = ointer;
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate continue;
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate gargs = glob(argv[i]);
5287c478bd9Sstevel@tonic-gate if (globerr != NULL) {
5297c478bd9Sstevel@tonic-gate (void) printf("%s\n", globerr);
5307c478bd9Sstevel@tonic-gate if (gargs)
5317c478bd9Sstevel@tonic-gate blkfree(gargs);
5327c478bd9Sstevel@tonic-gate continue;
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate for (cpp = gargs; cpp && *cpp != NULL; cpp++) {
5357c478bd9Sstevel@tonic-gate if (mflag && confirm(argv[0], *cpp)) {
5367c478bd9Sstevel@tonic-gate tp = (ntflag) ? dotrans(*cpp) : *cpp;
5377c478bd9Sstevel@tonic-gate tp = (mapflag) ? domap(tp) : tp;
5387c478bd9Sstevel@tonic-gate sendrequest((sunique) ? "STOU" : "STOR",
5397c478bd9Sstevel@tonic-gate *cpp, tp, 0);
5407c478bd9Sstevel@tonic-gate if (!mflag && fromatty) {
5417c478bd9Sstevel@tonic-gate ointer = interactive;
5427c478bd9Sstevel@tonic-gate interactive = 1;
5437c478bd9Sstevel@tonic-gate if (confirm("Continue with", "mput")) {
5447c478bd9Sstevel@tonic-gate mflag++;
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate interactive = ointer;
5477c478bd9Sstevel@tonic-gate }
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate }
5507c478bd9Sstevel@tonic-gate if (gargs != NULL)
5517c478bd9Sstevel@tonic-gate blkfree(gargs);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
5547c478bd9Sstevel@tonic-gate mflag = 0;
5557c478bd9Sstevel@tonic-gate }
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate /*
5587c478bd9Sstevel@tonic-gate * Restart transfer at a specific offset.
5597c478bd9Sstevel@tonic-gate */
5607c478bd9Sstevel@tonic-gate void
restart(int argc,char * argv[])5617c478bd9Sstevel@tonic-gate restart(int argc, char *argv[])
5627c478bd9Sstevel@tonic-gate {
5637c478bd9Sstevel@tonic-gate off_t orestart_point = restart_point;
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate if (argc > 2) {
5667c478bd9Sstevel@tonic-gate (void) printf("usage: %s [marker]\n", argv[0]);
5677c478bd9Sstevel@tonic-gate code = -1;
5687c478bd9Sstevel@tonic-gate return;
5697c478bd9Sstevel@tonic-gate }
5707c478bd9Sstevel@tonic-gate if (argc == 2) {
5717c478bd9Sstevel@tonic-gate longlong_t rp;
5727c478bd9Sstevel@tonic-gate char *endp;
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate errno = 0;
5757c478bd9Sstevel@tonic-gate rp = strtoll(argv[1], &endp, 10);
5767c478bd9Sstevel@tonic-gate if (errno || rp < 0 || *endp != '\0')
5777c478bd9Sstevel@tonic-gate (void) printf("%s: Invalid offset `%s'\n",
5787c478bd9Sstevel@tonic-gate argv[0], argv[1]);
5797c478bd9Sstevel@tonic-gate else
5807c478bd9Sstevel@tonic-gate restart_point = rp;
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate if (restart_point == 0) {
5837c478bd9Sstevel@tonic-gate if (orestart_point == 0)
5847c478bd9Sstevel@tonic-gate (void) printf("No restart marker defined\n");
5857c478bd9Sstevel@tonic-gate else
5867c478bd9Sstevel@tonic-gate (void) printf("Restart marker cleared\n");
5877c478bd9Sstevel@tonic-gate } else
5887c478bd9Sstevel@tonic-gate (void) printf(
5897c478bd9Sstevel@tonic-gate "Restarting at %lld for next get, put or append\n",
5907c478bd9Sstevel@tonic-gate (longlong_t)restart_point);
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate void
reget(int argc,char * argv[])5947c478bd9Sstevel@tonic-gate reget(int argc, char *argv[])
5957c478bd9Sstevel@tonic-gate {
5967c478bd9Sstevel@tonic-gate getit(argc, argv, 1, "r+w");
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate void
get(int argc,char * argv[])6007c478bd9Sstevel@tonic-gate get(int argc, char *argv[])
6017c478bd9Sstevel@tonic-gate {
6027c478bd9Sstevel@tonic-gate getit(argc, argv, 0, restart_point ? "r+w" : "w");
6037c478bd9Sstevel@tonic-gate }
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate /*
6067c478bd9Sstevel@tonic-gate * Receive one file.
6077c478bd9Sstevel@tonic-gate */
6087c478bd9Sstevel@tonic-gate static void
getit(int argc,char * argv[],int restartit,char * mode)6097c478bd9Sstevel@tonic-gate getit(int argc, char *argv[], int restartit, char *mode)
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate int loc = 0;
6127c478bd9Sstevel@tonic-gate int len;
6137c478bd9Sstevel@tonic-gate int allowpipe = 1;
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate if (argc == 2) {
6167c478bd9Sstevel@tonic-gate argc++;
6177c478bd9Sstevel@tonic-gate argv[2] = argv[1];
6187c478bd9Sstevel@tonic-gate /* Only permit !file if two arguments. */
6197c478bd9Sstevel@tonic-gate allowpipe = 0;
6207c478bd9Sstevel@tonic-gate loc++;
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate if (argc < 2) {
6237c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") == -1) {
6247c478bd9Sstevel@tonic-gate code = -1;
6257c478bd9Sstevel@tonic-gate return;
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate makeargv();
6287c478bd9Sstevel@tonic-gate argc = margc;
6297c478bd9Sstevel@tonic-gate argv = margv;
6307c478bd9Sstevel@tonic-gate }
6317c478bd9Sstevel@tonic-gate if (argc < 2) {
6327c478bd9Sstevel@tonic-gate usage:
6337c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-file [ local-file ]\n",
6347c478bd9Sstevel@tonic-gate argv[0]);
6357c478bd9Sstevel@tonic-gate code = -1;
6367c478bd9Sstevel@tonic-gate return;
6377c478bd9Sstevel@tonic-gate }
6387c478bd9Sstevel@tonic-gate if (argc < 3) {
6397c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") == -1) {
6407c478bd9Sstevel@tonic-gate code = -1;
6417c478bd9Sstevel@tonic-gate return;
6427c478bd9Sstevel@tonic-gate }
6437c478bd9Sstevel@tonic-gate makeargv();
6447c478bd9Sstevel@tonic-gate argc = margc;
6457c478bd9Sstevel@tonic-gate argv = margv;
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate if (argc < 3)
6487c478bd9Sstevel@tonic-gate goto usage;
6497c478bd9Sstevel@tonic-gate if (!globulize(&argv[2])) {
6507c478bd9Sstevel@tonic-gate code = -1;
6517c478bd9Sstevel@tonic-gate return;
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate if (loc && mcase) {
6547c478bd9Sstevel@tonic-gate char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate while (*tp) {
6577c478bd9Sstevel@tonic-gate if ((len = mblen(tp, MB_CUR_MAX)) <= 0)
6587c478bd9Sstevel@tonic-gate len = 1;
6597c478bd9Sstevel@tonic-gate if (islower(*tp))
6607c478bd9Sstevel@tonic-gate break;
6617c478bd9Sstevel@tonic-gate tp += len;
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate if (!*tp) {
6647c478bd9Sstevel@tonic-gate tp = argv[2];
6657c478bd9Sstevel@tonic-gate tp2 = tmpbuf;
6667c478bd9Sstevel@tonic-gate while (*tp) {
6677c478bd9Sstevel@tonic-gate if ((len = mblen(tp, MB_CUR_MAX)) <= 0)
6687c478bd9Sstevel@tonic-gate len = 1;
6697c478bd9Sstevel@tonic-gate memcpy(tp2, tp, len);
6707c478bd9Sstevel@tonic-gate if (isupper(*tp2))
6717c478bd9Sstevel@tonic-gate *tp2 = 'a' + *tp2 - 'A';
6727c478bd9Sstevel@tonic-gate tp += len;
6737c478bd9Sstevel@tonic-gate tp2 += len;
6747c478bd9Sstevel@tonic-gate }
6757c478bd9Sstevel@tonic-gate *tp2 = 0;
6767c478bd9Sstevel@tonic-gate argv[2] = tmpbuf;
6777c478bd9Sstevel@tonic-gate }
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate if (loc && ntflag) {
6807c478bd9Sstevel@tonic-gate argv[2] = dotrans(argv[2]);
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate if (loc && mapflag) {
6837c478bd9Sstevel@tonic-gate argv[2] = domap(argv[2]);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate if (restartit) {
6867c478bd9Sstevel@tonic-gate struct stat stbuf;
6877c478bd9Sstevel@tonic-gate
6887c478bd9Sstevel@tonic-gate if (stat(argv[2], &stbuf) < 0) {
6897c478bd9Sstevel@tonic-gate perror(argv[2]);
6907c478bd9Sstevel@tonic-gate code = -1;
6917c478bd9Sstevel@tonic-gate return;
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate restart_point = stbuf.st_size;
6947c478bd9Sstevel@tonic-gate }
6957c478bd9Sstevel@tonic-gate recvrequest("RETR", argv[2], argv[1], mode, allowpipe);
6967c478bd9Sstevel@tonic-gate restart_point = 0;
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate
6997c478bd9Sstevel@tonic-gate /*
7007c478bd9Sstevel@tonic-gate * Get multiple files.
7017c478bd9Sstevel@tonic-gate */
7027c478bd9Sstevel@tonic-gate void
mget(int argc,char * argv[])7037c478bd9Sstevel@tonic-gate mget(int argc, char *argv[])
7047c478bd9Sstevel@tonic-gate {
7057c478bd9Sstevel@tonic-gate char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN];
7067c478bd9Sstevel@tonic-gate int ointer;
7077c478bd9Sstevel@tonic-gate void (*oldintr)();
7087c478bd9Sstevel@tonic-gate int need_convert;
7097c478bd9Sstevel@tonic-gate int len;
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate if (argc < 2) {
7127c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) {
7137c478bd9Sstevel@tonic-gate code = -1;
7147c478bd9Sstevel@tonic-gate return;
7157c478bd9Sstevel@tonic-gate }
7167c478bd9Sstevel@tonic-gate makeargv();
7177c478bd9Sstevel@tonic-gate argc = margc;
7187c478bd9Sstevel@tonic-gate argv = margv;
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate if (argc < 2) {
7217c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-files\n", argv[0]);
7227c478bd9Sstevel@tonic-gate code = -1;
7237c478bd9Sstevel@tonic-gate return;
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate mname = argv[0];
7267c478bd9Sstevel@tonic-gate mflag = 1;
7277c478bd9Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
7287c478bd9Sstevel@tonic-gate (void) setjmp(jabort);
7297c478bd9Sstevel@tonic-gate while ((cp = remglob(argv, proxy)) != NULL) {
7307c478bd9Sstevel@tonic-gate if (*cp == '\0') {
7317c478bd9Sstevel@tonic-gate mflag = 0;
7327c478bd9Sstevel@tonic-gate continue;
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) {
7357c478bd9Sstevel@tonic-gate strcpy(tmpbuf, cp);
7367c478bd9Sstevel@tonic-gate tp = tmpbuf;
7377c478bd9Sstevel@tonic-gate need_convert = 1;
7387c478bd9Sstevel@tonic-gate if (mcase) {
7397c478bd9Sstevel@tonic-gate tp2 = tp;
7407c478bd9Sstevel@tonic-gate while (*tp2 && need_convert) {
7417c478bd9Sstevel@tonic-gate /* Need any case convert? */
7427c478bd9Sstevel@tonic-gate if (islower(*tp2))
7437c478bd9Sstevel@tonic-gate need_convert = 0;
7447c478bd9Sstevel@tonic-gate if ((len = mblen(tp2, MB_CUR_MAX)) <= 0)
7457c478bd9Sstevel@tonic-gate len = 1;
7467c478bd9Sstevel@tonic-gate tp2 += len;
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate tp2 = tp;
7497c478bd9Sstevel@tonic-gate while (need_convert && *tp2) {
7507c478bd9Sstevel@tonic-gate /* Convert to lower case */
7517c478bd9Sstevel@tonic-gate if (isupper(*tp2))
7527c478bd9Sstevel@tonic-gate *tp2 = tolower(*tp2);
7537c478bd9Sstevel@tonic-gate if ((len = mblen(tp2, MB_CUR_MAX)) <= 0)
7547c478bd9Sstevel@tonic-gate len = 1;
7557c478bd9Sstevel@tonic-gate tp2 += len;
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate }
7587c478bd9Sstevel@tonic-gate
7597c478bd9Sstevel@tonic-gate if (ntflag) {
7607c478bd9Sstevel@tonic-gate tp = dotrans(tp);
7617c478bd9Sstevel@tonic-gate }
7627c478bd9Sstevel@tonic-gate if (mapflag) {
7637c478bd9Sstevel@tonic-gate tp = domap(tp);
7647c478bd9Sstevel@tonic-gate }
7657c478bd9Sstevel@tonic-gate recvrequest("RETR", tp, cp, "w", 0);
7667c478bd9Sstevel@tonic-gate restart_point = 0;
7677c478bd9Sstevel@tonic-gate if (!mflag && fromatty) {
7687c478bd9Sstevel@tonic-gate ointer = interactive;
7697c478bd9Sstevel@tonic-gate interactive = 1;
7707c478bd9Sstevel@tonic-gate if (confirm("Continue with", "mget")) {
7717c478bd9Sstevel@tonic-gate mflag++;
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate interactive = ointer;
7747c478bd9Sstevel@tonic-gate }
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate }
7777c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
7787c478bd9Sstevel@tonic-gate mflag = 0;
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate static char *
remglob(char * argv[],int doswitch)7827c478bd9Sstevel@tonic-gate remglob(char *argv[], int doswitch)
7837c478bd9Sstevel@tonic-gate {
7847c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN];
7857c478bd9Sstevel@tonic-gate static char **args;
7867c478bd9Sstevel@tonic-gate int oldverbose, oldhash;
7877c478bd9Sstevel@tonic-gate char *cp;
7887c478bd9Sstevel@tonic-gate
7897c478bd9Sstevel@tonic-gate if (!mflag) {
7907c478bd9Sstevel@tonic-gate if (!doglob) {
7917c478bd9Sstevel@tonic-gate args = NULL;
7927c478bd9Sstevel@tonic-gate } else {
7937c478bd9Sstevel@tonic-gate if (tmp_nlst != NULL) {
7947c478bd9Sstevel@tonic-gate (void) fclose(tmp_nlst);
7957c478bd9Sstevel@tonic-gate tmp_nlst = NULL;
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate }
7987c478bd9Sstevel@tonic-gate return (NULL);
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate if (!doglob) {
8017c478bd9Sstevel@tonic-gate if (args == NULL)
8027c478bd9Sstevel@tonic-gate args = argv;
8037c478bd9Sstevel@tonic-gate if ((cp = *++args) == NULL)
8047c478bd9Sstevel@tonic-gate args = NULL;
8057c478bd9Sstevel@tonic-gate return (cp);
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate if (tmp_nlst == NULL) {
8087c478bd9Sstevel@tonic-gate if ((tmp_nlst = tmpfile()) == NULL) {
8097c478bd9Sstevel@tonic-gate (void) printf("%s\n", strerror(errno));
8107c478bd9Sstevel@tonic-gate return (NULL);
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate oldverbose = verbose, verbose = 0;
8137c478bd9Sstevel@tonic-gate oldhash = hash, hash = 0;
8147c478bd9Sstevel@tonic-gate if (doswitch) {
8157c478bd9Sstevel@tonic-gate pswitch(!proxy);
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate for (; *++argv != NULL; )
8187c478bd9Sstevel@tonic-gate recvrequest("NLST", NULL, *argv, "", 0);
8197c478bd9Sstevel@tonic-gate rewind(tmp_nlst);
8207c478bd9Sstevel@tonic-gate if (doswitch) {
8217c478bd9Sstevel@tonic-gate pswitch(!proxy);
8227c478bd9Sstevel@tonic-gate }
8237c478bd9Sstevel@tonic-gate verbose = oldverbose; hash = oldhash;
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate reset_timer();
8267c478bd9Sstevel@tonic-gate if (fgets(buf, sizeof (buf), tmp_nlst) == NULL) {
8277c478bd9Sstevel@tonic-gate (void) fclose(tmp_nlst), tmp_nlst = NULL;
8287c478bd9Sstevel@tonic-gate return (NULL);
8297c478bd9Sstevel@tonic-gate }
8307c478bd9Sstevel@tonic-gate if ((cp = index(buf, '\n')) != NULL)
8317c478bd9Sstevel@tonic-gate *cp = '\0';
8327c478bd9Sstevel@tonic-gate return (buf);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate
8357c478bd9Sstevel@tonic-gate static char *
onoff(int bool)8367c478bd9Sstevel@tonic-gate onoff(int bool)
8377c478bd9Sstevel@tonic-gate {
8387c478bd9Sstevel@tonic-gate return (bool ? "on" : "off");
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate /*
8427c478bd9Sstevel@tonic-gate * Show status.
8437c478bd9Sstevel@tonic-gate */
8447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8457c478bd9Sstevel@tonic-gate void
status(int argc,char * argv[])8467c478bd9Sstevel@tonic-gate status(int argc, char *argv[])
8477c478bd9Sstevel@tonic-gate {
8487c478bd9Sstevel@tonic-gate int i;
8497c478bd9Sstevel@tonic-gate char *levelp;
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate if (connected)
8527c478bd9Sstevel@tonic-gate (void) printf("Connected to %s.\n", hostname);
8537c478bd9Sstevel@tonic-gate else
8547c478bd9Sstevel@tonic-gate (void) printf("Not connected.\n");
8557c478bd9Sstevel@tonic-gate if (!proxy) {
8567c478bd9Sstevel@tonic-gate pswitch(1);
8577c478bd9Sstevel@tonic-gate if (connected) {
8587c478bd9Sstevel@tonic-gate (void) printf("Connected for proxy commands to %s.\n",
8597c478bd9Sstevel@tonic-gate hostname);
8607c478bd9Sstevel@tonic-gate } else {
8617c478bd9Sstevel@tonic-gate (void) printf("No proxy connection.\n");
8627c478bd9Sstevel@tonic-gate }
8637c478bd9Sstevel@tonic-gate pswitch(0);
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate if (auth_type != AUTHTYPE_NONE)
8677c478bd9Sstevel@tonic-gate (void) printf("Authentication type: %s\n",
8687c478bd9Sstevel@tonic-gate GSS_AUTHTYPE_NAME(auth_type));
8697c478bd9Sstevel@tonic-gate else
8707c478bd9Sstevel@tonic-gate (void) printf("Not authenticated.\n");
8717c478bd9Sstevel@tonic-gate (void) printf("Mechanism: %s\n", mechstr);
8727c478bd9Sstevel@tonic-gate (void) printf("Autoauth: %s; Autologin: %s\n",
8737c478bd9Sstevel@tonic-gate onoff(autoauth), onoff(autologin));
8747c478bd9Sstevel@tonic-gate levelp = getlevel(clevel);
8757c478bd9Sstevel@tonic-gate (void) printf("Control Channel Protection Level: %s\n",
8767c478bd9Sstevel@tonic-gate levelp ? levelp : "<unknown>");
8777c478bd9Sstevel@tonic-gate levelp = getlevel(dlevel);
8787c478bd9Sstevel@tonic-gate (void) printf("Data Channel Protection Level: %s\n",
8797c478bd9Sstevel@tonic-gate levelp ? levelp : "<unknown>");
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate (void) printf("Passive mode: %s.\n", onoff(passivemode));
8827c478bd9Sstevel@tonic-gate (void) printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n",
8837c478bd9Sstevel@tonic-gate modename, typename, formname, structname);
8847c478bd9Sstevel@tonic-gate (void) printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n",
8857c478bd9Sstevel@tonic-gate onoff(verbose), onoff(bell), onoff(interactive),
8867c478bd9Sstevel@tonic-gate onoff(doglob));
8877c478bd9Sstevel@tonic-gate (void) printf("Store unique: %s; Receive unique: %s\n", onoff(sunique),
8887c478bd9Sstevel@tonic-gate onoff(runique));
8897c478bd9Sstevel@tonic-gate (void) printf("Case: %s; CR stripping: %s\n",
8907c478bd9Sstevel@tonic-gate onoff(mcase), onoff(crflag));
8917c478bd9Sstevel@tonic-gate if (ntflag) {
8927c478bd9Sstevel@tonic-gate (void) printf("Ntrans: (in) %s (out) %s\n", ntin, ntout);
8937c478bd9Sstevel@tonic-gate } else {
8947c478bd9Sstevel@tonic-gate (void) printf("Ntrans: off\n");
8957c478bd9Sstevel@tonic-gate }
8967c478bd9Sstevel@tonic-gate if (mapflag) {
8977c478bd9Sstevel@tonic-gate (void) printf("Nmap: (in) %s (out) %s\n", mapin, mapout);
8987c478bd9Sstevel@tonic-gate } else {
8997c478bd9Sstevel@tonic-gate (void) printf("Nmap: off\n");
9007c478bd9Sstevel@tonic-gate }
9017c478bd9Sstevel@tonic-gate (void) printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
9027c478bd9Sstevel@tonic-gate onoff(hash), onoff(sendport));
9037c478bd9Sstevel@tonic-gate if (macnum > 0) {
9047c478bd9Sstevel@tonic-gate (void) printf("Macros:\n");
9057c478bd9Sstevel@tonic-gate for (i = 0; i < macnum; i++) {
9067c478bd9Sstevel@tonic-gate (void) printf("\t%s\n", macros[i].mac_name);
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate code = 0;
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate /*
9137c478bd9Sstevel@tonic-gate * Set beep on cmd completed mode.
9147c478bd9Sstevel@tonic-gate */
9157c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9167c478bd9Sstevel@tonic-gate void
setbell(int argc,char * argv[])9177c478bd9Sstevel@tonic-gate setbell(int argc, char *argv[])
9187c478bd9Sstevel@tonic-gate {
9197c478bd9Sstevel@tonic-gate bell = !bell;
9207c478bd9Sstevel@tonic-gate (void) printf("Bell mode %s.\n", onoff(bell));
9217c478bd9Sstevel@tonic-gate code = bell;
9227c478bd9Sstevel@tonic-gate }
9237c478bd9Sstevel@tonic-gate
9247c478bd9Sstevel@tonic-gate /*
9257c478bd9Sstevel@tonic-gate * Turn on packet tracing.
9267c478bd9Sstevel@tonic-gate */
9277c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9287c478bd9Sstevel@tonic-gate void
settrace(int argc,char * argv[])9297c478bd9Sstevel@tonic-gate settrace(int argc, char *argv[])
9307c478bd9Sstevel@tonic-gate {
9317c478bd9Sstevel@tonic-gate trace = !trace;
9327c478bd9Sstevel@tonic-gate (void) printf("Packet tracing %s.\n", onoff(trace));
9337c478bd9Sstevel@tonic-gate code = trace;
9347c478bd9Sstevel@tonic-gate }
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gate /*
9377c478bd9Sstevel@tonic-gate * Toggle hash mark printing during transfers.
9387c478bd9Sstevel@tonic-gate */
9397c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9407c478bd9Sstevel@tonic-gate void
sethash(int argc,char * argv[])9417c478bd9Sstevel@tonic-gate sethash(int argc, char *argv[])
9427c478bd9Sstevel@tonic-gate {
9437c478bd9Sstevel@tonic-gate hash = !hash;
9447c478bd9Sstevel@tonic-gate (void) printf("Hash mark printing %s", onoff(hash));
9457c478bd9Sstevel@tonic-gate code = hash;
9467c478bd9Sstevel@tonic-gate if (hash)
9477c478bd9Sstevel@tonic-gate (void) printf(" (%d bytes/hash mark)", HASHSIZ);
9487c478bd9Sstevel@tonic-gate (void) printf(".\n");
9497c478bd9Sstevel@tonic-gate }
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate /*
9527c478bd9Sstevel@tonic-gate * Turn on printing of server echo's.
9537c478bd9Sstevel@tonic-gate */
9547c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9557c478bd9Sstevel@tonic-gate void
setverbose(int argc,char * argv[])9567c478bd9Sstevel@tonic-gate setverbose(int argc, char *argv[])
9577c478bd9Sstevel@tonic-gate {
9587c478bd9Sstevel@tonic-gate verbose = !verbose;
9597c478bd9Sstevel@tonic-gate (void) printf("Verbose mode %s.\n", onoff(verbose));
9607c478bd9Sstevel@tonic-gate code = verbose;
9617c478bd9Sstevel@tonic-gate }
9627c478bd9Sstevel@tonic-gate
9637c478bd9Sstevel@tonic-gate /*
9647c478bd9Sstevel@tonic-gate * Toggle PORT cmd use before each data connection.
9657c478bd9Sstevel@tonic-gate */
9667c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9677c478bd9Sstevel@tonic-gate void
setport(int argc,char * argv[])9687c478bd9Sstevel@tonic-gate setport(int argc, char *argv[])
9697c478bd9Sstevel@tonic-gate {
9707c478bd9Sstevel@tonic-gate sendport = !sendport;
9717c478bd9Sstevel@tonic-gate (void) printf("Use of PORT cmds %s.\n", onoff(sendport));
9727c478bd9Sstevel@tonic-gate code = sendport;
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate /*
9767c478bd9Sstevel@tonic-gate * Turn on interactive prompting
9777c478bd9Sstevel@tonic-gate * during mget, mput, and mdelete.
9787c478bd9Sstevel@tonic-gate */
9797c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9807c478bd9Sstevel@tonic-gate void
setprompt(int argc,char * argv[])9817c478bd9Sstevel@tonic-gate setprompt(int argc, char *argv[])
9827c478bd9Sstevel@tonic-gate {
9837c478bd9Sstevel@tonic-gate interactive = !interactive;
9847c478bd9Sstevel@tonic-gate (void) printf("Interactive mode %s.\n", onoff(interactive));
9857c478bd9Sstevel@tonic-gate code = interactive;
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate /*
9897c478bd9Sstevel@tonic-gate * Toggle metacharacter interpretation
9907c478bd9Sstevel@tonic-gate * on local file names.
9917c478bd9Sstevel@tonic-gate */
9927c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9937c478bd9Sstevel@tonic-gate void
setglob(int argc,char * argv[])9947c478bd9Sstevel@tonic-gate setglob(int argc, char *argv[])
9957c478bd9Sstevel@tonic-gate {
9967c478bd9Sstevel@tonic-gate doglob = !doglob;
9977c478bd9Sstevel@tonic-gate (void) printf("Globbing %s.\n", onoff(doglob));
9987c478bd9Sstevel@tonic-gate code = doglob;
9997c478bd9Sstevel@tonic-gate }
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate /*
10027c478bd9Sstevel@tonic-gate * Set debugging mode on/off and/or
10037c478bd9Sstevel@tonic-gate * set level of debugging.
10047c478bd9Sstevel@tonic-gate */
10057c478bd9Sstevel@tonic-gate void
setdebug(int argc,char * argv[])10067c478bd9Sstevel@tonic-gate setdebug(int argc, char *argv[])
10077c478bd9Sstevel@tonic-gate {
10087c478bd9Sstevel@tonic-gate int val;
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate if (argc > 1) {
10117c478bd9Sstevel@tonic-gate val = atoi(argv[1]);
10127c478bd9Sstevel@tonic-gate if (val < 0) {
10137c478bd9Sstevel@tonic-gate (void) printf("%s: bad debugging value.\n", argv[1]);
10147c478bd9Sstevel@tonic-gate code = -1;
10157c478bd9Sstevel@tonic-gate return;
10167c478bd9Sstevel@tonic-gate }
10177c478bd9Sstevel@tonic-gate } else
10187c478bd9Sstevel@tonic-gate val = !debug;
10197c478bd9Sstevel@tonic-gate debug = val;
10207c478bd9Sstevel@tonic-gate if (debug)
10217c478bd9Sstevel@tonic-gate options |= SO_DEBUG;
10227c478bd9Sstevel@tonic-gate else
10237c478bd9Sstevel@tonic-gate options &= ~SO_DEBUG;
10247c478bd9Sstevel@tonic-gate (void) printf("Debugging %s (debug=%d).\n", onoff(debug), debug);
10257c478bd9Sstevel@tonic-gate code = debug > 0;
10267c478bd9Sstevel@tonic-gate }
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate /*
10297c478bd9Sstevel@tonic-gate * Set current working directory
10307c478bd9Sstevel@tonic-gate * on remote machine.
10317c478bd9Sstevel@tonic-gate */
10327c478bd9Sstevel@tonic-gate void
cd(int argc,char * argv[])10337c478bd9Sstevel@tonic-gate cd(int argc, char *argv[])
10347c478bd9Sstevel@tonic-gate {
10357c478bd9Sstevel@tonic-gate if (argc < 2) {
10367c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-directory") <
10377c478bd9Sstevel@tonic-gate 0) {
10387c478bd9Sstevel@tonic-gate code = -1;
10397c478bd9Sstevel@tonic-gate return;
10407c478bd9Sstevel@tonic-gate }
10417c478bd9Sstevel@tonic-gate makeargv();
10427c478bd9Sstevel@tonic-gate argc = margc;
10437c478bd9Sstevel@tonic-gate argv = margv;
10447c478bd9Sstevel@tonic-gate }
10457c478bd9Sstevel@tonic-gate if (argc < 2) {
10467c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-directory\n", argv[0]);
10477c478bd9Sstevel@tonic-gate code = -1;
10487c478bd9Sstevel@tonic-gate return;
10497c478bd9Sstevel@tonic-gate }
10507c478bd9Sstevel@tonic-gate (void) command("CWD %s", argv[1]);
10517c478bd9Sstevel@tonic-gate }
10527c478bd9Sstevel@tonic-gate
10537c478bd9Sstevel@tonic-gate /*
10547c478bd9Sstevel@tonic-gate * Set current working directory
10557c478bd9Sstevel@tonic-gate * on local machine.
10567c478bd9Sstevel@tonic-gate */
10577c478bd9Sstevel@tonic-gate void
lcd(int argc,char * argv[])10587c478bd9Sstevel@tonic-gate lcd(int argc, char *argv[])
10597c478bd9Sstevel@tonic-gate {
10607c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN], *bufptr;
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate if (argc < 2)
10637c478bd9Sstevel@tonic-gate argc++, argv[1] = home;
10647c478bd9Sstevel@tonic-gate if (argc != 2) {
10657c478bd9Sstevel@tonic-gate (void) printf("usage: %s local-directory\n", argv[0]);
10667c478bd9Sstevel@tonic-gate code = -1;
10677c478bd9Sstevel@tonic-gate return;
10687c478bd9Sstevel@tonic-gate }
10697c478bd9Sstevel@tonic-gate if (!globulize(&argv[1])) {
10707c478bd9Sstevel@tonic-gate code = -1;
10717c478bd9Sstevel@tonic-gate return;
10727c478bd9Sstevel@tonic-gate }
10737c478bd9Sstevel@tonic-gate if (chdir(argv[1]) < 0) {
10747c478bd9Sstevel@tonic-gate perror(argv[1]);
10757c478bd9Sstevel@tonic-gate code = -1;
10767c478bd9Sstevel@tonic-gate return;
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate bufptr = getcwd(buf, MAXPATHLEN);
10797c478bd9Sstevel@tonic-gate /*
10807c478bd9Sstevel@tonic-gate * Even though chdir may succeed, getcwd may fail if a component
10817c478bd9Sstevel@tonic-gate * of the pwd is unreadable. In this case, print the argument to
10827c478bd9Sstevel@tonic-gate * chdir as the resultant directory, since we know it succeeded above.
10837c478bd9Sstevel@tonic-gate */
10847c478bd9Sstevel@tonic-gate (void) printf("Local directory now %s\n", (bufptr ? bufptr : argv[1]));
10857c478bd9Sstevel@tonic-gate code = 0;
10867c478bd9Sstevel@tonic-gate }
10877c478bd9Sstevel@tonic-gate
10887c478bd9Sstevel@tonic-gate /*
10897c478bd9Sstevel@tonic-gate * Delete a single file.
10907c478bd9Sstevel@tonic-gate */
10917c478bd9Sstevel@tonic-gate void
delete(int argc,char * argv[])10927c478bd9Sstevel@tonic-gate delete(int argc, char *argv[])
10937c478bd9Sstevel@tonic-gate {
10947c478bd9Sstevel@tonic-gate
10957c478bd9Sstevel@tonic-gate if (argc < 2) {
10967c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-file") < 0) {
10977c478bd9Sstevel@tonic-gate code = -1;
10987c478bd9Sstevel@tonic-gate return;
10997c478bd9Sstevel@tonic-gate }
11007c478bd9Sstevel@tonic-gate makeargv();
11017c478bd9Sstevel@tonic-gate argc = margc;
11027c478bd9Sstevel@tonic-gate argv = margv;
11037c478bd9Sstevel@tonic-gate }
11047c478bd9Sstevel@tonic-gate if (argc < 2) {
11057c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-file\n", argv[0]);
11067c478bd9Sstevel@tonic-gate code = -1;
11077c478bd9Sstevel@tonic-gate return;
11087c478bd9Sstevel@tonic-gate }
11097c478bd9Sstevel@tonic-gate (void) command("DELE %s", argv[1]);
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate /*
11137c478bd9Sstevel@tonic-gate * Delete multiple files.
11147c478bd9Sstevel@tonic-gate */
11157c478bd9Sstevel@tonic-gate void
mdelete(int argc,char * argv[])11167c478bd9Sstevel@tonic-gate mdelete(int argc, char *argv[])
11177c478bd9Sstevel@tonic-gate {
11187c478bd9Sstevel@tonic-gate char *cp;
11197c478bd9Sstevel@tonic-gate int ointer;
11207c478bd9Sstevel@tonic-gate void (*oldintr)();
11217c478bd9Sstevel@tonic-gate
11227c478bd9Sstevel@tonic-gate if (argc < 2) {
11237c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) {
11247c478bd9Sstevel@tonic-gate code = -1;
11257c478bd9Sstevel@tonic-gate return;
11267c478bd9Sstevel@tonic-gate }
11277c478bd9Sstevel@tonic-gate makeargv();
11287c478bd9Sstevel@tonic-gate argc = margc;
11297c478bd9Sstevel@tonic-gate argv = margv;
11307c478bd9Sstevel@tonic-gate }
11317c478bd9Sstevel@tonic-gate if (argc < 2) {
11327c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-files\n", argv[0]);
11337c478bd9Sstevel@tonic-gate code = -1;
11347c478bd9Sstevel@tonic-gate return;
11357c478bd9Sstevel@tonic-gate }
11367c478bd9Sstevel@tonic-gate mname = argv[0];
11377c478bd9Sstevel@tonic-gate mflag = 1;
11387c478bd9Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
11397c478bd9Sstevel@tonic-gate (void) setjmp(jabort);
11407c478bd9Sstevel@tonic-gate while ((cp = remglob(argv, 0)) != NULL) {
11417c478bd9Sstevel@tonic-gate if (*cp == '\0') {
11427c478bd9Sstevel@tonic-gate mflag = 0;
11437c478bd9Sstevel@tonic-gate continue;
11447c478bd9Sstevel@tonic-gate }
11457c478bd9Sstevel@tonic-gate if (mflag && confirm(argv[0], cp)) {
11467c478bd9Sstevel@tonic-gate (void) command("DELE %s", cp);
11477c478bd9Sstevel@tonic-gate if (!mflag && fromatty) {
11487c478bd9Sstevel@tonic-gate ointer = interactive;
11497c478bd9Sstevel@tonic-gate interactive = 1;
11507c478bd9Sstevel@tonic-gate if (confirm("Continue with", "mdelete")) {
11517c478bd9Sstevel@tonic-gate mflag++;
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate interactive = ointer;
11547c478bd9Sstevel@tonic-gate }
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate }
11577c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
11587c478bd9Sstevel@tonic-gate mflag = 0;
11597c478bd9Sstevel@tonic-gate }
11607c478bd9Sstevel@tonic-gate
11617c478bd9Sstevel@tonic-gate /*
11627c478bd9Sstevel@tonic-gate * Rename a remote file.
11637c478bd9Sstevel@tonic-gate */
11647c478bd9Sstevel@tonic-gate void
renamefile(int argc,char * argv[])11657c478bd9Sstevel@tonic-gate renamefile(int argc, char *argv[])
11667c478bd9Sstevel@tonic-gate {
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate if (argc < 2) {
11697c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "from-name") < 0) {
11707c478bd9Sstevel@tonic-gate code = -1;
11717c478bd9Sstevel@tonic-gate return;
11727c478bd9Sstevel@tonic-gate }
11737c478bd9Sstevel@tonic-gate makeargv();
11747c478bd9Sstevel@tonic-gate argc = margc;
11757c478bd9Sstevel@tonic-gate argv = margv;
11767c478bd9Sstevel@tonic-gate }
11777c478bd9Sstevel@tonic-gate if (argc < 2) {
11787c478bd9Sstevel@tonic-gate usage:
11797c478bd9Sstevel@tonic-gate (void) printf("%s from-name to-name\n", argv[0]);
11807c478bd9Sstevel@tonic-gate code = -1;
11817c478bd9Sstevel@tonic-gate return;
11827c478bd9Sstevel@tonic-gate }
11837c478bd9Sstevel@tonic-gate if (argc < 3) {
11847c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "to-name") < 0) {
11857c478bd9Sstevel@tonic-gate code = -1;
11867c478bd9Sstevel@tonic-gate return;
11877c478bd9Sstevel@tonic-gate }
11887c478bd9Sstevel@tonic-gate makeargv();
11897c478bd9Sstevel@tonic-gate argc = margc;
11907c478bd9Sstevel@tonic-gate argv = margv;
11917c478bd9Sstevel@tonic-gate }
11927c478bd9Sstevel@tonic-gate if (argc < 3)
11937c478bd9Sstevel@tonic-gate goto usage;
11947c478bd9Sstevel@tonic-gate if (command("RNFR %s", argv[1]) == CONTINUE)
11957c478bd9Sstevel@tonic-gate (void) command("RNTO %s", argv[2]);
11967c478bd9Sstevel@tonic-gate }
11977c478bd9Sstevel@tonic-gate
11987c478bd9Sstevel@tonic-gate /*
11997c478bd9Sstevel@tonic-gate * Get a directory listing
12007c478bd9Sstevel@tonic-gate * of remote files.
12017c478bd9Sstevel@tonic-gate */
12027c478bd9Sstevel@tonic-gate void
ls(int argc,char * argv[])12037c478bd9Sstevel@tonic-gate ls(int argc, char *argv[])
12047c478bd9Sstevel@tonic-gate {
12057c478bd9Sstevel@tonic-gate char *cmd;
12067c478bd9Sstevel@tonic-gate
12077c478bd9Sstevel@tonic-gate if (argc < 2)
12087c478bd9Sstevel@tonic-gate argc++, argv[1] = NULL;
12097c478bd9Sstevel@tonic-gate if (argc < 3)
12107c478bd9Sstevel@tonic-gate argc++, argv[2] = "-";
12117c478bd9Sstevel@tonic-gate if (argc > 3) {
12127c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-directory local-file\n",
12137c478bd9Sstevel@tonic-gate argv[0]);
12147c478bd9Sstevel@tonic-gate code = -1;
12157c478bd9Sstevel@tonic-gate return;
12167c478bd9Sstevel@tonic-gate }
12177c478bd9Sstevel@tonic-gate if (ls_invokes_NLST) {
12187c478bd9Sstevel@tonic-gate cmd = ((argv[0][0] == 'l' || argv[0][0] == 'n') ?
12197c478bd9Sstevel@tonic-gate "NLST" : "LIST");
12207c478bd9Sstevel@tonic-gate } else {
12217c478bd9Sstevel@tonic-gate cmd = ((argv[0][0] == 'n') ? "NLST" : "LIST");
12227c478bd9Sstevel@tonic-gate }
12237c478bd9Sstevel@tonic-gate if (strcmp(argv[2], "-") && !globulize(&argv[2])) {
12247c478bd9Sstevel@tonic-gate code = -1;
12257c478bd9Sstevel@tonic-gate return;
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate recvrequest(cmd, argv[2], argv[1], "w", 1);
12287c478bd9Sstevel@tonic-gate }
12297c478bd9Sstevel@tonic-gate
12307c478bd9Sstevel@tonic-gate /*
12317c478bd9Sstevel@tonic-gate * Get a directory listing
12327c478bd9Sstevel@tonic-gate * of multiple remote files.
12337c478bd9Sstevel@tonic-gate */
12347c478bd9Sstevel@tonic-gate void
mls(int argc,char * argv[])12357c478bd9Sstevel@tonic-gate mls(int argc, char *argv[])
12367c478bd9Sstevel@tonic-gate {
12377c478bd9Sstevel@tonic-gate char *cmd, mode[1], *dest;
12387c478bd9Sstevel@tonic-gate int ointer, i;
12397c478bd9Sstevel@tonic-gate void (*oldintr)();
12407c478bd9Sstevel@tonic-gate
12417c478bd9Sstevel@tonic-gate if (argc < 2) {
12427c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "remote-files") < 0) {
12437c478bd9Sstevel@tonic-gate code = -1;
12447c478bd9Sstevel@tonic-gate return;
12457c478bd9Sstevel@tonic-gate }
12467c478bd9Sstevel@tonic-gate makeargv();
12477c478bd9Sstevel@tonic-gate argc = margc;
12487c478bd9Sstevel@tonic-gate argv = margv;
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate if (argc < 3) {
12517c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "local-file") < 0) {
12527c478bd9Sstevel@tonic-gate code = -1;
12537c478bd9Sstevel@tonic-gate return;
12547c478bd9Sstevel@tonic-gate }
12557c478bd9Sstevel@tonic-gate makeargv();
12567c478bd9Sstevel@tonic-gate argc = margc;
12577c478bd9Sstevel@tonic-gate argv = margv;
12587c478bd9Sstevel@tonic-gate }
12597c478bd9Sstevel@tonic-gate if (argc < 3) {
12607c478bd9Sstevel@tonic-gate (void) printf("usage: %s remote-files local-file\n", argv[0]);
12617c478bd9Sstevel@tonic-gate code = -1;
12627c478bd9Sstevel@tonic-gate return;
12637c478bd9Sstevel@tonic-gate }
12647c478bd9Sstevel@tonic-gate dest = argv[argc - 1];
12657c478bd9Sstevel@tonic-gate argv[argc - 1] = NULL;
12667c478bd9Sstevel@tonic-gate if (strcmp(dest, "-") && *dest != '|')
12677c478bd9Sstevel@tonic-gate if (!globulize(&dest) ||
12687c478bd9Sstevel@tonic-gate !confirm("output to local-file:", dest)) {
12697c478bd9Sstevel@tonic-gate code = -1;
12707c478bd9Sstevel@tonic-gate return;
12717c478bd9Sstevel@tonic-gate }
12727c478bd9Sstevel@tonic-gate cmd = argv[0][1] == 'l' ? "NLST" : "LIST";
12737c478bd9Sstevel@tonic-gate mname = argv[0];
12747c478bd9Sstevel@tonic-gate mflag = 1;
12757c478bd9Sstevel@tonic-gate oldintr = signal(SIGINT, mabort);
12767c478bd9Sstevel@tonic-gate (void) setjmp(jabort);
12777c478bd9Sstevel@tonic-gate for (i = 1; mflag && i < argc-1; ++i) {
12787c478bd9Sstevel@tonic-gate *mode = (i == 1) ? 'w' : 'a';
12797c478bd9Sstevel@tonic-gate recvrequest(cmd, dest, argv[i], mode, 1);
12807c478bd9Sstevel@tonic-gate if (!mflag && fromatty) {
12817c478bd9Sstevel@tonic-gate ointer = interactive;
12827c478bd9Sstevel@tonic-gate interactive = 1;
12837c478bd9Sstevel@tonic-gate if (confirm("Continue with", argv[0])) {
12847c478bd9Sstevel@tonic-gate mflag ++;
12857c478bd9Sstevel@tonic-gate }
12867c478bd9Sstevel@tonic-gate interactive = ointer;
12877c478bd9Sstevel@tonic-gate }
12887c478bd9Sstevel@tonic-gate }
12897c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
12907c478bd9Sstevel@tonic-gate mflag = 0;
12917c478bd9Sstevel@tonic-gate }
12927c478bd9Sstevel@tonic-gate
12937c478bd9Sstevel@tonic-gate /*
12947c478bd9Sstevel@tonic-gate * Do a shell escape
12957c478bd9Sstevel@tonic-gate */
12967c478bd9Sstevel@tonic-gate /*ARGSUSED*/
12977c478bd9Sstevel@tonic-gate void
shell(int argc,char * argv[])12987c478bd9Sstevel@tonic-gate shell(int argc, char *argv[])
12997c478bd9Sstevel@tonic-gate {
13007c478bd9Sstevel@tonic-gate pid_t pid;
13017c478bd9Sstevel@tonic-gate void (*old1)(), (*old2)();
13027c478bd9Sstevel@tonic-gate char *shellstring, *namep;
13037c478bd9Sstevel@tonic-gate int status;
13047c478bd9Sstevel@tonic-gate
13057c478bd9Sstevel@tonic-gate stop_timer();
13067c478bd9Sstevel@tonic-gate old1 = signal(SIGINT, SIG_IGN);
13077c478bd9Sstevel@tonic-gate old2 = signal(SIGQUIT, SIG_IGN);
13087c478bd9Sstevel@tonic-gate if ((pid = fork()) == 0) {
13097c478bd9Sstevel@tonic-gate closefrom(STDERR_FILENO + 1);
13107c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_DFL);
13117c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_DFL);
13127c478bd9Sstevel@tonic-gate shellstring = getenv("SHELL");
13137c478bd9Sstevel@tonic-gate if (shellstring == NULL)
13147c478bd9Sstevel@tonic-gate shellstring = "/bin/sh";
13157c478bd9Sstevel@tonic-gate namep = rindex(shellstring, '/');
13167c478bd9Sstevel@tonic-gate if (namep == NULL)
13177c478bd9Sstevel@tonic-gate namep = shellstring;
13187c478bd9Sstevel@tonic-gate if (argc > 1) {
13197c478bd9Sstevel@tonic-gate if (debug) {
13207c478bd9Sstevel@tonic-gate (void) printf("%s -c %s\n", shellstring,
13217c478bd9Sstevel@tonic-gate altarg);
13227c478bd9Sstevel@tonic-gate (void) fflush(stdout);
13237c478bd9Sstevel@tonic-gate }
13247c478bd9Sstevel@tonic-gate execl(shellstring, namep, "-c", altarg, (char *)0);
13257c478bd9Sstevel@tonic-gate } else {
13267c478bd9Sstevel@tonic-gate if (debug) {
13277c478bd9Sstevel@tonic-gate (void) printf("%s\n", shellstring);
13287c478bd9Sstevel@tonic-gate (void) fflush(stdout);
13297c478bd9Sstevel@tonic-gate }
13307c478bd9Sstevel@tonic-gate execl(shellstring, namep, (char *)0);
13317c478bd9Sstevel@tonic-gate }
13327c478bd9Sstevel@tonic-gate perror(shellstring);
13337c478bd9Sstevel@tonic-gate code = -1;
13347c478bd9Sstevel@tonic-gate exit(1);
13357c478bd9Sstevel@tonic-gate }
13367c478bd9Sstevel@tonic-gate if (pid > 0)
13377c478bd9Sstevel@tonic-gate while (wait(&status) != pid)
13387c478bd9Sstevel@tonic-gate ;
13397c478bd9Sstevel@tonic-gate (void) signal(SIGINT, old1);
13407c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, old2);
13417c478bd9Sstevel@tonic-gate reset_timer();
13427c478bd9Sstevel@tonic-gate if (pid == (pid_t)-1) {
13437c478bd9Sstevel@tonic-gate perror("Try again later");
13447c478bd9Sstevel@tonic-gate code = -1;
13457c478bd9Sstevel@tonic-gate } else {
13467c478bd9Sstevel@tonic-gate code = 0;
13477c478bd9Sstevel@tonic-gate }
13487c478bd9Sstevel@tonic-gate }
13497c478bd9Sstevel@tonic-gate
13507c478bd9Sstevel@tonic-gate /*
13517c478bd9Sstevel@tonic-gate * Send new user information (re-login)
13527c478bd9Sstevel@tonic-gate */
13537c478bd9Sstevel@tonic-gate void
user(int argc,char * argv[])13547c478bd9Sstevel@tonic-gate user(int argc, char *argv[])
13557c478bd9Sstevel@tonic-gate {
13567c478bd9Sstevel@tonic-gate char acct[80];
13577c478bd9Sstevel@tonic-gate int n, aflag = 0;
13587c478bd9Sstevel@tonic-gate
13597c478bd9Sstevel@tonic-gate if (argc < 2) {
13607c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "username") < 0) {
13617c478bd9Sstevel@tonic-gate code = -1;
13627c478bd9Sstevel@tonic-gate return;
13637c478bd9Sstevel@tonic-gate }
13647c478bd9Sstevel@tonic-gate makeargv();
13657c478bd9Sstevel@tonic-gate argc = margc;
13667c478bd9Sstevel@tonic-gate argv = margv;
13677c478bd9Sstevel@tonic-gate }
13687c478bd9Sstevel@tonic-gate if (argc > 4) {
13697c478bd9Sstevel@tonic-gate (void) printf("usage: %s username [password] [account]\n",
13707c478bd9Sstevel@tonic-gate argv[0]);
13717c478bd9Sstevel@tonic-gate code = -1;
13727c478bd9Sstevel@tonic-gate return;
13737c478bd9Sstevel@tonic-gate }
13747c478bd9Sstevel@tonic-gate if (argv[1] == 0) {
13757c478bd9Sstevel@tonic-gate (void) printf("access for user (nil) denied\n");
13767c478bd9Sstevel@tonic-gate code = -1;
13777c478bd9Sstevel@tonic-gate return;
13787c478bd9Sstevel@tonic-gate }
13797c478bd9Sstevel@tonic-gate n = command("USER %s", argv[1]);
13807c478bd9Sstevel@tonic-gate if (n == CONTINUE) {
13817c478bd9Sstevel@tonic-gate int oldclevel;
13827c478bd9Sstevel@tonic-gate if (argc < 3)
13837c478bd9Sstevel@tonic-gate argv[2] = mygetpass("Password: "), argc++;
13847c478bd9Sstevel@tonic-gate if ((oldclevel = clevel) == PROT_S)
13857c478bd9Sstevel@tonic-gate clevel = PROT_P;
13867c478bd9Sstevel@tonic-gate n = command("PASS %s", argv[2]);
13877c478bd9Sstevel@tonic-gate /* level may have changed */
13887c478bd9Sstevel@tonic-gate if (clevel == PROT_P)
13897c478bd9Sstevel@tonic-gate clevel = oldclevel;
13907c478bd9Sstevel@tonic-gate }
13917c478bd9Sstevel@tonic-gate if (n == CONTINUE) {
13927c478bd9Sstevel@tonic-gate if (argc < 4) {
13937c478bd9Sstevel@tonic-gate (void) printf("Account: "); (void) fflush(stdout);
13947c478bd9Sstevel@tonic-gate stop_timer();
13957c478bd9Sstevel@tonic-gate (void) fgets(acct, sizeof (acct) - 1, stdin);
13967c478bd9Sstevel@tonic-gate reset_timer();
13977c478bd9Sstevel@tonic-gate acct[strlen(acct) - 1] = '\0';
13987c478bd9Sstevel@tonic-gate argv[3] = acct; argc++;
13997c478bd9Sstevel@tonic-gate }
14007c478bd9Sstevel@tonic-gate n = command("ACCT %s", argv[3]);
14017c478bd9Sstevel@tonic-gate aflag++;
14027c478bd9Sstevel@tonic-gate }
14037c478bd9Sstevel@tonic-gate if (n != COMPLETE) {
14047c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "Login failed.\n");
14057c478bd9Sstevel@tonic-gate return;
14067c478bd9Sstevel@tonic-gate }
14077c478bd9Sstevel@tonic-gate if (!aflag && argc == 4) {
14087c478bd9Sstevel@tonic-gate (void) command("ACCT %s", argv[3]);
14097c478bd9Sstevel@tonic-gate }
14107c478bd9Sstevel@tonic-gate }
14117c478bd9Sstevel@tonic-gate
14127c478bd9Sstevel@tonic-gate /*
14137c478bd9Sstevel@tonic-gate * Print working directory.
14147c478bd9Sstevel@tonic-gate */
14157c478bd9Sstevel@tonic-gate /*ARGSUSED*/
14167c478bd9Sstevel@tonic-gate void
pwd(int argc,char * argv[])14177c478bd9Sstevel@tonic-gate pwd(int argc, char *argv[])
14187c478bd9Sstevel@tonic-gate {
14197c478bd9Sstevel@tonic-gate (void) command("PWD");
14207c478bd9Sstevel@tonic-gate }
14217c478bd9Sstevel@tonic-gate
14227c478bd9Sstevel@tonic-gate /*
14237c478bd9Sstevel@tonic-gate * Make a directory.
14247c478bd9Sstevel@tonic-gate */
14257c478bd9Sstevel@tonic-gate void
makedir(int argc,char * argv[])14267c478bd9Sstevel@tonic-gate makedir(int argc, char *argv[])
14277c478bd9Sstevel@tonic-gate {
14287c478bd9Sstevel@tonic-gate if (argc < 2) {
14297c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "directory-name") <
14307c478bd9Sstevel@tonic-gate 0) {
14317c478bd9Sstevel@tonic-gate code = -1;
14327c478bd9Sstevel@tonic-gate return;
14337c478bd9Sstevel@tonic-gate }
14347c478bd9Sstevel@tonic-gate makeargv();
14357c478bd9Sstevel@tonic-gate argc = margc;
14367c478bd9Sstevel@tonic-gate argv = margv;
14377c478bd9Sstevel@tonic-gate }
14387c478bd9Sstevel@tonic-gate if (argc < 2) {
14397c478bd9Sstevel@tonic-gate (void) printf("usage: %s directory-name\n", argv[0]);
14407c478bd9Sstevel@tonic-gate code = -1;
14417c478bd9Sstevel@tonic-gate return;
14427c478bd9Sstevel@tonic-gate }
14437c478bd9Sstevel@tonic-gate (void) command("MKD %s", argv[1]);
14447c478bd9Sstevel@tonic-gate }
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate /*
14477c478bd9Sstevel@tonic-gate * Remove a directory.
14487c478bd9Sstevel@tonic-gate */
14497c478bd9Sstevel@tonic-gate void
removedir(int argc,char * argv[])14507c478bd9Sstevel@tonic-gate removedir(int argc, char *argv[])
14517c478bd9Sstevel@tonic-gate {
14527c478bd9Sstevel@tonic-gate if (argc < 2) {
14537c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "directory-name") <
14547c478bd9Sstevel@tonic-gate 0) {
14557c478bd9Sstevel@tonic-gate code = -1;
14567c478bd9Sstevel@tonic-gate return;
14577c478bd9Sstevel@tonic-gate }
14587c478bd9Sstevel@tonic-gate makeargv();
14597c478bd9Sstevel@tonic-gate argc = margc;
14607c478bd9Sstevel@tonic-gate argv = margv;
14617c478bd9Sstevel@tonic-gate }
14627c478bd9Sstevel@tonic-gate if (argc < 2) {
14637c478bd9Sstevel@tonic-gate (void) printf("usage: %s directory-name\n", argv[0]);
14647c478bd9Sstevel@tonic-gate code = -1;
14657c478bd9Sstevel@tonic-gate return;
14667c478bd9Sstevel@tonic-gate }
14677c478bd9Sstevel@tonic-gate (void) command("RMD %s", argv[1]);
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate
14707c478bd9Sstevel@tonic-gate /*
14717c478bd9Sstevel@tonic-gate * Send a line, verbatim, to the remote machine.
14727c478bd9Sstevel@tonic-gate */
14737c478bd9Sstevel@tonic-gate void
quote(int argc,char * argv[])14747c478bd9Sstevel@tonic-gate quote(int argc, char *argv[])
14757c478bd9Sstevel@tonic-gate {
14767c478bd9Sstevel@tonic-gate int i, n, len;
14777c478bd9Sstevel@tonic-gate char buf[FTPBUFSIZ];
14787c478bd9Sstevel@tonic-gate
14797c478bd9Sstevel@tonic-gate if (argc < 2) {
14807c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line),
14817c478bd9Sstevel@tonic-gate "command line to send") == -1) {
14827c478bd9Sstevel@tonic-gate code = -1;
14837c478bd9Sstevel@tonic-gate return;
14847c478bd9Sstevel@tonic-gate }
14857c478bd9Sstevel@tonic-gate makeargv();
14867c478bd9Sstevel@tonic-gate argc = margc;
14877c478bd9Sstevel@tonic-gate argv = margv;
14887c478bd9Sstevel@tonic-gate }
14897c478bd9Sstevel@tonic-gate if (argc < 2) {
14907c478bd9Sstevel@tonic-gate (void) printf("usage: %s line-to-send\n", argv[0]);
14917c478bd9Sstevel@tonic-gate code = -1;
14927c478bd9Sstevel@tonic-gate return;
14937c478bd9Sstevel@tonic-gate }
14947c478bd9Sstevel@tonic-gate len = snprintf(buf, sizeof (buf), "%s", argv[1]);
14957c478bd9Sstevel@tonic-gate if (len >= 0 && len < sizeof (buf) - 1) {
14967c478bd9Sstevel@tonic-gate for (i = 2; i < argc; i++) {
14977c478bd9Sstevel@tonic-gate n = snprintf(&buf[len], sizeof (buf) - len, " %s",
14987c478bd9Sstevel@tonic-gate argv[i]);
14997c478bd9Sstevel@tonic-gate if (n < 0 || n >= sizeof (buf) - len)
15007c478bd9Sstevel@tonic-gate break;
15017c478bd9Sstevel@tonic-gate len += n;
15027c478bd9Sstevel@tonic-gate }
15037c478bd9Sstevel@tonic-gate }
15047c478bd9Sstevel@tonic-gate if (command("%s", buf) == PRELIM) {
15057c478bd9Sstevel@tonic-gate while (getreply(0) == PRELIM)
15067c478bd9Sstevel@tonic-gate ;
15077c478bd9Sstevel@tonic-gate }
15087c478bd9Sstevel@tonic-gate }
15097c478bd9Sstevel@tonic-gate
15107c478bd9Sstevel@tonic-gate /*
15117c478bd9Sstevel@tonic-gate * Send a line, verbatim, to the remote machine as a SITE command.
15127c478bd9Sstevel@tonic-gate */
15137c478bd9Sstevel@tonic-gate void
site(int argc,char * argv[])15147c478bd9Sstevel@tonic-gate site(int argc, char *argv[])
15157c478bd9Sstevel@tonic-gate {
15167c478bd9Sstevel@tonic-gate int i, n, len;
15177c478bd9Sstevel@tonic-gate char buf[FTPBUFSIZ];
15187c478bd9Sstevel@tonic-gate
15197c478bd9Sstevel@tonic-gate if (argc < 2) {
15207c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line),
15217c478bd9Sstevel@tonic-gate "arguments to SITE command") == -1) {
15227c478bd9Sstevel@tonic-gate code = -1;
15237c478bd9Sstevel@tonic-gate return;
15247c478bd9Sstevel@tonic-gate }
15257c478bd9Sstevel@tonic-gate makeargv();
15267c478bd9Sstevel@tonic-gate argc = margc;
15277c478bd9Sstevel@tonic-gate argv = margv;
15287c478bd9Sstevel@tonic-gate }
15297c478bd9Sstevel@tonic-gate if (argc < 2) {
15307c478bd9Sstevel@tonic-gate (void) printf("usage: %s arg1 [arg2] ...\n", argv[0]);
15317c478bd9Sstevel@tonic-gate code = -1;
15327c478bd9Sstevel@tonic-gate return;
15337c478bd9Sstevel@tonic-gate }
15347c478bd9Sstevel@tonic-gate len = snprintf(buf, sizeof (buf), "%s", argv[1]);
15357c478bd9Sstevel@tonic-gate if (len >= 0 && len < sizeof (buf) - 1) {
15367c478bd9Sstevel@tonic-gate for (i = 2; i < argc; i++) {
15377c478bd9Sstevel@tonic-gate n = snprintf(&buf[len], sizeof (buf) - len, " %s",
15387c478bd9Sstevel@tonic-gate argv[i]);
15397c478bd9Sstevel@tonic-gate if (n < 0 || n >= sizeof (buf) - len)
15407c478bd9Sstevel@tonic-gate break;
15417c478bd9Sstevel@tonic-gate len += n;
15427c478bd9Sstevel@tonic-gate }
15437c478bd9Sstevel@tonic-gate }
15447c478bd9Sstevel@tonic-gate if (command("SITE %s", buf) == PRELIM) {
15457c478bd9Sstevel@tonic-gate while (getreply(0) == PRELIM)
15467c478bd9Sstevel@tonic-gate ;
15477c478bd9Sstevel@tonic-gate }
15487c478bd9Sstevel@tonic-gate }
15497c478bd9Sstevel@tonic-gate
15507c478bd9Sstevel@tonic-gate /*
15517c478bd9Sstevel@tonic-gate * Ask the other side for help.
15527c478bd9Sstevel@tonic-gate */
15537c478bd9Sstevel@tonic-gate void
rmthelp(int argc,char * argv[])15547c478bd9Sstevel@tonic-gate rmthelp(int argc, char *argv[])
15557c478bd9Sstevel@tonic-gate {
15567c478bd9Sstevel@tonic-gate int oldverbose = verbose;
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gate verbose = 1;
15597c478bd9Sstevel@tonic-gate (void) command(argc == 1 ? "HELP" : "HELP %s", argv[1]);
15607c478bd9Sstevel@tonic-gate verbose = oldverbose;
15617c478bd9Sstevel@tonic-gate }
15627c478bd9Sstevel@tonic-gate
15637c478bd9Sstevel@tonic-gate /*
15647c478bd9Sstevel@tonic-gate * Terminate session and exit.
15657c478bd9Sstevel@tonic-gate */
15667c478bd9Sstevel@tonic-gate /*ARGSUSED*/
15677c478bd9Sstevel@tonic-gate void
quit(int argc,char * argv[])15687c478bd9Sstevel@tonic-gate quit(int argc, char *argv[])
15697c478bd9Sstevel@tonic-gate {
15707c478bd9Sstevel@tonic-gate if (connected)
15717c478bd9Sstevel@tonic-gate disconnect(0, NULL);
15727c478bd9Sstevel@tonic-gate pswitch(1);
15737c478bd9Sstevel@tonic-gate if (connected) {
15747c478bd9Sstevel@tonic-gate disconnect(0, NULL);
15757c478bd9Sstevel@tonic-gate }
15767c478bd9Sstevel@tonic-gate exit(0);
15777c478bd9Sstevel@tonic-gate }
15787c478bd9Sstevel@tonic-gate
15797c478bd9Sstevel@tonic-gate /*
15807c478bd9Sstevel@tonic-gate * Terminate session, but don't exit.
15817c478bd9Sstevel@tonic-gate */
15827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
15837c478bd9Sstevel@tonic-gate void
disconnect(int argc,char * argv[])15847c478bd9Sstevel@tonic-gate disconnect(int argc, char *argv[])
15857c478bd9Sstevel@tonic-gate {
15867c478bd9Sstevel@tonic-gate extern FILE *ctrl_in, *ctrl_out;
15877c478bd9Sstevel@tonic-gate extern int data;
15887c478bd9Sstevel@tonic-gate
15897c478bd9Sstevel@tonic-gate if (!connected)
15907c478bd9Sstevel@tonic-gate return;
15917c478bd9Sstevel@tonic-gate (void) command("QUIT");
15927c478bd9Sstevel@tonic-gate if (ctrl_in) {
15937c478bd9Sstevel@tonic-gate reset_timer();
15947c478bd9Sstevel@tonic-gate (void) fclose(ctrl_in);
15957c478bd9Sstevel@tonic-gate }
15967c478bd9Sstevel@tonic-gate if (ctrl_out) {
15977c478bd9Sstevel@tonic-gate reset_timer();
15987c478bd9Sstevel@tonic-gate (void) fclose(ctrl_out);
15997c478bd9Sstevel@tonic-gate }
16007c478bd9Sstevel@tonic-gate ctrl_out = ctrl_in = NULL;
16017c478bd9Sstevel@tonic-gate connected = 0;
16027c478bd9Sstevel@tonic-gate data = -1;
16037c478bd9Sstevel@tonic-gate if (!proxy) {
16047c478bd9Sstevel@tonic-gate macnum = 0;
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate
16077c478bd9Sstevel@tonic-gate auth_type = AUTHTYPE_NONE;
16087c478bd9Sstevel@tonic-gate clevel = dlevel = PROT_C;
16097c478bd9Sstevel@tonic-gate goteof = 0;
16107c478bd9Sstevel@tonic-gate }
16117c478bd9Sstevel@tonic-gate
16127c478bd9Sstevel@tonic-gate static int
confirm(char * cmd,char * file)16137c478bd9Sstevel@tonic-gate confirm(char *cmd, char *file)
16147c478bd9Sstevel@tonic-gate {
16157c478bd9Sstevel@tonic-gate char line[FTPBUFSIZ];
16167c478bd9Sstevel@tonic-gate
16177c478bd9Sstevel@tonic-gate if (!interactive)
16187c478bd9Sstevel@tonic-gate return (1);
16197c478bd9Sstevel@tonic-gate stop_timer();
16207c478bd9Sstevel@tonic-gate (void) printf("%s %s? ", cmd, file);
16217c478bd9Sstevel@tonic-gate (void) fflush(stdout);
16227c478bd9Sstevel@tonic-gate *line = '\0';
16237c478bd9Sstevel@tonic-gate (void) fgets(line, sizeof (line), stdin);
16247c478bd9Sstevel@tonic-gate reset_timer();
16257c478bd9Sstevel@tonic-gate return (*line != 'n' && *line != 'N');
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gate void
fatal(char * msg)16297c478bd9Sstevel@tonic-gate fatal(char *msg)
16307c478bd9Sstevel@tonic-gate {
16317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "ftp: %s\n", msg);
16327c478bd9Sstevel@tonic-gate exit(1);
16337c478bd9Sstevel@tonic-gate }
16347c478bd9Sstevel@tonic-gate
16357c478bd9Sstevel@tonic-gate /*
16367c478bd9Sstevel@tonic-gate * Glob a local file name specification with
16377c478bd9Sstevel@tonic-gate * the expectation of a single return value.
16387c478bd9Sstevel@tonic-gate * Can't control multiple values being expanded
16397c478bd9Sstevel@tonic-gate * from the expression, we return only the first.
16407c478bd9Sstevel@tonic-gate */
16417c478bd9Sstevel@tonic-gate static int
globulize(char ** cpp)16427c478bd9Sstevel@tonic-gate globulize(char **cpp)
16437c478bd9Sstevel@tonic-gate {
16447c478bd9Sstevel@tonic-gate char **globbed;
16457c478bd9Sstevel@tonic-gate
16467c478bd9Sstevel@tonic-gate if (!doglob)
16477c478bd9Sstevel@tonic-gate return (1);
16487c478bd9Sstevel@tonic-gate globbed = glob(*cpp);
16497c478bd9Sstevel@tonic-gate if (globbed != NULL && *globbed == NULL && globerr == NULL)
16507c478bd9Sstevel@tonic-gate globerr = "No match";
16517c478bd9Sstevel@tonic-gate if (globerr != NULL) {
16527c478bd9Sstevel@tonic-gate (void) printf("%s: %s\n", *cpp, globerr);
16537c478bd9Sstevel@tonic-gate if (globbed)
16547c478bd9Sstevel@tonic-gate blkfree(globbed);
16557c478bd9Sstevel@tonic-gate return (0);
16567c478bd9Sstevel@tonic-gate }
16577c478bd9Sstevel@tonic-gate if (globbed) {
16587c478bd9Sstevel@tonic-gate *cpp = strdup(*globbed);
16597c478bd9Sstevel@tonic-gate blkfree(globbed);
16607c478bd9Sstevel@tonic-gate if (!*cpp)
16617c478bd9Sstevel@tonic-gate return (0);
16627c478bd9Sstevel@tonic-gate }
16637c478bd9Sstevel@tonic-gate return (1);
16647c478bd9Sstevel@tonic-gate }
16657c478bd9Sstevel@tonic-gate
16667c478bd9Sstevel@tonic-gate void
account(int argc,char * argv[])16677c478bd9Sstevel@tonic-gate account(int argc, char *argv[])
16687c478bd9Sstevel@tonic-gate {
16697c478bd9Sstevel@tonic-gate char acct[50], *ap;
16707c478bd9Sstevel@tonic-gate
16717c478bd9Sstevel@tonic-gate if (argc > 1) {
16727c478bd9Sstevel@tonic-gate ++argv;
16737c478bd9Sstevel@tonic-gate --argc;
16747c478bd9Sstevel@tonic-gate (void) strncpy(acct, *argv, 49);
16757c478bd9Sstevel@tonic-gate acct[49] = '\0';
16767c478bd9Sstevel@tonic-gate while (argc > 1) {
16777c478bd9Sstevel@tonic-gate --argc;
16787c478bd9Sstevel@tonic-gate ++argv;
16797c478bd9Sstevel@tonic-gate (void) strncat(acct, *argv, 49 - strlen(acct));
16807c478bd9Sstevel@tonic-gate }
16817c478bd9Sstevel@tonic-gate ap = acct;
16827c478bd9Sstevel@tonic-gate } else {
16837c478bd9Sstevel@tonic-gate ap = mygetpass("Account:");
16847c478bd9Sstevel@tonic-gate }
16857c478bd9Sstevel@tonic-gate (void) command("ACCT %s", ap);
16867c478bd9Sstevel@tonic-gate }
16877c478bd9Sstevel@tonic-gate
16887c478bd9Sstevel@tonic-gate /*ARGSUSED*/
16897c478bd9Sstevel@tonic-gate static void
proxabort(int sig)16907c478bd9Sstevel@tonic-gate proxabort(int sig)
16917c478bd9Sstevel@tonic-gate {
16927c478bd9Sstevel@tonic-gate extern int proxy;
16937c478bd9Sstevel@tonic-gate
16947c478bd9Sstevel@tonic-gate if (!proxy) {
16957c478bd9Sstevel@tonic-gate pswitch(1);
16967c478bd9Sstevel@tonic-gate }
16977c478bd9Sstevel@tonic-gate if (connected) {
16987c478bd9Sstevel@tonic-gate proxflag = 1;
16997c478bd9Sstevel@tonic-gate } else {
17007c478bd9Sstevel@tonic-gate proxflag = 0;
17017c478bd9Sstevel@tonic-gate }
17027c478bd9Sstevel@tonic-gate pswitch(0);
17037c478bd9Sstevel@tonic-gate longjmp(abortprox, 1);
17047c478bd9Sstevel@tonic-gate }
17057c478bd9Sstevel@tonic-gate
17067c478bd9Sstevel@tonic-gate void
doproxy(int argc,char * argv[])17077c478bd9Sstevel@tonic-gate doproxy(int argc, char *argv[])
17087c478bd9Sstevel@tonic-gate {
17097c478bd9Sstevel@tonic-gate void (*oldintr)();
17107c478bd9Sstevel@tonic-gate struct cmd *c;
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gate if (argc < 2) {
17137c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "command") == -1) {
17147c478bd9Sstevel@tonic-gate code = -1;
17157c478bd9Sstevel@tonic-gate return;
17167c478bd9Sstevel@tonic-gate }
17177c478bd9Sstevel@tonic-gate makeargv();
17187c478bd9Sstevel@tonic-gate argc = margc;
17197c478bd9Sstevel@tonic-gate argv = margv;
17207c478bd9Sstevel@tonic-gate }
17217c478bd9Sstevel@tonic-gate if (argc < 2) {
17227c478bd9Sstevel@tonic-gate (void) printf("usage: %s command\n", argv[0]);
17237c478bd9Sstevel@tonic-gate code = -1;
17247c478bd9Sstevel@tonic-gate return;
17257c478bd9Sstevel@tonic-gate }
17267c478bd9Sstevel@tonic-gate c = getcmd(argv[1]);
17277c478bd9Sstevel@tonic-gate if (c == (struct cmd *)-1) {
17287c478bd9Sstevel@tonic-gate (void) printf("?Ambiguous command\n");
17297c478bd9Sstevel@tonic-gate (void) fflush(stdout);
17307c478bd9Sstevel@tonic-gate code = -1;
17317c478bd9Sstevel@tonic-gate return;
17327c478bd9Sstevel@tonic-gate }
17337c478bd9Sstevel@tonic-gate if (c == 0) {
17347c478bd9Sstevel@tonic-gate (void) printf("?Invalid command\n");
17357c478bd9Sstevel@tonic-gate (void) fflush(stdout);
17367c478bd9Sstevel@tonic-gate code = -1;
17377c478bd9Sstevel@tonic-gate return;
17387c478bd9Sstevel@tonic-gate }
17397c478bd9Sstevel@tonic-gate if (!c->c_proxy) {
17407c478bd9Sstevel@tonic-gate (void) printf("?Invalid proxy command\n");
17417c478bd9Sstevel@tonic-gate (void) fflush(stdout);
17427c478bd9Sstevel@tonic-gate code = -1;
17437c478bd9Sstevel@tonic-gate return;
17447c478bd9Sstevel@tonic-gate }
17457c478bd9Sstevel@tonic-gate if (setjmp(abortprox)) {
17467c478bd9Sstevel@tonic-gate code = -1;
17477c478bd9Sstevel@tonic-gate return;
17487c478bd9Sstevel@tonic-gate }
17497c478bd9Sstevel@tonic-gate oldintr = signal(SIGINT, (void (*)())proxabort);
17507c478bd9Sstevel@tonic-gate pswitch(1);
17517c478bd9Sstevel@tonic-gate if (c->c_conn && !connected) {
17527c478bd9Sstevel@tonic-gate (void) printf("Not connected\n");
17537c478bd9Sstevel@tonic-gate (void) fflush(stdout);
17547c478bd9Sstevel@tonic-gate pswitch(0);
17557c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
17567c478bd9Sstevel@tonic-gate code = -1;
17577c478bd9Sstevel@tonic-gate return;
17587c478bd9Sstevel@tonic-gate }
17597c478bd9Sstevel@tonic-gate (*c->c_handler)(argc-1, argv+1);
17607c478bd9Sstevel@tonic-gate if (connected) {
17617c478bd9Sstevel@tonic-gate proxflag = 1;
17627c478bd9Sstevel@tonic-gate } else {
17637c478bd9Sstevel@tonic-gate proxflag = 0;
17647c478bd9Sstevel@tonic-gate }
17657c478bd9Sstevel@tonic-gate pswitch(0);
17667c478bd9Sstevel@tonic-gate (void) signal(SIGINT, oldintr);
17677c478bd9Sstevel@tonic-gate }
17687c478bd9Sstevel@tonic-gate
17697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17707c478bd9Sstevel@tonic-gate void
setcase(int argc,char * argv[])17717c478bd9Sstevel@tonic-gate setcase(int argc, char *argv[])
17727c478bd9Sstevel@tonic-gate {
17737c478bd9Sstevel@tonic-gate mcase = !mcase;
17747c478bd9Sstevel@tonic-gate (void) printf("Case mapping %s.\n", onoff(mcase));
17757c478bd9Sstevel@tonic-gate code = mcase;
17767c478bd9Sstevel@tonic-gate }
17777c478bd9Sstevel@tonic-gate
17787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17797c478bd9Sstevel@tonic-gate void
setcr(int argc,char * argv[])17807c478bd9Sstevel@tonic-gate setcr(int argc, char *argv[])
17817c478bd9Sstevel@tonic-gate {
17827c478bd9Sstevel@tonic-gate crflag = !crflag;
17837c478bd9Sstevel@tonic-gate (void) printf("Carriage Return stripping %s.\n", onoff(crflag));
17847c478bd9Sstevel@tonic-gate code = crflag;
17857c478bd9Sstevel@tonic-gate }
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gate void
setntrans(int argc,char * argv[])17887c478bd9Sstevel@tonic-gate setntrans(int argc, char *argv[])
17897c478bd9Sstevel@tonic-gate {
17907c478bd9Sstevel@tonic-gate if (argc == 1) {
17917c478bd9Sstevel@tonic-gate ntflag = 0;
17927c478bd9Sstevel@tonic-gate (void) printf("Ntrans off.\n");
17937c478bd9Sstevel@tonic-gate code = ntflag;
17947c478bd9Sstevel@tonic-gate return;
17957c478bd9Sstevel@tonic-gate }
17967c478bd9Sstevel@tonic-gate ntflag++;
17977c478bd9Sstevel@tonic-gate code = ntflag;
17987c478bd9Sstevel@tonic-gate (void) strncpy(ntin, argv[1], 16);
17997c478bd9Sstevel@tonic-gate ntin[16] = '\0';
18007c478bd9Sstevel@tonic-gate if (argc == 2) {
18017c478bd9Sstevel@tonic-gate ntout[0] = '\0';
18027c478bd9Sstevel@tonic-gate return;
18037c478bd9Sstevel@tonic-gate }
18047c478bd9Sstevel@tonic-gate (void) strncpy(ntout, argv[2], 16);
18057c478bd9Sstevel@tonic-gate ntout[16] = '\0';
18067c478bd9Sstevel@tonic-gate }
18077c478bd9Sstevel@tonic-gate
18087c478bd9Sstevel@tonic-gate static char *
dotrans(char * name)18097c478bd9Sstevel@tonic-gate dotrans(char *name)
18107c478bd9Sstevel@tonic-gate {
18117c478bd9Sstevel@tonic-gate static char new[MAXPATHLEN];
18127c478bd9Sstevel@tonic-gate char *cp1, *cp2 = new;
18137c478bd9Sstevel@tonic-gate int i, ostop, found;
18147c478bd9Sstevel@tonic-gate
18157c478bd9Sstevel@tonic-gate for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
18167c478bd9Sstevel@tonic-gate ;
18177c478bd9Sstevel@tonic-gate for (cp1 = name; *cp1; cp1++) {
18187c478bd9Sstevel@tonic-gate found = 0;
18197c478bd9Sstevel@tonic-gate for (i = 0; *(ntin + i) && i < 16; i++) {
18207c478bd9Sstevel@tonic-gate if (*cp1 == *(ntin + i)) {
18217c478bd9Sstevel@tonic-gate found++;
18227c478bd9Sstevel@tonic-gate if (i < ostop) {
18237c478bd9Sstevel@tonic-gate *cp2++ = *(ntout + i);
18247c478bd9Sstevel@tonic-gate }
18257c478bd9Sstevel@tonic-gate break;
18267c478bd9Sstevel@tonic-gate }
18277c478bd9Sstevel@tonic-gate }
18287c478bd9Sstevel@tonic-gate if (!found) {
18297c478bd9Sstevel@tonic-gate *cp2++ = *cp1;
18307c478bd9Sstevel@tonic-gate }
18317c478bd9Sstevel@tonic-gate }
18327c478bd9Sstevel@tonic-gate *cp2 = '\0';
18337c478bd9Sstevel@tonic-gate return (new);
18347c478bd9Sstevel@tonic-gate }
18357c478bd9Sstevel@tonic-gate
18367c478bd9Sstevel@tonic-gate void
setnmap(int argc,char * argv[])18377c478bd9Sstevel@tonic-gate setnmap(int argc, char *argv[])
18387c478bd9Sstevel@tonic-gate {
18397c478bd9Sstevel@tonic-gate char *cp;
18407c478bd9Sstevel@tonic-gate
18417c478bd9Sstevel@tonic-gate if (argc == 1) {
18427c478bd9Sstevel@tonic-gate mapflag = 0;
18437c478bd9Sstevel@tonic-gate (void) printf("Nmap off.\n");
18447c478bd9Sstevel@tonic-gate code = mapflag;
18457c478bd9Sstevel@tonic-gate return;
18467c478bd9Sstevel@tonic-gate }
18477c478bd9Sstevel@tonic-gate if (argc < 3) {
18487c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "mapout") == -1) {
18497c478bd9Sstevel@tonic-gate code = -1;
18507c478bd9Sstevel@tonic-gate return;
18517c478bd9Sstevel@tonic-gate }
18527c478bd9Sstevel@tonic-gate makeargv();
18537c478bd9Sstevel@tonic-gate argc = margc;
18547c478bd9Sstevel@tonic-gate argv = margv;
18557c478bd9Sstevel@tonic-gate }
18567c478bd9Sstevel@tonic-gate if (argc < 3) {
18577c478bd9Sstevel@tonic-gate (void) printf("Usage: %s [mapin mapout]\n", argv[0]);
18587c478bd9Sstevel@tonic-gate code = -1;
18597c478bd9Sstevel@tonic-gate return;
18607c478bd9Sstevel@tonic-gate }
18617c478bd9Sstevel@tonic-gate mapflag = 1;
18627c478bd9Sstevel@tonic-gate code = 1;
18637c478bd9Sstevel@tonic-gate cp = index(altarg, ' ');
18647c478bd9Sstevel@tonic-gate if (proxy) {
18657c478bd9Sstevel@tonic-gate while (*++cp == ' ')
18667c478bd9Sstevel@tonic-gate /* NULL */;
18677c478bd9Sstevel@tonic-gate altarg = cp;
18687c478bd9Sstevel@tonic-gate cp = index(altarg, ' ');
18697c478bd9Sstevel@tonic-gate }
18707c478bd9Sstevel@tonic-gate *cp = '\0';
18717c478bd9Sstevel@tonic-gate (void) strncpy(mapin, altarg, MAXPATHLEN - 1);
18727c478bd9Sstevel@tonic-gate while (*++cp == ' ')
18737c478bd9Sstevel@tonic-gate /* NULL */;
18747c478bd9Sstevel@tonic-gate (void) strncpy(mapout, cp, MAXPATHLEN - 1);
18757c478bd9Sstevel@tonic-gate }
18767c478bd9Sstevel@tonic-gate
18777c478bd9Sstevel@tonic-gate static char *
domap(char * name)18787c478bd9Sstevel@tonic-gate domap(char *name)
18797c478bd9Sstevel@tonic-gate {
18807c478bd9Sstevel@tonic-gate static char new[MAXPATHLEN];
18817c478bd9Sstevel@tonic-gate char *cp1 = name, *cp2 = mapin;
18827c478bd9Sstevel@tonic-gate char *tp[9], *te[9];
18837c478bd9Sstevel@tonic-gate int i, toks[9], toknum, match = 1;
18847c478bd9Sstevel@tonic-gate wchar_t wc1, wc2;
18857c478bd9Sstevel@tonic-gate int len1, len2;
18867c478bd9Sstevel@tonic-gate
18877c478bd9Sstevel@tonic-gate for (i = 0; i < 9; ++i) {
18887c478bd9Sstevel@tonic-gate toks[i] = 0;
18897c478bd9Sstevel@tonic-gate }
18907c478bd9Sstevel@tonic-gate while (match && *cp1 && *cp2) {
18917c478bd9Sstevel@tonic-gate if ((len1 = mbtowc(&wc1, cp1, MB_CUR_MAX)) <= 0) {
18927c478bd9Sstevel@tonic-gate wc1 = (unsigned char)*cp1;
18937c478bd9Sstevel@tonic-gate len1 = 1;
18947c478bd9Sstevel@tonic-gate }
18957c478bd9Sstevel@tonic-gate cp1 += len1;
18967c478bd9Sstevel@tonic-gate if ((len2 = mbtowc(&wc2, cp2, MB_CUR_MAX)) <= 0) {
18977c478bd9Sstevel@tonic-gate wc2 = (unsigned char)*cp2;
18987c478bd9Sstevel@tonic-gate len2 = 1;
18997c478bd9Sstevel@tonic-gate }
19007c478bd9Sstevel@tonic-gate cp2 += len2;
19017c478bd9Sstevel@tonic-gate
19027c478bd9Sstevel@tonic-gate switch (wc2) {
19037c478bd9Sstevel@tonic-gate case '\\':
19047c478bd9Sstevel@tonic-gate if ((len2 = mbtowc(&wc2, cp2, MB_CUR_MAX)) <= 0) {
19057c478bd9Sstevel@tonic-gate wc2 = (unsigned char)*cp2;
19067c478bd9Sstevel@tonic-gate len2 = 1;
19077c478bd9Sstevel@tonic-gate }
19087c478bd9Sstevel@tonic-gate cp2 += len2;
19097c478bd9Sstevel@tonic-gate if (wc2 != wc1)
19107c478bd9Sstevel@tonic-gate match = 0;
19117c478bd9Sstevel@tonic-gate break;
19127c478bd9Sstevel@tonic-gate
19137c478bd9Sstevel@tonic-gate case '$':
19147c478bd9Sstevel@tonic-gate if (*cp2 >= '1' && *cp2 <= '9') {
19157c478bd9Sstevel@tonic-gate if ((len2 =
19167c478bd9Sstevel@tonic-gate mbtowc(&wc2, cp2 + 1, MB_CUR_MAX)) <= 0) {
19177c478bd9Sstevel@tonic-gate wc2 = (unsigned char)*(cp2 + 1);
19187c478bd9Sstevel@tonic-gate len2 = 1;
19197c478bd9Sstevel@tonic-gate }
19207c478bd9Sstevel@tonic-gate if (wc1 != wc2) {
19217c478bd9Sstevel@tonic-gate toks[toknum = *cp2 - '1']++;
19227c478bd9Sstevel@tonic-gate tp[toknum] = cp1 - len1;
19237c478bd9Sstevel@tonic-gate while (*cp1) {
19247c478bd9Sstevel@tonic-gate if ((len1 = mbtowc(&wc1,
19257c478bd9Sstevel@tonic-gate cp1, MB_CUR_MAX)) <= 0) {
19267c478bd9Sstevel@tonic-gate wc1 =
19277c478bd9Sstevel@tonic-gate (unsigned char)*cp1;
19287c478bd9Sstevel@tonic-gate len1 = 1;
19297c478bd9Sstevel@tonic-gate }
19307c478bd9Sstevel@tonic-gate cp1 += len1;
19317c478bd9Sstevel@tonic-gate if (wc2 == wc1)
19327c478bd9Sstevel@tonic-gate break;
19337c478bd9Sstevel@tonic-gate }
19347c478bd9Sstevel@tonic-gate if (*cp1 == 0 && wc2 != wc1)
19357c478bd9Sstevel@tonic-gate te[toknum] = cp1;
19367c478bd9Sstevel@tonic-gate else
19377c478bd9Sstevel@tonic-gate te[toknum] = cp1 - len1;
19387c478bd9Sstevel@tonic-gate }
19397c478bd9Sstevel@tonic-gate cp2++; /* Consume the digit */
19407c478bd9Sstevel@tonic-gate if (wc2)
19417c478bd9Sstevel@tonic-gate cp2 += len2; /* Consume wide char */
19427c478bd9Sstevel@tonic-gate break;
19437c478bd9Sstevel@tonic-gate }
19447c478bd9Sstevel@tonic-gate /* intentional drop through */
19457c478bd9Sstevel@tonic-gate default:
19467c478bd9Sstevel@tonic-gate if (wc2 != wc1)
19477c478bd9Sstevel@tonic-gate match = 0;
19487c478bd9Sstevel@tonic-gate break;
19497c478bd9Sstevel@tonic-gate }
19507c478bd9Sstevel@tonic-gate }
19517c478bd9Sstevel@tonic-gate
19527c478bd9Sstevel@tonic-gate cp1 = new;
19537c478bd9Sstevel@tonic-gate *cp1 = '\0';
19547c478bd9Sstevel@tonic-gate cp2 = mapout;
19557c478bd9Sstevel@tonic-gate while (*cp2) {
19567c478bd9Sstevel@tonic-gate match = 0;
19577c478bd9Sstevel@tonic-gate switch (*cp2) {
19587c478bd9Sstevel@tonic-gate case '\\':
19597c478bd9Sstevel@tonic-gate cp2++;
19607c478bd9Sstevel@tonic-gate if (*cp2) {
19617c478bd9Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 0)
19627c478bd9Sstevel@tonic-gate len2 = 1;
19637c478bd9Sstevel@tonic-gate memcpy(cp1, cp2, len2);
19647c478bd9Sstevel@tonic-gate cp1 += len2;
19657c478bd9Sstevel@tonic-gate cp2 += len2;
19667c478bd9Sstevel@tonic-gate }
19677c478bd9Sstevel@tonic-gate break;
19687c478bd9Sstevel@tonic-gate
19697c478bd9Sstevel@tonic-gate case '[':
19707c478bd9Sstevel@tonic-gate LOOP:
19717c478bd9Sstevel@tonic-gate cp2++;
19727c478bd9Sstevel@tonic-gate if (*cp2 == '$' && isdigit(*(cp2+1))) {
19737c478bd9Sstevel@tonic-gate if (*++cp2 == '0') {
19747c478bd9Sstevel@tonic-gate char *cp3 = name;
19757c478bd9Sstevel@tonic-gate
19767c478bd9Sstevel@tonic-gate while (*cp3) {
19777c478bd9Sstevel@tonic-gate *cp1++ = *cp3++;
19787c478bd9Sstevel@tonic-gate }
19797c478bd9Sstevel@tonic-gate match = 1;
19807c478bd9Sstevel@tonic-gate } else if (toks[toknum = *cp2 - '1']) {
19817c478bd9Sstevel@tonic-gate char *cp3 = tp[toknum];
19827c478bd9Sstevel@tonic-gate
19837c478bd9Sstevel@tonic-gate while (cp3 != te[toknum]) {
19847c478bd9Sstevel@tonic-gate *cp1++ = *cp3++;
19857c478bd9Sstevel@tonic-gate }
19867c478bd9Sstevel@tonic-gate match = 1;
19877c478bd9Sstevel@tonic-gate }
19887c478bd9Sstevel@tonic-gate } else {
19897c478bd9Sstevel@tonic-gate while (*cp2 && *cp2 != ',' && *cp2 != ']') {
19907c478bd9Sstevel@tonic-gate if (*cp2 == '\\') {
19917c478bd9Sstevel@tonic-gate cp2++;
19927c478bd9Sstevel@tonic-gate continue;
19937c478bd9Sstevel@tonic-gate }
19947c478bd9Sstevel@tonic-gate
19957c478bd9Sstevel@tonic-gate if (*cp2 == '$' && isdigit(*(cp2+1))) {
19967c478bd9Sstevel@tonic-gate if (*++cp2 == '0') {
19977c478bd9Sstevel@tonic-gate char *cp3 = name;
19987c478bd9Sstevel@tonic-gate
19997c478bd9Sstevel@tonic-gate while (*cp3)
20007c478bd9Sstevel@tonic-gate *cp1++ = *cp3++;
20017c478bd9Sstevel@tonic-gate continue;
20027c478bd9Sstevel@tonic-gate }
20037c478bd9Sstevel@tonic-gate if (toks[toknum = *cp2 - '1']) {
20047c478bd9Sstevel@tonic-gate char *cp3 = tp[toknum];
20057c478bd9Sstevel@tonic-gate
20067c478bd9Sstevel@tonic-gate while (cp3 !=
20077c478bd9Sstevel@tonic-gate te[toknum])
20087c478bd9Sstevel@tonic-gate *cp1++ = *cp3++;
20097c478bd9Sstevel@tonic-gate }
20107c478bd9Sstevel@tonic-gate continue;
20117c478bd9Sstevel@tonic-gate }
20127c478bd9Sstevel@tonic-gate if (*cp2) {
20137c478bd9Sstevel@tonic-gate if ((len2 =
20147c478bd9Sstevel@tonic-gate mblen(cp2, MB_CUR_MAX)) <=
20157c478bd9Sstevel@tonic-gate 0) {
20167c478bd9Sstevel@tonic-gate len2 = 1;
20177c478bd9Sstevel@tonic-gate }
20187c478bd9Sstevel@tonic-gate memcpy(cp1, cp2, len2);
20197c478bd9Sstevel@tonic-gate cp1 += len2;
20207c478bd9Sstevel@tonic-gate cp2 += len2;
20217c478bd9Sstevel@tonic-gate }
20227c478bd9Sstevel@tonic-gate }
20237c478bd9Sstevel@tonic-gate if (!*cp2) {
20247c478bd9Sstevel@tonic-gate (void) printf(
20257c478bd9Sstevel@tonic-gate "nmap: unbalanced brackets\n");
20267c478bd9Sstevel@tonic-gate return (name);
20277c478bd9Sstevel@tonic-gate }
20287c478bd9Sstevel@tonic-gate match = 1;
20297c478bd9Sstevel@tonic-gate }
20307c478bd9Sstevel@tonic-gate if (match) {
20317c478bd9Sstevel@tonic-gate while (*cp2 && *cp2 != ']') {
20327c478bd9Sstevel@tonic-gate if (*cp2 == '\\' && *(cp2 + 1)) {
20337c478bd9Sstevel@tonic-gate cp2++;
20347c478bd9Sstevel@tonic-gate }
20357c478bd9Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <=
20367c478bd9Sstevel@tonic-gate 0)
20377c478bd9Sstevel@tonic-gate len2 = 1;
20387c478bd9Sstevel@tonic-gate cp2 += len2;
20397c478bd9Sstevel@tonic-gate }
20407c478bd9Sstevel@tonic-gate if (!*cp2) {
20417c478bd9Sstevel@tonic-gate (void) printf(
20427c478bd9Sstevel@tonic-gate "nmap: unbalanced brackets\n");
20437c478bd9Sstevel@tonic-gate return (name);
20447c478bd9Sstevel@tonic-gate }
20457c478bd9Sstevel@tonic-gate cp2++;
20467c478bd9Sstevel@tonic-gate break;
20477c478bd9Sstevel@tonic-gate }
20487c478bd9Sstevel@tonic-gate switch (*++cp2) {
20497c478bd9Sstevel@tonic-gate case ',':
20507c478bd9Sstevel@tonic-gate goto LOOP;
20517c478bd9Sstevel@tonic-gate case ']':
20527c478bd9Sstevel@tonic-gate break;
20537c478bd9Sstevel@tonic-gate default:
20547c478bd9Sstevel@tonic-gate cp2--;
20557c478bd9Sstevel@tonic-gate goto LOOP;
20567c478bd9Sstevel@tonic-gate }
20577c478bd9Sstevel@tonic-gate cp2++;
20587c478bd9Sstevel@tonic-gate break;
20597c478bd9Sstevel@tonic-gate case '$':
20607c478bd9Sstevel@tonic-gate if (isdigit(*(cp2 + 1))) {
20617c478bd9Sstevel@tonic-gate if (*++cp2 == '0') {
20627c478bd9Sstevel@tonic-gate char *cp3 = name;
20637c478bd9Sstevel@tonic-gate
20647c478bd9Sstevel@tonic-gate while (*cp3) {
20657c478bd9Sstevel@tonic-gate *cp1++ = *cp3++;
20667c478bd9Sstevel@tonic-gate }
20677c478bd9Sstevel@tonic-gate } else if (toks[toknum = *cp2 - '1']) {
20687c478bd9Sstevel@tonic-gate char *cp3 = tp[toknum];
20697c478bd9Sstevel@tonic-gate
20707c478bd9Sstevel@tonic-gate while (cp3 != te[toknum]) {
20717c478bd9Sstevel@tonic-gate *cp1++ = *cp3++;
20727c478bd9Sstevel@tonic-gate }
20737c478bd9Sstevel@tonic-gate }
20747c478bd9Sstevel@tonic-gate cp2++;
20757c478bd9Sstevel@tonic-gate break;
20767c478bd9Sstevel@tonic-gate }
20777c478bd9Sstevel@tonic-gate /* intentional drop through */
20787c478bd9Sstevel@tonic-gate default:
20797c478bd9Sstevel@tonic-gate if ((len2 = mblen(cp2, MB_CUR_MAX)) <= 0)
20807c478bd9Sstevel@tonic-gate len2 = 1;
20817c478bd9Sstevel@tonic-gate memcpy(cp1, cp2, len2);
20827c478bd9Sstevel@tonic-gate cp1 += len2;
20837c478bd9Sstevel@tonic-gate cp2 += len2;
20847c478bd9Sstevel@tonic-gate break;
20857c478bd9Sstevel@tonic-gate }
20867c478bd9Sstevel@tonic-gate }
20877c478bd9Sstevel@tonic-gate *cp1 = '\0';
20887c478bd9Sstevel@tonic-gate if (!*new) {
20897c478bd9Sstevel@tonic-gate return (name);
20907c478bd9Sstevel@tonic-gate }
20917c478bd9Sstevel@tonic-gate return (new);
20927c478bd9Sstevel@tonic-gate }
20937c478bd9Sstevel@tonic-gate
20947c478bd9Sstevel@tonic-gate /*ARGSUSED*/
20957c478bd9Sstevel@tonic-gate void
setsunique(int argc,char * argv[])20967c478bd9Sstevel@tonic-gate setsunique(int argc, char *argv[])
20977c478bd9Sstevel@tonic-gate {
20987c478bd9Sstevel@tonic-gate sunique = !sunique;
20997c478bd9Sstevel@tonic-gate (void) printf("Store unique %s.\n", onoff(sunique));
21007c478bd9Sstevel@tonic-gate code = sunique;
21017c478bd9Sstevel@tonic-gate }
21027c478bd9Sstevel@tonic-gate
21037c478bd9Sstevel@tonic-gate /*ARGSUSED*/
21047c478bd9Sstevel@tonic-gate void
setrunique(int argc,char * argv[])21057c478bd9Sstevel@tonic-gate setrunique(int argc, char *argv[])
21067c478bd9Sstevel@tonic-gate {
21077c478bd9Sstevel@tonic-gate runique = !runique;
21087c478bd9Sstevel@tonic-gate (void) printf("Receive unique %s.\n", onoff(runique));
21097c478bd9Sstevel@tonic-gate code = runique;
21107c478bd9Sstevel@tonic-gate }
21117c478bd9Sstevel@tonic-gate
21127c478bd9Sstevel@tonic-gate /*ARGSUSED*/
21137c478bd9Sstevel@tonic-gate void
setpassive(int argc,char * argv[])21147c478bd9Sstevel@tonic-gate setpassive(int argc, char *argv[])
21157c478bd9Sstevel@tonic-gate {
21167c478bd9Sstevel@tonic-gate passivemode = !passivemode;
21177c478bd9Sstevel@tonic-gate (void) printf("Passive mode %s.\n", onoff(passivemode));
21187c478bd9Sstevel@tonic-gate code = passivemode;
21197c478bd9Sstevel@tonic-gate }
21207c478bd9Sstevel@tonic-gate
21217c478bd9Sstevel@tonic-gate void
settcpwindow(int argc,char * argv[])21227c478bd9Sstevel@tonic-gate settcpwindow(int argc, char *argv[])
21237c478bd9Sstevel@tonic-gate {
21247c478bd9Sstevel@tonic-gate int owindowsize = tcpwindowsize;
21257c478bd9Sstevel@tonic-gate
21267c478bd9Sstevel@tonic-gate if (argc > 2) {
21277c478bd9Sstevel@tonic-gate (void) printf("usage: %s [size]\n", argv[0]);
21287c478bd9Sstevel@tonic-gate code = -1;
21297c478bd9Sstevel@tonic-gate return;
21307c478bd9Sstevel@tonic-gate }
21317c478bd9Sstevel@tonic-gate if (argc == 2) {
21327c478bd9Sstevel@tonic-gate int window;
21337c478bd9Sstevel@tonic-gate char *endp;
21347c478bd9Sstevel@tonic-gate
21357c478bd9Sstevel@tonic-gate errno = 0;
21367c478bd9Sstevel@tonic-gate window = (int)strtol(argv[1], &endp, 10);
21377c478bd9Sstevel@tonic-gate if (errno || window < 0 || *endp != '\0')
21387c478bd9Sstevel@tonic-gate (void) printf("%s: Invalid size `%s'\n",
21397c478bd9Sstevel@tonic-gate argv[0], argv[1]);
21407c478bd9Sstevel@tonic-gate else
21417c478bd9Sstevel@tonic-gate tcpwindowsize = window;
21427c478bd9Sstevel@tonic-gate }
21437c478bd9Sstevel@tonic-gate if (tcpwindowsize == 0) {
21447c478bd9Sstevel@tonic-gate if (owindowsize == 0)
21457c478bd9Sstevel@tonic-gate (void) printf("No TCP window size defined\n");
21467c478bd9Sstevel@tonic-gate else
21477c478bd9Sstevel@tonic-gate (void) printf("TCP window size cleared\n");
21487c478bd9Sstevel@tonic-gate } else
21497c478bd9Sstevel@tonic-gate (void) printf("TCP window size is set to %d\n", tcpwindowsize);
21507c478bd9Sstevel@tonic-gate }
21517c478bd9Sstevel@tonic-gate
21527c478bd9Sstevel@tonic-gate /* change directory to parent directory */
21537c478bd9Sstevel@tonic-gate /*ARGSUSED*/
21547c478bd9Sstevel@tonic-gate void
cdup(int argc,char * argv[])21557c478bd9Sstevel@tonic-gate cdup(int argc, char *argv[])
21567c478bd9Sstevel@tonic-gate {
21577c478bd9Sstevel@tonic-gate (void) command("CDUP");
21587c478bd9Sstevel@tonic-gate }
21597c478bd9Sstevel@tonic-gate
21607c478bd9Sstevel@tonic-gate void
macdef(int argc,char * argv[])21617c478bd9Sstevel@tonic-gate macdef(int argc, char *argv[])
21627c478bd9Sstevel@tonic-gate {
21637c478bd9Sstevel@tonic-gate char *tmp;
21647c478bd9Sstevel@tonic-gate int c;
21657c478bd9Sstevel@tonic-gate
21667c478bd9Sstevel@tonic-gate if (macnum == 16) {
21677c478bd9Sstevel@tonic-gate (void) printf("Limit of 16 macros have already been defined\n");
21687c478bd9Sstevel@tonic-gate code = -1;
21697c478bd9Sstevel@tonic-gate return;
21707c478bd9Sstevel@tonic-gate }
21717c478bd9Sstevel@tonic-gate if (argc < 2) {
21727c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "macro name") == -1) {
21737c478bd9Sstevel@tonic-gate code = -1;
21747c478bd9Sstevel@tonic-gate return;
21757c478bd9Sstevel@tonic-gate }
21767c478bd9Sstevel@tonic-gate makeargv();
21777c478bd9Sstevel@tonic-gate argc = margc;
21787c478bd9Sstevel@tonic-gate argv = margv;
21797c478bd9Sstevel@tonic-gate }
21807c478bd9Sstevel@tonic-gate if (argc != 2) {
21817c478bd9Sstevel@tonic-gate (void) printf("Usage: %s macro_name\n", argv[0]);
21827c478bd9Sstevel@tonic-gate code = -1;
21837c478bd9Sstevel@tonic-gate return;
21847c478bd9Sstevel@tonic-gate }
21857c478bd9Sstevel@tonic-gate if (interactive) {
21867c478bd9Sstevel@tonic-gate (void) printf("Enter macro line by line, terminating "
21877c478bd9Sstevel@tonic-gate "it with a null line\n");
21887c478bd9Sstevel@tonic-gate }
21897c478bd9Sstevel@tonic-gate (void) strncpy(macros[macnum].mac_name, argv[1], 8);
21907c478bd9Sstevel@tonic-gate if (macnum == 0) {
21917c478bd9Sstevel@tonic-gate macros[macnum].mac_start = macbuf;
21927c478bd9Sstevel@tonic-gate } else {
21937c478bd9Sstevel@tonic-gate macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
21947c478bd9Sstevel@tonic-gate }
21957c478bd9Sstevel@tonic-gate tmp = macros[macnum].mac_start;
21967c478bd9Sstevel@tonic-gate while (tmp != macbuf+4096) {
21977c478bd9Sstevel@tonic-gate if ((c = getchar()) == EOF) {
21987c478bd9Sstevel@tonic-gate (void) printf("macdef:end of file encountered\n");
21997c478bd9Sstevel@tonic-gate code = -1;
22007c478bd9Sstevel@tonic-gate return;
22017c478bd9Sstevel@tonic-gate }
22027c478bd9Sstevel@tonic-gate if ((*tmp = c) == '\n') {
22037c478bd9Sstevel@tonic-gate if (tmp == macros[macnum].mac_start) {
22047c478bd9Sstevel@tonic-gate macros[macnum++].mac_end = tmp;
22057c478bd9Sstevel@tonic-gate code = 0;
22067c478bd9Sstevel@tonic-gate return;
22077c478bd9Sstevel@tonic-gate }
22087c478bd9Sstevel@tonic-gate if (*(tmp-1) == '\0') {
22097c478bd9Sstevel@tonic-gate macros[macnum++].mac_end = tmp - 1;
22107c478bd9Sstevel@tonic-gate code = 0;
22117c478bd9Sstevel@tonic-gate return;
22127c478bd9Sstevel@tonic-gate }
22137c478bd9Sstevel@tonic-gate *tmp = '\0';
22147c478bd9Sstevel@tonic-gate }
22157c478bd9Sstevel@tonic-gate tmp++;
22167c478bd9Sstevel@tonic-gate }
22177c478bd9Sstevel@tonic-gate for (;;) {
22187c478bd9Sstevel@tonic-gate while ((c = getchar()) != '\n' && c != EOF)
22197c478bd9Sstevel@tonic-gate /* NULL */;
22207c478bd9Sstevel@tonic-gate if (c == EOF || getchar() == '\n') {
22217c478bd9Sstevel@tonic-gate (void) printf(
22227c478bd9Sstevel@tonic-gate "Macro not defined - 4k buffer exceeded\n");
22237c478bd9Sstevel@tonic-gate code = -1;
22247c478bd9Sstevel@tonic-gate return;
22257c478bd9Sstevel@tonic-gate }
22267c478bd9Sstevel@tonic-gate }
22277c478bd9Sstevel@tonic-gate }
22287c478bd9Sstevel@tonic-gate
22297c478bd9Sstevel@tonic-gate /*
22307c478bd9Sstevel@tonic-gate * The p_name strings are for the getlevel and setlevel commands.
22317c478bd9Sstevel@tonic-gate * The name strings for printing are in the arpa/ftp.h file in the
22327c478bd9Sstevel@tonic-gate * protnames[] array of strings.
22337c478bd9Sstevel@tonic-gate */
22347c478bd9Sstevel@tonic-gate static struct levels {
22357c478bd9Sstevel@tonic-gate char *p_name;
22367c478bd9Sstevel@tonic-gate char *p_mode;
22377c478bd9Sstevel@tonic-gate int p_level;
22387c478bd9Sstevel@tonic-gate } levels[] = {
22397c478bd9Sstevel@tonic-gate { "clear", "C", PROT_C },
22407c478bd9Sstevel@tonic-gate { "safe", "S", PROT_S },
22417c478bd9Sstevel@tonic-gate { "private", "P", PROT_P },
22427c478bd9Sstevel@tonic-gate NULL
22437c478bd9Sstevel@tonic-gate };
22447c478bd9Sstevel@tonic-gate
22457c478bd9Sstevel@tonic-gate /*
22467c478bd9Sstevel@tonic-gate * Return a pointer to a string which is the readable version of the
22477c478bd9Sstevel@tonic-gate * protection level, or NULL if the input level is not found.
22487c478bd9Sstevel@tonic-gate */
22497c478bd9Sstevel@tonic-gate static char *
getlevel(int level)22507c478bd9Sstevel@tonic-gate getlevel(int level)
22517c478bd9Sstevel@tonic-gate {
22527c478bd9Sstevel@tonic-gate struct levels *p;
22537c478bd9Sstevel@tonic-gate
22547c478bd9Sstevel@tonic-gate for (p = levels; (p != NULL) && (p->p_level != level); p++)
22557c478bd9Sstevel@tonic-gate ;
22567c478bd9Sstevel@tonic-gate return (p ? p->p_name : NULL);
22577c478bd9Sstevel@tonic-gate }
22587c478bd9Sstevel@tonic-gate
22597c478bd9Sstevel@tonic-gate static char *plevel[] = {
22607c478bd9Sstevel@tonic-gate "protect",
22617c478bd9Sstevel@tonic-gate "",
22627c478bd9Sstevel@tonic-gate NULL
22637c478bd9Sstevel@tonic-gate };
22647c478bd9Sstevel@tonic-gate
22657c478bd9Sstevel@tonic-gate /*
22667c478bd9Sstevel@tonic-gate * Set control channel protection level.
22677c478bd9Sstevel@tonic-gate */
22687c478bd9Sstevel@tonic-gate void
setclevel(int argc,char * argv[])22697c478bd9Sstevel@tonic-gate setclevel(int argc, char *argv[])
22707c478bd9Sstevel@tonic-gate {
22717c478bd9Sstevel@tonic-gate struct levels *p;
22727c478bd9Sstevel@tonic-gate char *levelp;
22737c478bd9Sstevel@tonic-gate int comret;
22747c478bd9Sstevel@tonic-gate
22757c478bd9Sstevel@tonic-gate if (argc > 2) {
22767c478bd9Sstevel@tonic-gate char *sep;
22777c478bd9Sstevel@tonic-gate
22787c478bd9Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]);
22797c478bd9Sstevel@tonic-gate sep = " ";
22807c478bd9Sstevel@tonic-gate for (p = levels; p->p_name; p++) {
22817c478bd9Sstevel@tonic-gate (void) printf("%s%s", sep, p->p_name);
22827c478bd9Sstevel@tonic-gate if (*sep == ' ')
22837c478bd9Sstevel@tonic-gate sep = " | ";
22847c478bd9Sstevel@tonic-gate }
22857c478bd9Sstevel@tonic-gate (void) printf(" ]\n");
22867c478bd9Sstevel@tonic-gate code = -1;
22877c478bd9Sstevel@tonic-gate return;
22887c478bd9Sstevel@tonic-gate }
22897c478bd9Sstevel@tonic-gate if (argc < 2) {
22907c478bd9Sstevel@tonic-gate levelp = getlevel(clevel);
22917c478bd9Sstevel@tonic-gate (void) printf("Using %s protection level for commands.\n",
22927c478bd9Sstevel@tonic-gate levelp ? levelp : "<unknown>");
22937c478bd9Sstevel@tonic-gate code = 0;
22947c478bd9Sstevel@tonic-gate return;
22957c478bd9Sstevel@tonic-gate }
22967c478bd9Sstevel@tonic-gate for (p = levels; (p != NULL) && (p->p_name); p++)
22977c478bd9Sstevel@tonic-gate if (strcmp(argv[1], p->p_name) == 0)
22987c478bd9Sstevel@tonic-gate break;
22997c478bd9Sstevel@tonic-gate if (p->p_name == 0) {
23007c478bd9Sstevel@tonic-gate (void) printf("%s: unknown protection level\n", argv[1]);
23017c478bd9Sstevel@tonic-gate code = -1;
23027c478bd9Sstevel@tonic-gate return;
23037c478bd9Sstevel@tonic-gate }
23047c478bd9Sstevel@tonic-gate if (auth_type == AUTHTYPE_NONE) {
23057c478bd9Sstevel@tonic-gate if (strcmp(p->p_name, "clear"))
23067c478bd9Sstevel@tonic-gate (void) printf("Cannot set protection level to %s\n",
23077c478bd9Sstevel@tonic-gate argv[1]);
23087c478bd9Sstevel@tonic-gate return;
23097c478bd9Sstevel@tonic-gate }
23107c478bd9Sstevel@tonic-gate if (strcmp(p->p_name, "clear") == 0) {
23117c478bd9Sstevel@tonic-gate comret = command("CCC");
23127c478bd9Sstevel@tonic-gate if (comret == COMPLETE)
23137c478bd9Sstevel@tonic-gate clevel = PROT_C;
23147c478bd9Sstevel@tonic-gate return;
23157c478bd9Sstevel@tonic-gate }
23167c478bd9Sstevel@tonic-gate clevel = p->p_level;
23177c478bd9Sstevel@tonic-gate (void) printf("Control channel protection level set to %s.\n",
23187c478bd9Sstevel@tonic-gate p->p_name);
23197c478bd9Sstevel@tonic-gate }
23207c478bd9Sstevel@tonic-gate
23217c478bd9Sstevel@tonic-gate /*
23227c478bd9Sstevel@tonic-gate * Set data channel protection level.
23237c478bd9Sstevel@tonic-gate */
23247c478bd9Sstevel@tonic-gate void
setdlevel(int argc,char * argv[])23257c478bd9Sstevel@tonic-gate setdlevel(int argc, char *argv[])
23267c478bd9Sstevel@tonic-gate {
23277c478bd9Sstevel@tonic-gate struct levels *p;
23287c478bd9Sstevel@tonic-gate int comret;
23297c478bd9Sstevel@tonic-gate
23307c478bd9Sstevel@tonic-gate if (argc != 2) {
23317c478bd9Sstevel@tonic-gate char *sep;
23327c478bd9Sstevel@tonic-gate
23337c478bd9Sstevel@tonic-gate (void) printf("usage: %s [", argv[0]);
23347c478bd9Sstevel@tonic-gate sep = " ";
23357c478bd9Sstevel@tonic-gate for (p = levels; p->p_name; p++) {
23367c478bd9Sstevel@tonic-gate (void) printf("%s%s", sep, p->p_name);
23377c478bd9Sstevel@tonic-gate if (*sep == ' ')
23387c478bd9Sstevel@tonic-gate sep = " | ";
23397c478bd9Sstevel@tonic-gate }
23407c478bd9Sstevel@tonic-gate (void) printf(" ]\n");
23417c478bd9Sstevel@tonic-gate code = -1;
23427c478bd9Sstevel@tonic-gate return;
23437c478bd9Sstevel@tonic-gate }
23447c478bd9Sstevel@tonic-gate for (p = levels; p->p_name; p++)
23457c478bd9Sstevel@tonic-gate if (strcmp(argv[1], p->p_name) == 0)
23467c478bd9Sstevel@tonic-gate break;
23477c478bd9Sstevel@tonic-gate if (p->p_name == 0) {
23487c478bd9Sstevel@tonic-gate (void) printf("%s: unknown protection level\n", argv[1]);
23497c478bd9Sstevel@tonic-gate code = -1;
23507c478bd9Sstevel@tonic-gate return;
23517c478bd9Sstevel@tonic-gate }
23527c478bd9Sstevel@tonic-gate if (auth_type == AUTHTYPE_NONE) {
23537c478bd9Sstevel@tonic-gate if (strcmp(p->p_name, "clear"))
23547c478bd9Sstevel@tonic-gate (void) printf("Cannot set protection level to %s\n",
23557c478bd9Sstevel@tonic-gate argv[1]);
23567c478bd9Sstevel@tonic-gate return;
23577c478bd9Sstevel@tonic-gate }
23587c478bd9Sstevel@tonic-gate /* Start with a PBSZ of 1 meg */
23597c478bd9Sstevel@tonic-gate if (p->p_level != PROT_C)
23607c478bd9Sstevel@tonic-gate setpbsz(1<<20);
23617c478bd9Sstevel@tonic-gate comret = command("PROT %s", p->p_mode);
23627c478bd9Sstevel@tonic-gate if (comret == COMPLETE)
23637c478bd9Sstevel@tonic-gate dlevel = p->p_level;
23647c478bd9Sstevel@tonic-gate }
23657c478bd9Sstevel@tonic-gate
23667c478bd9Sstevel@tonic-gate /*
23677c478bd9Sstevel@tonic-gate * Set clear command protection level.
23687c478bd9Sstevel@tonic-gate */
23697c478bd9Sstevel@tonic-gate /* VARARGS */
23707c478bd9Sstevel@tonic-gate void
ccc(int argc,char * argv[])23717c478bd9Sstevel@tonic-gate ccc(int argc, char *argv[])
23727c478bd9Sstevel@tonic-gate {
23737c478bd9Sstevel@tonic-gate plevel[1] = "clear";
23747c478bd9Sstevel@tonic-gate setclevel(2, plevel);
23757c478bd9Sstevel@tonic-gate }
23767c478bd9Sstevel@tonic-gate
23777c478bd9Sstevel@tonic-gate /*
23787c478bd9Sstevel@tonic-gate * Set clear data protection level.
23797c478bd9Sstevel@tonic-gate */
23807c478bd9Sstevel@tonic-gate /* VARARGS */
23817c478bd9Sstevel@tonic-gate void
setclear(int argc,char * argv[])23827c478bd9Sstevel@tonic-gate setclear(int argc, char *argv[])
23837c478bd9Sstevel@tonic-gate {
23847c478bd9Sstevel@tonic-gate plevel[1] = "clear";
23857c478bd9Sstevel@tonic-gate setdlevel(2, plevel);
23867c478bd9Sstevel@tonic-gate }
23877c478bd9Sstevel@tonic-gate
23887c478bd9Sstevel@tonic-gate /*
23897c478bd9Sstevel@tonic-gate * Set safe data protection level.
23907c478bd9Sstevel@tonic-gate */
23917c478bd9Sstevel@tonic-gate /* VARARGS */
23927c478bd9Sstevel@tonic-gate void
setsafe(int argc,char * argv[])23937c478bd9Sstevel@tonic-gate setsafe(int argc, char *argv[])
23947c478bd9Sstevel@tonic-gate {
23957c478bd9Sstevel@tonic-gate plevel[1] = "safe";
23967c478bd9Sstevel@tonic-gate setdlevel(2, plevel);
23977c478bd9Sstevel@tonic-gate }
23987c478bd9Sstevel@tonic-gate
23997c478bd9Sstevel@tonic-gate /*
24007c478bd9Sstevel@tonic-gate * Set private data protection level.
24017c478bd9Sstevel@tonic-gate */
24027c478bd9Sstevel@tonic-gate /* VARARGS */
24037c478bd9Sstevel@tonic-gate void
setprivate(int argc,char * argv[])24047c478bd9Sstevel@tonic-gate setprivate(int argc, char *argv[])
24057c478bd9Sstevel@tonic-gate {
24067c478bd9Sstevel@tonic-gate plevel[1] = "private";
24077c478bd9Sstevel@tonic-gate setdlevel(2, plevel);
24087c478bd9Sstevel@tonic-gate }
24097c478bd9Sstevel@tonic-gate
24107c478bd9Sstevel@tonic-gate /*
24117c478bd9Sstevel@tonic-gate * Set mechanism type
24127c478bd9Sstevel@tonic-gate */
24137c478bd9Sstevel@tonic-gate void
setmech(int argc,char * argv[])24147c478bd9Sstevel@tonic-gate setmech(int argc, char *argv[])
24157c478bd9Sstevel@tonic-gate {
24167c478bd9Sstevel@tonic-gate char tempmech[MECH_SZ];
24177c478bd9Sstevel@tonic-gate
24187c478bd9Sstevel@tonic-gate if (argc < 2) {
24197c478bd9Sstevel@tonic-gate if (prompt_for_arg(line, sizeof (line), "mech-type") == -1) {
24207c478bd9Sstevel@tonic-gate code = -1;
24217c478bd9Sstevel@tonic-gate return;
24227c478bd9Sstevel@tonic-gate }
24237c478bd9Sstevel@tonic-gate makeargv();
24247c478bd9Sstevel@tonic-gate argc = margc;
24257c478bd9Sstevel@tonic-gate argv = margv;
24267c478bd9Sstevel@tonic-gate }
24277c478bd9Sstevel@tonic-gate
24287c478bd9Sstevel@tonic-gate if (argc != 2) {
24297c478bd9Sstevel@tonic-gate (void) printf("usage: %s [ mechanism type ]\n", argv[0]);
24307c478bd9Sstevel@tonic-gate code = -1;
24317c478bd9Sstevel@tonic-gate return;
24327c478bd9Sstevel@tonic-gate }
24337c478bd9Sstevel@tonic-gate
24347c478bd9Sstevel@tonic-gate if ((strlcpy(tempmech, argv[1], MECH_SZ) >= MECH_SZ) ||
24357c478bd9Sstevel@tonic-gate __gss_mech_to_oid(tempmech, (gss_OID*)&mechoid) !=
24367c478bd9Sstevel@tonic-gate GSS_S_COMPLETE) {
24377c478bd9Sstevel@tonic-gate (void) printf("%s: %s: not a valid security mechanism\n",
24387c478bd9Sstevel@tonic-gate argv[0], tempmech);
24397c478bd9Sstevel@tonic-gate code = -1;
24407c478bd9Sstevel@tonic-gate return;
24417c478bd9Sstevel@tonic-gate } else {
24427c478bd9Sstevel@tonic-gate (void) strlcpy(mechstr, tempmech, MECH_SZ);
24437c478bd9Sstevel@tonic-gate (void) printf("Using %s mechanism type\n", mechstr);
24447c478bd9Sstevel@tonic-gate code = 0;
24457c478bd9Sstevel@tonic-gate return;
24467c478bd9Sstevel@tonic-gate }
24477c478bd9Sstevel@tonic-gate }
2448