Subject: Re: NetBSD-3 NIS-compat getpwnam()/getpwuid iterate entire map [was Re: 3.0 YP lookup latency]
To: Christos Zoulas <christos@zoulas.com>
From: Brian Ginsbach <ginsbach@NetBSD.org>
List: tech-net
Date: 06/21/2006 21:00:30
On Wed, Jun 21, 2006 at 04:19:34PM -0400, Christos Zoulas wrote:
>
> Something like this?
>
> Index: getpwent.c
> ===================================================================
> RCS file: /cvsroot/src/lib/libc/gen/getpwent.c,v
> retrieving revision 1.71
> diff -u -u -r1.71 getpwent.c
> --- getpwent.c 19 Mar 2006 03:05:57 -0000 1.71
> +++ getpwent.c 21 Jun 2006 20:15:23 -0000
> @@ -1934,9 +1934,22 @@
>
> case COMPAT_FULL:
> /* get next user */
> - rv = _passwdcompat_pwscan(&cpw,
> - cbuf, sizeof(cbuf),
> - _PW_KEYBYNUM, NULL, 0);
> + switch (search) {
> + case _PW_KEYBYNUM:
> + rv = _passwdcompat_pwscan(&cpw, cbuf,
> + sizeof(cbuf), search, NULL, 0);
> + break;
> + case _PW_KEYBYNAME:
> + rv = _passwdcompat_pwscan(&cpw, cbuf,
> + sizeof(cbuf), search, name, 0);
> + break;
> + case _PW_KEYBYUID:
> + rv = _passwdcompat_pwscan(&cpw, cbuf,
> + sizeof(cbuf), search, NULL, uid);
> + break;
> + default:
> + abort();
> + }
> if (rv != NS_SUCCESS)
> state->mode = COMPAT_NONE;
> break;
There shouldn't be a need for the extra switch statement as
_passwdcompat_pwscan() will do the right thing -- essentially you've
just repeated the switch statement from _passwdcompat_pwscan()...
diff -u -u -r1.71 getpwent.c
--- getpwent.c 19 Mar 2006 03:05:57 -0000 1.71
+++ getpwent.c 21 Jun 2006 20:15:23 -0000
@@ -1936,7 +1936,7 @@
/* get next user */
rv = _passwdcompat_pwscan(&cpw,
cbuf, sizeof(cbuf),
- _PW_KEYBYNUM, NULL, 0);
+ search, name, uid);