diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
commit | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch) | |
tree | 2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /nis/nss_compat/compat-pwd.c | |
parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.xz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip |
2.5-18.1
Diffstat (limited to 'nis/nss_compat/compat-pwd.c')
-rw-r--r-- | nis/nss_compat/compat-pwd.c | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c index 89a6a7013e..ac132046da 100644 --- a/nis/nss_compat/compat-pwd.c +++ b/nis/nss_compat/compat-pwd.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc. +/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996. @@ -62,9 +62,10 @@ struct blacklist_t struct ent_t { - bool_t netgroup; - bool_t first; - bool_t files; + bool netgroup; + bool first; + bool files; + enum nss_status setent_status; FILE *stream; struct blacklist_t blacklist; struct passwd pwd; @@ -72,8 +73,9 @@ struct ent_t }; typedef struct ent_t ent_t; -static ent_t ext_ent = {0, 0, TRUE, NULL, {NULL, 0, 0}, - {NULL, NULL, 0, 0, NULL, NULL, NULL}}; +static ent_t ext_ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, + { NULL, 0, 0 }, + { NULL, NULL, 0, 0, NULL, NULL, NULL }}; /* Protect global state against multiple changers. */ __libc_lock_define_initialized (static, lock) @@ -202,12 +204,13 @@ copy_pwd_changes (struct passwd *dest, struct passwd *src, } static enum nss_status -internal_setpwent (ent_t *ent, int stayopen) +internal_setpwent (ent_t *ent, int stayopen, int needent) { enum nss_status status = NSS_STATUS_SUCCESS; - ent->first = ent->netgroup = FALSE; - ent->files = TRUE; + ent->first = ent->netgroup = false; + ent->files = true; + ent->setent_status = NSS_STATUS_SUCCESS; /* If something was left over free it. */ if (ent->netgroup) @@ -257,8 +260,8 @@ internal_setpwent (ent_t *ent, int stayopen) give_pwd_free (&ent->pwd); - if (status == NSS_STATUS_SUCCESS && nss_setpwent) - return nss_setpwent (stayopen); + if (needent && status == NSS_STATUS_SUCCESS && nss_setpwent) + ent->setent_status = nss_setpwent (stayopen); return status; } @@ -274,7 +277,7 @@ _nss_compat_setpwent (int stayopen) if (ni == NULL) init_nss_interface (); - result = internal_setpwent (&ext_ent, stayopen); + result = internal_setpwent (&ext_ent, stayopen, 1); __libc_lock_unlock (lock); @@ -297,7 +300,7 @@ internal_endpwent (ent_t *ent) if (ent->netgroup) __internal_endnetgrent (&ent->netgrdata); - ent->first = ent->netgroup = FALSE; + ent->first = ent->netgroup = false; if (ent->blacklist.data != NULL) { @@ -344,17 +347,17 @@ getpwent_next_nss_netgr (const char *name, struct passwd *result, ent_t *ent, if (yp_get_default_domain (&curdomain) != YPERR_SUCCESS) { - ent->netgroup = FALSE; - ent->first = FALSE; + ent->netgroup = false; + ent->first = false; give_pwd_free (&ent->pwd); return NSS_STATUS_UNAVAIL; } - if (ent->first == TRUE) + if (ent->first == true) { memset (&ent->netgrdata, 0, sizeof (struct __netgrent)); __internal_setnetgrent (group, &ent->netgrdata); - ent->first = FALSE; + ent->first = false; } while (1) @@ -423,6 +426,10 @@ getpwent_next_nss (struct passwd *result, ent_t *ent, char *buffer, if (!nss_getpwent_r) return NSS_STATUS_UNAVAIL; + /* If the setpwent call failed, say so. */ + if (ent->setent_status != NSS_STATUS_SUCCESS) + return ent->setent_status; + p2len = pwd_need_buflen (&ent->pwd); if (p2len > buflen) { @@ -433,7 +440,7 @@ getpwent_next_nss (struct passwd *result, ent_t *ent, char *buffer, buflen -= p2len; if (ent->first) - ent->first = FALSE; + ent->first = false; do { @@ -453,29 +460,27 @@ static enum nss_status getpwnam_plususer (const char *name, struct passwd *result, ent_t *ent, char *buffer, size_t buflen, int *errnop) { - struct passwd pwd; - char *p; - size_t plen; - if (!nss_getpwnam_r) return NSS_STATUS_UNAVAIL; + struct passwd pwd; memset (&pwd, '\0', sizeof (struct passwd)); copy_pwd_changes (&pwd, result, NULL, 0); - plen = pwd_need_buflen (&pwd); + size_t plen = pwd_need_buflen (&pwd); if (plen > buflen) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } - p = buffer + (buflen - plen); + char *p = buffer + (buflen - plen); buflen -= plen; - if (nss_getpwnam_r (name, result, buffer, buflen, errnop) != - NSS_STATUS_SUCCESS) - return NSS_STATUS_NOTFOUND; + enum nss_status status = nss_getpwnam_r (name, result, buffer, buflen, + errnop); + if (status != NSS_STATUS_SUCCESS) + return status; if (in_blacklist (result->pw_name, strlen (result->pw_name), ent)) return NSS_STATUS_NOTFOUND; @@ -568,8 +573,8 @@ getpwent_next_file (struct passwd *result, ent_t *ent, { enum nss_status status; - ent->netgroup = TRUE; - ent->first = TRUE; + ent->netgroup = true; + ent->first = true; copy_pwd_changes (&ent->pwd, result, NULL, 0); status = getpwent_next_nss_netgr (NULL, result, ent, @@ -624,8 +629,8 @@ getpwent_next_file (struct passwd *result, ent_t *ent, /* +:... */ if (result->pw_name[0] == '+' && result->pw_name[1] == '\0') { - ent->files = FALSE; - ent->first = TRUE; + ent->files = false; + ent->first = true; copy_pwd_changes (&ent->pwd, result, NULL, 0); return getpwent_next_nss (result, ent, buffer, buflen, errnop); @@ -673,7 +678,7 @@ _nss_compat_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen, init_nss_interface (); if (ext_ent.stream == NULL) - result = internal_setpwent (&ext_ent, 1); + result = internal_setpwent (&ext_ent, 1, 1); if (result == NSS_STATUS_SUCCESS) result = internal_getpwent_r (pwd, &ext_ent, buffer, buflen, errnop); @@ -825,8 +830,8 @@ _nss_compat_getpwnam_r (const char *name, struct passwd *pwd, char *buffer, size_t buflen, int *errnop) { enum nss_status result; - ent_t ent = {0, 0, TRUE, NULL, {NULL, 0, 0}, - {NULL, NULL, 0, 0, NULL, NULL, NULL}}; + ent_t ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }, + { NULL, NULL, 0, 0, NULL, NULL, NULL }}; if (name[0] == '-' || name[0] == '+') return NSS_STATUS_NOTFOUND; @@ -838,7 +843,7 @@ _nss_compat_getpwnam_r (const char *name, struct passwd *pwd, __libc_lock_unlock (lock); - result = internal_setpwent (&ent, 0); + result = internal_setpwent (&ent, 0, 0); if (result == NSS_STATUS_SUCCESS) result = internal_getpwnam_r (name, pwd, &ent, buffer, buflen, errnop); @@ -1067,8 +1072,8 @@ _nss_compat_getpwuid_r (uid_t uid, struct passwd *pwd, char *buffer, size_t buflen, int *errnop) { enum nss_status result; - ent_t ent = {0, 0, TRUE, NULL, {NULL, 0, 0}, - {NULL, NULL, 0, 0, NULL, NULL, NULL}}; + ent_t ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }, + { NULL, NULL, 0, 0, NULL, NULL, NULL }}; __libc_lock_lock (lock); @@ -1077,7 +1082,7 @@ _nss_compat_getpwuid_r (uid_t uid, struct passwd *pwd, __libc_lock_unlock (lock); - result = internal_setpwent (&ent, 0); + result = internal_setpwent (&ent, 0, 0); if (result == NSS_STATUS_SUCCESS) result = internal_getpwuid_r (uid, pwd, &ent, buffer, buflen, errnop); @@ -1134,7 +1139,7 @@ blacklist_store_name (const char *name, ent_t *ent) return; } -/* returns TRUE if ent->blacklist contains name, else FALSE */ +/* Returns TRUE if ent->blacklist contains name, else FALSE. */ static bool_t in_blacklist (const char *name, int namelen, ent_t *ent) { |