Subject: lib/3114: getgr{nam,gid}() loop through the entire YP database
To: None <gnats-bugs@gnats.netbsd.org>
From: None <Michael.Eriksson@era-t.ericsson.se>
List: netbsd-bugs
Date: 01/16/1997 15:43:18
>Number: 3114
>Category: lib
>Synopsis: getgr{nam,gid}() loop through the entire YP database
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Thu Jan 16 06:50:01 1997
>Last-Modified:
>Originator: Michael Eriksson
>Organization:
Ericsson Radio Systems AB
>Release: 1.2
>Environment:
NetBSD 1.2 (and -current)
>Description:
getgr{nam,gid}() loop through the entire YP database (with
yp_{first,next}). They should use yp_match(), which is *much* more
efficient (it has a cache as well).
>How-To-Repeat:
Try "ls -l" in a directory with a lot of files with group ids which
are in YP, on a network which loses a lot of packets...
>Fix:
*** lib/libc/gen/getgrent.c.orig Fri Jul 28 07:43:57 1995
--- lib/libc/gen/getgrent.c Thu Jan 16 13:26:49 1997
***************
*** 165,179 ****
register char *cp, **m;
char *bp;
#ifdef YP
char *grname = (char *)NULL;
#endif
for (;;) {
#ifdef YP
if(__ypmode != YPMODE_NONE) {
- char *key, *data;
- int keylen, datalen;
- int r;
if(!__ypdomain) {
if(yp_get_default_domain(&__ypdomain)) {
--- 165,179 ----
register char *cp, **m;
char *bp;
#ifdef YP
+ char *key, *data;
+ int keylen, datalen;
+ int r;
char *grname = (char *)NULL;
#endif
for (;;) {
#ifdef YP
if(__ypmode != YPMODE_NONE) {
if(!__ypdomain) {
if(yp_get_default_domain(&__ypdomain)) {
***************
*** 258,273 ****
case '\0':
case '\n':
if(_yp_check(NULL)) {
! __ypmode = YPMODE_FULL;
! continue;
}
break;
default:
if(_yp_check(NULL)) {
register char *tptr;
- __ypmode = YPMODE_NAME;
tptr = strsep(&bp, ":\n");
grname = strdup(tptr + 1);
continue;
}
--- 258,307 ----
case '\0':
case '\n':
if(_yp_check(NULL)) {
! if (!search) {
! __ypmode = YPMODE_FULL;
! continue;
! }
! if(!__ypdomain &&
! yp_get_default_domain(&__ypdomain))
! continue;
! if (name) {
! r = yp_match(__ypdomain,
! "group.byname",
! name, strlen(name),
! &data, &datalen);
! } else {
! char buf[20];
! sprintf(buf, "%d", gid);
! r = yp_match(__ypdomain,
! "group.bygid",
! buf, strlen(buf),
! &data, &datalen);
! }
! if (r != 0)
! continue;
! bcopy(data, line, datalen);
! free(data);
! line[datalen] = '\0';
! bp = line;
! _gr_group.gr_name = strsep(&bp, ":\n");
! _gr_group.gr_passwd =
! strsep(&bp, ":\n");
! if (!(cp = strsep(&bp, ":\n")))
! continue;
! _gr_group.gr_gid =
! name ? atoi(cp) : gid;
! goto found_it;
}
break;
default:
if(_yp_check(NULL)) {
register char *tptr;
tptr = strsep(&bp, ":\n");
+ if (search && name && strcmp(tptr, name))
+ continue;
+ __ypmode = YPMODE_NAME;
grname = strdup(tptr + 1);
continue;
}
***************
*** 285,290 ****
--- 319,325 ----
_gr_group.gr_gid = atoi(cp);
if (search && name == NULL && _gr_group.gr_gid != gid)
continue;
+ found_it:
cp = NULL;
if (bp == NULL)
continue;
>Audit-Trail:
>Unformatted: