summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-09-05 03:52:25 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-09-05 03:52:25 +0000
commit93feb74e65aea37837ae0c88b9795ba02bfb7424 (patch)
tree2f626609cf1c879560d774aea30f63c28f8e58bb /lib
parentdfb18b6cba56df1f42418ed3f5fc26807ee79d43 (diff)
Preserve errno across calls to open the password database(s), so
that errno isn't changed when a normal user (who can't open spwd.db) does a lookup. Problem pointed out by Tim van der Molen (tbvdm at xs4all.nl)
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/getpwent.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index e65ffdc488f..a9d4b8540c5 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getpwent.c,v 1.42 2009/11/21 10:24:59 chl Exp $ */
+/* $OpenBSD: getpwent.c,v 1.43 2011/09/05 03:52:24 guenther Exp $ */
/*
* Copyright (c) 2008 Theo de Raadt
* Copyright (c) 1988, 1993
@@ -844,14 +844,17 @@ static int
__initdb(void)
{
static int warned;
+ int saved_errno = errno;
#ifdef YP
__ypmode = YPMODE_NONE;
__getpwent_has_yppw = -1;
#endif
if ((_pw_db = dbopen(_PATH_SMP_DB, O_RDONLY, 0, DB_HASH, NULL)) ||
- (_pw_db = dbopen(_PATH_MP_DB, O_RDONLY, 0, DB_HASH, NULL)))
+ (_pw_db = dbopen(_PATH_MP_DB, O_RDONLY, 0, DB_HASH, NULL))) {
+ errno = saved_errno;
return (1);
+ }
if (!warned)
syslog(LOG_ERR, "%s: %m", _PATH_MP_DB);
warned = 1;