diff options
Diffstat (limited to 'contrib/tnftp/src/ruserpass.c')
-rw-r--r-- | contrib/tnftp/src/ruserpass.c | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/contrib/tnftp/src/ruserpass.c b/contrib/tnftp/src/ruserpass.c index 9cb318a..a2e0360 100644 --- a/contrib/tnftp/src/ruserpass.c +++ b/contrib/tnftp/src/ruserpass.c @@ -1,4 +1,5 @@ -/* $NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp $ */ +/* $NetBSD: ruserpass.c,v 1.8 2007/08/06 04:33:24 lukem Exp $ */ +/* from NetBSD: ruserpass.c,v 1.33 2007/04/17 05:52:04 lukem Exp */ /* * Copyright (c) 1985, 1993, 1994 @@ -29,12 +30,16 @@ * SUCH DAMAGE. */ +#include "tnftp.h" + +#if 0 /* tnftp */ + #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp $"); +__RCSID(" NetBSD: ruserpass.c,v 1.33 2007/04/17 05:52:04 lukem Exp "); #endif #endif /* not lint */ @@ -50,6 +55,8 @@ __RCSID("$NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp $"); #include <string.h> #include <unistd.h> +#endif /* tnftp */ + #include "ftp_var.h" static int token(void); @@ -66,7 +73,7 @@ static FILE *cfile; static char tokval[100]; static struct toktab { - char *tokstr; + const char *tokstr; int tval; } toktab[] = { { "default", DEFAULT }, @@ -80,11 +87,11 @@ static struct toktab { }; int -ruserpass(const char *host, const char **aname, const char **apass, - const char **aacct) +ruserpass(const char *host, char **aname, char **apass, char **aacct) { char *tmp; - char myname[MAXHOSTNAMELEN + 1], *mydomain; + const char *mydomain; + char myname[MAXHOSTNAMELEN + 1]; int t, i, c, usedefault = 0; struct stat stb; @@ -93,7 +100,7 @@ ruserpass(const char *host, const char **aname, const char **apass, cfile = fopen(netrc, "r"); if (cfile == NULL) { if (errno != ENOENT) - warn("%s", netrc); + warn("Can't read `%s'", netrc); return (0); } if (gethostname(myname, sizeof(myname)) < 0) @@ -102,7 +109,7 @@ ruserpass(const char *host, const char **aname, const char **apass, if ((mydomain = strchr(myname, '.')) == NULL) mydomain = ""; next: - while ((t = token())) switch(t) { + while ((t = token()) > 0) switch(t) { case DEFAULT: usedefault = 1; @@ -110,7 +117,9 @@ ruserpass(const char *host, const char **aname, const char **apass, case MACH: if (!usedefault) { - if (token() != ID) + if ((t = token()) == -1) + goto bad; + if (t != ID) continue; /* * Allow match either for user's input host name @@ -134,12 +143,15 @@ ruserpass(const char *host, const char **aname, const char **apass, continue; } match: - while ((t = token()) && t != MACH && t != DEFAULT) switch(t) { + while ((t = token()) > 0 && + t != MACH && t != DEFAULT) switch(t) { case LOGIN: - if (token()) { + if ((t = token()) == -1) + goto bad; + if (t) { if (*aname == NULL) - *aname = xstrdup(tokval); + *aname = ftp_strdup(tokval); else { if (strcmp(*aname, tokval)) goto next; @@ -150,22 +162,26 @@ ruserpass(const char *host, const char **aname, const char **apass, if ((*aname == NULL || strcmp(*aname, "anonymous")) && fstat(fileno(cfile), &stb) >= 0 && (stb.st_mode & 077) != 0) { - warnx("Error: .netrc file is readable by others."); - warnx("Remove password or make file unreadable by others."); + warnx("Error: .netrc file is readable by others"); + warnx("Remove password or make file unreadable by others"); goto bad; } - if (token() && *apass == NULL) - *apass = xstrdup(tokval); + if ((t = token()) == -1) + goto bad; + if (t && *apass == NULL) + *apass = ftp_strdup(tokval); break; case ACCOUNT: if (fstat(fileno(cfile), &stb) >= 0 && (stb.st_mode & 077) != 0) { - warnx("Error: .netrc file is readable by others."); - warnx("Remove account or make file unreadable by others."); + warnx("Error: .netrc file is readable by others"); + warnx("Remove account or make file unreadable by others"); goto bad; } - if (token() && *aacct == NULL) - *aacct = xstrdup(tokval); + if ((t = token()) == -1) + goto bad; + if (t && *aacct == NULL) + *aacct = ftp_strdup(tokval); break; case MACDEF: if (proxy) { @@ -225,9 +241,13 @@ ruserpass(const char *host, const char **aname, const char **apass, } *tmp = c; if (*tmp == '\n') { - if (*(tmp-1) == '\0') { - macros[macnum++].mac_end = tmp - 1; - break; + if (tmp == macros[macnum].mac_start) { + macros[macnum++].mac_end = tmp; + break; + } else if (*(tmp - 1) == '\0') { + macros[macnum++].mac_end = + tmp - 1; + break; } *tmp = '\0'; } @@ -240,12 +260,14 @@ ruserpass(const char *host, const char **aname, const char **apass, } break; default: - warnx("Unknown .netrc keyword %s", tokval); + warnx("Unknown .netrc keyword `%s'", tokval); break; } goto done; } done: + if (t == -1) + goto bad; (void)fclose(cfile); return (0); bad: @@ -271,16 +293,26 @@ token(void) if (c == '"') { while ((c = getc(cfile)) != EOF && c != '"') { if (c == '\\') - c = getc(cfile); + if ((c = getc(cfile)) == EOF) + break; *cp++ = c; + if (cp == tokval + sizeof(tokval)) { + warnx("Token in .netrc too long"); + return (-1); + } } } else { *cp++ = c; while ((c = getc(cfile)) != EOF && c != '\n' && c != '\t' && c != ' ' && c != ',') { if (c == '\\') - c = getc(cfile); + if ((c = getc(cfile)) == EOF) + break; *cp++ = c; + if (cp == tokval + sizeof(tokval)) { + warnx("Token in .netrc too long"); + return (-1); + } } } *cp = 0; |