Date: Tue, 5 Sep 1995 19:11:58 PDT From: Bill Fenner <fenner@parc.xerox.com> To: bugs@freebsd.org Cc: Bill Fenner <fenner@parc.xerox.com> Subject: Re: NIS passwd file doesn't work on 2.1.0-950726-SNAP? Message-ID: <95Sep5.191208pdt.177475@crevenia.parc.xerox.com> In-Reply-To: Your message of "Tue, 05 Sep 95 17:40:38 PDT." <95Sep5.174045pdt.177475@crevenia.parc.xerox.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Urgh, after looking over my changes, it looks like it could be much simpler, without doing any truncation. I also removed the static resultbuf[] and the copies; seemed like a waste. These are from the original, not from the first diffs I sent. Bill --- getpwent.c.orig Tue Sep 5 17:04:47 1995 +++ getpwent.c Tue Sep 5 18:30:56 1995 @@ -586,13 +586,11 @@ _getyppass(struct passwd *pw, const char *name, const char *map) { char *result, *s; - static char resultbuf[1024]; int resultlen; char mastermap[1024]; int gotmaster = 0; struct _pw_cache *m, *p; struct _namelist *n; - char user[UT_NAMESIZE]; if(!_pw_yp_domain) { if(yp_get_default_domain(&_pw_yp_domain)) @@ -613,18 +611,23 @@ return 0; s = strchr(result, '\n'); - if(s) *s = '\0'; + if (s) *s = '\0'; - if(resultlen >= sizeof resultbuf) return 0; - strcpy(resultbuf, result); - sprintf (user, "%.*s", (strchr(result, ':') - result), result); + s = strchr(result, ':'); + if (s) { + *s = '\0'; + } else { + /* malformed, no colon */ + free(result); + return 0; + } _pw_passwd.pw_fields = -1; /* Impossible value */ if (_minuscnt && _minushead) { m = _minushead; while (m) { n = m->namelist; while (n) { - if (!strcmp(n->name,user) || *n->name == '\0') { + if (!strcmp(n->name,result) || *n->name == '\0') { free(result); return (0); } @@ -638,7 +641,7 @@ while (p) { n = p->namelist; while (n) { - if (!strcmp(n->name, user) || *n->name == '\0') + if (!strcmp(n->name, result) || *n->name == '\0') bcopy((char *)&p->pw_entry, (char *)&_pw_passwd, sizeof(p->pw_entry)); n = n->next; @@ -646,12 +649,14 @@ p = p->next; } } - free(result); /* No hits in the plus or minus lists: Bzzt! reject. */ - if (_pw_passwd.pw_fields == -1) + if (_pw_passwd.pw_fields == -1) { + free(result); return(0); - result = resultbuf; - _pw_breakout_yp(pw, resultbuf, gotmaster); + } + *s = ':'; /* Put colon back */ + _pw_breakout_yp(pw, result, gotmaster); + free(result); return 1; } @@ -662,14 +667,13 @@ static char *key; static int keylen; char *lastkey, *result; - static char resultbuf[1024]; int resultlen; int rv; char *map = "passwd.byname"; int gotmaster = 0; struct _pw_cache *m, *p; struct _namelist *n; - char user[UT_NAMESIZE]; + char *s; if(!_pw_yp_domain) { if(yp_get_default_domain(&_pw_yp_domain)) @@ -704,20 +708,21 @@ return 0; } - if(resultlen > sizeof(resultbuf)) { + s = strchr(result, ':'); + if (s) { + *s = '\0'; + } else { + /* malformed, no colon */ free(result); goto tryagain; } - - strcpy(resultbuf, result); - sprintf(user, "%.*s", (strchr(result, ':') - result), result); _pw_passwd.pw_fields = -1; /* Impossible value */ if (_minuscnt && _minushead) { m = _minushead; while (m) { n = m->namelist; while (n) { - if (!strcmp(n->name, user) || *n->name == '\0') { + if (!strcmp(n->name, result) || *n->name == '\0') { free(result); goto tryagain; } @@ -731,7 +736,7 @@ while (p) { n = p->namelist; while (n) { - if (!strcmp(n->name, user) || *n->name == '\0') + if (!strcmp(n->name, result) || *n->name == '\0') bcopy((char *)&p->pw_entry, (char*)&_pw_passwd, sizeof(p->pw_entry)); n = n->next; @@ -739,12 +744,15 @@ p = p->next; } } - free(result); /* No plus or minus hits: Bzzzt! reject. */ - if (_pw_passwd.pw_fields == -1) + if (_pw_passwd.pw_fields == -1) { + free(result); goto tryagain; - if(result = strchr(resultbuf, '\n')) *result = '\0'; - _pw_breakout_yp(pw, resultbuf, gotmaster); + } + *s = ':'; /* Put colon back */ + if(s = strchr(result, '\n')) *s = '\0'; + _pw_breakout_yp(pw, result, gotmaster); + free(result); } return 1; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?95Sep5.191208pdt.177475>