summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2009-05-05 19:35:31 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2009-05-05 19:35:31 +0000
commitfc00281133cda43c13f628083337636552178c5b (patch)
tree71067df8a22d8351c6157bb713b7282529d9dfae
parent9ba9fea3f98a262c162ae879fc06dcddc33ad2af (diff)
make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit agreed by millert@, krw@ ok theo, sthen@
-rw-r--r--usr.bin/ftp/Makefile6
-rw-r--r--usr.bin/ftp/cmds.c681
-rw-r--r--usr.bin/ftp/cmds.h84
-rw-r--r--usr.bin/ftp/cmdtab.c36
-rw-r--r--usr.bin/ftp/complete.c5
-rw-r--r--usr.bin/ftp/cookie.c5
-rw-r--r--usr.bin/ftp/domacro.c3
-rw-r--r--usr.bin/ftp/extern.h139
-rw-r--r--usr.bin/ftp/fetch.c8
-rw-r--r--usr.bin/ftp/ftp_var.h5
-rw-r--r--usr.bin/ftp/list.c5
-rw-r--r--usr.bin/ftp/main.c51
-rw-r--r--usr.bin/ftp/ruserpass.c4
-rw-r--r--usr.bin/ftp/small.c723
-rw-r--r--usr.bin/ftp/small.h35
-rw-r--r--usr.bin/ftp/stringlist.c7
-rw-r--r--usr.bin/ftp/stringlist.h7
-rw-r--r--usr.bin/ftp/util.c11
18 files changed, 949 insertions, 866 deletions
diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile
index a08c78af65f..876cb494f4e 100644
--- a/usr.bin/ftp/Makefile
+++ b/usr.bin/ftp/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.24 2009/01/05 18:51:49 martynas Exp $
+# $OpenBSD: Makefile,v 1.25 2009/05/05 19:35:30 martynas Exp $
# Define SMALL to disable command line editing and https support
#CFLAGS+=-DSMALL
@@ -12,8 +12,8 @@ LDADD += -L/usr/local/lib -lsocks
.endif
PROG= ftp
-SRCS= cmds.c cmdtab.c complete.c cookie.c domacro.c fetch.c ftp.c list.c \
- main.c ruserpass.c stringlist.c util.c
+SRCS= cmds.c cmdtab.c complete.c cookie.c domacro.c fetch.c ftp.c \
+ list.c main.c ruserpass.c small.c stringlist.c util.c
CPPFLAGS+= -DINET6
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index d050003c2dc..ec6e99357b2 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmds.c,v 1.69 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: cmds.c,v 1.70 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */
/*
@@ -59,6 +59,8 @@
* SUCH DAMAGE.
*/
+#ifndef SMALL
+
/*
* FTP User Program -- Command Routines.
*/
@@ -70,9 +72,7 @@
#include <ctype.h>
#include <err.h>
-#ifndef SMALL
#include <fnmatch.h>
-#endif /* !SMALL */
#include <glob.h>
#include <netdb.h>
#include <stdio.h>
@@ -82,124 +82,7 @@
#include "ftp_var.h"
#include "pathnames.h"
-
-jmp_buf jabort;
-char *mname;
-char *home = "/";
-
-struct types {
- char *t_name;
- char *t_mode;
- int t_type;
- char *t_arg;
-} types[] = {
- { "ascii", "A", TYPE_A, 0 },
- { "binary", "I", TYPE_I, 0 },
- { "image", "I", TYPE_I, 0 },
- { "ebcdic", "E", TYPE_E, 0 },
- { "tenex", "L", TYPE_L, bytename },
- { NULL }
-};
-
-/*
- * Set transfer type.
- */
-void
-settype(int argc, char *argv[])
-{
- struct types *p;
- int comret;
-
- if (argc > 2) {
- char *sep;
-
- fprintf(ttyout, "usage: %s [", argv[0]);
- sep = "";
- for (p = types; p->t_name; p++) {
- fprintf(ttyout, "%s%s", sep, p->t_name);
- sep = " | ";
- }
- fputs("]\n", ttyout);
- code = -1;
- return;
- }
- if (argc < 2) {
- fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
- code = 0;
- return;
- }
- for (p = types; p->t_name; p++)
- if (strcmp(argv[1], p->t_name) == 0)
- break;
- if (p->t_name == 0) {
- fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
- code = -1;
- return;
- }
- if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
- comret = command("TYPE %s %s", p->t_mode, p->t_arg);
- else
- comret = command("TYPE %s", p->t_mode);
- if (comret == COMPLETE) {
- (void)strlcpy(typename, p->t_name, sizeof typename);
- curtype = type = p->t_type;
- }
-}
-
-/*
- * Internal form of settype; changes current type in use with server
- * without changing our notion of the type for data transfers.
- * Used to change to and from ascii for listings.
- */
-void
-changetype(int newtype, int show)
-{
- struct types *p;
- int comret, oldverbose = verbose;
-
- if (newtype == 0)
- newtype = TYPE_I;
- if (newtype == curtype)
- return;
- if (
-#ifndef SMALL
- !debug &&
-#endif /* !SMALL */
- show == 0)
- verbose = 0;
- for (p = types; p->t_name; p++)
- if (newtype == p->t_type)
- break;
- if (p->t_name == 0) {
- warnx("internal error: unknown type %d.", newtype);
- return;
- }
- if (newtype == TYPE_L && bytename[0] != '\0')
- comret = command("TYPE %s %s", p->t_mode, bytename);
- else
- comret = command("TYPE %s", p->t_mode);
- if (comret == COMPLETE)
- curtype = newtype;
- verbose = oldverbose;
-}
-
-char *stype[] = {
- "type",
- "",
- 0
-};
-
-/*
- * Set binary transfer type.
- */
-/*ARGSUSED*/
-void
-setbinary(int argc, char *argv[])
-{
-
- stype[1] = "binary";
- settype(2, stype);
-}
+#include "cmds.h"
/*
* Set ascii transfer type.
@@ -261,28 +144,23 @@ setstruct(int argc, char *argv[])
code = -1;
}
-#ifndef SMALL
void
reput(int argc, char *argv[])
{
(void)putit(argc, argv, 1);
}
-#endif /* !SMALL */
-#ifndef SMALL
void
put(int argc, char *argv[])
{
(void)putit(argc, argv, 0);
}
-#endif /* !SMALL */
/*
* Send a single file.
*/
-#ifndef SMALL
void
putit(int argc, char *argv[], int restartit)
{
@@ -317,7 +195,6 @@ usage:
if (argv[1] != oldargv1 && argv[2] == oldargv1) {
argv[2] = argv[1];
}
-#ifndef SMALL
if (restartit == 1) {
if (curtype != type)
changetype(type, 0);
@@ -328,7 +205,6 @@ usage:
return;
}
}
-#endif /* !SMALL */
if (strcmp(argv[0], "append") == 0) {
restartit = 1;
}
@@ -345,12 +221,10 @@ usage:
if (oldargv1 != argv[1]) /* free up after globulize() */
free(argv[1]);
}
-#endif /* !SMALL */
/*
* Send multiple files.
*/
-#ifndef SMALL
void
mput(int argc, char *argv[])
{
@@ -361,7 +235,6 @@ mput(int argc, char *argv[])
optind = optreset = 1;
-#ifndef SMALL
while ((ch = getopt(argc, argv, "c")) != -1) {
switch(ch) {
case 'c':
@@ -371,7 +244,6 @@ mput(int argc, char *argv[])
goto usage;
}
}
-#endif /* !SMALL */
if (argc - optind < 1 && !another(&argc, &argv, "local-files")) {
usage:
@@ -380,11 +252,9 @@ usage:
return;
}
-#ifndef SMALL
argv[optind - 1] = argv[0];
argc -= optind - 1;
argv += optind - 1;
-#endif /* !SMALL */
mname = argv[0];
mflag = 1;
@@ -425,7 +295,6 @@ usage:
if (mapflag) {
tp = domap(tp);
}
-#ifndef SMALL
if (restartit == 1) {
off_t ret;
@@ -434,7 +303,6 @@ usage:
ret = remotesize(tp, 0);
restart_point = (ret < 0) ? 0 : ret;
}
-#endif /* !SMALL */
cmd = restartit ? "APPE" : ((sunique) ?
"STOU" : "STOR");
sendrequest(cmd, cp, tp,
@@ -459,7 +327,6 @@ usage:
if (mflag && confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
tp = (mapflag) ? domap(tp) : tp;
-#ifndef SMALL
if (restartit == 1) {
off_t ret;
@@ -468,7 +335,6 @@ usage:
ret = remotesize(tp, 0);
restart_point = (ret < 0) ? 0 : ret;
}
-#endif /* !SMALL */
cmd = restartit ? "APPE" : ((sunique) ?
"STOU" : "STOR");
sendrequest(cmd, argv[i], tp,
@@ -493,7 +359,6 @@ usage:
if (mflag && confirm(argv[0], *cpp)) {
tp = (ntflag) ? dotrans(*cpp) : *cpp;
tp = (mapflag) ? domap(tp) : tp;
-#ifndef SMALL
if (restartit == 1) {
off_t ret;
@@ -502,7 +367,6 @@ usage:
ret = remotesize(tp, 0);
restart_point = (ret < 0) ? 0 : ret;
}
-#endif /* !SMALL */
cmd = restartit ? "APPE" : ((sunique) ?
"STOU" : "STOR");
sendrequest(cmd, *cpp, tp,
@@ -519,286 +383,13 @@ usage:
(void)signal(SIGINT, oldintr);
mflag = 0;
}
-#endif /* !SMALL */
-#ifndef SMALL
void
reget(int argc, char *argv[])
{
(void)getit(argc, argv, 1, "a+w");
}
-#endif /* !SMALL */
-
-void
-get(int argc, char *argv[])
-{
-
- (void)getit(argc, argv, 0, restart_point ? "a+w" : "w" );
-}
-
-/*
- * Receive one file.
- */
-int
-getit(int argc, char *argv[], int restartit, const char *mode)
-{
- int loc = 0;
- int rval = 0;
- char *oldargv1, *oldargv2, *globargv2;
-
- if (argc == 2) {
- argc++;
- argv[2] = argv[1];
- loc++;
- }
- if (argc < 2 && !another(&argc, &argv, "remote-file"))
- goto usage;
- if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
-usage:
- fprintf(ttyout, "usage: %s remote-file [local-file]\n",
- argv[0]);
- code = -1;
- return (0);
- }
- oldargv1 = argv[1];
- oldargv2 = argv[2];
- if (!globulize(&argv[2])) {
- code = -1;
- return (0);
- }
- globargv2 = argv[2];
- if (loc && mcase) {
- char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
-
- while (*tp && !islower(*tp)) {
- tp++;
- }
- if (!*tp) {
- tp = argv[2];
- tp2 = tmpbuf;
- while ((*tp2 = *tp) != '\0') {
- if (isupper(*tp2)) {
- *tp2 = tolower(*tp2);
- }
- tp++;
- tp2++;
- }
- argv[2] = tmpbuf;
- }
- }
- if (loc && ntflag)
- argv[2] = dotrans(argv[2]);
- if (loc && mapflag)
- argv[2] = domap(argv[2]);
-#ifndef SMALL
- if (restartit) {
- struct stat stbuf;
- int ret;
-
- ret = stat(argv[2], &stbuf);
- if (restartit == 1) {
- restart_point = (ret < 0) ? 0 : stbuf.st_size;
- } else {
- if (ret == 0) {
- time_t mtime;
-
- mtime = remotemodtime(argv[1], 0);
- if (mtime == -1)
- goto freegetit;
- if (stbuf.st_mtime >= mtime) {
- rval = 1;
- goto freegetit;
- }
- }
- }
- }
-#endif /* !SMALL */
-
- recvrequest("RETR", argv[2], argv[1], mode,
- argv[1] != oldargv1 || argv[2] != oldargv2 || !interactive, loc);
- restart_point = 0;
-freegetit:
- if (oldargv2 != globargv2) /* free up after globulize() */
- free(globargv2);
- return (rval);
-}
-
-/* XXX - Signal race. */
-/* ARGSUSED */
-void
-mabort(int signo)
-{
- alarmtimer(0);
- putc('\n', ttyout);
- (void)fflush(ttyout);
- if (mflag && fromatty)
- if (confirm(mname, NULL))
- longjmp(jabort, 1);
- mflag = 0;
- longjmp(jabort, 1);
-}
-
-/*
- * Get multiple files.
- */
-void
-mget(int argc, char *argv[])
-{
- extern int optind, optreset;
- sig_t oldintr;
- int ch, xargc = 2;
- char *cp, localcwd[MAXPATHLEN], *xargv[] = {argv[0], NULL, NULL};
- static int restartit = 0;
-#ifndef SMALL
- extern char *optarg;
- const char *errstr;
- int i = 1;
- char type = NULL, *dummyargv[] = {argv[0], ".", NULL};
- FILE *ftemp = NULL;
- static int depth = 0, max_depth = 0;
-#endif /* !SMALL */
-
- optind = optreset = 1;
-
-#ifndef SMALL
-
- if (depth)
- depth++;
-
- while ((ch = getopt(argc, argv, "cd:nr")) != -1) {
- switch(ch) {
- case 'c':
- restartit = 1;
- break;
- case 'd':
- max_depth = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL) {
- fprintf(ttyout, "bad depth value, %s: %s\n",
- errstr, optarg);
- code = -1;
- return;
- }
- break;
- case 'n':
- restartit = -1;
- break;
- case 'r':
- depth = 1;
- break;
- default:
- goto usage;
- }
- }
-#endif /* !SMALL */
-
- if (argc - optind < 1 && !another(&argc, &argv, "remote-files")) {
-usage:
- fprintf(ttyout, "usage: %s [-cnr] [-d depth] remote-files\n",
- argv[0]);
- code = -1;
- return;
- }
-
-#ifndef SMALL
- argv[optind - 1] = argv[0];
- argc -= optind - 1;
- argv += optind - 1;
-#endif /* !SMALL */
-
- mname = argv[0];
- mflag = 1;
- if (getcwd(localcwd, sizeof(localcwd)) == NULL)
- err(1, "can't get cwd");
-
- oldintr = signal(SIGINT, mabort);
- (void)setjmp(jabort);
- while ((cp =
-#ifndef SMALL
- depth ? remglob2(dummyargv, proxy, NULL, &ftemp, &type) :
-#endif /* !SMALL */
- remglob(argv, proxy, NULL)) != NULL
-#ifndef SMALL
- || (mflag && depth && ++i < argc)
-#endif /* !SMALL */
- ) {
-#ifndef SMALL
- if (cp == NULL)
- continue;
-#endif /* !SMALL */
- if (*cp == '\0') {
- mflag = 0;
- continue;
- }
- if (!mflag)
- continue;
-#ifndef SMALL
- if (depth && fnmatch(argv[i], cp, FNM_PATHNAME) != 0)
- continue;
-#endif /* !SMALL */
- if (!fileindir(cp, localcwd)) {
- fprintf(ttyout, "Skipping non-relative filename `%s'\n",
- cp);
- continue;
- }
-#ifndef SMALL
- if (type == 'd' && depth == max_depth)
- continue;
-#endif /* !SMALL */
- if (confirm(argv[0], cp)) {
-#ifndef SMALL
- if (type == 'd') {
- mkdir(cp, 0755);
- if (chdir(cp) != 0) {
- warn("local: %s", cp);
- continue;
- }
-
- xargv[1] = cp;
- cd(xargc, xargv);
- if (dirchange != 1)
- goto out;
-
- xargv[1] = "*";
- mget(xargc, xargv);
-
- xargv[1] = "..";
- cd(xargc, xargv);
- if (dirchange != 1) {
- mflag = 0;
- goto out;
- }
-
-out:
- if (chdir("..") != 0) {
- warn("local: %s", cp);
- mflag = 0;
- }
- continue;
- }
- if (type == 's')
- /* Currently ignored. */
- continue;
-#endif /* !SMALL */
- xargv[1] = cp;
- (void)getit(xargc, xargv, restartit,
- (restartit == 1 || restart_point) ? "a+w" : "w");
- if (!mflag && fromatty) {
- if (confirm(argv[0], NULL))
- mflag = 1;
- }
- }
- }
- (void)signal(SIGINT, oldintr);
-#ifndef SMALL
- if (depth)
- depth--;
- if (depth == 0 || mflag == 0)
- depth = max_depth = mflag = restartit = 0;
-#else /* !SMALL */
- mflag = 0;
-#endif /* !SMALL */
-}
char *
onoff(int bool)
@@ -861,7 +452,6 @@ status(int argc, char *argv[])
fprintf(ttyout, "Use of PORT/LPRT cmds: %s.\n", onoff(sendport));
fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
epsv4bad ? " (disabled for this connection)" : "");
-#ifndef SMALL
fprintf(ttyout, "Command line editing: %s.\n", onoff(editing));
if (macnum > 0) {
fputs("Macros:\n", ttyout);
@@ -869,7 +459,6 @@ status(int argc, char *argv[])
fprintf(ttyout, "\t%s\n", macros[i].mac_name);
}
}
-#endif /* !SMALL */
code = 0;
}
@@ -908,7 +497,6 @@ setbell(int argc, char *argv[])
/*
* Set command line editing
*/
-#ifndef SMALL
/*ARGSUSED*/
void
setedit(int argc, char *argv[])
@@ -917,7 +505,6 @@ setedit(int argc, char *argv[])
code = togglevar(argc, argv, &editing, "Editing mode");
controlediting();
}
-#endif /* !SMALL */
/*
* Toggle use of IPv4 EPSV/EPRT
@@ -1093,7 +680,6 @@ setpreserve(int argc, char *argv[])
/*
* Set debugging mode on/off and/or set level of debugging.
*/
-#ifndef SMALL
/*ARGSUSED*/
void
setdebug(int argc, char *argv[])
@@ -1129,35 +715,6 @@ setdebug(int argc, char *argv[])
fprintf(ttyout, "Debugging %s (debug=%d).\n", onoff(debug), debug);
code = debug > 0;
}
-#endif /* !SMALL */
-
-/*
- * Set current working directory on remote machine.
- */
-void
-cd(int argc, char *argv[])
-{
- int r;
-
- if ((argc < 2 && !another(&argc, &argv, "remote-directory")) ||
- argc > 2) {
- fprintf(ttyout, "usage: %s remote-directory\n", argv[0]);
- code = -1;
- return;
- }
- r = command("CWD %s", argv[1]);
- if (r == ERROR && code == 500) {
- if (verbose)
- fputs("CWD command not recognized, trying XCWD.\n", ttyout);
- r = command("XCWD %s", argv[1]);
- }
- if (r == ERROR && code == 550) {
- dirchange = 0;
- return;
- }
- if (r == COMPLETE)
- dirchange = 1;
-}
/*
* Set current working directory on local machine.
@@ -1378,13 +935,11 @@ shell(int argc, char *argv[])
(void)strlcpy(shellnam + 1, ++namep, sizeof(shellnam) - 1);
if (strcmp(namep, "sh") != 0)
shellnam[0] = '+';
-#ifndef SMALL
if (debug) {
fputs(shellp, ttyout);
fputc('\n', ttyout);
(void)fflush(ttyout);
}
-#endif /* !SMALL */
if (argc > 1) {
execl(shellp, shellnam, "-c", altarg, (char *)0);
}
@@ -1671,30 +1226,6 @@ quit(int argc, char *argv[])
exit(0);
}
-/*
- * Terminate session, but don't exit.
- */
-/* ARGSUSED */
-void
-disconnect(int argc, char *argv[])
-{
-
- if (!connected)
- return;
- (void)command("QUIT");
- if (cout) {
- (void)fclose(cout);
- }
- cout = NULL;
- connected = 0;
- data = -1;
-#ifndef SMALL
- if (!proxy) {
- macnum = 0;
- }
-#endif /* !SMALL */
-}
-
void
account(int argc, char *argv[])
{
@@ -1825,34 +1356,6 @@ setntrans(int argc, char *argv[])
(void)strlcpy(ntout, argv[2], sizeof(ntout));
}
-char *
-dotrans(char *name)
-{
- static char new[MAXPATHLEN];
- char *cp1, *cp2 = new;
- int i, ostop, found;
-
- for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
- continue;
- for (cp1 = name; *cp1; cp1++) {
- found = 0;
- for (i = 0; *(ntin + i) && i < 16; i++) {
- if (*cp1 == *(ntin + i)) {
- found++;
- if (i < ostop) {
- *cp2++ = *(ntout + i);
- }
- break;
- }
- }
- if (!found) {
- *cp2++ = *cp1;
- }
- }
- *cp2 = '\0';
- return (new);
-}
-
void
setnmap(int argc, char *argv[])
{
@@ -1885,177 +1388,6 @@ setnmap(int argc, char *argv[])
(void)strncpy(mapout, cp, MAXPATHLEN - 1);
}
-char *
-domap(char *name)
-{
- static char new[MAXPATHLEN];
- char *cp1 = name, *cp2 = mapin;
- char *tp[9], *te[9];
- int i, toks[9], toknum = 0, match = 1;
-
- for (i=0; i < 9; ++i) {
- toks[i] = 0;
- }
- while (match && *cp1 && *cp2) {
- switch (*cp2) {
- case '\\':
- if (*++cp2 != *cp1) {
- match = 0;
- }
- break;
- case '$':
- if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
- if (*cp1 != *(++cp2+1)) {
- toks[toknum = *cp2 - '1']++;
- tp[toknum] = cp1;
- while (*++cp1 && *(cp2+1)
- != *cp1);
- te[toknum] = cp1;
- }
- cp2++;
- break;
- }
- /* FALLTHROUGH */
- default:
- if (*cp2 != *cp1) {
- match = 0;
- }
- break;
- }
- if (match && *cp1) {
- cp1++;
- }
- if (match && *cp2) {
- cp2++;
- }
- }
- if (!match && *cp1) /* last token mismatch */
- {
- toks[toknum] = 0;
- }
- cp1 = new;
- *cp1 = '\0';
- cp2 = mapout;
- while (*cp2) {
- match = 0;
- switch (*cp2) {
- case '\\':
- if (*(cp2 + 1)) {
- *cp1++ = *++cp2;
- }
- break;
- case '[':
-LOOP:
- if (*++cp2 == '$' && isdigit(*(cp2+1))) {
- if (*++cp2 == '0') {
- char *cp3 = name;
-
- while (*cp3) {
- *cp1++ = *cp3++;
- }
- match = 1;
- }
- else if (toks[toknum = *cp2 - '1']) {
- char *cp3 = tp[toknum];
-
- while (cp3 != te[toknum]) {
- *cp1++ = *cp3++;
- }
- match = 1;
- }
- }
- else {
- while (*cp2 && *cp2 != ',' &&
- *cp2 != ']') {
- if (*cp2 == '\\') {
- cp2++;
- }
- else if (*cp2 == '$' &&
- isdigit(*(cp2+1))) {
- if (*++cp2 == '0') {
- char *cp3 = name;
-
- while (*cp3) {
- *cp1++ = *cp3++;
- }
- }
- else if (toks[toknum =
- *cp2 - '1']) {
- char *cp3=tp[toknum];
-
- while (cp3 !=
- te[toknum]) {
- *cp1++ = *cp3++;
- }
- }
- }
- else if (*cp2) {
- *cp1++ = *cp2++;
- }
- }
- if (!*cp2) {
- fputs(
-"nmap: unbalanced brackets.\n", ttyout);
- return (name);
- }
- match = 1;
- cp2--;
- }
- if (match) {
- while (*++cp2 && *cp2 != ']') {
- if (*cp2 == '\\' && *(cp2 + 1)) {
- cp2++;
- }
- }
- if (!*cp2) {
- fputs(
-"nmap: unbalanced brackets.\n", ttyout);
- return (name);
- }
- break;
- }
- switch (*++cp2) {
- case ',':
- goto LOOP;
- case ']':
- break;
- default:
- cp2--;
- goto LOOP;
- }
- break;
- case '$':
- if (isdigit(*(cp2 + 1))) {
- if (*++cp2 == '0') {
- char *cp3 = name;
-
- while (*cp3) {
- *cp1++ = *cp3++;
- }
- }
- else if (toks[toknum = *cp2 - '1']) {
- char *cp3 = tp[toknum];
-
- while (cp3 != te[toknum]) {
- *cp1++ = *cp3++;
- }
- }
- break;
- }
- /* FALLTHROUGH */
- default:
- *cp1++ = *cp2;
- break;
- }
- cp2++;
- }
- *cp1 = '\0';
- if (!*new) {
- return (name);
- }
- return (new);
-}
-
void
setpassive(int argc, char *argv[])
{
@@ -2130,7 +1462,6 @@ syst(int argc, char *argv[])
(void)command("SYST");
}
-#ifndef SMALL
void
macdef(int argc, char *argv[])
{
@@ -2188,7 +1519,6 @@ macdef(int argc, char *argv[])
}
}
}
-#endif /* !SMALL */
/*
* Get size of file on remote machine
@@ -2287,3 +1617,6 @@ page(int argc, char *argv[])
if (oldargv1 != argv[1]) /* free up after globulize() */
free(argv[1]);
}
+
+#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/cmds.h b/usr.bin/ftp/cmds.h
new file mode 100644
index 00000000000..2d7740761b2
--- /dev/null
+++ b/usr.bin/ftp/cmds.h
@@ -0,0 +1,84 @@
+/* $OpenBSD: cmds.h,v 1.1 2009/05/05 19:35:30 martynas Exp $ */
+
+/*
+ * Copyright (c) 2009 Martynas Venckus <martynas@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+void setascii(int, char **);
+void settenex(int, char **);
+void setftmode(int, char **);
+void setform(int, char **);
+void setstruct(int, char **);
+void reput(int, char **);
+void put(int, char **);
+void putit(int, char **, int);
+void mput(int, char **);
+void reget(int, char **);
+char *onoff(int);
+void status(int, char **);
+int togglevar(int, char **, int *, const char *);
+void setbell(int, char **);
+void setedit(int, char **);
+void setepsv4(int, char **);
+void settrace(int, char **);
+void sethash(int, char **);
+void setverbose(int, char **);
+void setport(int, char **);
+void setprogress(int, char **);
+void setprompt(int, char **);
+void setgate(int, char **);
+void setglob(int, char **);
+void setpreserve(int, char **);
+void setdebug(int, char **);
+void lcd(int, char **);
+void deletecmd(int, char **);
+void mdelete(int, char **);
+void renamefile(int, char **);
+void ls(int, char **);
+void mls(int, char **);
+void shell(int, char **);
+void user(int, char **);
+void pwd(int, char **);
+void lpwd(int, char **);
+void makedir(int, char **);
+void removedir(int, char **);
+void quote(int, char **);
+void site(int, char **);
+void quote1(const char *, int, char **);
+void do_chmod(int, char **);
+void do_umask(int, char **);
+void idle(int, char **);
+void rmthelp(int, char **);
+void quit(int, char **);
+void account(int, char **);
+void proxabort(int);
+void doproxy(int, char **);
+void setcase(int, char **);
+void setcr(int, char **);
+void setntrans(int, char **);
+void setnmap(int, char **);
+void setpassive(int, char **);
+void setsunique(int, char **);
+void setrunique(int, char **);
+void cdup(int, char **);
+void restart(int, char **);
+void syst(int, char **);
+void macdef(int, char **);
+void sizecmd(int, char **);
+void modtime(int, char **);
+void rmtstatus(int, char **);
+void newer(int, char **);
+void page(int, char **);
+
diff --git a/usr.bin/ftp/cmdtab.c b/usr.bin/ftp/cmdtab.c
index b96a9004e26..49bf88f8b01 100644
--- a/usr.bin/ftp/cmdtab.c
+++ b/usr.bin/ftp/cmdtab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmdtab.c,v 1.25 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: cmdtab.c,v 1.26 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: cmdtab.c,v 1.17 1997/08/18 10:20:17 lukem Exp $ */
/*
@@ -30,14 +30,16 @@
* SUCH DAMAGE.
*/
+#ifndef SMALL
+
#include <stdio.h>
#include "ftp_var.h"
+#include "cmds.h"
/*
* User FTP -- Command Tables.
*/
-#ifndef SMALL
char accounthelp[] = "send account command to remote server";
char appendhelp[] = "append to a file";
char asciihelp[] = "set ascii transfer type";
@@ -115,29 +117,18 @@ char typehelp[] = "set file transfer type";
char umaskhelp[] = "get (set) umask on remote side";
char userhelp[] = "send new user information";
char verbosehelp[] = "toggle verbose mode";
-#endif /* !SMALL */
char empty[] = "";
-#ifdef SMALL
-#define CMPL(x)
-#define CMPL0
-#define H(x) empty
-#else /* SMALL */
#define CMPL(x) __STRING(x),
#define CMPL0 "",
#define H(x) x
-#endif /* SMALL */
struct cmd cmdtab[] = {
{ "!", H(shellhelp), 0, 0, 0, CMPL0 shell },
-#ifndef SMALL
{ "$", H(domachelp), 1, 0, 0, CMPL0 domacro },
-#endif /* !SMALL */
{ "account", H(accounthelp), 0, 1, 1, CMPL0 account},
-#ifndef SMALL
{ "append", H(appendhelp), 1, 1, 1, CMPL(lr) put },
-#endif /* !SMALL */
{ "ascii", H(asciihelp), 0, 1, 1, CMPL0 setascii },
{ "bell", H(beephelp), 0, 0, 0, CMPL0 setbell },
{ "binary", H(binaryhelp), 0, 1, 1, CMPL0 setbinary },
@@ -148,15 +139,11 @@ struct cmd cmdtab[] = {
{ "chmod", H(chmodhelp), 0, 1, 1, CMPL(nr) do_chmod },
{ "close", H(disconhelp), 0, 1, 1, CMPL0 disconnect },
{ "cr", H(crhelp), 0, 0, 0, CMPL0 setcr },
-#ifndef SMALL
{ "debug", H(debughelp), 0, 0, 0, CMPL0 setdebug },
-#endif /* !SMALL */
{ "delete", H(deletehelp), 0, 1, 1, CMPL(r) deletecmd },
{ "dir", H(dirhelp), 1, 1, 1, CMPL(rl) ls },
{ "disconnect", H(disconhelp), 0, 1, 1, CMPL0 disconnect },
-#ifndef SMALL
{ "edit", H(edithelp), 0, 0, 0, CMPL0 setedit },
-#endif /* !SMALL */
{ "epsv4", H(epsv4help), 0, 0, 0, CMPL0 setepsv4 },
{ "exit", H(quithelp), 0, 0, 0, CMPL0 quit },
{ "form", H(formhelp), 0, 1, 1, CMPL0 setform },
@@ -172,9 +159,7 @@ struct cmd cmdtab[] = {
{ "less", H(pagehelp), 1, 1, 1, CMPL(r) page },
{ "lpwd", H(lpwdhelp), 0, 0, 0, CMPL0 lpwd },
{ "ls", H(lshelp), 1, 1, 1, CMPL(rl) ls },
-#ifndef SMALL
{ "macdef", H(macdefhelp), 0, 0, 0, CMPL0 macdef },
-#endif /* !SMALL */
{ "mdelete", H(mdeletehelp), 1, 1, 1, CMPL(R) mdelete },
{ "mdir", H(mdirhelp), 1, 1, 1, CMPL(R) mls },
{ "mget", H(mgethelp), 1, 1, 1, CMPL(R) mget },
@@ -183,10 +168,8 @@ struct cmd cmdtab[] = {
{ "mode", H(modehelp), 0, 1, 1, CMPL0 setftmode },
{ "modtime", H(modtimehelp), 0, 1, 1, CMPL(r) modtime },
{ "more", H(pagehelp), 1, 1, 1, CMPL(r) page },
-#ifndef SMALL
{ "mput", H(mputhelp), 1, 1, 1, CMPL(L) mput },
{ "msend", H(mputhelp), 1, 1, 1, CMPL(L) mput },
-#endif /* !SMALL */
{ "newer", H(newerhelp), 1, 1, 1, CMPL(r) newer },
{ "nlist", H(nlisthelp), 1, 1, 1, CMPL(rl) ls },
{ "nmap", H(nmaphelp), 0, 0, 1, CMPL0 setnmap },
@@ -198,29 +181,21 @@ struct cmd cmdtab[] = {
{ "progress", H(progresshelp),0, 0, 0, CMPL0 setprogress },
{ "prompt", H(prompthelp), 0, 0, 0, CMPL0 setprompt },
{ "proxy", H(proxyhelp), 0, 0, 1, CMPL(c) doproxy },
-#ifndef SMALL
{ "put", H(sendhelp), 1, 1, 1, CMPL(lr) put },
-#endif /* !SMALL */
{ "pwd", H(pwdhelp), 0, 1, 1, CMPL0 pwd },
{ "quit", H(quithelp), 0, 0, 0, CMPL0 quit },
{ "quote", H(quotehelp), 1, 1, 1, CMPL0 quote },
{ "recv", H(receivehelp), 1, 1, 1, CMPL(rl) get },
-#ifndef SMALL
{ "reget", H(regethelp), 1, 1, 1, CMPL(rl) reget },
-#endif /* !SMALL */
{ "rename", H(renamehelp), 0, 1, 1, CMPL(rr) renamefile },
-#ifndef SMALL
{ "reput", H(reputhelp), 1, 1, 1, CMPL(lr) reput },
-#endif /* !SMALL */
{ "reset", H(resethelp), 0, 1, 1, CMPL0 reset },
{ "restart", H(restarthelp), 1, 1, 1, CMPL0 restart },
{ "rhelp", H(remotehelp), 0, 1, 1, CMPL0 rmthelp },
{ "rmdir", H(rmdirhelp), 0, 1, 1, CMPL(r) removedir },
{ "rstatus", H(rmtstatushelp),0, 1, 1, CMPL(r) rmtstatus },
{ "runique", H(runiquehelp), 0, 0, 1, CMPL0 setrunique },
-#ifndef SMALL
{ "send", H(sendhelp), 1, 1, 1, CMPL(lr) put },
-#endif /* !SMALL */
{ "sendport", H(porthelp), 0, 0, 0, CMPL0 setport },
{ "site", H(sitehelp), 0, 1, 1, CMPL0 site },
{ "size", H(sizecmdhelp), 1, 1, 1, CMPL(r) sizecmd },
@@ -239,3 +214,6 @@ struct cmd cmdtab[] = {
};
int NCMDS = (sizeof(cmdtab) / sizeof(cmdtab[0])) - 1;
+
+#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c
index 8acd8e907e5..aaedf2dbafc 100644
--- a/usr.bin/ftp/complete.c
+++ b/usr.bin/ftp/complete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: complete.c,v 1.22 2009/04/27 21:37:13 deraadt Exp $ */
+/* $OpenBSD: complete.c,v 1.23 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: complete.c,v 1.10 1997/08/18 10:20:18 lukem Exp $ */
/*-
@@ -231,10 +231,8 @@ complete_remote(char *word, int list)
mflag = 1;
emesg = NULL;
-#ifndef SMALL
if (debug)
(void)putc('\n', ttyout);
-#endif /* !SMALL */
while ((cp = remglob(dummyargv, 0, &emesg)) != NULL) {
char *tcp;
@@ -350,3 +348,4 @@ complete(EditLine *el, int ch)
}
#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/cookie.c b/usr.bin/ftp/cookie.c
index 9fde85a245d..266f24dbcd4 100644
--- a/usr.bin/ftp/cookie.c
+++ b/usr.bin/ftp/cookie.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: cookie.c,v 1.4 2008/12/07 21:12:07 cloder Exp $ */
+/* $OpenBSD: cookie.c,v 1.5 2009/05/05 19:35:30 martynas Exp $ */
+
/*
* Copyright (c) 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
*
@@ -16,6 +17,7 @@
*/
#ifndef SMALL
+
#include <sys/types.h>
#include <sys/queue.h>
@@ -226,3 +228,4 @@ cookie_get(const char *domain, const char *path, int secure, char **pstr)
}
#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/domacro.c b/usr.bin/ftp/domacro.c
index 69013024023..107708deb51 100644
--- a/usr.bin/ftp/domacro.c
+++ b/usr.bin/ftp/domacro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: domacro.c,v 1.16 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: domacro.c,v 1.17 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: domacro.c,v 1.10 1997/07/20 09:45:45 lukem Exp $ */
/*
@@ -146,3 +146,4 @@ TOP:
}
#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index fd6ec8b7bcc..56c47aea643 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.38 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: extern.h,v 1.39 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */
/*
@@ -63,161 +63,69 @@
#include <sys/types.h>
-void abort_remote(FILE *);
-void abortpt(int);
-void abortrecv(int);
-#ifndef SMALL
-void abortsend(int);
-#endif /* !SMALL */
-void account(int, char **);
+void abort_remote(FILE *);
+void abortpt(int);
+void abortrecv(int);
void alarmtimer(int);
int another(int *, char ***, const char *);
int auto_fetch(int, char **, char *);
void blkfree(char **);
-void cd(int, char **);
void cdup(int, char **);
-void changetype(int, int);
void cmdabort(int);
void cmdscanner(int);
int command(const char *, ...);
-#ifndef SMALL
-unsigned char complete(EditLine *, int);
-void controlediting(void);
-#endif /* !SMALL */
int confirm(const char *, const char *);
FILE *dataconn(const char *);
-void deletecmd(int, char **);
-void disconnect(int, char **);
-void do_chmod(int, char **);
-void do_umask(int, char **);
-#ifndef SMALL
-void domacro(int, char **);
-#endif /* !SMALL */
-char *domap(char *);
-void doproxy(int, char **);
-char *dotrans(char *);
int foregroundproc(void);
int fileindir(const char *, const char *);
-void get(int, char **);
struct cmd *getcmd(const char *);
-int getit(int, char **, int, const char *);
int getreply(int);
int globulize(char **);
char *gunique(const char *);
void help(int, char **);
char *hookup(char *, char *);
-void idle(int, char **);
-int initconn(void);
+int initconn(void);
void intr(void);
int isurl(const char *);
-void list_vertical(StringList *);
-void lcd(int, char **);
int ftp_login(const char *, char *, char *);
void lostpeer(void);
-void lpwd(int, char **);
-void ls(int, char **);
-void mabort(int);
-#ifndef SMALL
-void macdef(int, char **);
-#endif /* !SMALL */
void makeargv(void);
-void makedir(int, char **);
-void mdelete(int, char **);
-void mget(int, char **);
-void mls(int, char **);
-void modtime(int, char **);
-#ifndef SMALL
-void mput(int, char **);
-#endif /* !SMALL */
-char *onoff(int);
-void newer(int, char **);
-void page(int, char **);
-void progressmeter(int, const char *);
+void progressmeter(int, const char *);
char *prompt(void);
-void proxabort(int);
-void proxtrans(const char *, const char *, const char *);
-void psabort(int);
+void proxtrans(const char *, const char *, const char *);
+void psabort(int);
void psummary(int);
-void pswitch(int);
-void ptransfer(int);
-#ifndef SMALL
-void put(int, char **);
-void putit(int, char **, int);
-#endif /* !SMALL */
-void pwd(int, char **);
-void quit(int, char **);
-void quote(int, char **);
-void quote1(const char *, int, char **);
-void recvrequest(const char *, const char *, const char *,
+void pswitch(int);
+void ptransfer(int);
+void recvrequest(const char *, const char *, const char *,
const char *, int, int);
-void reget(int, char **);
char *remglob(char **, int, char **);
#ifndef SMALL
-char *remglob2(char **, int, char **, FILE **ftemp, char *type);
#endif /* !SMALL */
off_t remotesize(const char *, int);
time_t remotemodtime(const char *, int);
-void removedir(int, char **);
-void renamefile(int, char **);
-#ifndef SMALL
-void reput(int, char **);
-#endif /* !SMALL */
-void reset(int, char **);
-void restart(int, char **);
+void reset(int, char **);
void rmthelp(int, char **);
-void rmtstatus(int, char **);
-#ifndef SMALL
-void sendrequest(const char *, const char *, const char *, int);
-#endif /* !SMALL */
-void setascii(int, char **);
-void setbell(int, char **);
-void setbinary(int, char **);
-void setcase(int, char **);
-void setcr(int, char **);
-#ifndef SMALL
-void setdebug(int, char **);
-#endif /* !SMALL */
-void setedit(int, char **);
-void setepsv4(int, char **);
-void setform(int, char **);
-void setftmode(int, char **);
-void setgate(int, char **);
-void setglob(int, char **);
void sethash(int, char **);
-void setnmap(int, char **);
-void setntrans(int, char **);
-void setpassive(int, char **);
void setpeer(int, char **);
-void setport(int, char **);
-void setpreserve(int, char **);
-void setprogress(int, char **);
-void setprompt(int, char **);
-void setrunique(int, char **);
-void setstruct(int, char **);
-void setsunique(int, char **);
-void settenex(int, char **);
-void settrace(int, char **);
void setttywidth(int);
-void settype(int, char **);
-void setverbose(int, char **);
-void shell(int, char **);
-void site(int, char **);
-void sizecmd(int, char **);
char *slurpstring(void);
-void status(int, char **);
-void syst(int, char **);
-int togglevar(int, char **, int *, const char *);
void usage(void);
-void user(int, char **);
#ifndef SMALL
-int ruserpass(const char *, char **, char **, char **);
-void cookie_load(void);
+void abortsend(int);
+unsigned char complete(EditLine *, int);
+void controlediting(void);
void cookie_get(const char *, const char *, int, char **);
+void cookie_load(void);
+void domacro(int, char **);
+void list_vertical(StringList *);
void parse_list(char **, char *);
+char *remglob2(char **, int, char **, FILE **ftemp, char *type);
+int ruserpass(const char *, char **, char **, char **);
+void sendrequest(const char *, const char *, const char *, int);
#endif /* !SMALL */
-
extern jmp_buf abortprox;
extern int abrtflag;
extern struct cmd cmdtab[];
@@ -229,8 +137,11 @@ extern int family;
extern int proxy;
extern char reply_string[];
extern off_t restart_point;
-extern int NCMDS;
extern int keep_alive_timeout;
+#ifndef SMALL
+extern int NCMDS;
+#endif /* !SMALL */
+
extern char *__progname; /* from crt0.o */
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 4cc777d7d95..947589b7be6 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.85 2009/04/27 21:37:13 deraadt Exp $ */
+/* $OpenBSD: fetch.c,v 1.86 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -68,6 +68,7 @@
#endif /* !SMALL */
#include "ftp_var.h"
+#include "cmds.h"
static int url_get(const char *, const char *, const char *);
void aborthttp(int);
@@ -1045,7 +1046,12 @@ bad_ftp_url:
}
if (EMPTYSTRING(file)) {
+#ifndef SMALL
rval = -1;
+#else /* !SMALL */
+ recvrequest("NLST", "-", NULL, "w", 0, 0);
+ rval = 0;
+#endif /* !SMALL */
continue;
}
diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h
index ac5ec68981b..b2824f8ce27 100644
--- a/usr.bin/ftp/ftp_var.h
+++ b/usr.bin/ftp/ftp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp_var.h,v 1.28 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: ftp_var.h,v 1.29 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: ftp_var.h,v 1.18 1997/08/18 10:20:25 lukem Exp $ */
/*
@@ -79,6 +79,7 @@ int fclose(FILE *);
#include "stringlist.h"
#include "extern.h"
+#include "small.h"
#define HASHBYTES 1024
#define FTPBUFLEN MAXPATHLEN + 200
@@ -187,7 +188,9 @@ char line[FTPBUFLEN]; /* input line buffer */
char *stringbase; /* current scan point in line buffer */
char argbuf[FTPBUFLEN]; /* argument storage buffer */
char *argbase; /* current storage point in arg buffer */
+#ifndef SMALL
StringList *marg_sl; /* stringlist containing margv */
+#endif /* !SMALL */
int margc; /* count of arguments on input line */
#define margv (marg_sl->sl_str) /* args parsed from input line */
int cpend; /* flag: if != 0, then pending server reply */
diff --git a/usr.bin/ftp/list.c b/usr.bin/ftp/list.c
index 6f0befb997e..d0d9621875a 100644
--- a/usr.bin/ftp/list.c
+++ b/usr.bin/ftp/list.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: list.c,v 1.2 2008/10/21 17:54:00 martynas Exp $ */
+/* $OpenBSD: list.c,v 1.3 2009/05/05 19:35:30 martynas Exp $ */
+
/*
* Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
*
@@ -16,6 +17,7 @@
*/
#ifndef SMALL
+
#include <string.h>
void
@@ -75,3 +77,4 @@ parse_list(char **line, char *type)
}
#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index 32b78c18863..7f53dc531b1 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.76 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: main.c,v 1.77 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
@@ -76,6 +76,7 @@
#include <unistd.h>
#include "ftp_var.h"
+#include "cmds.h"
int family = PF_UNSPEC;
@@ -112,9 +113,9 @@ main(volatile int argc, char *argv[])
hist = NULL;
cookiefile = NULL;
resume = 0;
+ marg_sl = sl_init();
#endif /* !SMALL */
mark = HASHBYTES;
- marg_sl = sl_init();
#ifdef INET6
epsv4 = 1;
#else
@@ -318,6 +319,7 @@ main(volatile int argc, char *argv[])
if (rval >= 0) /* -1 == connected and cd-ed */
exit(rval);
} else {
+#ifndef SMALL
char *xargv[5];
if (setjmp(toplevel))
@@ -334,19 +336,17 @@ main(volatile int argc, char *argv[])
if (!retry_connect)
break;
if (!connected) {
-#ifndef SMALL
macnum = 0;
-#endif /* !SMALL */
fputs("Retrying...\n", ttyout);
sleep(retry_connect);
}
} while (!connected);
retry_connect = 0; /* connected, stop hiding msgs */
+#endif /* !SMALL */
}
}
#ifndef SMALL
controlediting();
-#endif /* !SMALL */
top = setjmp(toplevel) == 0;
if (top) {
(void)signal(SIGINT, (sig_t)intr);
@@ -356,6 +356,9 @@ main(volatile int argc, char *argv[])
cmdscanner(top);
top = 1;
}
+#else /* !SMALL */
+ usage();
+#endif /* !SMALL */
}
void
@@ -399,6 +402,7 @@ lostpeer(void)
errno = save_errno;
}
+#ifndef SMALL
/*
* Generate a prompt
*/
@@ -416,20 +420,12 @@ cmdscanner(int top)
{
struct cmd *c;
int num;
-#ifndef SMALL
HistEvent hev;
-#endif /* !SMALL */
- if (!top
-#ifndef SMALL
- && !editing
-#endif /* !SMALL */
- )
+ if (!top && !editing)
(void)putc('\n', ttyout);
for (;;) {
-#ifndef SMALL
if (!editing) {
-#endif /* !SMALL */
if (fromatty) {
fputs(prompt(), ttyout);
(void)fflush(ttyout);
@@ -449,7 +445,6 @@ cmdscanner(int top)
/* void */;
break;
} /* else it was a line without a newline */
-#ifndef SMALL
} else {
const char *buf;
cursor_pos = NULL;
@@ -468,7 +463,6 @@ cmdscanner(int top)
line[num] = '\0';
history(hist, &hev, H_ENTER, buf);
}
-#endif /* !SMALL */
makeargv();
if (margc == 0)
@@ -479,7 +473,6 @@ cmdscanner(int top)
continue;
}
if (c == 0) {
-#ifndef SMALL
/*
* Give editline(3) a shot at unknown commands.
* XXX - bogus commands with a colon in
@@ -487,7 +480,6 @@ cmdscanner(int top)
*/
if (editing &&
el_parse(el, margc, (const char **)margv) != 0)
-#endif /* !SMALL */
fputs("?Invalid command.\n", ttyout);
continue;
}
@@ -558,7 +550,6 @@ makeargv(void)
if (argp == NULL)
break;
}
-#ifndef SMALL
if (cursor_pos == line) {
cursor_argc = 0;
cursor_argo = 0;
@@ -566,20 +557,14 @@ makeargv(void)
cursor_argc = margc;
cursor_argo = strlen(margv[margc-1]);
}
-#endif /* !SMALL */
}
-#ifdef SMALL
-#define INC_CHKCURSOR(x) (x)++
-#else /* SMALL */
#define INC_CHKCURSOR(x) { (x)++ ; \
if (x == cursor_pos) { \
cursor_argc = margc; \
cursor_argo = ap-argbase; \
cursor_pos = NULL; \
} }
-
-#endif /* SMALL */
/*
* Parse string into argbuf;
@@ -753,19 +738,16 @@ help(int argc, char *argv[])
c->c_name, c->c_help);
}
}
+#endif /* !SMALL */
void
usage(void)
{
- (void)fprintf(stderr,
- "usage: %s [-46Aa"
+ (void)fprintf(stderr, "usage: %s "
#ifndef SMALL
- "d"
-#endif /* !SMALL */
- "EegimnptVv] [-k seconds] [-P port] [-r seconds] [host [port]]\n"
- " %s "
-#ifndef SMALL
- "[-C] "
+ "[-46AadEegimnptVv] [-k seconds] [-P port] "
+ "[-r seconds] [host [port]]\n"
+ " %s [-C] "
#endif /* !SMALL */
"[-o output] "
"ftp://[user:password@]host[:port]/file[/]\n"
@@ -787,7 +769,8 @@ usage(void)
#ifndef SMALL
__progname, __progname, __progname, __progname, __progname);
#else /* !SMALL */
- __progname, __progname, __progname, __progname);
+ __progname, __progname, __progname);
#endif /* !SMALL */
exit(1);
}
+
diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c
index bdb8e961181..3f52d6c523a 100644
--- a/usr.bin/ftp/ruserpass.c
+++ b/usr.bin/ftp/ruserpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruserpass.c,v 1.27 2009/04/27 21:37:13 deraadt Exp $ */
+/* $OpenBSD: ruserpass.c,v 1.28 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: ruserpass.c,v 1.14 1997/07/20 09:46:01 lukem Exp $ */
/*
@@ -312,4 +312,6 @@ token(void)
return (t->tval);
return (ID);
}
+
#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/small.c b/usr.bin/ftp/small.c
new file mode 100644
index 00000000000..ce31ef8b535
--- /dev/null
+++ b/usr.bin/ftp/small.c
@@ -0,0 +1,723 @@
+/* $OpenBSD: small.c,v 1.1 2009/05/05 19:35:30 martynas Exp $ */
+/* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */
+
+/*
+ * Copyright (C) 1997 and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1985, 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * FTP User Program -- Command Routines.
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <arpa/ftp.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <fnmatch.h>
+#include <glob.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "ftp_var.h"
+#include "pathnames.h"
+#include "small.h"
+
+jmp_buf jabort;
+char *mname;
+char *home = "/";
+
+struct types {
+ char *t_name;
+ char *t_mode;
+ int t_type;
+ char *t_arg;
+} types[] = {
+ { "ascii", "A", TYPE_A, 0 },
+ { "binary", "I", TYPE_I, 0 },
+ { "image", "I", TYPE_I, 0 },
+ { "ebcdic", "E", TYPE_E, 0 },
+ { "tenex", "L", TYPE_L, bytename },
+ { NULL }
+};
+
+/*
+ * Set transfer type.
+ */
+void
+settype(int argc, char *argv[])
+{
+ struct types *p;
+ int comret;
+
+ if (argc > 2) {
+ char *sep;
+
+ fprintf(ttyout, "usage: %s [", argv[0]);
+ sep = "";
+ for (p = types; p->t_name; p++) {
+ fprintf(ttyout, "%s%s", sep, p->t_name);
+ sep = " | ";
+ }
+ fputs("]\n", ttyout);
+ code = -1;
+ return;
+ }
+ if (argc < 2) {
+ fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
+ code = 0;
+ return;
+ }
+ for (p = types; p->t_name; p++)
+ if (strcmp(argv[1], p->t_name) == 0)
+ break;
+ if (p->t_name == 0) {
+ fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
+ code = -1;
+ return;
+ }
+ if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
+ comret = command("TYPE %s %s", p->t_mode, p->t_arg);
+ else
+ comret = command("TYPE %s", p->t_mode);
+ if (comret == COMPLETE) {
+ (void)strlcpy(typename, p->t_name, sizeof typename);
+ curtype = type = p->t_type;
+ }
+}
+
+/*
+ * Internal form of settype; changes current type in use with server
+ * without changing our notion of the type for data transfers.
+ * Used to change to and from ascii for listings.
+ */
+void
+changetype(int newtype, int show)
+{
+ struct types *p;
+ int comret, oldverbose = verbose;
+
+ if (newtype == 0)
+ newtype = TYPE_I;
+ if (newtype == curtype)
+ return;
+ if (
+#ifndef SMALL
+ !debug &&
+#endif /* !SMALL */
+ show == 0)
+ verbose = 0;
+ for (p = types; p->t_name; p++)
+ if (newtype == p->t_type)
+ break;
+ if (p->t_name == 0) {
+ warnx("internal error: unknown type %d.", newtype);
+ return;
+ }
+ if (newtype == TYPE_L && bytename[0] != '\0')
+ comret = command("TYPE %s %s", p->t_mode, bytename);
+ else
+ comret = command("TYPE %s", p->t_mode);
+ if (comret == COMPLETE)
+ curtype = newtype;
+ verbose = oldverbose;
+}
+
+char *stype[] = {
+ "type",
+ "",
+ 0
+};
+
+/*
+ * Set binary transfer type.
+ */
+/*ARGSUSED*/
+void
+setbinary(int argc, char *argv[])
+{
+
+ stype[1] = "binary";
+ settype(2, stype);
+}
+
+void
+get(int argc, char *argv[])
+{
+
+ (void)getit(argc, argv, 0, restart_point ? "a+w" : "w" );
+}
+
+/*
+ * Receive one file.
+ */
+int
+getit(int argc, char *argv[], int restartit, const char *mode)
+{
+ int loc = 0;
+ int rval = 0;
+ char *oldargv1, *oldargv2, *globargv2;
+
+ if (argc == 2) {
+ argc++;
+ argv[2] = argv[1];
+ loc++;
+ }
+#ifndef SMALL
+ if (argc < 2 && !another(&argc, &argv, "remote-file"))
+ goto usage;
+ if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
+usage:
+ fprintf(ttyout, "usage: %s remote-file [local-file]\n",
+ argv[0]);
+ code = -1;
+ return (0);
+ }
+#endif /* !SMALL */
+ oldargv1 = argv[1];
+ oldargv2 = argv[2];
+ if (!globulize(&argv[2])) {
+ code = -1;
+ return (0);
+ }
+ globargv2 = argv[2];
+ if (loc && mcase) {
+ char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
+
+ while (*tp && !islower(*tp)) {
+ tp++;
+ }
+ if (!*tp) {
+ tp = argv[2];
+ tp2 = tmpbuf;
+ while ((*tp2 = *tp) != '\0') {
+ if (isupper(*tp2)) {
+ *tp2 = tolower(*tp2);
+ }
+ tp++;
+ tp2++;
+ }
+ argv[2] = tmpbuf;
+ }
+ }
+ if (loc && ntflag)
+ argv[2] = dotrans(argv[2]);
+ if (loc && mapflag)
+ argv[2] = domap(argv[2]);
+#ifndef SMALL
+ if (restartit) {
+ struct stat stbuf;
+ int ret;
+
+ ret = stat(argv[2], &stbuf);
+ if (restartit == 1) {
+ restart_point = (ret < 0) ? 0 : stbuf.st_size;
+ } else {
+ if (ret == 0) {
+ time_t mtime;
+
+ mtime = remotemodtime(argv[1], 0);
+ if (mtime == -1)
+ goto freegetit;
+ if (stbuf.st_mtime >= mtime) {
+ rval = 1;
+ goto freegetit;
+ }
+ }
+ }
+ }
+#endif /* !SMALL */
+
+ recvrequest("RETR", argv[2], argv[1], mode,
+ argv[1] != oldargv1 || argv[2] != oldargv2 || !interactive, loc);
+ restart_point = 0;
+freegetit:
+ if (oldargv2 != globargv2) /* free up after globulize() */
+ free(globargv2);
+ return (rval);
+}
+
+/* XXX - Signal race. */
+/* ARGSUSED */
+void
+mabort(int signo)
+{
+ alarmtimer(0);
+ putc('\n', ttyout);
+ (void)fflush(ttyout);
+#ifndef SMALL
+ if (mflag && fromatty)
+ if (confirm(mname, NULL))
+ longjmp(jabort, 1);
+#endif /* !SMALL */
+ mflag = 0;
+ longjmp(jabort, 1);
+}
+
+/*
+ * Get multiple files.
+ */
+void
+mget(int argc, char *argv[])
+{
+ extern int optind, optreset;
+ sig_t oldintr;
+ int ch, xargc = 2;
+ char *cp, localcwd[MAXPATHLEN], *xargv[] = { argv[0], NULL, NULL };
+ static int restartit = 0;
+#ifndef SMALL
+ extern char *optarg;
+ const char *errstr;
+ int i = 1;
+ char type = 0, *dummyargv[] = { argv[0], ".", NULL };
+ FILE *ftemp = NULL;
+ static int depth = 0, max_depth = 0;
+
+ optind = optreset = 1;
+
+ if (depth)
+ depth++;
+
+ while ((ch = getopt(argc, argv, "cd:nr")) != -1) {
+ switch(ch) {
+ case 'c':
+ restartit = 1;
+ break;
+ case 'd':
+ max_depth = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ fprintf(ttyout, "bad depth value, %s: %s\n",
+ errstr, optarg);
+ code = -1;
+ return;
+ }
+ break;
+ case 'n':
+ restartit = -1;
+ break;
+ case 'r':
+ depth = 1;
+ break;
+ default:
+ goto usage;
+ }
+ }
+
+ if (argc - optind < 1 && !another(&argc, &argv, "remote-files")) {
+usage:
+ fprintf(ttyout, "usage: %s [-cnr] [-d depth] remote-files\n",
+ argv[0]);
+ code = -1;
+ return;
+ }
+
+ argv[optind - 1] = argv[0];
+ argc -= optind - 1;
+ argv += optind - 1;
+#endif /* !SMALL */
+
+ mname = argv[0];
+ mflag = 1;
+ if (getcwd(localcwd, sizeof(localcwd)) == NULL)
+ err(1, "can't get cwd");
+
+ oldintr = signal(SIGINT, mabort);
+ (void)setjmp(jabort);
+ while ((cp =
+#ifdef SMALL
+ remglob(argv, proxy, NULL)) != NULL
+ ) {
+#else /* SMALL */
+ depth ? remglob2(dummyargv, proxy, NULL, &ftemp, &type) :
+ remglob(argv, proxy, NULL)) != NULL
+ || (mflag && depth && ++i < argc)
+ ) {
+ if (cp == NULL)
+ continue;
+#endif /* SMALL */
+ if (*cp == '\0') {
+ mflag = 0;
+ continue;
+ }
+ if (!mflag)
+ continue;
+#ifndef SMALL
+ if (depth && fnmatch(argv[i], cp, FNM_PATHNAME) != 0)
+ continue;
+#endif /* !SMALL */
+ if (!fileindir(cp, localcwd)) {
+ fprintf(ttyout, "Skipping non-relative filename `%s'\n",
+ cp);
+ continue;
+ }
+#ifndef SMALL
+ if (type == 'd' && depth == max_depth)
+ continue;
+ if (!confirm(argv[0], cp))
+ continue;
+ if (type == 'd') {
+ mkdir(cp, 0755);
+ if (chdir(cp) != 0) {
+ warn("local: %s", cp);
+ continue;
+ }
+
+ xargv[1] = cp;
+ cd(xargc, xargv);
+ if (dirchange != 1)
+ goto out;
+
+ xargv[1] = "*";
+ mget(xargc, xargv);
+
+ xargv[1] = "..";
+ cd(xargc, xargv);
+ if (dirchange != 1) {
+ mflag = 0;
+ goto out;
+ }
+
+out:
+ if (chdir("..") != 0) {
+ warn("local: %s", cp);
+ mflag = 0;
+ }
+ continue;
+ }
+ if (type == 's')
+ /* Currently ignored. */
+ continue;
+#endif /* !SMALL */
+ xargv[1] = cp;
+ (void)getit(xargc, xargv, restartit,
+ (restartit == 1 || restart_point) ? "a+w" : "w");
+#ifndef SMALL
+ if (!mflag && fromatty) {
+ if (confirm(argv[0], NULL))
+ mflag = 1;
+ }
+#endif /* !SMALL */
+ }
+ (void)signal(SIGINT, oldintr);
+#ifndef SMALL
+ if (depth)
+ depth--;
+ if (depth == 0 || mflag == 0)
+ depth = max_depth = mflag = restartit = 0;
+#else /* !SMALL */
+ mflag = 0;
+#endif /* !SMALL */
+}
+
+/*
+ * Set current working directory on remote machine.
+ */
+void
+cd(int argc, char *argv[])
+{
+ int r;
+
+#ifndef SMALL
+ if ((argc < 2 && !another(&argc, &argv, "remote-directory")) ||
+ argc > 2) {
+ fprintf(ttyout, "usage: %s remote-directory\n", argv[0]);
+ code = -1;
+ return;
+ }
+#endif /* !SMALL */
+ r = command("CWD %s", argv[1]);
+ if (r == ERROR && code == 500) {
+ if (verbose)
+ fputs("CWD command not recognized, trying XCWD.\n", ttyout);
+ r = command("XCWD %s", argv[1]);
+ }
+ if (r == ERROR && code == 550) {
+ dirchange = 0;
+ return;
+ }
+ if (r == COMPLETE)
+ dirchange = 1;
+}
+
+/*
+ * Terminate session, but don't exit.
+ */
+/* ARGSUSED */
+void
+disconnect(int argc, char *argv[])
+{
+
+ if (!connected)
+ return;
+ (void)command("QUIT");
+ if (cout) {
+ (void)fclose(cout);
+ }
+ cout = NULL;
+ connected = 0;
+ data = -1;
+#ifndef SMALL
+ if (!proxy) {
+ macnum = 0;
+ }
+#endif /* !SMALL */
+}
+
+char *
+dotrans(char *name)
+{
+ static char new[MAXPATHLEN];
+ char *cp1, *cp2 = new;
+ int i, ostop, found;
+
+ for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
+ continue;
+ for (cp1 = name; *cp1; cp1++) {
+ found = 0;
+ for (i = 0; *(ntin + i) && i < 16; i++) {
+ if (*cp1 == *(ntin + i)) {
+ found++;
+ if (i < ostop) {
+ *cp2++ = *(ntout + i);
+ }
+ break;
+ }
+ }
+ if (!found) {
+ *cp2++ = *cp1;
+ }
+ }
+ *cp2 = '\0';
+ return (new);
+}
+
+char *
+domap(char *name)
+{
+ static char new[MAXPATHLEN];
+ char *cp1 = name, *cp2 = mapin;
+ char *tp[9], *te[9];
+ int i, toks[9], toknum = 0, match = 1;
+
+ for (i=0; i < 9; ++i) {
+ toks[i] = 0;
+ }
+ while (match && *cp1 && *cp2) {
+ switch (*cp2) {
+ case '\\':
+ if (*++cp2 != *cp1) {
+ match = 0;
+ }
+ break;
+ case '$':
+ if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
+ if (*cp1 != *(++cp2+1)) {
+ toks[toknum = *cp2 - '1']++;
+ tp[toknum] = cp1;
+ while (*++cp1 && *(cp2+1)
+ != *cp1);
+ te[toknum] = cp1;
+ }
+ cp2++;
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ if (*cp2 != *cp1) {
+ match = 0;
+ }
+ break;
+ }
+ if (match && *cp1) {
+ cp1++;
+ }
+ if (match && *cp2) {
+ cp2++;
+ }
+ }
+ if (!match && *cp1) /* last token mismatch */
+ {
+ toks[toknum] = 0;
+ }
+ cp1 = new;
+ *cp1 = '\0';
+ cp2 = mapout;
+ while (*cp2) {
+ match = 0;
+ switch (*cp2) {
+ case '\\':
+ if (*(cp2 + 1)) {
+ *cp1++ = *++cp2;
+ }
+ break;
+ case '[':
+LOOP:
+ if (*++cp2 == '$' && isdigit(*(cp2+1))) {
+ if (*++cp2 == '0') {
+ char *cp3 = name;
+
+ while (*cp3) {
+ *cp1++ = *cp3++;
+ }
+ match = 1;
+ }
+ else if (toks[toknum = *cp2 - '1']) {
+ char *cp3 = tp[toknum];
+
+ while (cp3 != te[toknum]) {
+ *cp1++ = *cp3++;
+ }
+ match = 1;
+ }
+ }
+ else {
+ while (*cp2 && *cp2 != ',' &&
+ *cp2 != ']') {
+ if (*cp2 == '\\') {
+ cp2++;
+ }
+ else if (*cp2 == '$' &&
+ isdigit(*(cp2+1))) {
+ if (*++cp2 == '0') {
+ char *cp3 = name;
+
+ while (*cp3) {
+ *cp1++ = *cp3++;
+ }
+ }
+ else if (toks[toknum =
+ *cp2 - '1']) {
+ char *cp3=tp[toknum];
+
+ while (cp3 !=
+ te[toknum]) {
+ *cp1++ = *cp3++;
+ }
+ }
+ }
+ else if (*cp2) {
+ *cp1++ = *cp2++;
+ }
+ }
+ if (!*cp2) {
+ fputs(
+"nmap: unbalanced brackets.\n", ttyout);
+ return (name);
+ }
+ match = 1;
+ cp2--;
+ }
+ if (match) {
+ while (*++cp2 && *cp2 != ']') {
+ if (*cp2 == '\\' && *(cp2 + 1)) {
+ cp2++;
+ }
+ }
+ if (!*cp2) {
+ fputs(
+"nmap: unbalanced brackets.\n", ttyout);
+ return (name);
+ }
+ break;
+ }
+ switch (*++cp2) {
+ case ',':
+ goto LOOP;
+ case ']':
+ break;
+ default:
+ cp2--;
+ goto LOOP;
+ }
+ break;
+ case '$':
+ if (isdigit(*(cp2 + 1))) {
+ if (*++cp2 == '0') {
+ char *cp3 = name;
+
+ while (*cp3) {
+ *cp1++ = *cp3++;
+ }
+ }
+ else if (toks[toknum = *cp2 - '1']) {
+ char *cp3 = tp[toknum];
+
+ while (cp3 != te[toknum]) {
+ *cp1++ = *cp3++;
+ }
+ }
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ *cp1++ = *cp2;
+ break;
+ }
+ cp2++;
+ }
+ *cp1 = '\0';
+ if (!*new) {
+ return (name);
+ }
+ return (new);
+}
+
diff --git a/usr.bin/ftp/small.h b/usr.bin/ftp/small.h
new file mode 100644
index 00000000000..a051f2dc621
--- /dev/null
+++ b/usr.bin/ftp/small.h
@@ -0,0 +1,35 @@
+/* $OpenBSD: small.h,v 1.1 2009/05/05 19:35:30 martynas Exp $ */
+
+/*
+ * Copyright (c) 2009 Martynas Venckus <martynas@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+extern jmp_buf jabort;
+extern char *mname;
+extern char *home;
+extern char *stype[];
+
+void settype(int, char **);
+void changetype(int, int);
+void setbinary(int, char **);
+void get(int, char **);
+int getit(int, char **, int, const char *);
+void mabort(int);
+void mget(int, char **);
+void cd(int, char **);
+void disconnect(int, char **);
+char *dotrans(char *);
+char *domap(char *);
+
diff --git a/usr.bin/ftp/stringlist.c b/usr.bin/ftp/stringlist.c
index c10df836572..ea65fcdbfbd 100644
--- a/usr.bin/ftp/stringlist.c
+++ b/usr.bin/ftp/stringlist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stringlist.c,v 1.9 2009/04/27 21:37:13 deraadt Exp $ */
+/* $OpenBSD: stringlist.c,v 1.10 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $ */
/*
@@ -32,6 +32,8 @@
* SUCH DAMAGE.
*/
+#ifndef SMALL
+
#include <stdio.h>
#include <string.h>
#include <err.h>
@@ -94,3 +96,6 @@ sl_free(StringList *sl, int all)
}
free(sl);
}
+
+#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/stringlist.h b/usr.bin/ftp/stringlist.h
index 1f7630c0112..00def0b132a 100644
--- a/usr.bin/ftp/stringlist.h
+++ b/usr.bin/ftp/stringlist.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stringlist.h,v 1.2 2002/02/16 21:27:46 millert Exp $ */
+/* $OpenBSD: stringlist.h,v 1.3 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: stringlist.h,v 1.2 1997/01/17 06:11:36 lukem Exp $ */
/*
@@ -32,6 +32,8 @@
* SUCH DAMAGE.
*/
+#ifndef SMALL
+
#ifndef _STRINGLIST_H
#define _STRINGLIST_H
@@ -55,3 +57,6 @@ char *sl_find(StringList *, char *);
__END_DECLS
#endif /* _STRINGLIST_H */
+
+#endif /* !SMALL */
+
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index bc32c337552..92cbbf12871 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.61 2009/04/27 22:51:51 martynas Exp $ */
+/* $OpenBSD: util.c,v 1.62 2009/05/05 19:35:30 martynas Exp $ */
/* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */
/*-
@@ -106,6 +106,7 @@ setpeer(int argc, char *argv[])
code = -1;
return;
}
+#ifndef SMALL
if (argc < 2)
(void)another(&argc, &argv, "to");
if (argc < 2 || argc > 3) {
@@ -113,6 +114,7 @@ setpeer(int argc, char *argv[])
code = -1;
return;
}
+#endif /* !SMALL */
if (gatemode)
port = gateport;
else
@@ -335,6 +337,7 @@ tryagain:
*
* Returns false if no new arguments have been added.
*/
+#ifndef SMALL
int
another(int *pargc, char ***pargv, const char *prompt)
{
@@ -359,6 +362,7 @@ another(int *pargc, char ***pargv, const char *prompt)
*pargv = margv;
return (ret);
}
+#endif /* !SMALL */
/*
* glob files given in argv[] from the remote server.
@@ -478,6 +482,7 @@ remglob(char *argv[], int doswitch, char **errbuf)
return remglob2(argv, doswitch, errbuf, &ftemp, NULL);
}
+#ifndef SMALL
int
confirm(const char *cmd, const char *file)
{
@@ -530,6 +535,7 @@ quit:
}
return (1);
}
+#endif /* !SMALL */
/*
* Glob a local file name specification with
@@ -937,6 +943,7 @@ ptransfer(int siginfo)
/*
* List words in stringlist, vertically arranged
*/
+#ifndef SMALL
void
list_vertical(StringList *sl)
{
@@ -974,6 +981,7 @@ list_vertical(StringList *sl)
}
}
}
+#endif /* !SMALL */
/*
* Update the global ttywidth value, using TIOCGWINSZ.
@@ -1044,3 +1052,4 @@ controlediting(void)
}
}
#endif /* !SMALL */
+