Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-4]: src/usr.bin/ftp pullup 1.46->1.49 (lukem)
details: https://anonhg.NetBSD.org/src/rev/5db4832f4498
branches: netbsd-1-4
changeset: 468907:5db4832f4498
user: perry <perry%NetBSD.org@localhost>
date: Tue Jun 22 21:03:25 1999 +0000
description:
pullup 1.46->1.49 (lukem)
diffstat:
usr.bin/ftp/util.c | 88 ++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 62 insertions(+), 26 deletions(-)
diffs (174 lines):
diff -r d42965e32f19 -r 5db4832f4498 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c Tue Jun 22 21:03:02 1999 +0000
+++ b/usr.bin/ftp/util.c Tue Jun 22 21:03:25 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.46 1999/03/08 03:09:08 lukem Exp $ */
+/* $NetBSD: util.c,v 1.46.2.1 1999/06/22 21:03:25 perry Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: util.c,v 1.46 1999/03/08 03:09:08 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.46.2.1 1999/06/22 21:03:25 perry Exp $");
#endif /* not lint */
/*
@@ -164,13 +164,10 @@
if (host) {
int overbose;
- if (gatemode) {
- if (command("PASSERVE %s", argv[1]) != COMPLETE)
- return;
- if (verbose)
- fprintf(ttyout,
- "Connected via pass-through server %s\n",
- gateserver);
+ if (gatemode && verbose) {
+ fprintf(ttyout,
+ "Connecting via pass-through server %s\n",
+ gateserver);
}
connected = 1;
@@ -249,28 +246,22 @@
{
char tmp[80];
const char *acct;
- char anonpass[MAXLOGNAME + 2]; /* "user@" */
struct passwd *pw;
- int n, aflag = 0;
+ int n, aflag, rval, freeuser, freepass, freeacct, len;
acct = NULL;
- if (user == NULL) {
- if (ruserpass(host, &user, &pass, &acct) < 0) {
- code = -1;
- return (0);
- }
- }
+ aflag = rval = freeuser = freepass = freeacct = 0;
/*
* Set up arguments for an anonymous FTP session, if necessary.
*/
- if ((user == NULL || pass == NULL) && anonftp) {
- memset(anonpass, 0, sizeof(anonpass));
-
+ if (anonftp) {
/*
* Set up anonymous login password.
*/
if ((pass = getenv("FTPANONPASS")) == NULL) {
+ char *anonpass;
+
if ((pass = getlogin()) == NULL) {
if ((pw = getpwuid(getuid())) == NULL)
pass = "anonymous";
@@ -285,12 +276,26 @@
* a FQDN in the anonymous password.
* - thorpej%netbsd.org@localhost
*/
- snprintf(anonpass, sizeof(anonpass) - 1, "%s@", pass);
+ len = strlen(pass) + 2;
+ anonpass = xmalloc(len);
+ snprintf(anonpass, len, "%s@", pass);
pass = anonpass;
+ freepass = 1;
}
user = "anonymous"; /* as per RFC 1635 */
}
+ if (user == NULL) {
+ freeuser = 1;
+ if (pass == NULL)
+ freepass = 1;
+ freeacct = 1;
+ if (ruserpass(host, &user, &pass, &acct) < 0) {
+ code = -1;
+ goto cleanup_ftp_login;
+ }
+ }
+
while (user == NULL) {
const char *myname = getlogin();
@@ -301,13 +306,29 @@
else
fprintf(ttyout, "Name (%s): ", host);
*tmp = '\0';
- (void)fgets(tmp, sizeof(tmp) - 1, stdin);
+ if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
+ fprintf(ttyout, "\nEOF received; login aborted.\n");
+ code = -1;
+ goto cleanup_ftp_login;
+ }
tmp[strlen(tmp) - 1] = '\0';
if (*tmp == '\0')
user = myname;
else
user = tmp;
}
+
+ if (gatemode) {
+ char *nuser;
+ int len;
+
+ len = strlen(user) + 1 + strlen(host) + 1;
+ nuser = xmalloc(len);
+ snprintf(nuser, len, "%s@%s", user, host);
+ user = nuser;
+ freeuser = 1;
+ }
+
n = command("USER %s", user);
if (n == CONTINUE) {
if (pass == NULL)
@@ -316,17 +337,25 @@
}
if (n == CONTINUE) {
aflag++;
- if (acct == NULL)
+ if (acct == NULL) {
acct = getpass("Account:");
+ freeacct = 0;
+ }
+ if (acct[0] == '\0') {
+ warnx("Login failed.");
+ goto cleanup_ftp_login;
+ }
n = command("ACCT %s", acct);
}
if ((n != COMPLETE) ||
(!aflag && acct != NULL && command("ACCT %s", acct) != COMPLETE)) {
warnx("Login failed.");
- return (0);
+ goto cleanup_ftp_login;
}
+ rval = 1;
if (proxy)
- return (1);
+ goto cleanup_ftp_login;
+
connected = -1;
for (n = 0; n < macnum; ++n) {
if (!strcmp("init", macros[n].mac_name)) {
@@ -336,7 +365,14 @@
break;
}
}
- return (1);
+cleanup_ftp_login:
+ if (user != NULL && freeuser)
+ free((char *)user);
+ if (pass != NULL && freepass)
+ free((char *)pass);
+ if (acct != NULL && freeacct)
+ free((char *)acct);
+ return (rval);
}
/*
Home |
Main Index |
Thread Index |
Old Index