diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-05 23:44:48 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-05 23:44:48 +0000 |
commit | 5051930d85fb3692af2bfaf5e6f4f328472422b7 (patch) | |
tree | ffdb790dab32016fda6465e1a36f85d5f1839154 /lib/libc | |
parent | 26a05c808498ad25616d9dea17501303c007e490 (diff) |
Fix the return values of getpwnam_r(), getpwuid_r(), getgrnam_r(),
and getgrgid_r() to agree with POSIX. Not touching errno handling
yet, which will also need fixing.
Problem originally reported by william at 25thandClement dot com on bugs@.
OK sthen@, and kettenis@ agrees it's "a step in the right direction".
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getgrent.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/getpwent.c | 22 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 72b030b0bad..01ae4ffad60 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getgrent.c,v 1.38 2013/04/17 17:40:35 tedu Exp $ */ +/* $OpenBSD: getgrent.c,v 1.39 2014/03/05 23:44:47 schwarze Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -134,6 +134,7 @@ getgrnam_r(const char *name, struct group *grp, char *buffer, if (bufsize < GETGR_R_SIZE_MAX) return ERANGE; errnosave = errno; + errno = 0; *result = getgrnam_gs(name, grp, (struct group_storage *)buffer); if (*result == NULL) ret = errno; @@ -180,6 +181,7 @@ getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, if (bufsize < GETGR_R_SIZE_MAX) return ERANGE; errnosave = errno; + errno = 0; *result = getgrgid_gs(gid, grp, (struct group_storage *)buffer); if (*result == NULL) ret = errno; diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index a35419db325..b16626d6171 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getpwent.c,v 1.48 2013/11/15 22:32:55 benno Exp $ */ +/* $OpenBSD: getpwent.c,v 1.49 2014/03/05 23:44:47 schwarze Exp $ */ /* * Copyright (c) 2008 Theo de Raadt * Copyright (c) 1988, 1993 @@ -708,8 +708,12 @@ getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t buflen, { struct passwd *pwret = NULL; int flags = 0, *flagsp; + int my_errno = 0; + int saved_errno; _THREAD_PRIVATE_MUTEX_LOCK(pw); + saved_errno = errno; + errno = 0; if (!_pw_db && !__initdb()) goto fail; @@ -733,8 +737,12 @@ getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t buflen, fail: if (pwretp) *pwretp = pwret; + if (pwret == NULL) + my_errno = errno; + if (!errno) + errno = saved_errno; _THREAD_PRIVATE_MUTEX_UNLOCK(pw); - return (pwret ? 0 : 1); + return (my_errno); } struct passwd * @@ -753,8 +761,12 @@ getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t buflen, { struct passwd *pwret = NULL; int flags = 0, *flagsp; + int my_errno = 0; + int saved_errno; _THREAD_PRIVATE_MUTEX_LOCK(pw); + saved_errno = errno; + errno = 0; if (!_pw_db && !__initdb()) goto fail; @@ -778,8 +790,12 @@ getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t buflen, fail: if (pwretp) *pwretp = pwret; + if (pwret == NULL) + my_errno = errno; + if (!errno) + errno = saved_errno; _THREAD_PRIVATE_MUTEX_UNLOCK(pw); - return (pwret ? 0 : 1); + return (my_errno); } struct passwd * |