NetBSD Problem Report #3114

Received: (qmail-queue invoked from smtpd); 16 Jan 1997 14:47:09 -0000
Message-Id: <199701161443.PAA27667@abro.ericsson.se>
Date: Thu, 16 Jan 1997 15:43:18 +0100 (MET)
From: Michael.Eriksson@era-t.ericsson.se
Reply-To: Michael.Eriksson@era-t.ericsson.se
To: gnats-bugs@gnats.netbsd.org
Subject: getgr{nam,gid}() loop through the entire YP database
X-Send-Pr-Version: 3.95

>Number:         3114
>Category:       lib
>Synopsis:       getgr{nam,gid}() loop through the entire YP database
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    thorpej
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 16 06:50:01 +0000 1997
>Closed-Date:    Wed Jan 22 01:19:25 +0000 1997
>Last-Modified:  Wed Jan 22 01:21:25 +0000 1997
>Originator:     Michael Eriksson
>Release:        1.2
>Organization:
Ericsson Radio Systems AB
>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;

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: lukem 
State-Changed-When: Thu Jan 16 07:07:17 PST 1997 
State-Changed-Why:  
The nsswitch() code fixes this, albiet differently. 
(I'll still leave this PR here until nsswitch is in the main trunk) 
Responsible-Changed-From-To: lib-bug-people->thorpej 
Responsible-Changed-By: thorpej 
Responsible-Changed-When: Tue Jan 21 16:50:31 PST 1997 
Responsible-Changed-Why:  
I'll claim this. 
State-Changed-From-To: analyzed->closed 
State-Changed-By: thorpej 
State-Changed-When: Tue Jan 21 17:19:25 PST 1997 
State-Changed-Why:  
Patch applied.  Thanks! 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.