diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-03 15:55:49 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-03 15:55:49 +0000 |
commit | 7cbd0f09957baa7a85cb201458fc3a8078448197 (patch) | |
tree | c316a8a556a0079929212ceb8e2bc27b09a89b28 | |
parent | b1418276bc6baa64d701881139a06c66a85df8f7 (diff) |
add support for automatic anonftp fetches of host:path
add support for -p portnum
might need todo: -N for silence, better exit status for failures
-rw-r--r-- | usr.bin/ftp/ftp.c | 9 | ||||
-rw-r--r-- | usr.bin/ftp/ftp_var.h | 1 | ||||
-rw-r--r-- | usr.bin/ftp/main.c | 85 |
3 files changed, 94 insertions, 1 deletions
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index 48dc3470e2e..0496b16c435 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -201,12 +201,21 @@ login(host) char tmp[80]; char *user, *pass, *acct; int n, aflag = 0; + char anonpass[MAXHOSTNAMELEN+2+32]; user = pass = acct = 0; if (ruserpass(host, &user, &pass, &acct) < 0) { code = -1; return (0); } + if (anonftp) { + user = getlogin(); + strncpy(anonpass, user, 32); + strcat(anonpass, "@"); + gethostname(&anonpass[strlen(anonpass)-1], MAXHOSTNAMELEN); + pass = anonpass; + user = "anonymous"; + } while (user == NULL) { char *myname = getlogin(); diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h index 5a66028d26b..333bd3c160c 100644 --- a/usr.bin/ftp/ftp_var.h +++ b/usr.bin/ftp/ftp_var.h @@ -85,6 +85,7 @@ char modename[32]; /* name of file transfer mode */ int mode; /* file transfer mode */ char bytename[32]; /* local byte size in ascii */ int bytesize; /* local byte size in binary */ +int anonftp; /* force an anonftp login */ char *hostname; /* name of host connected to */ int unix_server; /* server is unix, can use binary for ascii */ diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index a9b2116bbf6..b7321d89607 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -74,6 +74,7 @@ main(argc, argv) int ch, top; struct passwd *pw = NULL; char *cp, homedir[MAXPATHLEN]; + int force_port = 0; sp = getservbyname("ftp", "tcp"); if (sp == 0) @@ -82,7 +83,7 @@ main(argc, argv) interactive = 1; autologin = 1; - while ((ch = getopt(argc, argv, "dgintv")) != EOF) { + while ((ch = getopt(argc, argv, "p:dgintv")) != EOF) { switch (ch) { case 'd': options |= SO_DEBUG; @@ -101,6 +102,10 @@ main(argc, argv) autologin = 0; break; + case 'p': + force_port = atoi(optarg); + break; + case 't': trace++; break; @@ -139,6 +144,84 @@ main(argc, argv) home = homedir; (void) strcpy(home, pw->pw_dir); } + if (argc > 0 && strchr(argv[0], ':')) { + int ret = 0; + anonftp = 1; + + while (argc > 0 && strchr(argv[0], ':')) { + char *xargv[5]; + extern char *__progname; + char portstr[20], *p, *bufp; + int xargc = 2; + + if (setjmp(toplevel)) + exit(0); + (void) signal(SIGINT, intr); + (void) signal(SIGPIPE, lostpeer); + xargv[0] = __progname; + + /* connect to host */ + bufp = xargv[1] = strdup(argv[0]); + p = strchr(xargv[1], ':'); + *p = '\0'; + xargv[2] = NULL; + if (force_port) { + xargv[2] = portstr; + snprintf(portstr, sizeof portstr, "%d", + force_port); + xargc++; + } + setpeer(xargc, xargv); + if (!connected) { + printf("failed to connect to %s\n", xargv[1]); + ret = 1; + goto bail; + } + free(bufp); + + setbinary(NULL, 0); + + /* cd into correct directory */ + bufp = xargv[1] = strdup(argv[0]); + if (xargv[1] == NULL) { + ret = 1; + goto bail; + } + xargv[1] = strchr(xargv[1], ':'); + xargv[1]++; + p = strrchr(xargv[1], '/'); + if (p) + *p = '\0'; + xargv[2] = NULL; + xargc = 2; + cd(xargc, xargv); + free(bufp); + + /* fetch file */ + bufp = xargv[1] = strdup(argv[0]); + if (xargv[1] == NULL) { + ret = 1; + goto bail; + } + xargv[1] = strchr(xargv[1], ':'); + xargv[1]++; + p = strrchr(xargv[1], '/'); + if (p) + xargv[1] = p + 1; + xargv[2] = NULL; + xargc = 2; + get(xargc, xargv); + free(bufp); + + /* get ready for the next file */ +bail: + if (connected) + disconnect(1, xargv); + --argc; + argv++; + } + exit(ret); + } if (argc > 0) { char *xargv[5]; extern char *__progname; |