Home | History | Annotate | Line # | Download | only in ftp
cmds.c revision 1.117
      1  1.117  christos /*	$NetBSD: cmds.c,v 1.117 2006/01/31 20:01:23 christos Exp $	*/
      2   1.39   thorpej 
      3   1.39   thorpej /*-
      4  1.109     lukem  * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
      5   1.39   thorpej  * All rights reserved.
      6   1.39   thorpej  *
      7   1.39   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.70     lukem  * by Luke Mewburn.
      9   1.70     lukem  *
     10   1.70     lukem  * This code is derived from software contributed to The NetBSD Foundation
     11   1.39   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     12   1.39   thorpej  * NASA Ames Research Center.
     13   1.39   thorpej  *
     14   1.39   thorpej  * Redistribution and use in source and binary forms, with or without
     15   1.39   thorpej  * modification, are permitted provided that the following conditions
     16   1.39   thorpej  * are met:
     17   1.39   thorpej  * 1. Redistributions of source code must retain the above copyright
     18   1.39   thorpej  *    notice, this list of conditions and the following disclaimer.
     19   1.39   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     20   1.39   thorpej  *    notice, this list of conditions and the following disclaimer in the
     21   1.39   thorpej  *    documentation and/or other materials provided with the distribution.
     22   1.39   thorpej  * 3. All advertising materials mentioning features or use of this software
     23   1.39   thorpej  *    must display the following acknowledgement:
     24   1.39   thorpej  *	This product includes software developed by the NetBSD
     25   1.39   thorpej  *	Foundation, Inc. and its contributors.
     26   1.39   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     27   1.39   thorpej  *    contributors may be used to endorse or promote products derived
     28   1.39   thorpej  *    from this software without specific prior written permission.
     29   1.39   thorpej  *
     30   1.39   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     31   1.39   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     32   1.39   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     33   1.39   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     34   1.39   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     35   1.39   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     36   1.39   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     37   1.39   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     38   1.39   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39   1.39   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     40   1.39   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     41   1.39   thorpej  */
     42    1.8       tls 
     43    1.1       cgd /*
     44    1.4       cgd  * Copyright (c) 1985, 1989, 1993, 1994
     45    1.4       cgd  *	The Regents of the University of California.  All rights reserved.
     46    1.1       cgd  *
     47    1.1       cgd  * Redistribution and use in source and binary forms, with or without
     48    1.1       cgd  * modification, are permitted provided that the following conditions
     49    1.1       cgd  * are met:
     50    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     51    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     52    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     53    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     54    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     55  1.102       agc  * 3. Neither the name of the University nor the names of its contributors
     56    1.1       cgd  *    may be used to endorse or promote products derived from this software
     57    1.1       cgd  *    without specific prior written permission.
     58    1.1       cgd  *
     59    1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60    1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61    1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62    1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63    1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64    1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65    1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66    1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67    1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68    1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69    1.1       cgd  * SUCH DAMAGE.
     70    1.1       cgd  */
     71    1.1       cgd 
     72   1.65     lukem /*
     73   1.65     lukem  * Copyright (C) 1997 and 1998 WIDE Project.
     74   1.65     lukem  * All rights reserved.
     75  1.112     lukem  *
     76   1.65     lukem  * Redistribution and use in source and binary forms, with or without
     77   1.65     lukem  * modification, are permitted provided that the following conditions
     78   1.65     lukem  * are met:
     79   1.65     lukem  * 1. Redistributions of source code must retain the above copyright
     80   1.65     lukem  *    notice, this list of conditions and the following disclaimer.
     81   1.65     lukem  * 2. Redistributions in binary form must reproduce the above copyright
     82   1.65     lukem  *    notice, this list of conditions and the following disclaimer in the
     83   1.65     lukem  *    documentation and/or other materials provided with the distribution.
     84   1.65     lukem  * 3. Neither the name of the project nor the names of its contributors
     85   1.65     lukem  *    may be used to endorse or promote products derived from this software
     86   1.65     lukem  *    without specific prior written permission.
     87  1.112     lukem  *
     88   1.65     lukem  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     89   1.65     lukem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     90   1.65     lukem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     91   1.65     lukem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     92   1.65     lukem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     93   1.65     lukem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     94   1.65     lukem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     95   1.65     lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     96   1.65     lukem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     97   1.65     lukem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     98   1.65     lukem  * SUCH DAMAGE.
     99   1.65     lukem  */
    100   1.65     lukem 
    101   1.25     lukem #include <sys/cdefs.h>
    102    1.1       cgd #ifndef lint
    103    1.8       tls #if 0
    104    1.8       tls static char sccsid[] = "@(#)cmds.c	8.6 (Berkeley) 10/9/94";
    105    1.8       tls #else
    106  1.117  christos __RCSID("$NetBSD: cmds.c,v 1.117 2006/01/31 20:01:23 christos Exp $");
    107    1.8       tls #endif
    108    1.1       cgd #endif /* not lint */
    109    1.1       cgd 
    110    1.1       cgd /*
    111    1.1       cgd  * FTP User Program -- Command Routines.
    112    1.1       cgd  */
    113   1.16     lukem #include <sys/types.h>
    114   1.16     lukem #include <sys/socket.h>
    115   1.16     lukem #include <sys/stat.h>
    116    1.1       cgd #include <sys/wait.h>
    117    1.1       cgd #include <arpa/ftp.h>
    118    1.1       cgd 
    119    1.4       cgd #include <ctype.h>
    120    1.4       cgd #include <err.h>
    121    1.4       cgd #include <glob.h>
    122   1.42     lukem #include <limits.h>
    123    1.4       cgd #include <netdb.h>
    124   1.67     lukem #include <paths.h>
    125    1.1       cgd #include <stdio.h>
    126    1.4       cgd #include <stdlib.h>
    127    1.4       cgd #include <string.h>
    128   1.35    kleink #include <time.h>
    129    1.4       cgd #include <unistd.h>
    130    1.1       cgd 
    131    1.1       cgd #include "ftp_var.h"
    132   1.81     lukem #include "version.h"
    133    1.1       cgd 
    134    1.1       cgd struct	types {
    135    1.1       cgd 	char	*t_name;
    136    1.1       cgd 	char	*t_mode;
    137    1.1       cgd 	int	t_type;
    138    1.1       cgd 	char	*t_arg;
    139    1.1       cgd } types[] = {
    140    1.1       cgd 	{ "ascii",	"A",	TYPE_A,	0 },
    141    1.1       cgd 	{ "binary",	"I",	TYPE_I,	0 },
    142    1.1       cgd 	{ "image",	"I",	TYPE_I,	0 },
    143    1.1       cgd 	{ "ebcdic",	"E",	TYPE_E,	0 },
    144    1.1       cgd 	{ "tenex",	"L",	TYPE_L,	bytename },
    145    1.4       cgd 	{ NULL }
    146    1.1       cgd };
    147    1.1       cgd 
    148   1.74     lukem sigjmp_buf	 jabort;
    149  1.107     lukem const char	*mname;
    150   1.74     lukem 
    151   1.85     lukem static int	confirm(const char *, const char *);
    152   1.74     lukem 
    153  1.110  christos static const char *doprocess(char *, size_t, const char *, int, int, int);
    154  1.110  christos static const char *domap(char *, size_t, const char *);
    155  1.110  christos static const char *docase(char *, size_t, const char *);
    156  1.110  christos static const char *dotrans(char *, size_t, const char *);
    157  1.110  christos 
    158   1.74     lukem static int
    159   1.85     lukem confirm(const char *cmd, const char *file)
    160   1.74     lukem {
    161  1.115     lukem 	const char *errormsg;
    162   1.74     lukem 	char line[BUFSIZ];
    163   1.74     lukem 
    164   1.74     lukem 	if (!interactive || confirmrest)
    165   1.74     lukem 		return (1);
    166   1.74     lukem 	while (1) {
    167   1.74     lukem 		fprintf(ttyout, "%s %s [anpqy?]? ", cmd, file);
    168   1.74     lukem 		(void)fflush(ttyout);
    169  1.115     lukem 		if (getline(stdin, line, sizeof(line), &errormsg) < 0) {
    170   1.74     lukem 			mflag = 0;
    171  1.115     lukem 			fprintf(ttyout, "%s; %s aborted\n", errormsg, mname);
    172   1.74     lukem 			return (0);
    173   1.74     lukem 		}
    174  1.108       dsl 		switch (tolower((unsigned char)*line)) {
    175   1.74     lukem 			case 'a':
    176   1.74     lukem 				confirmrest = 1;
    177   1.74     lukem 				fprintf(ttyout,
    178   1.74     lukem 				    "Prompting off for duration of %s.\n", cmd);
    179   1.74     lukem 				break;
    180   1.74     lukem 			case 'p':
    181   1.74     lukem 				interactive = 0;
    182   1.74     lukem 				fputs("Interactive mode: off.\n", ttyout);
    183   1.74     lukem 				break;
    184   1.74     lukem 			case 'q':
    185   1.74     lukem 				mflag = 0;
    186   1.76     lukem 				fprintf(ttyout, "%s aborted.\n", mname);
    187   1.75     lukem 				/* FALLTHROUGH */
    188   1.75     lukem 			case 'n':
    189   1.74     lukem 				return (0);
    190   1.74     lukem 			case '?':
    191   1.74     lukem 				fprintf(ttyout,
    192   1.76     lukem 				    "  confirmation options:\n"
    193   1.74     lukem 				    "\ta  answer `yes' for the duration of %s\n"
    194   1.74     lukem 				    "\tn  answer `no' for this file\n"
    195   1.74     lukem 				    "\tp  turn off `prompt' mode\n"
    196   1.74     lukem 				    "\tq  stop the current %s\n"
    197   1.74     lukem 				    "\ty  answer `yes' for this file\n"
    198   1.74     lukem 				    "\t?  this help list\n",
    199   1.74     lukem 				    cmd, cmd);
    200   1.75     lukem 				continue;	/* back to while(1) */
    201   1.74     lukem 		}
    202   1.75     lukem 		return (1);
    203   1.74     lukem 	}
    204   1.74     lukem 	/* NOTREACHED */
    205   1.74     lukem }
    206   1.74     lukem 
    207    1.1       cgd /*
    208    1.1       cgd  * Set transfer type.
    209    1.1       cgd  */
    210    1.4       cgd void
    211   1.85     lukem settype(int argc, char *argv[])
    212    1.1       cgd {
    213    1.4       cgd 	struct types *p;
    214    1.1       cgd 	int comret;
    215    1.1       cgd 
    216   1.88     lukem 	if (argc == 0 || argc > 2) {
    217    1.1       cgd 		char *sep;
    218    1.1       cgd 
    219  1.116  christos 		UPRINTF("usage: %s [", argv[0]);
    220    1.1       cgd 		sep = " ";
    221    1.1       cgd 		for (p = types; p->t_name; p++) {
    222   1.37     lukem 			fprintf(ttyout, "%s%s", sep, p->t_name);
    223    1.1       cgd 			sep = " | ";
    224    1.1       cgd 		}
    225   1.37     lukem 		fputs(" ]\n", ttyout);
    226    1.1       cgd 		code = -1;
    227    1.1       cgd 		return;
    228    1.1       cgd 	}
    229    1.1       cgd 	if (argc < 2) {
    230   1.37     lukem 		fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
    231    1.1       cgd 		code = 0;
    232    1.1       cgd 		return;
    233    1.1       cgd 	}
    234    1.1       cgd 	for (p = types; p->t_name; p++)
    235    1.1       cgd 		if (strcmp(argv[1], p->t_name) == 0)
    236    1.1       cgd 			break;
    237    1.1       cgd 	if (p->t_name == 0) {
    238   1.37     lukem 		fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
    239    1.1       cgd 		code = -1;
    240    1.1       cgd 		return;
    241    1.1       cgd 	}
    242    1.1       cgd 	if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
    243   1.19     lukem 		comret = command("TYPE %s %s", p->t_mode, p->t_arg);
    244    1.1       cgd 	else
    245    1.1       cgd 		comret = command("TYPE %s", p->t_mode);
    246    1.1       cgd 	if (comret == COMPLETE) {
    247   1.63     lukem 		(void)strlcpy(typename, p->t_name, sizeof(typename));
    248    1.1       cgd 		curtype = type = p->t_type;
    249    1.1       cgd 	}
    250    1.1       cgd }
    251    1.1       cgd 
    252    1.1       cgd /*
    253    1.1       cgd  * Internal form of settype; changes current type in use with server
    254    1.1       cgd  * without changing our notion of the type for data transfers.
    255    1.1       cgd  * Used to change to and from ascii for listings.
    256    1.1       cgd  */
    257    1.4       cgd void
    258   1.85     lukem changetype(int newtype, int show)
    259    1.1       cgd {
    260    1.4       cgd 	struct types *p;
    261    1.1       cgd 	int comret, oldverbose = verbose;
    262    1.1       cgd 
    263    1.1       cgd 	if (newtype == 0)
    264    1.1       cgd 		newtype = TYPE_I;
    265    1.1       cgd 	if (newtype == curtype)
    266    1.1       cgd 		return;
    267    1.1       cgd 	if (debug == 0 && show == 0)
    268    1.1       cgd 		verbose = 0;
    269    1.1       cgd 	for (p = types; p->t_name; p++)
    270    1.1       cgd 		if (newtype == p->t_type)
    271    1.1       cgd 			break;
    272    1.1       cgd 	if (p->t_name == 0) {
    273   1.19     lukem 		warnx("internal error: unknown type %d.", newtype);
    274    1.1       cgd 		return;
    275    1.1       cgd 	}
    276    1.1       cgd 	if (newtype == TYPE_L && bytename[0] != '\0')
    277    1.1       cgd 		comret = command("TYPE %s %s", p->t_mode, bytename);
    278    1.1       cgd 	else
    279    1.1       cgd 		comret = command("TYPE %s", p->t_mode);
    280    1.1       cgd 	if (comret == COMPLETE)
    281    1.1       cgd 		curtype = newtype;
    282    1.1       cgd 	verbose = oldverbose;
    283    1.1       cgd }
    284    1.1       cgd 
    285    1.1       cgd char *stype[] = {
    286    1.1       cgd 	"type",
    287    1.1       cgd 	"",
    288    1.1       cgd 	0
    289    1.1       cgd };
    290    1.1       cgd 
    291    1.1       cgd /*
    292    1.1       cgd  * Set binary transfer type.
    293    1.1       cgd  */
    294    1.1       cgd /*VARARGS*/
    295    1.4       cgd void
    296   1.85     lukem setbinary(int argc, char *argv[])
    297    1.1       cgd {
    298    1.4       cgd 
    299   1.88     lukem 	if (argc == 0) {
    300  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    301   1.76     lukem 		code = -1;
    302   1.76     lukem 		return;
    303   1.76     lukem 	}
    304    1.1       cgd 	stype[1] = "binary";
    305    1.1       cgd 	settype(2, stype);
    306    1.1       cgd }
    307    1.1       cgd 
    308    1.1       cgd /*
    309    1.1       cgd  * Set ascii transfer type.
    310    1.1       cgd  */
    311    1.1       cgd /*VARARGS*/
    312    1.4       cgd void
    313   1.85     lukem setascii(int argc, char *argv[])
    314    1.1       cgd {
    315    1.4       cgd 
    316   1.88     lukem 	if (argc == 0) {
    317  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    318   1.76     lukem 		code = -1;
    319   1.76     lukem 		return;
    320   1.76     lukem 	}
    321    1.1       cgd 	stype[1] = "ascii";
    322    1.1       cgd 	settype(2, stype);
    323    1.1       cgd }
    324    1.1       cgd 
    325    1.1       cgd /*
    326    1.1       cgd  * Set tenex transfer type.
    327    1.1       cgd  */
    328    1.1       cgd /*VARARGS*/
    329    1.4       cgd void
    330   1.85     lukem settenex(int argc, char *argv[])
    331    1.1       cgd {
    332    1.4       cgd 
    333   1.88     lukem 	if (argc == 0) {
    334  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    335   1.76     lukem 		code = -1;
    336   1.76     lukem 		return;
    337   1.76     lukem 	}
    338    1.1       cgd 	stype[1] = "tenex";
    339    1.1       cgd 	settype(2, stype);
    340    1.1       cgd }
    341    1.1       cgd 
    342    1.1       cgd /*
    343    1.1       cgd  * Set file transfer mode.
    344    1.1       cgd  */
    345    1.1       cgd /*ARGSUSED*/
    346    1.4       cgd void
    347   1.85     lukem setftmode(int argc, char *argv[])
    348    1.1       cgd {
    349    1.1       cgd 
    350   1.88     lukem 	if (argc != 2) {
    351  1.116  christos 		UPRINTF("usage: %s mode-name\n", argv[0]);
    352   1.76     lukem 		code = -1;
    353   1.76     lukem 		return;
    354   1.76     lukem 	}
    355   1.37     lukem 	fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
    356    1.1       cgd 	code = -1;
    357    1.1       cgd }
    358    1.1       cgd 
    359    1.1       cgd /*
    360    1.1       cgd  * Set file transfer format.
    361    1.1       cgd  */
    362    1.1       cgd /*ARGSUSED*/
    363    1.4       cgd void
    364   1.85     lukem setform(int argc, char *argv[])
    365    1.1       cgd {
    366    1.1       cgd 
    367   1.88     lukem 	if (argc != 2) {
    368  1.116  christos 		UPRINTF("usage: %s format\n", argv[0]);
    369   1.76     lukem 		code = -1;
    370   1.76     lukem 		return;
    371   1.76     lukem 	}
    372   1.37     lukem 	fprintf(ttyout, "We only support %s format, sorry.\n", formname);
    373    1.1       cgd 	code = -1;
    374    1.1       cgd }
    375    1.1       cgd 
    376    1.1       cgd /*
    377    1.1       cgd  * Set file transfer structure.
    378    1.1       cgd  */
    379    1.1       cgd /*ARGSUSED*/
    380    1.4       cgd void
    381   1.85     lukem setstruct(int argc, char *argv[])
    382    1.1       cgd {
    383    1.1       cgd 
    384   1.88     lukem 	if (argc != 2) {
    385  1.116  christos 		UPRINTF("usage: %s struct-mode\n", argv[0]);
    386   1.76     lukem 		code = -1;
    387   1.76     lukem 		return;
    388   1.76     lukem 	}
    389   1.37     lukem 	fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
    390    1.1       cgd 	code = -1;
    391    1.1       cgd }
    392    1.1       cgd 
    393    1.1       cgd /*
    394    1.1       cgd  * Send a single file.
    395    1.1       cgd  */
    396    1.4       cgd void
    397   1.85     lukem put(int argc, char *argv[])
    398    1.1       cgd {
    399  1.110  christos 	char buf[MAXPATHLEN];
    400    1.1       cgd 	char *cmd;
    401    1.1       cgd 	int loc = 0;
    402  1.110  christos 	char *locfile;
    403  1.110  christos 	const char *remfile;
    404    1.1       cgd 
    405    1.1       cgd 	if (argc == 2) {
    406    1.1       cgd 		argc++;
    407    1.1       cgd 		argv[2] = argv[1];
    408    1.1       cgd 		loc++;
    409    1.1       cgd 	}
    410   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file")))
    411    1.1       cgd 		goto usage;
    412   1.10     lukem 	if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
    413   1.88     lukem  usage:
    414  1.116  christos 		UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
    415    1.1       cgd 		code = -1;
    416    1.1       cgd 		return;
    417    1.1       cgd 	}
    418   1.63     lukem 	if ((locfile = globulize(argv[1])) == NULL) {
    419    1.1       cgd 		code = -1;
    420    1.1       cgd 		return;
    421    1.1       cgd 	}
    422   1.63     lukem 	remfile = argv[2];
    423   1.63     lukem 	if (loc)	/* If argv[2] is a copy of the old argv[1], update it */
    424   1.63     lukem 		remfile = locfile;
    425    1.1       cgd 	cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
    426  1.110  christos 	remfile = doprocess(buf, sizeof(buf), remfile,
    427  1.110  christos 		0, loc && ntflag, loc && mapflag);
    428   1.63     lukem 	sendrequest(cmd, locfile, remfile,
    429   1.63     lukem 	    locfile != argv[1] || remfile != argv[2]);
    430   1.63     lukem 	free(locfile);
    431    1.1       cgd }
    432    1.1       cgd 
    433  1.110  christos static const char *
    434  1.110  christos doprocess(char *dst, size_t dlen, const char *src,
    435  1.110  christos     int casef, int transf, int mapf)
    436  1.110  christos {
    437  1.110  christos 	if (casef)
    438  1.110  christos 		src = docase(dst, dlen, src);
    439  1.110  christos 	if (transf)
    440  1.110  christos 		src = dotrans(dst, dlen, src);
    441  1.110  christos 	if (mapf)
    442  1.110  christos 		src = domap(dst, dlen, src);
    443  1.110  christos 	return src;
    444  1.110  christos }
    445  1.110  christos 
    446    1.1       cgd /*
    447    1.1       cgd  * Send multiple files.
    448    1.1       cgd  */
    449    1.4       cgd void
    450   1.85     lukem mput(int argc, char *argv[])
    451    1.1       cgd {
    452    1.4       cgd 	int i;
    453   1.82     lukem 	sigfunc oldintr;
    454    1.1       cgd 	int ointer;
    455  1.110  christos 	const char *tp;
    456    1.1       cgd 
    457   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
    458  1.116  christos 		UPRINTF("usage: %s local-files\n", argv[0]);
    459    1.1       cgd 		code = -1;
    460    1.1       cgd 		return;
    461    1.1       cgd 	}
    462    1.1       cgd 	mname = argv[0];
    463    1.1       cgd 	mflag = 1;
    464   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
    465   1.72     lukem 	if (sigsetjmp(jabort, 1))
    466   1.72     lukem 		mabort();
    467    1.1       cgd 	if (proxy) {
    468   1.63     lukem 		char *cp;
    469    1.1       cgd 
    470   1.19     lukem 		while ((cp = remglob(argv, 0, NULL)) != NULL) {
    471   1.76     lukem 			if (*cp == '\0' || !connected) {
    472    1.1       cgd 				mflag = 0;
    473    1.1       cgd 				continue;
    474    1.1       cgd 			}
    475    1.1       cgd 			if (mflag && confirm(argv[0], cp)) {
    476  1.110  christos 				char buf[MAXPATHLEN];
    477  1.110  christos 				tp = doprocess(buf, sizeof(buf), cp,
    478  1.110  christos 				    mcase, ntflag, mapflag);
    479    1.1       cgd 				sendrequest((sunique) ? "STOU" : "STOR",
    480    1.1       cgd 				    cp, tp, cp != tp || !interactive);
    481    1.1       cgd 				if (!mflag && fromatty) {
    482    1.1       cgd 					ointer = interactive;
    483    1.1       cgd 					interactive = 1;
    484   1.10     lukem 					if (confirm("Continue with", "mput")) {
    485    1.1       cgd 						mflag++;
    486    1.1       cgd 					}
    487    1.1       cgd 					interactive = ointer;
    488    1.1       cgd 				}
    489    1.1       cgd 			}
    490    1.1       cgd 		}
    491   1.72     lukem 		goto cleanupmput;
    492    1.1       cgd 	}
    493   1.76     lukem 	for (i = 1; i < argc && connected; i++) {
    494    1.9     lukem 		char **cpp;
    495    1.4       cgd 		glob_t gl;
    496    1.4       cgd 		int flags;
    497    1.1       cgd 
    498    1.1       cgd 		if (!doglob) {
    499    1.1       cgd 			if (mflag && confirm(argv[0], argv[i])) {
    500  1.110  christos 				char buf[MAXPATHLEN];
    501  1.110  christos 				tp = doprocess(buf, sizeof(buf), argv[i],
    502  1.110  christos 					0, ntflag, mapflag);
    503    1.1       cgd 				sendrequest((sunique) ? "STOU" : "STOR",
    504    1.1       cgd 				    argv[i], tp, tp != argv[i] || !interactive);
    505    1.1       cgd 				if (!mflag && fromatty) {
    506    1.1       cgd 					ointer = interactive;
    507    1.1       cgd 					interactive = 1;
    508   1.10     lukem 					if (confirm("Continue with", "mput")) {
    509    1.1       cgd 						mflag++;
    510    1.1       cgd 					}
    511    1.1       cgd 					interactive = ointer;
    512    1.1       cgd 				}
    513    1.1       cgd 			}
    514    1.1       cgd 			continue;
    515    1.1       cgd 		}
    516    1.4       cgd 
    517    1.4       cgd 		memset(&gl, 0, sizeof(gl));
    518   1.38    kleink 		flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
    519    1.4       cgd 		if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
    520    1.4       cgd 			warnx("%s: not found", argv[i]);
    521    1.4       cgd 			globfree(&gl);
    522    1.1       cgd 			continue;
    523    1.1       cgd 		}
    524   1.76     lukem 		for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
    525   1.76     lukem 		    cpp++) {
    526    1.1       cgd 			if (mflag && confirm(argv[0], *cpp)) {
    527  1.110  christos 				char buf[MAXPATHLEN];
    528  1.110  christos 				tp = *cpp;
    529  1.110  christos 				tp = doprocess(buf, sizeof(buf), *cpp,
    530  1.110  christos 				    0, ntflag, mapflag);
    531    1.1       cgd 				sendrequest((sunique) ? "STOU" : "STOR",
    532    1.1       cgd 				    *cpp, tp, *cpp != tp || !interactive);
    533    1.1       cgd 				if (!mflag && fromatty) {
    534    1.1       cgd 					ointer = interactive;
    535    1.1       cgd 					interactive = 1;
    536   1.10     lukem 					if (confirm("Continue with", "mput")) {
    537    1.1       cgd 						mflag++;
    538    1.1       cgd 					}
    539    1.1       cgd 					interactive = ointer;
    540    1.1       cgd 				}
    541    1.1       cgd 			}
    542    1.1       cgd 		}
    543    1.4       cgd 		globfree(&gl);
    544    1.1       cgd 	}
    545   1.88     lukem  cleanupmput:
    546   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
    547    1.1       cgd 	mflag = 0;
    548    1.1       cgd }
    549    1.1       cgd 
    550    1.4       cgd void
    551   1.85     lukem reget(int argc, char *argv[])
    552    1.1       cgd {
    553    1.4       cgd 
    554   1.97     lukem 	(void)getit(argc, argv, 1, "r+");
    555    1.1       cgd }
    556    1.1       cgd 
    557    1.4       cgd void
    558   1.85     lukem get(int argc, char *argv[])
    559    1.1       cgd {
    560    1.4       cgd 
    561   1.97     lukem 	(void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
    562    1.1       cgd }
    563    1.1       cgd 
    564    1.1       cgd /*
    565    1.1       cgd  * Receive one file.
    566   1.92     lukem  * If restartit is  1, restart the xfer always.
    567   1.92     lukem  * If restartit is -1, restart the xfer only if the remote file is newer.
    568    1.1       cgd  */
    569    1.4       cgd int
    570   1.85     lukem getit(int argc, char *argv[], int restartit, const char *mode)
    571    1.1       cgd {
    572  1.112     lukem 	int	loc, rval;
    573  1.110  christos 	char	*remfile, *olocfile;
    574  1.110  christos 	const char *locfile;
    575  1.112     lukem 	char	buf[MAXPATHLEN];
    576    1.1       cgd 
    577   1.94     lukem 	loc = rval = 0;
    578    1.1       cgd 	if (argc == 2) {
    579    1.1       cgd 		argc++;
    580    1.1       cgd 		argv[2] = argv[1];
    581    1.1       cgd 		loc++;
    582    1.1       cgd 	}
    583   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file")))
    584    1.1       cgd 		goto usage;
    585   1.10     lukem 	if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
    586   1.88     lukem  usage:
    587  1.116  christos 		UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
    588    1.1       cgd 		code = -1;
    589    1.1       cgd 		return (0);
    590    1.1       cgd 	}
    591   1.63     lukem 	remfile = argv[1];
    592   1.63     lukem 	if ((olocfile = globulize(argv[2])) == NULL) {
    593    1.1       cgd 		code = -1;
    594    1.1       cgd 		return (0);
    595    1.1       cgd 	}
    596  1.110  christos 	locfile = doprocess(buf, sizeof(buf), olocfile,
    597  1.110  christos 		loc && mcase, loc && ntflag, loc && mapflag);
    598    1.1       cgd 	if (restartit) {
    599    1.1       cgd 		struct stat stbuf;
    600    1.1       cgd 		int ret;
    601    1.1       cgd 
    602   1.88     lukem 		if (! features[FEAT_REST_STREAM]) {
    603   1.88     lukem 			fprintf(ttyout,
    604   1.88     lukem 			    "Restart is not supported by the remote server.\n");
    605   1.88     lukem 			return (0);
    606   1.88     lukem 		}
    607   1.63     lukem 		ret = stat(locfile, &stbuf);
    608    1.1       cgd 		if (restartit == 1) {
    609    1.1       cgd 			if (ret < 0) {
    610   1.63     lukem 				warn("local: %s", locfile);
    611   1.27     lukem 				goto freegetit;
    612    1.1       cgd 			}
    613    1.1       cgd 			restart_point = stbuf.st_size;
    614    1.1       cgd 		} else {
    615    1.1       cgd 			if (ret == 0) {
    616   1.10     lukem 				time_t mtime;
    617    1.1       cgd 
    618   1.13     lukem 				mtime = remotemodtime(argv[1], 0);
    619   1.10     lukem 				if (mtime == -1)
    620   1.27     lukem 					goto freegetit;
    621   1.27     lukem 				if (stbuf.st_mtime >= mtime) {
    622   1.27     lukem 					rval = 1;
    623   1.27     lukem 					goto freegetit;
    624   1.27     lukem 				}
    625    1.1       cgd 			}
    626    1.1       cgd 		}
    627    1.1       cgd 	}
    628    1.1       cgd 
    629   1.63     lukem 	recvrequest("RETR", locfile, remfile, mode,
    630   1.63     lukem 	    remfile != argv[1] || locfile != argv[2], loc);
    631    1.1       cgd 	restart_point = 0;
    632   1.88     lukem  freegetit:
    633   1.63     lukem 	(void)free(olocfile);
    634   1.27     lukem 	return (rval);
    635    1.1       cgd }
    636    1.1       cgd 
    637    1.4       cgd /* ARGSUSED */
    638    1.1       cgd void
    639   1.85     lukem mintr(int signo)
    640    1.1       cgd {
    641   1.72     lukem 
    642   1.72     lukem 	alarmtimer(0);
    643   1.74     lukem 	if (fromatty)
    644   1.74     lukem 		write(fileno(ttyout), "\n", 1);
    645   1.72     lukem 	siglongjmp(jabort, 1);
    646   1.72     lukem }
    647   1.72     lukem 
    648   1.72     lukem void
    649   1.85     lukem mabort(void)
    650   1.72     lukem {
    651   1.10     lukem 	int ointer, oconf;
    652    1.1       cgd 
    653    1.1       cgd 	if (mflag && fromatty) {
    654    1.1       cgd 		ointer = interactive;
    655   1.10     lukem 		oconf = confirmrest;
    656    1.1       cgd 		interactive = 1;
    657   1.10     lukem 		confirmrest = 0;
    658    1.1       cgd 		if (confirm("Continue with", mname)) {
    659    1.1       cgd 			interactive = ointer;
    660   1.10     lukem 			confirmrest = oconf;
    661   1.72     lukem 			return;
    662    1.1       cgd 		}
    663    1.1       cgd 		interactive = ointer;
    664   1.10     lukem 		confirmrest = oconf;
    665    1.1       cgd 	}
    666    1.1       cgd 	mflag = 0;
    667    1.1       cgd }
    668    1.1       cgd 
    669    1.1       cgd /*
    670    1.1       cgd  * Get multiple files.
    671    1.1       cgd  */
    672    1.4       cgd void
    673   1.85     lukem mget(int argc, char *argv[])
    674    1.1       cgd {
    675   1.82     lukem 	sigfunc oldintr;
    676   1.92     lukem 	int ointer;
    677  1.110  christos 	char *cp;
    678  1.110  christos 	const char *tp;
    679   1.92     lukem 	int restartit;
    680    1.1       cgd 
    681   1.88     lukem 	if (argc == 0 ||
    682   1.76     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-files"))) {
    683  1.116  christos 		UPRINTF("usage: %s remote-files\n", argv[0]);
    684    1.1       cgd 		code = -1;
    685    1.1       cgd 		return;
    686    1.1       cgd 	}
    687    1.1       cgd 	mname = argv[0];
    688    1.1       cgd 	mflag = 1;
    689   1.92     lukem 	restart_point = 0;
    690   1.92     lukem 	restartit = 0;
    691   1.92     lukem 	if (strcmp(argv[0], "mreget") == 0) {
    692   1.92     lukem 		if (! features[FEAT_REST_STREAM]) {
    693   1.92     lukem 			fprintf(ttyout,
    694   1.92     lukem 		    "Restart is not supported by the remote server.\n");
    695   1.92     lukem 			return;
    696   1.92     lukem 		}
    697   1.92     lukem 		restartit = 1;
    698   1.92     lukem 	}
    699   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
    700   1.72     lukem 	if (sigsetjmp(jabort, 1))
    701   1.72     lukem 		mabort();
    702   1.19     lukem 	while ((cp = remglob(argv, proxy, NULL)) != NULL) {
    703  1.110  christos 		char buf[MAXPATHLEN];
    704   1.76     lukem 		if (*cp == '\0' || !connected) {
    705    1.1       cgd 			mflag = 0;
    706    1.1       cgd 			continue;
    707    1.1       cgd 		}
    708  1.109     lukem 		if (! mflag)
    709  1.109     lukem 			continue;
    710  1.109     lukem 		if (! fileindir(cp, localcwd)) {
    711  1.109     lukem 			fprintf(ttyout, "Skipping non-relative filename `%s'\n",
    712  1.109     lukem 			    cp);
    713  1.109     lukem 			continue;
    714  1.109     lukem 		}
    715  1.109     lukem 		if (!confirm(argv[0], cp))
    716   1.92     lukem 			continue;
    717  1.110  christos 		tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
    718   1.92     lukem 		if (restartit) {
    719   1.92     lukem 			struct stat stbuf;
    720   1.92     lukem 
    721   1.92     lukem 			if (stat(tp, &stbuf) == 0)
    722   1.92     lukem 				restart_point = stbuf.st_size;
    723   1.92     lukem 			else
    724   1.92     lukem 				warn("stat %s", tp);
    725   1.92     lukem 		}
    726   1.97     lukem 		recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
    727   1.92     lukem 		    tp != cp || !interactive, 1);
    728   1.92     lukem 		restart_point = 0;
    729   1.92     lukem 		if (!mflag && fromatty) {
    730   1.92     lukem 			ointer = interactive;
    731   1.92     lukem 			interactive = 1;
    732   1.92     lukem 			if (confirm("Continue with", "mget"))
    733   1.92     lukem 				mflag++;
    734   1.92     lukem 			interactive = ointer;
    735    1.1       cgd 		}
    736    1.1       cgd 	}
    737   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
    738    1.1       cgd 	mflag = 0;
    739   1.84     lukem }
    740   1.84     lukem 
    741   1.84     lukem /*
    742   1.84     lukem  * Read list of filenames from a local file and get those
    743   1.84     lukem  */
    744   1.84     lukem void
    745   1.85     lukem fget(int argc, char *argv[])
    746   1.84     lukem {
    747   1.84     lukem 	char	*buf, *mode;
    748   1.84     lukem 	FILE	*fp;
    749   1.84     lukem 
    750   1.84     lukem 	if (argc != 2) {
    751  1.116  christos 		UPRINTF("usage: %s localfile\n", argv[0]);
    752   1.84     lukem 		code = -1;
    753   1.84     lukem 		return;
    754   1.84     lukem 	}
    755   1.84     lukem 
    756   1.84     lukem 	fp = fopen(argv[1], "r");
    757   1.84     lukem 	if (fp == NULL) {
    758   1.84     lukem 		fprintf(ttyout, "Cannot open source file %s\n", argv[1]);
    759   1.84     lukem 		code = -1;
    760   1.84     lukem 		return;
    761   1.84     lukem 	}
    762   1.84     lukem 
    763   1.84     lukem 	argv[0] = "get";
    764   1.97     lukem 	mode = restart_point ? "r+" : "w";
    765   1.84     lukem 
    766   1.84     lukem 	for (;
    767   1.84     lukem 	    (buf = fparseln(fp, NULL, NULL, "\0\0\0", 0)) != NULL;
    768   1.84     lukem 	    free(buf)) {
    769   1.84     lukem 		if (buf[0] == '\0')
    770   1.84     lukem 			continue;
    771   1.84     lukem 		argv[1] = buf;
    772   1.84     lukem 		(void)getit(argc, argv, 0, mode);
    773   1.84     lukem 	}
    774   1.84     lukem 	fclose(fp);
    775    1.1       cgd }
    776    1.1       cgd 
    777  1.113     lukem const char *
    778   1.85     lukem onoff(int bool)
    779    1.1       cgd {
    780    1.1       cgd 
    781    1.1       cgd 	return (bool ? "on" : "off");
    782    1.1       cgd }
    783    1.1       cgd 
    784    1.1       cgd /*
    785    1.1       cgd  * Show status.
    786    1.1       cgd  */
    787    1.1       cgd /*ARGSUSED*/
    788    1.4       cgd void
    789   1.85     lukem status(int argc, char *argv[])
    790    1.1       cgd {
    791    1.1       cgd 
    792   1.88     lukem 	if (argc == 0) {
    793  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    794   1.76     lukem 		code = -1;
    795   1.76     lukem 		return;
    796   1.76     lukem 	}
    797  1.105    kleink #ifndef NO_STATUS
    798    1.1       cgd 	if (connected)
    799   1.37     lukem 		fprintf(ttyout, "Connected %sto %s.\n",
    800   1.23     lukem 		    connected == -1 ? "and logged in" : "", hostname);
    801    1.1       cgd 	else
    802   1.37     lukem 		fputs("Not connected.\n", ttyout);
    803    1.1       cgd 	if (!proxy) {
    804    1.1       cgd 		pswitch(1);
    805    1.1       cgd 		if (connected) {
    806   1.37     lukem 			fprintf(ttyout, "Connected for proxy commands to %s.\n",
    807   1.10     lukem 			    hostname);
    808    1.1       cgd 		}
    809    1.1       cgd 		else {
    810   1.37     lukem 			fputs("No proxy connection.\n", ttyout);
    811    1.1       cgd 		}
    812    1.1       cgd 		pswitch(0);
    813    1.1       cgd 	}
    814   1.54    itojun 	fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
    815   1.54    itojun 	    *gateserver ? gateserver : "(none)", gateport);
    816   1.76     lukem 	fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
    817   1.76     lukem 	    onoff(passivemode), onoff(activefallback));
    818   1.37     lukem 	fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
    819   1.37     lukem 	    modename, typename, formname, structname);
    820   1.37     lukem 	fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
    821   1.37     lukem 	    onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
    822   1.37     lukem 	fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
    823   1.37     lukem 	    onoff(sunique), onoff(runique));
    824   1.37     lukem 	fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
    825   1.37     lukem 	fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
    826   1.37     lukem 	    onoff(crflag));
    827    1.1       cgd 	if (ntflag) {
    828   1.37     lukem 		fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
    829    1.1       cgd 	}
    830    1.1       cgd 	else {
    831   1.37     lukem 		fputs("Ntrans: off.\n", ttyout);
    832    1.1       cgd 	}
    833    1.1       cgd 	if (mapflag) {
    834   1.37     lukem 		fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
    835    1.1       cgd 	}
    836    1.1       cgd 	else {
    837   1.37     lukem 		fputs("Nmap: off.\n", ttyout);
    838    1.1       cgd 	}
    839   1.37     lukem 	fprintf(ttyout,
    840   1.37     lukem 	    "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
    841   1.11     lukem 	    onoff(hash), mark, onoff(progress));
    842   1.52     lukem 	fprintf(ttyout,
    843   1.52     lukem 	    "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
    844   1.52     lukem 	    onoff(rate_get), rate_get, rate_get_incr);
    845   1.52     lukem 	fprintf(ttyout,
    846   1.52     lukem 	    "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
    847   1.52     lukem 	    onoff(rate_put), rate_put, rate_put_incr);
    848   1.58     lukem 	fprintf(ttyout,
    849   1.58     lukem 	    "Socket buffer sizes: send %d, receive %d.\n",
    850   1.58     lukem 	    sndbuf_size, rcvbuf_size);
    851   1.37     lukem 	fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
    852   1.68     lukem 	fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
    853   1.68     lukem 	    epsv4bad ? " (disabled for this connection)" : "");
    854   1.69     lukem 	fprintf(ttyout, "Command line editing: %s.\n",
    855   1.69     lukem #ifdef NO_EDITCOMPLETE
    856   1.69     lukem 	    "support not compiled in"
    857   1.69     lukem #else	/* !def NO_EDITCOMPLETE */
    858   1.69     lukem 	    onoff(editing)
    859   1.69     lukem #endif	/* !def NO_EDITCOMPLETE */
    860   1.69     lukem 	    );
    861    1.1       cgd 	if (macnum > 0) {
    862  1.104     pooka 		int i;
    863  1.104     pooka 
    864   1.37     lukem 		fputs("Macros:\n", ttyout);
    865    1.1       cgd 		for (i=0; i<macnum; i++) {
    866   1.37     lukem 			fprintf(ttyout, "\t%s\n", macros[i].mac_name);
    867    1.1       cgd 		}
    868    1.1       cgd 	}
    869  1.105    kleink #endif /* !def NO_STATUS */
    870  1.103  christos 	fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
    871    1.1       cgd 	code = 0;
    872    1.1       cgd }
    873    1.1       cgd 
    874    1.1       cgd /*
    875   1.10     lukem  * Toggle a variable
    876   1.10     lukem  */
    877   1.10     lukem int
    878   1.85     lukem togglevar(int argc, char *argv[], int *var, const char *mesg)
    879   1.10     lukem {
    880   1.76     lukem 	if (argc == 1) {
    881   1.10     lukem 		*var = !*var;
    882   1.10     lukem 	} else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
    883   1.10     lukem 		*var = 1;
    884   1.10     lukem 	} else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
    885   1.10     lukem 		*var = 0;
    886   1.10     lukem 	} else {
    887  1.116  christos 		UPRINTF("usage: %s [ on | off ]\n", argv[0]);
    888   1.19     lukem 		return (-1);
    889   1.10     lukem 	}
    890   1.46     lukem 	if (mesg)
    891   1.37     lukem 		fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
    892   1.19     lukem 	return (*var);
    893   1.10     lukem }
    894   1.10     lukem 
    895   1.10     lukem /*
    896    1.1       cgd  * Set beep on cmd completed mode.
    897    1.1       cgd  */
    898    1.1       cgd /*VARARGS*/
    899    1.4       cgd void
    900   1.85     lukem setbell(int argc, char *argv[])
    901    1.1       cgd {
    902    1.1       cgd 
    903   1.10     lukem 	code = togglevar(argc, argv, &bell, "Bell mode");
    904    1.1       cgd }
    905    1.1       cgd 
    906   1.16     lukem /*
    907   1.16     lukem  * Set command line editing
    908   1.16     lukem  */
    909   1.16     lukem /*VARARGS*/
    910   1.16     lukem void
    911   1.85     lukem setedit(int argc, char *argv[])
    912   1.16     lukem {
    913   1.16     lukem 
    914   1.69     lukem #ifdef NO_EDITCOMPLETE
    915   1.88     lukem 	if (argc == 0) {
    916  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    917   1.76     lukem 		code = -1;
    918   1.76     lukem 		return;
    919   1.76     lukem 	}
    920   1.69     lukem 	if (verbose)
    921   1.69     lukem 		fputs("Editing support not compiled in; ignoring command.\n",
    922   1.69     lukem 		    ttyout);
    923   1.69     lukem #else	/* !def NO_EDITCOMPLETE */
    924   1.16     lukem 	code = togglevar(argc, argv, &editing, "Editing mode");
    925   1.22     lukem 	controlediting();
    926   1.69     lukem #endif	/* !def NO_EDITCOMPLETE */
    927   1.16     lukem }
    928   1.16     lukem 
    929    1.1       cgd /*
    930    1.1       cgd  * Turn on packet tracing.
    931    1.1       cgd  */
    932    1.1       cgd /*VARARGS*/
    933    1.4       cgd void
    934   1.85     lukem settrace(int argc, char *argv[])
    935    1.1       cgd {
    936    1.1       cgd 
    937   1.10     lukem 	code = togglevar(argc, argv, &trace, "Packet tracing");
    938    1.1       cgd }
    939    1.1       cgd 
    940    1.1       cgd /*
    941    1.9     lukem  * Toggle hash mark printing during transfers, or set hash mark bytecount.
    942    1.1       cgd  */
    943    1.1       cgd /*VARARGS*/
    944    1.4       cgd void
    945   1.85     lukem sethash(int argc, char *argv[])
    946    1.1       cgd {
    947   1.10     lukem 	if (argc == 1)
    948    1.9     lukem 		hash = !hash;
    949   1.10     lukem 	else if (argc != 2) {
    950  1.116  christos 		UPRINTF("usage: %s [ on | off | bytecount ]\n",
    951   1.37     lukem 		    argv[0]);
    952   1.10     lukem 		code = -1;
    953   1.10     lukem 		return;
    954   1.10     lukem 	} else if (strcasecmp(argv[1], "on") == 0)
    955   1.10     lukem 		hash = 1;
    956   1.10     lukem 	else if (strcasecmp(argv[1], "off") == 0)
    957   1.10     lukem 		hash = 0;
    958   1.10     lukem 	else {
    959   1.31     lukem 		int nmark;
    960   1.31     lukem 
    961   1.52     lukem 		nmark = strsuftoi(argv[1]);
    962   1.52     lukem 		if (nmark < 1) {
    963   1.37     lukem 			fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
    964   1.37     lukem 			    argv[1]);
    965   1.10     lukem 			code = -1;
    966   1.10     lukem 			return;
    967    1.9     lukem 		}
    968   1.10     lukem 		mark = nmark;
    969   1.10     lukem 		hash = 1;
    970    1.9     lukem 	}
    971   1.37     lukem 	fprintf(ttyout, "Hash mark printing %s", onoff(hash));
    972   1.10     lukem 	if (hash)
    973   1.37     lukem 		fprintf(ttyout, " (%d bytes/hash mark)", mark);
    974   1.37     lukem 	fputs(".\n", ttyout);
    975   1.44     lukem 	if (hash)
    976   1.44     lukem 		progress = 0;
    977   1.10     lukem 	code = hash;
    978    1.1       cgd }
    979    1.1       cgd 
    980    1.1       cgd /*
    981    1.1       cgd  * Turn on printing of server echo's.
    982    1.1       cgd  */
    983    1.1       cgd /*VARARGS*/
    984    1.4       cgd void
    985   1.85     lukem setverbose(int argc, char *argv[])
    986    1.1       cgd {
    987    1.1       cgd 
    988   1.10     lukem 	code = togglevar(argc, argv, &verbose, "Verbose mode");
    989    1.1       cgd }
    990    1.1       cgd 
    991    1.1       cgd /*
    992   1.54    itojun  * Toggle PORT/LPRT cmd use before each data connection.
    993    1.1       cgd  */
    994    1.1       cgd /*VARARGS*/
    995    1.4       cgd void
    996   1.85     lukem setport(int argc, char *argv[])
    997    1.1       cgd {
    998    1.1       cgd 
    999   1.54    itojun 	code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
   1000    1.1       cgd }
   1001    1.1       cgd 
   1002    1.1       cgd /*
   1003   1.11     lukem  * Toggle transfer progress bar.
   1004   1.11     lukem  */
   1005   1.11     lukem /*VARARGS*/
   1006   1.11     lukem void
   1007   1.85     lukem setprogress(int argc, char *argv[])
   1008   1.11     lukem {
   1009   1.11     lukem 
   1010   1.11     lukem 	code = togglevar(argc, argv, &progress, "Progress bar");
   1011   1.44     lukem 	if (progress)
   1012   1.44     lukem 		hash = 0;
   1013   1.11     lukem }
   1014   1.11     lukem 
   1015   1.11     lukem /*
   1016   1.27     lukem  * Turn on interactive prompting during mget, mput, and mdelete.
   1017    1.1       cgd  */
   1018    1.1       cgd /*VARARGS*/
   1019    1.4       cgd void
   1020   1.85     lukem setprompt(int argc, char *argv[])
   1021    1.1       cgd {
   1022    1.1       cgd 
   1023   1.10     lukem 	code = togglevar(argc, argv, &interactive, "Interactive mode");
   1024    1.1       cgd }
   1025    1.1       cgd 
   1026    1.1       cgd /*
   1027   1.27     lukem  * Toggle gate-ftp mode, or set gate-ftp server
   1028   1.27     lukem  */
   1029   1.27     lukem /*VARARGS*/
   1030   1.27     lukem void
   1031   1.85     lukem setgate(int argc, char *argv[])
   1032   1.27     lukem {
   1033   1.27     lukem 	static char gsbuf[MAXHOSTNAMELEN];
   1034   1.27     lukem 
   1035   1.88     lukem 	if (argc == 0 || argc > 3) {
   1036  1.116  christos 		UPRINTF(
   1037   1.76     lukem 		    "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
   1038   1.27     lukem 		code = -1;
   1039   1.27     lukem 		return;
   1040   1.27     lukem 	} else if (argc < 2) {
   1041   1.27     lukem 		gatemode = !gatemode;
   1042   1.27     lukem 	} else {
   1043   1.27     lukem 		if (argc == 2 && strcasecmp(argv[1], "on") == 0)
   1044   1.27     lukem 			gatemode = 1;
   1045   1.27     lukem 		else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
   1046   1.27     lukem 			gatemode = 0;
   1047   1.27     lukem 		else {
   1048   1.59     lukem 			if (argc == 3)
   1049  1.117  christos 				gateport = ftp_strdup(argv[2]);
   1050   1.63     lukem 			(void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
   1051   1.27     lukem 			gateserver = gsbuf;
   1052   1.27     lukem 			gatemode = 1;
   1053   1.27     lukem 		}
   1054   1.27     lukem 	}
   1055   1.27     lukem 	if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
   1056   1.37     lukem 		fprintf(ttyout,
   1057   1.27     lukem 		    "Disabling gate-ftp mode - no gate-ftp server defined.\n");
   1058   1.27     lukem 		gatemode = 0;
   1059   1.27     lukem 	} else {
   1060   1.54    itojun 		fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
   1061   1.37     lukem 		    onoff(gatemode), *gateserver ? gateserver : "(none)",
   1062   1.54    itojun 		    gateport);
   1063   1.27     lukem 	}
   1064   1.27     lukem 	code = gatemode;
   1065   1.27     lukem }
   1066   1.27     lukem 
   1067   1.27     lukem /*
   1068   1.27     lukem  * Toggle metacharacter interpretation on local file names.
   1069    1.1       cgd  */
   1070    1.1       cgd /*VARARGS*/
   1071    1.4       cgd void
   1072   1.85     lukem setglob(int argc, char *argv[])
   1073    1.1       cgd {
   1074    1.9     lukem 
   1075   1.10     lukem 	code = togglevar(argc, argv, &doglob, "Globbing");
   1076   1.10     lukem }
   1077   1.10     lukem 
   1078   1.10     lukem /*
   1079   1.40     lukem  * Toggle preserving modification times on retrieved files.
   1080   1.10     lukem  */
   1081   1.10     lukem /*VARARGS*/
   1082   1.10     lukem void
   1083   1.85     lukem setpreserve(int argc, char *argv[])
   1084   1.10     lukem {
   1085   1.10     lukem 
   1086   1.10     lukem 	code = togglevar(argc, argv, &preserve, "Preserve modification times");
   1087    1.1       cgd }
   1088    1.1       cgd 
   1089    1.1       cgd /*
   1090   1.27     lukem  * Set debugging mode on/off and/or set level of debugging.
   1091    1.1       cgd  */
   1092    1.1       cgd /*VARARGS*/
   1093    1.4       cgd void
   1094   1.85     lukem setdebug(int argc, char *argv[])
   1095    1.1       cgd {
   1096   1.88     lukem 	if (argc == 0 || argc > 2) {
   1097  1.116  christos 		UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
   1098   1.10     lukem 		code = -1;
   1099   1.10     lukem 		return;
   1100   1.10     lukem 	} else if (argc == 2) {
   1101   1.10     lukem 		if (strcasecmp(argv[1], "on") == 0)
   1102   1.10     lukem 			debug = 1;
   1103   1.10     lukem 		else if (strcasecmp(argv[1], "off") == 0)
   1104   1.10     lukem 			debug = 0;
   1105   1.10     lukem 		else {
   1106   1.52     lukem 			int val;
   1107   1.25     lukem 
   1108   1.52     lukem 			val = strsuftoi(argv[1]);
   1109   1.52     lukem 			if (val < 0) {
   1110   1.37     lukem 				fprintf(ttyout, "%s: bad debugging value.\n",
   1111   1.37     lukem 				    argv[1]);
   1112   1.10     lukem 				code = -1;
   1113   1.10     lukem 				return;
   1114   1.10     lukem 			}
   1115   1.52     lukem 			debug = val;
   1116    1.1       cgd 		}
   1117    1.1       cgd 	} else
   1118   1.11     lukem 		debug = !debug;
   1119    1.1       cgd 	if (debug)
   1120    1.1       cgd 		options |= SO_DEBUG;
   1121    1.1       cgd 	else
   1122    1.1       cgd 		options &= ~SO_DEBUG;
   1123   1.37     lukem 	fprintf(ttyout, "Debugging %s (debug=%d).\n", onoff(debug), debug);
   1124    1.1       cgd 	code = debug > 0;
   1125    1.1       cgd }
   1126    1.1       cgd 
   1127    1.1       cgd /*
   1128   1.27     lukem  * Set current working directory on remote machine.
   1129    1.1       cgd  */
   1130    1.4       cgd void
   1131   1.85     lukem cd(int argc, char *argv[])
   1132    1.1       cgd {
   1133   1.16     lukem 	int r;
   1134    1.1       cgd 
   1135   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1136   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
   1137  1.116  christos 		UPRINTF("usage: %s remote-directory\n", argv[0]);
   1138    1.1       cgd 		code = -1;
   1139    1.1       cgd 		return;
   1140    1.1       cgd 	}
   1141   1.17     veego 	r = command("CWD %s", argv[1]);
   1142   1.16     lukem 	if (r == ERROR && code == 500) {
   1143    1.1       cgd 		if (verbose)
   1144   1.37     lukem 			fputs("CWD command not recognized, trying XCWD.\n",
   1145   1.37     lukem 			    ttyout);
   1146   1.16     lukem 		r = command("XCWD %s", argv[1]);
   1147    1.1       cgd 	}
   1148   1.79     lukem 	if (r == COMPLETE) {
   1149   1.16     lukem 		dirchange = 1;
   1150  1.109     lukem 		updateremotecwd();
   1151   1.79     lukem 	}
   1152    1.1       cgd }
   1153    1.1       cgd 
   1154    1.1       cgd /*
   1155   1.27     lukem  * Set current working directory on local machine.
   1156    1.1       cgd  */
   1157    1.4       cgd void
   1158   1.85     lukem lcd(int argc, char *argv[])
   1159    1.1       cgd {
   1160   1.63     lukem 	char *locdir;
   1161    1.1       cgd 
   1162   1.76     lukem 	code = -1;
   1163   1.76     lukem 	if (argc == 1) {
   1164   1.64     lukem 		argc++;
   1165   1.92     lukem 		argv[1] = localhome;
   1166   1.64     lukem 	}
   1167    1.1       cgd 	if (argc != 2) {
   1168  1.116  christos 		UPRINTF("usage: %s [local-directory]\n", argv[0]);
   1169    1.1       cgd 		return;
   1170    1.1       cgd 	}
   1171   1.76     lukem 	if ((locdir = globulize(argv[1])) == NULL)
   1172    1.1       cgd 		return;
   1173  1.109     lukem 	if (chdir(locdir) == -1)
   1174  1.109     lukem 		warn("lcd %s", locdir);
   1175   1.76     lukem 	else {
   1176  1.109     lukem 		updatelocalcwd();
   1177  1.109     lukem 		if (localcwd[0]) {
   1178  1.109     lukem 			fprintf(ttyout, "Local directory now: %s\n", localcwd);
   1179   1.76     lukem 			code = 0;
   1180  1.109     lukem 		} else {
   1181  1.109     lukem 			fprintf(ttyout, "Unable to determine local directory\n");
   1182  1.109     lukem 		}
   1183    1.1       cgd 	}
   1184   1.63     lukem 	(void)free(locdir);
   1185    1.1       cgd }
   1186    1.1       cgd 
   1187    1.1       cgd /*
   1188    1.1       cgd  * Delete a single file.
   1189    1.1       cgd  */
   1190    1.4       cgd void
   1191   1.85     lukem delete(int argc, char *argv[])
   1192    1.1       cgd {
   1193    1.1       cgd 
   1194   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1195   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   1196  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   1197    1.1       cgd 		code = -1;
   1198    1.1       cgd 		return;
   1199    1.1       cgd 	}
   1200  1.101     lukem 	if (command("DELE %s", argv[1]) == COMPLETE)
   1201  1.101     lukem 		dirchange = 1;
   1202    1.1       cgd }
   1203    1.1       cgd 
   1204    1.1       cgd /*
   1205    1.1       cgd  * Delete multiple files.
   1206    1.1       cgd  */
   1207    1.4       cgd void
   1208   1.85     lukem mdelete(int argc, char *argv[])
   1209    1.1       cgd {
   1210   1.82     lukem 	sigfunc oldintr;
   1211    1.1       cgd 	int ointer;
   1212    1.1       cgd 	char *cp;
   1213    1.1       cgd 
   1214   1.88     lukem 	if (argc == 0 ||
   1215   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-files"))) {
   1216  1.116  christos 		UPRINTF("usage: %s [remote-files]\n", argv[0]);
   1217    1.1       cgd 		code = -1;
   1218    1.1       cgd 		return;
   1219    1.1       cgd 	}
   1220    1.1       cgd 	mname = argv[0];
   1221    1.1       cgd 	mflag = 1;
   1222   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
   1223   1.72     lukem 	if (sigsetjmp(jabort, 1))
   1224   1.72     lukem 		mabort();
   1225   1.19     lukem 	while ((cp = remglob(argv, 0, NULL)) != NULL) {
   1226    1.1       cgd 		if (*cp == '\0') {
   1227    1.1       cgd 			mflag = 0;
   1228    1.1       cgd 			continue;
   1229    1.1       cgd 		}
   1230    1.1       cgd 		if (mflag && confirm(argv[0], cp)) {
   1231  1.101     lukem 			if (command("DELE %s", cp) == COMPLETE)
   1232  1.101     lukem 				dirchange = 1;
   1233    1.1       cgd 			if (!mflag && fromatty) {
   1234    1.1       cgd 				ointer = interactive;
   1235    1.1       cgd 				interactive = 1;
   1236    1.1       cgd 				if (confirm("Continue with", "mdelete")) {
   1237    1.1       cgd 					mflag++;
   1238    1.1       cgd 				}
   1239    1.1       cgd 				interactive = ointer;
   1240    1.1       cgd 			}
   1241    1.1       cgd 		}
   1242    1.1       cgd 	}
   1243   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
   1244    1.1       cgd 	mflag = 0;
   1245    1.1       cgd }
   1246    1.1       cgd 
   1247    1.1       cgd /*
   1248    1.1       cgd  * Rename a remote file.
   1249    1.1       cgd  */
   1250    1.4       cgd void
   1251   1.85     lukem renamefile(int argc, char *argv[])
   1252    1.1       cgd {
   1253    1.1       cgd 
   1254   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
   1255    1.1       cgd 		goto usage;
   1256   1.10     lukem 	if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
   1257   1.88     lukem  usage:
   1258  1.116  christos 		UPRINTF("usage: %s from-name to-name\n", argv[0]);
   1259    1.1       cgd 		code = -1;
   1260    1.1       cgd 		return;
   1261    1.1       cgd 	}
   1262  1.101     lukem 	if (command("RNFR %s", argv[1]) == CONTINUE &&
   1263  1.101     lukem 	    command("RNTO %s", argv[2]) == COMPLETE)
   1264  1.101     lukem 		dirchange = 1;
   1265    1.1       cgd }
   1266    1.1       cgd 
   1267    1.1       cgd /*
   1268   1.27     lukem  * Get a directory listing of remote files.
   1269   1.88     lukem  * Supports being invoked as:
   1270   1.88     lukem  *	cmd		runs
   1271   1.88     lukem  *	---		----
   1272   1.88     lukem  *	dir, ls		LIST
   1273   1.88     lukem  *	mlsd		MLSD
   1274   1.88     lukem  *	nlist		NLST
   1275   1.88     lukem  *	pdir, pls	LIST |$PAGER
   1276   1.88     lukem  *	mmlsd		MLSD |$PAGER
   1277    1.1       cgd  */
   1278    1.4       cgd void
   1279   1.85     lukem ls(int argc, char *argv[])
   1280    1.1       cgd {
   1281   1.10     lukem 	const char *cmd;
   1282   1.63     lukem 	char *remdir, *locfile;
   1283   1.88     lukem 	int freelocfile, pagecmd, mlsdcmd;
   1284    1.1       cgd 
   1285   1.63     lukem 	remdir = NULL;
   1286   1.63     lukem 	locfile = "-";
   1287   1.88     lukem 	freelocfile = pagecmd = mlsdcmd = 0;
   1288   1.63     lukem 			/*
   1289   1.88     lukem 			 * the only commands that start with `p' are
   1290   1.88     lukem 			 * the `pager' versions.
   1291   1.63     lukem 			 */
   1292   1.63     lukem 	if (argv[0][0] == 'p')
   1293   1.63     lukem 		pagecmd = 1;
   1294   1.88     lukem 	if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
   1295   1.88     lukem 		if (! features[FEAT_MLST]) {
   1296   1.88     lukem 			fprintf(ttyout,
   1297   1.88     lukem 			   "MLSD is not supported by the remote server.\n");
   1298   1.88     lukem 			return;
   1299   1.88     lukem 		}
   1300   1.88     lukem 		mlsdcmd = 1;
   1301   1.88     lukem 	}
   1302   1.88     lukem 	if (argc == 0)
   1303   1.76     lukem 		goto usage;
   1304   1.63     lukem 
   1305   1.88     lukem 	if (mlsdcmd)
   1306   1.88     lukem 		cmd = "MLSD";
   1307   1.88     lukem 	else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
   1308   1.86     lukem 		cmd = "NLST";
   1309   1.88     lukem 	else
   1310   1.88     lukem 		cmd = "LIST";
   1311   1.63     lukem 
   1312   1.63     lukem 	if (argc > 1)
   1313   1.63     lukem 		remdir = argv[1];
   1314   1.63     lukem 	if (argc > 2)
   1315   1.63     lukem 		locfile = argv[2];
   1316   1.88     lukem 	if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
   1317   1.76     lukem  usage:
   1318   1.88     lukem 		if (pagecmd || mlsdcmd)
   1319  1.116  christos 			UPRINTF("usage: %s [remote-path]\n", argv[0]);
   1320   1.63     lukem 		else
   1321  1.116  christos 			UPRINTF("usage: %s [remote-path [local-file]]\n",
   1322   1.63     lukem 			    argv[0]);
   1323    1.1       cgd 		code = -1;
   1324   1.63     lukem 		goto freels;
   1325    1.1       cgd 	}
   1326   1.63     lukem 
   1327   1.63     lukem 	if (pagecmd) {
   1328   1.63     lukem 		char *p;
   1329  1.114     lukem 		size_t len;
   1330   1.63     lukem 
   1331   1.76     lukem 		p = getoptionvalue("pager");
   1332   1.76     lukem 		if (EMPTYSTRING(p))
   1333   1.76     lukem 			p = DEFAULTPAGER;
   1334   1.63     lukem 		len = strlen(p) + 2;
   1335  1.117  christos 		locfile = ftp_malloc(len);
   1336   1.63     lukem 		locfile[0] = '|';
   1337   1.63     lukem 		(void)strlcpy(locfile + 1, p, len - 1);
   1338   1.63     lukem 		freelocfile = 1;
   1339   1.63     lukem 	} else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
   1340  1.107     lukem 		mname = argv[0];
   1341   1.63     lukem 		if ((locfile = globulize(locfile)) == NULL ||
   1342   1.63     lukem 		    !confirm("output to local-file:", locfile)) {
   1343    1.1       cgd 			code = -1;
   1344   1.27     lukem 			goto freels;
   1345   1.63     lukem 		}
   1346   1.63     lukem 		freelocfile = 1;
   1347    1.1       cgd 	}
   1348   1.63     lukem 	recvrequest(cmd, locfile, remdir, "w", 0, 0);
   1349   1.88     lukem  freels:
   1350   1.63     lukem 	if (freelocfile && locfile)
   1351   1.63     lukem 		(void)free(locfile);
   1352    1.1       cgd }
   1353    1.1       cgd 
   1354    1.1       cgd /*
   1355   1.27     lukem  * Get a directory listing of multiple remote files.
   1356    1.1       cgd  */
   1357    1.4       cgd void
   1358   1.85     lukem mls(int argc, char *argv[])
   1359    1.1       cgd {
   1360   1.82     lukem 	sigfunc oldintr;
   1361    1.1       cgd 	int ointer, i;
   1362   1.25     lukem 	int dolist;
   1363   1.96     lukem 	char *mode, *dest, *odest;
   1364    1.1       cgd 
   1365   1.88     lukem 	if (argc == 0)
   1366   1.76     lukem 		goto usage;
   1367    1.1       cgd 	if (argc < 2 && !another(&argc, &argv, "remote-files"))
   1368    1.1       cgd 		goto usage;
   1369    1.1       cgd 	if (argc < 3 && !another(&argc, &argv, "local-file")) {
   1370   1.88     lukem  usage:
   1371  1.116  christos 		UPRINTF("usage: %s remote-files local-file\n", argv[0]);
   1372    1.1       cgd 		code = -1;
   1373    1.1       cgd 		return;
   1374    1.1       cgd 	}
   1375   1.27     lukem 	odest = dest = argv[argc - 1];
   1376    1.1       cgd 	argv[argc - 1] = NULL;
   1377  1.107     lukem 	mname = argv[0];
   1378    1.1       cgd 	if (strcmp(dest, "-") && *dest != '|')
   1379   1.63     lukem 		if (((dest = globulize(dest)) == NULL) ||
   1380    1.1       cgd 		    !confirm("output to local-file:", dest)) {
   1381    1.1       cgd 			code = -1;
   1382    1.1       cgd 			return;
   1383    1.1       cgd 	}
   1384   1.25     lukem 	dolist = strcmp(argv[0], "mls");
   1385    1.1       cgd 	mflag = 1;
   1386   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
   1387   1.72     lukem 	if (sigsetjmp(jabort, 1))
   1388   1.72     lukem 		mabort();
   1389   1.76     lukem 	for (i = 1; mflag && i < argc-1 && connected; i++) {
   1390   1.96     lukem 		mode = (i == 1) ? "w" : "a";
   1391   1.27     lukem 		recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
   1392   1.27     lukem 		    0, 0);
   1393    1.1       cgd 		if (!mflag && fromatty) {
   1394    1.1       cgd 			ointer = interactive;
   1395    1.1       cgd 			interactive = 1;
   1396    1.1       cgd 			if (confirm("Continue with", argv[0])) {
   1397  1.111    simonb 				mflag++;
   1398    1.1       cgd 			}
   1399    1.1       cgd 			interactive = ointer;
   1400    1.1       cgd 		}
   1401    1.1       cgd 	}
   1402   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
   1403    1.1       cgd 	mflag = 0;
   1404   1.27     lukem 	if (dest != odest)			/* free up after globulize() */
   1405   1.27     lukem 		free(dest);
   1406    1.1       cgd }
   1407    1.1       cgd 
   1408    1.1       cgd /*
   1409    1.1       cgd  * Do a shell escape
   1410    1.1       cgd  */
   1411    1.1       cgd /*ARGSUSED*/
   1412    1.4       cgd void
   1413   1.85     lukem shell(int argc, char *argv[])
   1414    1.1       cgd {
   1415    1.4       cgd 	pid_t pid;
   1416  1.106     lukem 	sigfunc oldintr;
   1417   1.13     lukem 	char shellnam[MAXPATHLEN], *shell, *namep;
   1418   1.29     lukem 	int wait_status;
   1419    1.1       cgd 
   1420   1.88     lukem 	if (argc == 0) {
   1421  1.116  christos 		UPRINTF("usage: %s [command [args]]\n", argv[0]);
   1422   1.76     lukem 		code = -1;
   1423   1.76     lukem 		return;
   1424   1.76     lukem 	}
   1425  1.106     lukem 	oldintr = xsignal(SIGINT, SIG_IGN);
   1426    1.1       cgd 	if ((pid = fork()) == 0) {
   1427    1.1       cgd 		for (pid = 3; pid < 20; pid++)
   1428   1.19     lukem 			(void)close(pid);
   1429   1.62     lukem 		(void)xsignal(SIGINT, SIG_DFL);
   1430    1.1       cgd 		shell = getenv("SHELL");
   1431    1.1       cgd 		if (shell == NULL)
   1432    1.1       cgd 			shell = _PATH_BSHELL;
   1433   1.10     lukem 		namep = strrchr(shell, '/');
   1434    1.1       cgd 		if (namep == NULL)
   1435    1.1       cgd 			namep = shell;
   1436   1.71     lukem 		else
   1437   1.71     lukem 			namep++;
   1438   1.71     lukem 		(void)strlcpy(shellnam, namep, sizeof(shellnam));
   1439    1.1       cgd 		if (debug) {
   1440   1.37     lukem 			fputs(shell, ttyout);
   1441   1.37     lukem 			putc('\n', ttyout);
   1442    1.1       cgd 		}
   1443    1.1       cgd 		if (argc > 1) {
   1444   1.10     lukem 			execl(shell, shellnam, "-c", altarg, (char *)0);
   1445    1.1       cgd 		}
   1446    1.1       cgd 		else {
   1447   1.10     lukem 			execl(shell, shellnam, (char *)0);
   1448    1.1       cgd 		}
   1449    1.4       cgd 		warn("%s", shell);
   1450    1.1       cgd 		code = -1;
   1451    1.1       cgd 		exit(1);
   1452    1.4       cgd 	}
   1453    1.1       cgd 	if (pid > 0)
   1454   1.29     lukem 		while (wait(&wait_status) != pid)
   1455    1.1       cgd 			;
   1456  1.106     lukem 	(void)xsignal(SIGINT, oldintr);
   1457    1.1       cgd 	if (pid == -1) {
   1458   1.19     lukem 		warn("Try again later");
   1459    1.1       cgd 		code = -1;
   1460   1.76     lukem 	} else
   1461    1.1       cgd 		code = 0;
   1462    1.1       cgd }
   1463    1.1       cgd 
   1464    1.1       cgd /*
   1465    1.1       cgd  * Send new user information (re-login)
   1466    1.1       cgd  */
   1467    1.4       cgd void
   1468   1.85     lukem user(int argc, char *argv[])
   1469    1.1       cgd {
   1470  1.115     lukem 	char *password;
   1471    1.1       cgd 	int n, aflag = 0;
   1472    1.1       cgd 
   1473   1.88     lukem 	if (argc == 0)
   1474   1.76     lukem 		goto usage;
   1475    1.1       cgd 	if (argc < 2)
   1476   1.19     lukem 		(void)another(&argc, &argv, "username");
   1477    1.1       cgd 	if (argc < 2 || argc > 4) {
   1478   1.76     lukem  usage:
   1479  1.116  christos 		UPRINTF("usage: %s username [password [account]]\n",
   1480   1.37     lukem 		    argv[0]);
   1481    1.1       cgd 		code = -1;
   1482    1.4       cgd 		return;
   1483    1.1       cgd 	}
   1484    1.1       cgd 	n = command("USER %s", argv[1]);
   1485    1.1       cgd 	if (n == CONTINUE) {
   1486   1.49     lukem 		if (argc < 3) {
   1487  1.115     lukem 			password = getpass("Password: ");
   1488  1.115     lukem 		} else {
   1489  1.115     lukem 			password = argv[2];
   1490   1.49     lukem 		}
   1491  1.115     lukem 		n = command("PASS %s", password);
   1492  1.115     lukem 		memset(password, 0, strlen(password));
   1493    1.1       cgd 	}
   1494    1.1       cgd 	if (n == CONTINUE) {
   1495  1.115     lukem 		aflag++;
   1496    1.1       cgd 		if (argc < 4) {
   1497  1.115     lukem 			password = getpass("Account: ");
   1498  1.115     lukem 		} else {
   1499  1.115     lukem 			password = argv[3];
   1500    1.1       cgd 		}
   1501  1.115     lukem 		n = command("ACCT %s", password);
   1502  1.115     lukem 		memset(password, 0, strlen(password));
   1503    1.1       cgd 	}
   1504    1.1       cgd 	if (n != COMPLETE) {
   1505   1.37     lukem 		fputs("Login failed.\n", ttyout);
   1506    1.4       cgd 		return;
   1507    1.1       cgd 	}
   1508    1.1       cgd 	if (!aflag && argc == 4) {
   1509  1.115     lukem 		password = argv[3];
   1510  1.115     lukem 		(void)command("ACCT %s", password);
   1511  1.115     lukem 		memset(password, 0, strlen(password));
   1512    1.1       cgd 	}
   1513   1.23     lukem 	connected = -1;
   1514   1.88     lukem 	getremoteinfo();
   1515    1.1       cgd }
   1516    1.1       cgd 
   1517    1.1       cgd /*
   1518   1.10     lukem  * Print working directory on remote machine.
   1519    1.1       cgd  */
   1520    1.1       cgd /*VARARGS*/
   1521    1.4       cgd void
   1522   1.85     lukem pwd(int argc, char *argv[])
   1523    1.1       cgd {
   1524    1.1       cgd 
   1525  1.109     lukem 	code = -1;
   1526  1.109     lukem 	if (argc != 1) {
   1527  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1528   1.76     lukem 		return;
   1529   1.76     lukem 	}
   1530  1.109     lukem 	if (! remotecwd[0])
   1531  1.109     lukem 		updateremotecwd();
   1532  1.109     lukem 	if (! remotecwd[0])
   1533  1.109     lukem 		fprintf(ttyout, "Unable to determine remote directory\n");
   1534  1.109     lukem 	else {
   1535  1.109     lukem 		fprintf(ttyout, "Remote directory: %s\n", remotecwd);
   1536  1.109     lukem 		code = 0;
   1537    1.1       cgd 	}
   1538    1.1       cgd }
   1539    1.1       cgd 
   1540    1.1       cgd /*
   1541   1.10     lukem  * Print working directory on local machine.
   1542   1.10     lukem  */
   1543   1.10     lukem void
   1544   1.85     lukem lpwd(int argc, char *argv[])
   1545   1.10     lukem {
   1546   1.10     lukem 
   1547  1.109     lukem 	code = -1;
   1548  1.109     lukem 	if (argc != 1) {
   1549  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1550   1.76     lukem 		return;
   1551   1.76     lukem 	}
   1552  1.109     lukem 	if (! localcwd[0])
   1553  1.109     lukem 		updatelocalcwd();
   1554  1.109     lukem 	if (! localcwd[0])
   1555  1.109     lukem 		fprintf(ttyout, "Unable to determine local directory\n");
   1556  1.109     lukem 	else {
   1557  1.109     lukem 		fprintf(ttyout, "Local directory: %s\n", localcwd);
   1558   1.76     lukem 		code = 0;
   1559   1.76     lukem 	}
   1560   1.10     lukem }
   1561   1.10     lukem 
   1562   1.10     lukem /*
   1563    1.1       cgd  * Make a directory.
   1564    1.1       cgd  */
   1565    1.4       cgd void
   1566   1.85     lukem makedir(int argc, char *argv[])
   1567    1.1       cgd {
   1568  1.101     lukem 	int r;
   1569    1.1       cgd 
   1570   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1571   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "directory-name"))) {
   1572  1.116  christos 		UPRINTF("usage: %s directory-name\n", argv[0]);
   1573    1.1       cgd 		code = -1;
   1574    1.1       cgd 		return;
   1575    1.1       cgd 	}
   1576  1.101     lukem 	r = command("MKD %s", argv[1]);
   1577  1.101     lukem 	if (r == ERROR && code == 500) {
   1578    1.1       cgd 		if (verbose)
   1579   1.37     lukem 			fputs("MKD command not recognized, trying XMKD.\n",
   1580   1.37     lukem 			    ttyout);
   1581  1.101     lukem 		r = command("XMKD %s", argv[1]);
   1582    1.1       cgd 	}
   1583  1.101     lukem 	if (r == COMPLETE)
   1584  1.101     lukem 		dirchange = 1;
   1585    1.1       cgd }
   1586    1.1       cgd 
   1587    1.1       cgd /*
   1588    1.1       cgd  * Remove a directory.
   1589    1.1       cgd  */
   1590    1.4       cgd void
   1591   1.85     lukem removedir(int argc, char *argv[])
   1592    1.1       cgd {
   1593  1.101     lukem 	int r;
   1594    1.1       cgd 
   1595   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1596   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "directory-name"))) {
   1597  1.116  christos 		UPRINTF("usage: %s directory-name\n", argv[0]);
   1598    1.1       cgd 		code = -1;
   1599    1.1       cgd 		return;
   1600    1.1       cgd 	}
   1601  1.101     lukem 	r = command("RMD %s", argv[1]);
   1602  1.101     lukem 	if (r == ERROR && code == 500) {
   1603    1.1       cgd 		if (verbose)
   1604   1.37     lukem 			fputs("RMD command not recognized, trying XRMD.\n",
   1605   1.37     lukem 			    ttyout);
   1606  1.101     lukem 		r = command("XRMD %s", argv[1]);
   1607    1.1       cgd 	}
   1608  1.101     lukem 	if (r == COMPLETE)
   1609  1.101     lukem 		dirchange = 1;
   1610    1.1       cgd }
   1611    1.1       cgd 
   1612    1.1       cgd /*
   1613    1.1       cgd  * Send a line, verbatim, to the remote machine.
   1614    1.1       cgd  */
   1615    1.4       cgd void
   1616   1.85     lukem quote(int argc, char *argv[])
   1617    1.1       cgd {
   1618    1.1       cgd 
   1619   1.88     lukem 	if (argc == 0 ||
   1620   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "command line to send"))) {
   1621  1.116  christos 		UPRINTF("usage: %s line-to-send\n", argv[0]);
   1622    1.1       cgd 		code = -1;
   1623    1.1       cgd 		return;
   1624    1.1       cgd 	}
   1625    1.1       cgd 	quote1("", argc, argv);
   1626    1.1       cgd }
   1627    1.1       cgd 
   1628    1.1       cgd /*
   1629    1.1       cgd  * Send a SITE command to the remote machine.  The line
   1630    1.1       cgd  * is sent verbatim to the remote machine, except that the
   1631    1.1       cgd  * word "SITE" is added at the front.
   1632    1.1       cgd  */
   1633    1.4       cgd void
   1634   1.85     lukem site(int argc, char *argv[])
   1635    1.1       cgd {
   1636    1.1       cgd 
   1637   1.88     lukem 	if (argc == 0 ||
   1638   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
   1639  1.116  christos 		UPRINTF("usage: %s line-to-send\n", argv[0]);
   1640    1.1       cgd 		code = -1;
   1641    1.1       cgd 		return;
   1642    1.1       cgd 	}
   1643    1.1       cgd 	quote1("SITE ", argc, argv);
   1644    1.1       cgd }
   1645    1.1       cgd 
   1646    1.1       cgd /*
   1647    1.1       cgd  * Turn argv[1..argc) into a space-separated string, then prepend initial text.
   1648    1.1       cgd  * Send the result as a one-line command and get response.
   1649    1.1       cgd  */
   1650    1.4       cgd void
   1651   1.85     lukem quote1(const char *initial, int argc, char *argv[])
   1652    1.1       cgd {
   1653   1.63     lukem 	int i;
   1654    1.1       cgd 	char buf[BUFSIZ];		/* must be >= sizeof(line) */
   1655    1.1       cgd 
   1656   1.63     lukem 	(void)strlcpy(buf, initial, sizeof(buf));
   1657   1.63     lukem 	for (i = 1; i < argc; i++) {
   1658   1.63     lukem 		(void)strlcat(buf, argv[i], sizeof(buf));
   1659   1.63     lukem 		if (i < (argc - 1))
   1660   1.63     lukem 			(void)strlcat(buf, " ", sizeof(buf));
   1661    1.1       cgd 	}
   1662   1.43     lukem 	if (command("%s", buf) == PRELIM) {
   1663    1.4       cgd 		while (getreply(0) == PRELIM)
   1664    1.4       cgd 			continue;
   1665    1.1       cgd 	}
   1666  1.101     lukem 	dirchange = 1;
   1667    1.1       cgd }
   1668    1.1       cgd 
   1669    1.4       cgd void
   1670   1.85     lukem do_chmod(int argc, char *argv[])
   1671    1.1       cgd {
   1672    1.1       cgd 
   1673   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
   1674    1.1       cgd 		goto usage;
   1675   1.76     lukem 	if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
   1676   1.88     lukem  usage:
   1677  1.116  christos 		UPRINTF("usage: %s mode remote-file\n", argv[0]);
   1678    1.1       cgd 		code = -1;
   1679    1.1       cgd 		return;
   1680    1.1       cgd 	}
   1681   1.19     lukem 	(void)command("SITE CHMOD %s %s", argv[1], argv[2]);
   1682    1.1       cgd }
   1683    1.1       cgd 
   1684  1.112     lukem #define COMMAND_1ARG(argc, argv, cmd)			\
   1685   1.91        is 	if (argc == 1)					\
   1686   1.91        is 		command(cmd);				\
   1687   1.91        is 	else						\
   1688   1.91        is 		command(cmd " %s", argv[1])
   1689   1.91        is 
   1690    1.4       cgd void
   1691   1.85     lukem do_umask(int argc, char *argv[])
   1692    1.1       cgd {
   1693    1.1       cgd 	int oldverbose = verbose;
   1694    1.1       cgd 
   1695   1.88     lukem 	if (argc == 0) {
   1696  1.116  christos 		UPRINTF("usage: %s [umask]\n", argv[0]);
   1697   1.76     lukem 		code = -1;
   1698   1.76     lukem 		return;
   1699   1.76     lukem 	}
   1700    1.1       cgd 	verbose = 1;
   1701   1.91        is 	COMMAND_1ARG(argc, argv, "SITE UMASK");
   1702    1.1       cgd 	verbose = oldverbose;
   1703    1.1       cgd }
   1704    1.1       cgd 
   1705    1.4       cgd void
   1706   1.85     lukem idlecmd(int argc, char *argv[])
   1707    1.1       cgd {
   1708    1.1       cgd 	int oldverbose = verbose;
   1709    1.1       cgd 
   1710   1.80     lukem 	if (argc < 1 || argc > 2) {
   1711  1.116  christos 		UPRINTF("usage: %s [seconds]\n", argv[0]);
   1712   1.76     lukem 		code = -1;
   1713   1.76     lukem 		return;
   1714   1.76     lukem 	}
   1715    1.1       cgd 	verbose = 1;
   1716   1.91        is 	COMMAND_1ARG(argc, argv, "SITE IDLE");
   1717    1.1       cgd 	verbose = oldverbose;
   1718    1.1       cgd }
   1719    1.1       cgd 
   1720    1.1       cgd /*
   1721    1.1       cgd  * Ask the other side for help.
   1722    1.1       cgd  */
   1723    1.4       cgd void
   1724   1.85     lukem rmthelp(int argc, char *argv[])
   1725    1.1       cgd {
   1726    1.1       cgd 	int oldverbose = verbose;
   1727    1.1       cgd 
   1728   1.88     lukem 	if (argc == 0) {
   1729  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1730   1.76     lukem 		code = -1;
   1731   1.76     lukem 		return;
   1732   1.76     lukem 	}
   1733    1.1       cgd 	verbose = 1;
   1734   1.91        is 	COMMAND_1ARG(argc, argv, "HELP");
   1735    1.1       cgd 	verbose = oldverbose;
   1736    1.1       cgd }
   1737    1.1       cgd 
   1738    1.1       cgd /*
   1739    1.1       cgd  * Terminate session and exit.
   1740   1.88     lukem  * May be called with 0, NULL.
   1741    1.1       cgd  */
   1742    1.1       cgd /*VARARGS*/
   1743    1.4       cgd void
   1744   1.85     lukem quit(int argc, char *argv[])
   1745    1.1       cgd {
   1746    1.1       cgd 
   1747   1.88     lukem 			/* this may be called with argc == 0, argv == NULL */
   1748   1.76     lukem 	if (argc == 0 && argv != NULL) {
   1749  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1750   1.76     lukem 		code = -1;
   1751   1.76     lukem 		return;
   1752   1.76     lukem 	}
   1753    1.1       cgd 	if (connected)
   1754   1.76     lukem 		disconnect(0, NULL);
   1755    1.1       cgd 	pswitch(1);
   1756   1.76     lukem 	if (connected)
   1757   1.76     lukem 		disconnect(0, NULL);
   1758    1.1       cgd 	exit(0);
   1759    1.1       cgd }
   1760    1.1       cgd 
   1761    1.1       cgd /*
   1762    1.1       cgd  * Terminate session, but don't exit.
   1763   1.88     lukem  * May be called with 0, NULL.
   1764    1.1       cgd  */
   1765    1.4       cgd void
   1766   1.85     lukem disconnect(int argc, char *argv[])
   1767    1.1       cgd {
   1768    1.1       cgd 
   1769   1.88     lukem 			/* this may be called with argc == 0, argv == NULL */
   1770   1.76     lukem 	if (argc == 0 && argv != NULL) {
   1771  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1772   1.76     lukem 		code = -1;
   1773   1.76     lukem 		return;
   1774   1.76     lukem 	}
   1775    1.1       cgd 	if (!connected)
   1776    1.1       cgd 		return;
   1777   1.19     lukem 	(void)command("QUIT");
   1778   1.76     lukem 	cleanuppeer();
   1779    1.1       cgd }
   1780    1.1       cgd 
   1781    1.4       cgd void
   1782   1.85     lukem account(int argc, char *argv[])
   1783    1.1       cgd {
   1784   1.13     lukem 	char *ap;
   1785    1.1       cgd 
   1786   1.88     lukem 	if (argc == 0 || argc > 2) {
   1787  1.116  christos 		UPRINTF("usage: %s [password]\n", argv[0]);
   1788   1.13     lukem 		code = -1;
   1789   1.13     lukem 		return;
   1790    1.1       cgd 	}
   1791   1.13     lukem 	else if (argc == 2)
   1792   1.13     lukem 		ap = argv[1];
   1793   1.13     lukem 	else
   1794    1.1       cgd 		ap = getpass("Account:");
   1795   1.19     lukem 	(void)command("ACCT %s", ap);
   1796    1.1       cgd }
   1797    1.1       cgd 
   1798   1.73     lukem sigjmp_buf abortprox;
   1799    1.1       cgd 
   1800    1.1       cgd void
   1801   1.85     lukem proxabort(int notused)
   1802    1.1       cgd {
   1803    1.1       cgd 
   1804  1.106     lukem 	sigint_raised = 1;
   1805   1.18     lukem 	alarmtimer(0);
   1806    1.1       cgd 	if (!proxy) {
   1807    1.1       cgd 		pswitch(1);
   1808    1.1       cgd 	}
   1809    1.1       cgd 	if (connected) {
   1810    1.1       cgd 		proxflag = 1;
   1811    1.1       cgd 	}
   1812    1.1       cgd 	else {
   1813    1.1       cgd 		proxflag = 0;
   1814    1.1       cgd 	}
   1815    1.1       cgd 	pswitch(0);
   1816   1.72     lukem 	siglongjmp(abortprox, 1);
   1817    1.1       cgd }
   1818    1.1       cgd 
   1819    1.4       cgd void
   1820   1.85     lukem doproxy(int argc, char *argv[])
   1821    1.1       cgd {
   1822    1.4       cgd 	struct cmd *c;
   1823   1.14     lukem 	int cmdpos;
   1824   1.82     lukem 	sigfunc oldintr;
   1825    1.1       cgd 
   1826   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
   1827  1.116  christos 		UPRINTF("usage: %s command\n", argv[0]);
   1828    1.1       cgd 		code = -1;
   1829    1.1       cgd 		return;
   1830    1.1       cgd 	}
   1831    1.1       cgd 	c = getcmd(argv[1]);
   1832    1.1       cgd 	if (c == (struct cmd *) -1) {
   1833   1.37     lukem 		fputs("?Ambiguous command.\n", ttyout);
   1834    1.1       cgd 		code = -1;
   1835    1.1       cgd 		return;
   1836    1.1       cgd 	}
   1837    1.1       cgd 	if (c == 0) {
   1838   1.37     lukem 		fputs("?Invalid command.\n", ttyout);
   1839    1.1       cgd 		code = -1;
   1840    1.1       cgd 		return;
   1841    1.1       cgd 	}
   1842    1.1       cgd 	if (!c->c_proxy) {
   1843   1.37     lukem 		fputs("?Invalid proxy command.\n", ttyout);
   1844    1.1       cgd 		code = -1;
   1845    1.1       cgd 		return;
   1846    1.1       cgd 	}
   1847   1.72     lukem 	if (sigsetjmp(abortprox, 1)) {
   1848    1.1       cgd 		code = -1;
   1849    1.1       cgd 		return;
   1850    1.1       cgd 	}
   1851   1.62     lukem 	oldintr = xsignal(SIGINT, proxabort);
   1852    1.1       cgd 	pswitch(1);
   1853    1.1       cgd 	if (c->c_conn && !connected) {
   1854   1.37     lukem 		fputs("Not connected.\n", ttyout);
   1855    1.1       cgd 		pswitch(0);
   1856   1.62     lukem 		(void)xsignal(SIGINT, oldintr);
   1857    1.1       cgd 		code = -1;
   1858    1.1       cgd 		return;
   1859    1.1       cgd 	}
   1860   1.14     lukem 	cmdpos = strcspn(line, " \t");
   1861   1.14     lukem 	if (cmdpos > 0)		/* remove leading "proxy " from input buffer */
   1862   1.14     lukem 		memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
   1863   1.93     lukem 	argv[1] = c->c_name;
   1864    1.1       cgd 	(*c->c_handler)(argc-1, argv+1);
   1865    1.1       cgd 	if (connected) {
   1866    1.1       cgd 		proxflag = 1;
   1867    1.1       cgd 	}
   1868    1.1       cgd 	else {
   1869    1.1       cgd 		proxflag = 0;
   1870    1.1       cgd 	}
   1871    1.1       cgd 	pswitch(0);
   1872   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
   1873    1.1       cgd }
   1874    1.1       cgd 
   1875    1.4       cgd void
   1876   1.85     lukem setcase(int argc, char *argv[])
   1877    1.1       cgd {
   1878    1.4       cgd 
   1879   1.10     lukem 	code = togglevar(argc, argv, &mcase, "Case mapping");
   1880    1.1       cgd }
   1881    1.1       cgd 
   1882   1.63     lukem /*
   1883   1.63     lukem  * convert the given name to lower case if it's all upper case, into
   1884   1.63     lukem  * a static buffer which is returned to the caller
   1885   1.63     lukem  */
   1886  1.110  christos static const char *
   1887  1.110  christos docase(char *dst, size_t dlen, const char *src)
   1888   1.63     lukem {
   1889  1.110  christos 	size_t i;
   1890  1.110  christos 	int dochange = 1;
   1891   1.63     lukem 
   1892  1.110  christos 	for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
   1893  1.110  christos 		dst[i] = src[i];
   1894  1.110  christos 		if (islower((unsigned char)dst[i]))
   1895   1.63     lukem 			dochange = 0;
   1896   1.63     lukem 	}
   1897  1.110  christos 	dst[i] = '\0';
   1898   1.63     lukem 
   1899   1.63     lukem 	if (dochange) {
   1900  1.110  christos 		for (i = 0; dst[i] != '\0'; i++)
   1901  1.110  christos 			if (isupper((unsigned char)dst[i]))
   1902  1.110  christos 				dst[i] = tolower((unsigned char)dst[i]);
   1903   1.63     lukem 	}
   1904  1.110  christos 	return dst;
   1905   1.63     lukem }
   1906   1.63     lukem 
   1907    1.4       cgd void
   1908   1.85     lukem setcr(int argc, char *argv[])
   1909    1.1       cgd {
   1910    1.4       cgd 
   1911   1.10     lukem 	code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
   1912    1.1       cgd }
   1913    1.1       cgd 
   1914    1.4       cgd void
   1915   1.85     lukem setntrans(int argc, char *argv[])
   1916    1.1       cgd {
   1917   1.76     lukem 
   1918   1.88     lukem 	if (argc == 0 || argc > 3) {
   1919  1.116  christos 		UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
   1920   1.76     lukem 		code = -1;
   1921   1.76     lukem 		return;
   1922   1.76     lukem 	}
   1923    1.1       cgd 	if (argc == 1) {
   1924    1.1       cgd 		ntflag = 0;
   1925   1.37     lukem 		fputs("Ntrans off.\n", ttyout);
   1926    1.1       cgd 		code = ntflag;
   1927    1.1       cgd 		return;
   1928    1.1       cgd 	}
   1929    1.1       cgd 	ntflag++;
   1930    1.1       cgd 	code = ntflag;
   1931   1.63     lukem 	(void)strlcpy(ntin, argv[1], sizeof(ntin));
   1932    1.1       cgd 	if (argc == 2) {
   1933    1.1       cgd 		ntout[0] = '\0';
   1934    1.1       cgd 		return;
   1935    1.1       cgd 	}
   1936   1.63     lukem 	(void)strlcpy(ntout, argv[2], sizeof(ntout));
   1937    1.1       cgd }
   1938    1.1       cgd 
   1939  1.110  christos static const char *
   1940  1.110  christos dotrans(char *dst, size_t dlen, const char *src)
   1941    1.1       cgd {
   1942  1.110  christos 	const char *cp1;
   1943  1.110  christos 	char *cp2 = dst;
   1944  1.110  christos 	size_t i, ostop;
   1945    1.1       cgd 
   1946    1.4       cgd 	for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
   1947    1.4       cgd 		continue;
   1948  1.110  christos 	for (cp1 = src; *cp1; cp1++) {
   1949  1.110  christos 		int found = 0;
   1950    1.1       cgd 		for (i = 0; *(ntin + i) && i < 16; i++) {
   1951    1.1       cgd 			if (*cp1 == *(ntin + i)) {
   1952    1.1       cgd 				found++;
   1953    1.1       cgd 				if (i < ostop) {
   1954    1.1       cgd 					*cp2++ = *(ntout + i);
   1955  1.110  christos 					if (cp2 - dst >= dlen - 1)
   1956  1.110  christos 						goto out;
   1957    1.1       cgd 				}
   1958    1.1       cgd 				break;
   1959    1.1       cgd 			}
   1960    1.1       cgd 		}
   1961    1.1       cgd 		if (!found) {
   1962    1.1       cgd 			*cp2++ = *cp1;
   1963    1.1       cgd 		}
   1964    1.1       cgd 	}
   1965  1.110  christos out:
   1966    1.1       cgd 	*cp2 = '\0';
   1967  1.110  christos 	return dst;
   1968    1.1       cgd }
   1969    1.1       cgd 
   1970    1.4       cgd void
   1971   1.85     lukem setnmap(int argc, char *argv[])
   1972    1.1       cgd {
   1973    1.1       cgd 	char *cp;
   1974    1.1       cgd 
   1975    1.1       cgd 	if (argc == 1) {
   1976    1.1       cgd 		mapflag = 0;
   1977   1.37     lukem 		fputs("Nmap off.\n", ttyout);
   1978    1.1       cgd 		code = mapflag;
   1979    1.1       cgd 		return;
   1980    1.1       cgd 	}
   1981   1.88     lukem 	if (argc == 0 ||
   1982   1.76     lukem 	    (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
   1983  1.116  christos 		UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
   1984    1.1       cgd 		code = -1;
   1985    1.1       cgd 		return;
   1986    1.1       cgd 	}
   1987    1.1       cgd 	mapflag = 1;
   1988    1.1       cgd 	code = 1;
   1989    1.4       cgd 	cp = strchr(altarg, ' ');
   1990    1.1       cgd 	if (proxy) {
   1991    1.4       cgd 		while(*++cp == ' ')
   1992    1.4       cgd 			continue;
   1993    1.1       cgd 		altarg = cp;
   1994    1.4       cgd 		cp = strchr(altarg, ' ');
   1995    1.1       cgd 	}
   1996    1.1       cgd 	*cp = '\0';
   1997   1.63     lukem 	(void)strlcpy(mapin, altarg, MAXPATHLEN);
   1998    1.4       cgd 	while (*++cp == ' ')
   1999    1.4       cgd 		continue;
   2000   1.63     lukem 	(void)strlcpy(mapout, cp, MAXPATHLEN);
   2001    1.1       cgd }
   2002    1.1       cgd 
   2003  1.110  christos static const char *
   2004  1.110  christos domap(char *dst, size_t dlen, const char *src)
   2005    1.1       cgd {
   2006  1.110  christos 	const char *cp1 = src;
   2007  1.110  christos 	char *cp2 = mapin;
   2008  1.110  christos 	const char *tp[9], *te[9];
   2009    1.1       cgd 	int i, toks[9], toknum = 0, match = 1;
   2010    1.1       cgd 
   2011    1.1       cgd 	for (i=0; i < 9; ++i) {
   2012    1.1       cgd 		toks[i] = 0;
   2013    1.1       cgd 	}
   2014    1.1       cgd 	while (match && *cp1 && *cp2) {
   2015    1.1       cgd 		switch (*cp2) {
   2016    1.1       cgd 			case '\\':
   2017    1.1       cgd 				if (*++cp2 != *cp1) {
   2018    1.1       cgd 					match = 0;
   2019    1.1       cgd 				}
   2020    1.1       cgd 				break;
   2021    1.1       cgd 			case '$':
   2022    1.1       cgd 				if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
   2023    1.1       cgd 					if (*cp1 != *(++cp2+1)) {
   2024    1.1       cgd 						toks[toknum = *cp2 - '1']++;
   2025    1.1       cgd 						tp[toknum] = cp1;
   2026    1.1       cgd 						while (*++cp1 && *(cp2+1)
   2027    1.1       cgd 							!= *cp1);
   2028    1.1       cgd 						te[toknum] = cp1;
   2029    1.1       cgd 					}
   2030    1.1       cgd 					cp2++;
   2031    1.1       cgd 					break;
   2032    1.1       cgd 				}
   2033    1.1       cgd 				/* FALLTHROUGH */
   2034    1.1       cgd 			default:
   2035    1.1       cgd 				if (*cp2 != *cp1) {
   2036    1.1       cgd 					match = 0;
   2037    1.1       cgd 				}
   2038    1.1       cgd 				break;
   2039    1.1       cgd 		}
   2040    1.1       cgd 		if (match && *cp1) {
   2041    1.1       cgd 			cp1++;
   2042    1.1       cgd 		}
   2043    1.1       cgd 		if (match && *cp2) {
   2044    1.1       cgd 			cp2++;
   2045    1.1       cgd 		}
   2046    1.1       cgd 	}
   2047    1.1       cgd 	if (!match && *cp1) /* last token mismatch */
   2048    1.1       cgd 	{
   2049    1.1       cgd 		toks[toknum] = 0;
   2050    1.1       cgd 	}
   2051  1.110  christos 	cp2 = dst;
   2052  1.110  christos 	*cp2 = '\0';
   2053  1.110  christos 	cp1 = mapout;
   2054  1.110  christos 	while (*cp1) {
   2055    1.1       cgd 		match = 0;
   2056  1.110  christos 		switch (*cp1) {
   2057    1.1       cgd 			case '\\':
   2058  1.110  christos 				if (*(cp1 + 1)) {
   2059  1.110  christos 					*cp2++ = *++cp1;
   2060    1.1       cgd 				}
   2061    1.1       cgd 				break;
   2062    1.1       cgd 			case '[':
   2063    1.1       cgd LOOP:
   2064  1.110  christos 				if (*++cp1 == '$' &&
   2065  1.110  christos 				    isdigit((unsigned char)*(cp1+1))) {
   2066  1.110  christos 					if (*++cp1 == '0') {
   2067  1.110  christos 						const char *cp3 = src;
   2068    1.1       cgd 
   2069    1.1       cgd 						while (*cp3) {
   2070  1.110  christos 							*cp2++ = *cp3++;
   2071    1.1       cgd 						}
   2072    1.1       cgd 						match = 1;
   2073    1.1       cgd 					}
   2074  1.110  christos 					else if (toks[toknum = *cp1 - '1']) {
   2075  1.110  christos 						const char *cp3 = tp[toknum];
   2076    1.1       cgd 
   2077    1.1       cgd 						while (cp3 != te[toknum]) {
   2078  1.110  christos 							*cp2++ = *cp3++;
   2079    1.1       cgd 						}
   2080    1.1       cgd 						match = 1;
   2081    1.1       cgd 					}
   2082    1.1       cgd 				}
   2083    1.1       cgd 				else {
   2084  1.110  christos 					while (*cp1 && *cp1 != ',' &&
   2085  1.110  christos 					    *cp1 != ']') {
   2086  1.110  christos 						if (*cp1 == '\\') {
   2087  1.110  christos 							cp1++;
   2088    1.1       cgd 						}
   2089  1.110  christos 						else if (*cp1 == '$' &&
   2090  1.110  christos 						    isdigit((unsigned char)*(cp1+1))) {
   2091  1.110  christos 							if (*++cp1 == '0') {
   2092  1.110  christos 							   const char *cp3 = src;
   2093    1.1       cgd 
   2094    1.1       cgd 							   while (*cp3) {
   2095  1.110  christos 								*cp2++ = *cp3++;
   2096    1.1       cgd 							   }
   2097    1.1       cgd 							}
   2098    1.1       cgd 							else if (toks[toknum =
   2099  1.110  christos 							    *cp1 - '1']) {
   2100  1.110  christos 							   const char *cp3=tp[toknum];
   2101    1.1       cgd 
   2102    1.1       cgd 							   while (cp3 !=
   2103    1.1       cgd 								  te[toknum]) {
   2104  1.110  christos 								*cp2++ = *cp3++;
   2105    1.1       cgd 							   }
   2106    1.1       cgd 							}
   2107    1.1       cgd 						}
   2108  1.110  christos 						else if (*cp1) {
   2109  1.110  christos 							*cp2++ = *cp1++;
   2110    1.1       cgd 						}
   2111    1.1       cgd 					}
   2112  1.110  christos 					if (!*cp1) {
   2113   1.37     lukem 						fputs(
   2114   1.37     lukem 						"nmap: unbalanced brackets.\n",
   2115   1.37     lukem 						    ttyout);
   2116  1.110  christos 						return (src);
   2117    1.1       cgd 					}
   2118    1.1       cgd 					match = 1;
   2119  1.110  christos 					cp1--;
   2120    1.1       cgd 				}
   2121    1.1       cgd 				if (match) {
   2122  1.110  christos 					while (*++cp1 && *cp1 != ']') {
   2123  1.110  christos 					      if (*cp1 == '\\' && *(cp1 + 1)) {
   2124  1.110  christos 							cp1++;
   2125    1.1       cgd 					      }
   2126    1.1       cgd 					}
   2127  1.110  christos 					if (!*cp1) {
   2128   1.37     lukem 						fputs(
   2129   1.37     lukem 						"nmap: unbalanced brackets.\n",
   2130   1.37     lukem 						    ttyout);
   2131  1.110  christos 						return (src);
   2132    1.1       cgd 					}
   2133    1.1       cgd 					break;
   2134    1.1       cgd 				}
   2135  1.110  christos 				switch (*++cp1) {
   2136    1.1       cgd 					case ',':
   2137    1.1       cgd 						goto LOOP;
   2138    1.1       cgd 					case ']':
   2139    1.1       cgd 						break;
   2140    1.1       cgd 					default:
   2141  1.110  christos 						cp1--;
   2142    1.1       cgd 						goto LOOP;
   2143    1.1       cgd 				}
   2144    1.1       cgd 				break;
   2145    1.1       cgd 			case '$':
   2146  1.110  christos 				if (isdigit((unsigned char)*(cp1 + 1))) {
   2147  1.110  christos 					if (*++cp1 == '0') {
   2148  1.110  christos 						const char *cp3 = src;
   2149    1.1       cgd 
   2150    1.1       cgd 						while (*cp3) {
   2151  1.110  christos 							*cp2++ = *cp3++;
   2152    1.1       cgd 						}
   2153    1.1       cgd 					}
   2154  1.110  christos 					else if (toks[toknum = *cp1 - '1']) {
   2155  1.110  christos 						const char *cp3 = tp[toknum];
   2156    1.1       cgd 
   2157    1.1       cgd 						while (cp3 != te[toknum]) {
   2158  1.110  christos 							*cp2++ = *cp3++;
   2159    1.1       cgd 						}
   2160    1.1       cgd 					}
   2161    1.1       cgd 					break;
   2162    1.1       cgd 				}
   2163    1.1       cgd 				/* intentional drop through */
   2164    1.1       cgd 			default:
   2165  1.110  christos 				*cp2++ = *cp1;
   2166    1.1       cgd 				break;
   2167    1.1       cgd 		}
   2168  1.110  christos 		cp1++;
   2169    1.1       cgd 	}
   2170  1.110  christos 	*cp2 = '\0';
   2171  1.110  christos 	return *dst ? dst : src;
   2172    1.1       cgd }
   2173    1.1       cgd 
   2174    1.4       cgd void
   2175   1.85     lukem setpassive(int argc, char *argv[])
   2176    1.5       cgd {
   2177    1.5       cgd 
   2178   1.76     lukem 	if (argc == 1) {
   2179   1.76     lukem 		passivemode = !passivemode;
   2180   1.76     lukem 		activefallback = passivemode;
   2181   1.76     lukem 	} else if (argc != 2) {
   2182   1.76     lukem  passiveusage:
   2183  1.116  christos 		UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
   2184   1.76     lukem 		code = -1;
   2185   1.76     lukem 		return;
   2186   1.76     lukem 	} else if (strcasecmp(argv[1], "on") == 0) {
   2187   1.76     lukem 		passivemode = 1;
   2188   1.76     lukem 		activefallback = 0;
   2189   1.76     lukem 	} else if (strcasecmp(argv[1], "off") == 0) {
   2190   1.76     lukem 		passivemode = 0;
   2191   1.76     lukem 		activefallback = 0;
   2192   1.76     lukem 	} else if (strcasecmp(argv[1], "auto") == 0) {
   2193   1.76     lukem 		passivemode = 1;
   2194   1.76     lukem 		activefallback = 1;
   2195   1.76     lukem 	} else
   2196   1.76     lukem 		goto passiveusage;
   2197   1.76     lukem 	fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
   2198   1.76     lukem 	    onoff(passivemode), onoff(activefallback));
   2199   1.76     lukem 	code = passivemode;
   2200    1.5       cgd }
   2201    1.5       cgd 
   2202    1.5       cgd void
   2203   1.85     lukem setepsv4(int argc, char *argv[])
   2204   1.68     lukem {
   2205   1.68     lukem 
   2206   1.68     lukem 	code = togglevar(argc, argv, &epsv4,
   2207   1.68     lukem 	    verbose ? "EPSV/EPRT on IPv4" : NULL);
   2208   1.68     lukem 	epsv4bad = 0;
   2209   1.68     lukem }
   2210   1.68     lukem 
   2211   1.68     lukem void
   2212   1.85     lukem setsunique(int argc, char *argv[])
   2213    1.1       cgd {
   2214    1.4       cgd 
   2215   1.10     lukem 	code = togglevar(argc, argv, &sunique, "Store unique");
   2216    1.1       cgd }
   2217    1.1       cgd 
   2218    1.4       cgd void
   2219   1.85     lukem setrunique(int argc, char *argv[])
   2220    1.1       cgd {
   2221    1.4       cgd 
   2222   1.10     lukem 	code = togglevar(argc, argv, &runique, "Receive unique");
   2223    1.1       cgd }
   2224    1.1       cgd 
   2225   1.52     lukem int
   2226   1.85     lukem parserate(int argc, char *argv[], int cmdlineopt)
   2227   1.52     lukem {
   2228   1.52     lukem 	int dir, max, incr, showonly;
   2229   1.82     lukem 	sigfunc oldusr1, oldusr2;
   2230   1.52     lukem 
   2231   1.52     lukem 	if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
   2232   1.88     lukem  usage:
   2233   1.52     lukem 		if (cmdlineopt)
   2234  1.116  christos 			UPRINTF(
   2235   1.66     lukem 	"usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
   2236   1.52     lukem 			    argv[0]);
   2237   1.52     lukem 		else
   2238  1.116  christos 			UPRINTF(
   2239   1.66     lukem 	"usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
   2240   1.52     lukem 			    argv[0]);
   2241   1.52     lukem 		return -1;
   2242   1.52     lukem 	}
   2243   1.52     lukem 	dir = max = incr = showonly = 0;
   2244   1.76     lukem #define	RATE_GET	1
   2245   1.76     lukem #define	RATE_PUT	2
   2246   1.76     lukem #define	RATE_ALL	(RATE_GET | RATE_PUT)
   2247   1.52     lukem 
   2248   1.52     lukem 	if (strcasecmp(argv[1], "all") == 0)
   2249   1.52     lukem 		dir = RATE_ALL;
   2250   1.52     lukem 	else if (strcasecmp(argv[1], "get") == 0)
   2251   1.52     lukem 		dir = RATE_GET;
   2252   1.52     lukem 	else if (strcasecmp(argv[1], "put") == 0)
   2253   1.52     lukem 		dir = RATE_PUT;
   2254   1.52     lukem 	else
   2255   1.52     lukem 		goto usage;
   2256   1.52     lukem 
   2257   1.52     lukem 	if (argc >= 3) {
   2258   1.52     lukem 		if ((max = strsuftoi(argv[2])) < 0)
   2259   1.52     lukem 			goto usage;
   2260   1.52     lukem 	} else
   2261   1.52     lukem 		showonly = 1;
   2262   1.52     lukem 
   2263   1.52     lukem 	if (argc == 4) {
   2264   1.52     lukem 		if ((incr = strsuftoi(argv[3])) <= 0)
   2265   1.52     lukem 			goto usage;
   2266   1.52     lukem 	} else
   2267   1.52     lukem 		incr = DEFAULTINCR;
   2268   1.52     lukem 
   2269   1.62     lukem 	oldusr1 = xsignal(SIGUSR1, SIG_IGN);
   2270   1.62     lukem 	oldusr2 = xsignal(SIGUSR2, SIG_IGN);
   2271   1.52     lukem 	if (dir & RATE_GET) {
   2272   1.52     lukem 		if (!showonly) {
   2273   1.52     lukem 			rate_get = max;
   2274   1.52     lukem 			rate_get_incr = incr;
   2275   1.52     lukem 		}
   2276   1.52     lukem 		if (!cmdlineopt || verbose)
   2277   1.52     lukem 			fprintf(ttyout,
   2278   1.53     lukem 		"Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
   2279   1.52     lukem 			    onoff(rate_get), rate_get, rate_get_incr);
   2280   1.52     lukem 	}
   2281   1.52     lukem 	if (dir & RATE_PUT) {
   2282   1.52     lukem 		if (!showonly) {
   2283   1.52     lukem 			rate_put = max;
   2284   1.52     lukem 			rate_put_incr = incr;
   2285   1.52     lukem 		}
   2286   1.52     lukem 		if (!cmdlineopt || verbose)
   2287   1.52     lukem 			fprintf(ttyout,
   2288   1.53     lukem 		"Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
   2289   1.52     lukem 			    onoff(rate_put), rate_put, rate_put_incr);
   2290   1.52     lukem 	}
   2291   1.62     lukem 	(void)xsignal(SIGUSR1, oldusr1);
   2292   1.62     lukem 	(void)xsignal(SIGUSR2, oldusr2);
   2293   1.52     lukem 	return 0;
   2294   1.52     lukem }
   2295   1.52     lukem 
   2296   1.52     lukem void
   2297   1.85     lukem setrate(int argc, char *argv[])
   2298   1.52     lukem {
   2299   1.52     lukem 
   2300   1.52     lukem 	code = parserate(argc, argv, 0);
   2301   1.52     lukem }
   2302   1.52     lukem 
   2303   1.16     lukem /* change directory to parent directory */
   2304    1.4       cgd void
   2305   1.85     lukem cdup(int argc, char *argv[])
   2306    1.1       cgd {
   2307   1.16     lukem 	int r;
   2308    1.4       cgd 
   2309   1.88     lukem 	if (argc == 0) {
   2310  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   2311   1.76     lukem 		code = -1;
   2312   1.76     lukem 		return;
   2313   1.76     lukem 	}
   2314   1.16     lukem 	r = command("CDUP");
   2315   1.16     lukem 	if (r == ERROR && code == 500) {
   2316    1.1       cgd 		if (verbose)
   2317   1.37     lukem 			fputs("CDUP command not recognized, trying XCUP.\n",
   2318   1.37     lukem 			    ttyout);
   2319   1.16     lukem 		r = command("XCUP");
   2320    1.1       cgd 	}
   2321   1.79     lukem 	if (r == COMPLETE) {
   2322   1.16     lukem 		dirchange = 1;
   2323  1.109     lukem 		updateremotecwd();
   2324   1.79     lukem 	}
   2325    1.1       cgd }
   2326    1.1       cgd 
   2327   1.27     lukem /*
   2328   1.27     lukem  * Restart transfer at specific point
   2329   1.27     lukem  */
   2330    1.4       cgd void
   2331   1.85     lukem restart(int argc, char *argv[])
   2332    1.1       cgd {
   2333    1.4       cgd 
   2334   1.88     lukem 	if (argc == 0 || argc > 2) {
   2335  1.116  christos 		UPRINTF("usage: %s [restart-point]\n", argv[0]);
   2336   1.31     lukem 		code = -1;
   2337   1.31     lukem 		return;
   2338   1.31     lukem 	}
   2339   1.88     lukem 	if (! features[FEAT_REST_STREAM]) {
   2340   1.88     lukem 		fprintf(ttyout,
   2341   1.88     lukem 		    "Restart is not supported by the remote server.\n");
   2342   1.88     lukem 		return;
   2343   1.88     lukem 	}
   2344   1.31     lukem 	if (argc == 2) {
   2345   1.60     lukem 		off_t rp;
   2346   1.31     lukem 		char *ep;
   2347   1.31     lukem 
   2348   1.89     lukem 		rp = STRTOLL(argv[1], &ep, 10);
   2349   1.31     lukem 		if (rp < 0 || *ep != '\0')
   2350   1.37     lukem 			fprintf(ttyout, "restart: Invalid offset `%s'\n",
   2351   1.37     lukem 			    argv[1]);
   2352   1.31     lukem 		else
   2353   1.31     lukem 			restart_point = rp;
   2354    1.1       cgd 	}
   2355   1.31     lukem 	if (restart_point == 0)
   2356   1.37     lukem 		fputs("No restart point defined.\n", ttyout);
   2357   1.31     lukem 	else
   2358   1.37     lukem 		fprintf(ttyout,
   2359   1.90     lukem 		    "Restarting at " LLF " for next get, put or append\n",
   2360   1.90     lukem 		    (LLT)restart_point);
   2361    1.1       cgd }
   2362    1.1       cgd 
   2363   1.47     lukem /*
   2364   1.27     lukem  * Show remote system type
   2365   1.27     lukem  */
   2366    1.4       cgd void
   2367   1.85     lukem syst(int argc, char *argv[])
   2368    1.1       cgd {
   2369   1.88     lukem 	int oldverbose = verbose;
   2370    1.4       cgd 
   2371   1.88     lukem 	if (argc == 0) {
   2372  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   2373   1.76     lukem 		code = -1;
   2374   1.76     lukem 		return;
   2375   1.76     lukem 	}
   2376   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2377   1.19     lukem 	(void)command("SYST");
   2378   1.88     lukem 	verbose = oldverbose;
   2379    1.1       cgd }
   2380    1.1       cgd 
   2381    1.4       cgd void
   2382   1.85     lukem macdef(int argc, char *argv[])
   2383    1.1       cgd {
   2384    1.1       cgd 	char *tmp;
   2385    1.1       cgd 	int c;
   2386    1.1       cgd 
   2387   1.88     lukem 	if (argc == 0)
   2388   1.76     lukem 		goto usage;
   2389    1.1       cgd 	if (macnum == 16) {
   2390   1.37     lukem 		fputs("Limit of 16 macros have already been defined.\n",
   2391   1.37     lukem 		    ttyout);
   2392    1.1       cgd 		code = -1;
   2393    1.1       cgd 		return;
   2394    1.1       cgd 	}
   2395   1.10     lukem 	if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
   2396   1.76     lukem  usage:
   2397  1.116  christos 		UPRINTF("usage: %s macro_name\n", argv[0]);
   2398    1.1       cgd 		code = -1;
   2399    1.1       cgd 		return;
   2400    1.1       cgd 	}
   2401   1.19     lukem 	if (interactive)
   2402   1.37     lukem 		fputs(
   2403   1.37     lukem 		"Enter macro line by line, terminating it with a null line.\n",
   2404   1.37     lukem 		    ttyout);
   2405   1.63     lukem 	(void)strlcpy(macros[macnum].mac_name, argv[1],
   2406   1.63     lukem 	    sizeof(macros[macnum].mac_name));
   2407   1.19     lukem 	if (macnum == 0)
   2408    1.1       cgd 		macros[macnum].mac_start = macbuf;
   2409   1.19     lukem 	else
   2410    1.1       cgd 		macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
   2411    1.1       cgd 	tmp = macros[macnum].mac_start;
   2412    1.1       cgd 	while (tmp != macbuf+4096) {
   2413    1.1       cgd 		if ((c = getchar()) == EOF) {
   2414   1.37     lukem 			fputs("macdef: end of file encountered.\n", ttyout);
   2415    1.1       cgd 			code = -1;
   2416    1.1       cgd 			return;
   2417    1.1       cgd 		}
   2418    1.1       cgd 		if ((*tmp = c) == '\n') {
   2419    1.1       cgd 			if (tmp == macros[macnum].mac_start) {
   2420    1.1       cgd 				macros[macnum++].mac_end = tmp;
   2421    1.1       cgd 				code = 0;
   2422    1.1       cgd 				return;
   2423    1.1       cgd 			}
   2424    1.1       cgd 			if (*(tmp-1) == '\0') {
   2425    1.1       cgd 				macros[macnum++].mac_end = tmp - 1;
   2426    1.1       cgd 				code = 0;
   2427    1.1       cgd 				return;
   2428    1.1       cgd 			}
   2429    1.1       cgd 			*tmp = '\0';
   2430    1.1       cgd 		}
   2431    1.1       cgd 		tmp++;
   2432    1.1       cgd 	}
   2433    1.1       cgd 	while (1) {
   2434    1.1       cgd 		while ((c = getchar()) != '\n' && c != EOF)
   2435    1.1       cgd 			/* LOOP */;
   2436    1.1       cgd 		if (c == EOF || getchar() == '\n') {
   2437   1.37     lukem 			fputs("Macro not defined - 4K buffer exceeded.\n",
   2438   1.37     lukem 			    ttyout);
   2439    1.1       cgd 			code = -1;
   2440    1.1       cgd 			return;
   2441    1.1       cgd 		}
   2442    1.1       cgd 	}
   2443    1.1       cgd }
   2444    1.1       cgd 
   2445    1.1       cgd /*
   2446   1.27     lukem  * Get size of file on remote machine
   2447    1.1       cgd  */
   2448    1.4       cgd void
   2449   1.85     lukem sizecmd(int argc, char *argv[])
   2450    1.1       cgd {
   2451   1.11     lukem 	off_t size;
   2452    1.1       cgd 
   2453   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2454   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   2455  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   2456    1.1       cgd 		code = -1;
   2457    1.1       cgd 		return;
   2458    1.1       cgd 	}
   2459   1.13     lukem 	size = remotesize(argv[1], 1);
   2460   1.11     lukem 	if (size != -1)
   2461   1.37     lukem 		fprintf(ttyout,
   2462   1.90     lukem 		    "%s\t" LLF "\n", argv[1], (LLT)size);
   2463   1.76     lukem 	code = (size > 0);
   2464   1.10     lukem }
   2465   1.10     lukem 
   2466   1.10     lukem /*
   2467   1.27     lukem  * Get last modification time of file on remote machine
   2468   1.10     lukem  */
   2469   1.10     lukem void
   2470   1.85     lukem modtime(int argc, char *argv[])
   2471   1.10     lukem {
   2472   1.10     lukem 	time_t mtime;
   2473   1.10     lukem 
   2474   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2475   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   2476  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   2477   1.10     lukem 		code = -1;
   2478   1.10     lukem 		return;
   2479   1.10     lukem 	}
   2480   1.13     lukem 	mtime = remotemodtime(argv[1], 1);
   2481   1.10     lukem 	if (mtime != -1)
   2482   1.37     lukem 		fprintf(ttyout, "%s\t%s", argv[1], asctime(localtime(&mtime)));
   2483   1.76     lukem 	code = (mtime > 0);
   2484    1.1       cgd }
   2485    1.1       cgd 
   2486    1.1       cgd /*
   2487   1.27     lukem  * Show status on remote machine
   2488    1.1       cgd  */
   2489    1.4       cgd void
   2490   1.85     lukem rmtstatus(int argc, char *argv[])
   2491    1.1       cgd {
   2492    1.4       cgd 
   2493   1.88     lukem 	if (argc == 0) {
   2494  1.116  christos 		UPRINTF("usage: %s [remote-file]\n", argv[0]);
   2495   1.76     lukem 		code = -1;
   2496   1.76     lukem 		return;
   2497   1.76     lukem 	}
   2498   1.91        is 	COMMAND_1ARG(argc, argv, "STAT");
   2499    1.1       cgd }
   2500    1.1       cgd 
   2501    1.1       cgd /*
   2502   1.27     lukem  * Get file if modtime is more recent than current file
   2503    1.1       cgd  */
   2504    1.4       cgd void
   2505   1.85     lukem newer(int argc, char *argv[])
   2506    1.1       cgd {
   2507    1.4       cgd 
   2508    1.1       cgd 	if (getit(argc, argv, -1, "w"))
   2509   1.37     lukem 		fprintf(ttyout,
   2510   1.37     lukem 		    "Local file \"%s\" is newer than remote file \"%s\".\n",
   2511   1.37     lukem 		    argv[2], argv[1]);
   2512   1.19     lukem }
   2513   1.19     lukem 
   2514   1.19     lukem /*
   2515   1.76     lukem  * Display one local file through $PAGER.
   2516   1.19     lukem  */
   2517   1.19     lukem void
   2518   1.85     lukem lpage(int argc, char *argv[])
   2519   1.19     lukem {
   2520  1.114     lukem 	size_t len;
   2521   1.63     lukem 	char *p, *pager, *locfile;
   2522   1.19     lukem 
   2523   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2524   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "local-file"))) {
   2525  1.116  christos 		UPRINTF("usage: %s local-file\n", argv[0]);
   2526   1.19     lukem 		code = -1;
   2527   1.19     lukem 		return;
   2528   1.19     lukem 	}
   2529   1.63     lukem 	if ((locfile = globulize(argv[1])) == NULL) {
   2530   1.63     lukem 		code = -1;
   2531   1.63     lukem 		return;
   2532   1.63     lukem 	}
   2533   1.76     lukem 	p = getoptionvalue("pager");
   2534   1.76     lukem 	if (EMPTYSTRING(p))
   2535   1.76     lukem 		p = DEFAULTPAGER;
   2536   1.63     lukem 	len = strlen(p) + strlen(locfile) + 2;
   2537  1.117  christos 	pager = ftp_malloc(len);
   2538   1.63     lukem 	(void)strlcpy(pager, p,		len);
   2539   1.63     lukem 	(void)strlcat(pager, " ",	len);
   2540   1.63     lukem 	(void)strlcat(pager, locfile,	len);
   2541   1.63     lukem 	system(pager);
   2542   1.76     lukem 	code = 0;
   2543   1.63     lukem 	(void)free(pager);
   2544   1.63     lukem 	(void)free(locfile);
   2545   1.63     lukem }
   2546   1.63     lukem 
   2547   1.63     lukem /*
   2548   1.76     lukem  * Display one remote file through $PAGER.
   2549   1.63     lukem  */
   2550   1.63     lukem void
   2551   1.85     lukem page(int argc, char *argv[])
   2552   1.63     lukem {
   2553  1.114     lukem 	int ohash, orestart_point, overbose;
   2554  1.114     lukem 	size_t len;
   2555   1.63     lukem 	char *p, *pager;
   2556   1.63     lukem 
   2557   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2558   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   2559  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   2560   1.19     lukem 		code = -1;
   2561   1.19     lukem 		return;
   2562   1.19     lukem 	}
   2563   1.76     lukem 	p = getoptionvalue("pager");
   2564   1.76     lukem 	if (EMPTYSTRING(p))
   2565   1.76     lukem 		p = DEFAULTPAGER;
   2566   1.49     lukem 	len = strlen(p) + 2;
   2567  1.117  christos 	pager = ftp_malloc(len);
   2568   1.57     lukem 	pager[0] = '|';
   2569   1.63     lukem 	(void)strlcpy(pager + 1, p, len - 1);
   2570   1.19     lukem 
   2571   1.19     lukem 	ohash = hash;
   2572   1.37     lukem 	orestart_point = restart_point;
   2573   1.19     lukem 	overbose = verbose;
   2574   1.37     lukem 	hash = restart_point = verbose = 0;
   2575   1.97     lukem 	recvrequest("RETR", pager, argv[1], "r+", 1, 0);
   2576   1.19     lukem 	hash = ohash;
   2577   1.37     lukem 	restart_point = orestart_point;
   2578   1.19     lukem 	verbose = overbose;
   2579   1.63     lukem 	(void)free(pager);
   2580   1.39   thorpej }
   2581   1.39   thorpej 
   2582   1.39   thorpej /*
   2583   1.58     lukem  * Set the socket send or receive buffer size.
   2584   1.39   thorpej  */
   2585   1.39   thorpej void
   2586   1.85     lukem setxferbuf(int argc, char *argv[])
   2587   1.39   thorpej {
   2588   1.58     lukem 	int size, dir;
   2589   1.39   thorpej 
   2590   1.39   thorpej 	if (argc != 2) {
   2591   1.58     lukem  usage:
   2592  1.116  christos 		UPRINTF("usage: %s size\n", argv[0]);
   2593   1.39   thorpej 		code = -1;
   2594   1.39   thorpej 		return;
   2595   1.39   thorpej 	}
   2596   1.58     lukem 	if (strcasecmp(argv[0], "sndbuf") == 0)
   2597   1.58     lukem 		dir = RATE_PUT;
   2598   1.58     lukem 	else if (strcasecmp(argv[0], "rcvbuf") == 0)
   2599   1.58     lukem 		dir = RATE_GET;
   2600   1.58     lukem 	else if (strcasecmp(argv[0], "xferbuf") == 0)
   2601   1.58     lukem 		dir = RATE_ALL;
   2602   1.39   thorpej 	else
   2603   1.58     lukem 		goto usage;
   2604   1.39   thorpej 
   2605   1.58     lukem 	if ((size = strsuftoi(argv[1])) == -1)
   2606   1.58     lukem 		goto usage;
   2607   1.39   thorpej 
   2608   1.58     lukem 	if (size == 0) {
   2609   1.58     lukem 		fprintf(ttyout, "%s: size must be positive.\n", argv[0]);
   2610   1.58     lukem 		goto usage;
   2611   1.39   thorpej 	}
   2612   1.39   thorpej 
   2613   1.58     lukem 	if (dir & RATE_PUT)
   2614   1.58     lukem 		sndbuf_size = size;
   2615   1.58     lukem 	if (dir & RATE_GET)
   2616   1.58     lukem 		rcvbuf_size = size;
   2617   1.58     lukem 	fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
   2618   1.58     lukem 	    sndbuf_size, rcvbuf_size);
   2619   1.76     lukem 	code = 0;
   2620   1.76     lukem }
   2621   1.76     lukem 
   2622   1.76     lukem /*
   2623   1.76     lukem  * Set or display options (defaults are provided by various env vars)
   2624   1.76     lukem  */
   2625   1.76     lukem void
   2626   1.85     lukem setoption(int argc, char *argv[])
   2627   1.76     lukem {
   2628   1.76     lukem 	struct option *o;
   2629   1.76     lukem 
   2630   1.76     lukem 	code = -1;
   2631   1.88     lukem 	if (argc == 0 || (argc != 1 && argc != 3)) {
   2632  1.116  christos 		UPRINTF("usage: %s [option value]\n", argv[0]);
   2633   1.76     lukem 		return;
   2634   1.76     lukem 	}
   2635   1.76     lukem 
   2636   1.76     lukem #define	OPTIONINDENT ((int) sizeof("http_proxy"))
   2637   1.76     lukem 	if (argc == 1) {
   2638   1.76     lukem 		for (o = optiontab; o->name != NULL; o++) {
   2639   1.76     lukem 			fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
   2640   1.76     lukem 			    o->name, o->value ? o->value : "");
   2641   1.76     lukem 		}
   2642   1.76     lukem 	} else {
   2643   1.76     lukem 		o = getoption(argv[1]);
   2644   1.76     lukem 		if (o == NULL) {
   2645   1.76     lukem 			fprintf(ttyout, "No such option `%s'.\n", argv[1]);
   2646   1.76     lukem 			return;
   2647   1.76     lukem 		}
   2648   1.76     lukem 		FREEPTR(o->value);
   2649  1.117  christos 		o->value = ftp_strdup(argv[2]);
   2650   1.76     lukem 		if (verbose)
   2651   1.76     lukem 			fprintf(ttyout, "Setting `%s' to `%s'.\n",
   2652   1.76     lukem 			    o->name, o->value);
   2653   1.76     lukem 	}
   2654   1.76     lukem 	code = 0;
   2655   1.76     lukem }
   2656   1.76     lukem 
   2657   1.76     lukem /*
   2658   1.76     lukem  * Unset an option
   2659   1.76     lukem  */
   2660   1.76     lukem void
   2661   1.85     lukem unsetoption(int argc, char *argv[])
   2662   1.76     lukem {
   2663   1.76     lukem 	struct option *o;
   2664   1.76     lukem 
   2665   1.76     lukem 	code = -1;
   2666   1.88     lukem 	if (argc == 0 || argc != 2) {
   2667  1.116  christos 		UPRINTF("usage: %s option\n", argv[0]);
   2668   1.76     lukem 		return;
   2669   1.76     lukem 	}
   2670   1.76     lukem 
   2671   1.76     lukem 	o = getoption(argv[1]);
   2672   1.76     lukem 	if (o == NULL) {
   2673   1.76     lukem 		fprintf(ttyout, "No such option `%s'.\n", argv[1]);
   2674   1.76     lukem 		return;
   2675   1.76     lukem 	}
   2676   1.76     lukem 	FREEPTR(o->value);
   2677   1.76     lukem 	fprintf(ttyout, "Unsetting `%s'.\n", o->name);
   2678   1.76     lukem 	code = 0;
   2679   1.88     lukem }
   2680   1.88     lukem 
   2681   1.88     lukem /*
   2682   1.88     lukem  * Display features supported by the remote host.
   2683   1.88     lukem  */
   2684   1.88     lukem void
   2685   1.88     lukem feat(int argc, char *argv[])
   2686   1.88     lukem {
   2687   1.88     lukem 	int oldverbose = verbose;
   2688   1.88     lukem 
   2689   1.88     lukem 	if (argc == 0) {
   2690  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   2691   1.88     lukem 		code = -1;
   2692   1.88     lukem 		return;
   2693   1.88     lukem 	}
   2694   1.88     lukem 	if (! features[FEAT_FEAT]) {
   2695   1.88     lukem 		fprintf(ttyout,
   2696   1.88     lukem 		    "FEAT is not supported by the remote server.\n");
   2697   1.88     lukem 		return;
   2698   1.88     lukem 	}
   2699   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2700   1.88     lukem 	(void)command("FEAT");
   2701   1.88     lukem 	verbose = oldverbose;
   2702   1.88     lukem }
   2703   1.88     lukem 
   2704   1.88     lukem void
   2705   1.88     lukem mlst(int argc, char *argv[])
   2706   1.88     lukem {
   2707   1.88     lukem 	int oldverbose = verbose;
   2708   1.88     lukem 
   2709   1.88     lukem 	if (argc < 1 || argc > 2) {
   2710  1.116  christos 		UPRINTF("usage: %s [remote-path]\n", argv[0]);
   2711   1.88     lukem 		code = -1;
   2712   1.88     lukem 		return;
   2713   1.88     lukem 	}
   2714   1.88     lukem 	if (! features[FEAT_MLST]) {
   2715   1.88     lukem 		fprintf(ttyout,
   2716   1.88     lukem 		    "MLST is not supported by the remote server.\n");
   2717   1.88     lukem 		return;
   2718   1.88     lukem 	}
   2719   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2720   1.91        is 	COMMAND_1ARG(argc, argv, "MLST");
   2721   1.88     lukem 	verbose = oldverbose;
   2722   1.88     lukem }
   2723   1.88     lukem 
   2724   1.88     lukem void
   2725   1.88     lukem opts(int argc, char *argv[])
   2726   1.88     lukem {
   2727   1.88     lukem 	int oldverbose = verbose;
   2728   1.88     lukem 
   2729   1.88     lukem 	if (argc < 2 || argc > 3) {
   2730  1.116  christos 		UPRINTF("usage: %s command [options]\n", argv[0]);
   2731   1.88     lukem 		code = -1;
   2732   1.88     lukem 		return;
   2733   1.88     lukem 	}
   2734   1.88     lukem 	if (! features[FEAT_FEAT]) {
   2735   1.88     lukem 		fprintf(ttyout,
   2736   1.88     lukem 		    "OPTS is not supported by the remote server.\n");
   2737   1.88     lukem 		return;
   2738   1.88     lukem 	}
   2739   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2740   1.91        is 	if (argc == 2)
   2741   1.91        is 		command("OPTS %s", argv[1]);
   2742   1.91        is 	else
   2743   1.91        is 		command("OPTS %s %s", argv[1], argv[2]);
   2744   1.88     lukem 	verbose = oldverbose;
   2745    1.1       cgd }
   2746