summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-07-14 18:19:17 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-07-14 18:19:17 +0000
commitfa763ccbb3994188b59f29dcd2ef06265de926c3 (patch)
treeed43443038e548b3d9c52dbe234c9ed96385b0d8 /lib
parent33eaef58ef32eb20d7b537cfad8ad3697ef73e45 (diff)
avoid calling __has_yppw() everytime through getpwent(), by caching the YP status along with the open file status
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/getpwent.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index cd3af21eecd..4144b356bbb 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -33,7 +33,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getpwent.c,v 1.12 1997/12/18 10:12:00 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: getpwent.c,v 1.13 1998/07/14 18:19:16 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -293,6 +293,8 @@ char *s;
}
#endif
+static int __getpwent_has_yppw = -1;
+
struct passwd *
getpwent()
{
@@ -301,17 +303,17 @@ getpwent()
#ifdef YP
static char *name = (char *)NULL;
const char *user, *host, *dom;
- int has_yppw;
#endif
if (!_pw_db && !__initdb())
return((struct passwd *)NULL);
#ifdef YP
- has_yppw = __has_yppw();
+ if (__getpwent_has_yppw == -1)
+ __getpwent_has_yppw = __has_yppw();
again:
- if(has_yppw && (__ypmode != YPMODE_NONE)) {
+ if(__getpwent_has_yppw && (__ypmode != YPMODE_NONE)) {
char *key, *data;
int keylen, datalen;
int r, s;
@@ -421,7 +423,7 @@ again:
if(__hashpw(&key)) {
#ifdef YP
/* if we don't have YP at all, don't bother. */
- if(has_yppw) {
+ if (__getpwent_has_yppw) {
if(_pw_passwd.pw_name[0] == '+') {
/* set the mode */
switch(_pw_passwd.pw_name[1]) {
@@ -942,6 +944,7 @@ __initdb()
#ifdef YP
__ypmode = YPMODE_NONE;
+ __getpwent_has_yppw = -1;
#endif
p = (geteuid()) ? _PATH_MP_DB : _PATH_SMP_DB;
_pw_db = dbopen(p, O_RDONLY, 0, DB_HASH, NULL);