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-spwd.c | |
parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.bz2 glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip |
2.5-18.1
Diffstat (limited to 'nis/nss_compat/compat-spwd.c')
-rw-r--r-- | nis/nss_compat/compat-spwd.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c index 4ca6368139..d1de3f75b0 100644 --- a/nis/nss_compat/compat-spwd.c +++ b/nis/nss_compat/compat-spwd.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. @@ -59,9 +59,10 @@ struct blacklist_t struct ent_t { - bool_t netgroup; - bool_t files; - bool_t first; + bool netgroup; + bool files; + bool first; + enum nss_status setent_status; FILE *stream; struct blacklist_t blacklist; struct spwd pwd; @@ -69,8 +70,9 @@ struct ent_t }; typedef struct ent_t ent_t; -static ent_t ext_ent = {0, TRUE, 0, NULL, {NULL, 0, 0}, - {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}}; +static ent_t ext_ent = { false, true, false, NSS_STATUS_SUCCESS, NULL, + { NULL, 0, 0}, + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0}}; /* Protect global state against multiple changers. */ __libc_lock_define_initialized (static, lock) @@ -161,7 +163,7 @@ internal_setspent (ent_t *ent, int stayopen) enum nss_status status = NSS_STATUS_SUCCESS; ent->first = ent->netgroup = 0; - ent->files = TRUE; + ent->files = true; /* If something was left over free it. */ if (ent->netgroup) @@ -212,7 +214,7 @@ internal_setspent (ent_t *ent, int stayopen) give_spwd_free (&ent->pwd); if (status == NSS_STATUS_SUCCESS && nss_setspent) - return nss_setspent (stayopen); + ent->setent_status = nss_setspent (stayopen); return status; } @@ -251,8 +253,8 @@ internal_endspent (ent_t *ent) if (ent->netgroup) __internal_endnetgrent (&ent->netgrdata); - ent->first = ent->netgroup = FALSE; - ent->files = TRUE; + ent->first = ent->netgroup = false; + ent->files = true; if (ent->blacklist.data != NULL) { @@ -294,19 +296,23 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent, if (!nss_getspnam_r) return NSS_STATUS_UNAVAIL; + /* If the setpwent call failed, say so. */ + if (ent->setent_status != NSS_STATUS_SUCCESS) + return ent->setent_status; + if (yp_get_default_domain (&curdomain) != YPERR_SUCCESS) { - ent->netgroup = FALSE; - ent->first = FALSE; + ent->netgroup = false; + ent->first = false; give_spwd_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) @@ -321,7 +327,7 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent, if (status != 1) { __internal_endnetgrent (&ent->netgrdata); - ent->netgroup = FALSE; + ent->netgroup = false; give_spwd_free (&ent->pwd); return NSS_STATUS_RETURN; } @@ -396,18 +402,16 @@ getspent_next_nss (struct spwd *result, ent_t *ent, return NSS_STATUS_SUCCESS; } + /* This function handle the +user entrys in /etc/shadow */ static enum nss_status getspnam_plususer (const char *name, struct spwd *result, ent_t *ent, char *buffer, size_t buflen, int *errnop) { - struct spwd pwd; - char *p; - size_t plen; - if (!nss_getspnam_r) return NSS_STATUS_UNAVAIL; + struct spwd pwd; memset (&pwd, '\0', sizeof (struct spwd)); pwd.sp_warn = -1; pwd.sp_inact = -1; @@ -416,18 +420,19 @@ getspnam_plususer (const char *name, struct spwd *result, ent_t *ent, copy_spwd_changes (&pwd, result, NULL, 0); - plen = spwd_need_buflen (&pwd); + size_t plen = spwd_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_getspnam_r (name, result, buffer, buflen, errnop) != - NSS_STATUS_SUCCESS) - return NSS_STATUS_NOTFOUND; + enum nss_status status = nss_getspnam_r (name, result, buffer, buflen, + errnop); + if (status != NSS_STATUS_SUCCESS) + return status; if (in_blacklist (result->sp_namp, strlen (result->sp_namp), ent)) return NSS_STATUS_NOTFOUND; @@ -438,6 +443,7 @@ getspnam_plususer (const char *name, struct spwd *result, ent_t *ent, return NSS_STATUS_SUCCESS; } + static enum nss_status getspent_next_file (struct spwd *result, ent_t *ent, char *buffer, size_t buflen, int *errnop) @@ -518,8 +524,8 @@ getspent_next_file (struct spwd *result, ent_t *ent, { int status; - ent->netgroup = TRUE; - ent->first = TRUE; + ent->netgroup = true; + ent->first = true; copy_spwd_changes (&ent->pwd, result, NULL, 0); status = getspent_next_nss_netgr (NULL, result, ent, @@ -575,8 +581,8 @@ getspent_next_file (struct spwd *result, ent_t *ent, /* +:... */ if (result->sp_namp[0] == '+' && result->sp_namp[1] == '\0') { - ent->files = FALSE; - ent->first = TRUE; + ent->files = false; + ent->first = true; copy_spwd_changes (&ent->pwd, result, NULL, 0); return getspent_next_nss (result, ent, buffer, buflen, errnop); @@ -611,6 +617,7 @@ internal_getspent_r (struct spwd *pw, ent_t *ent, return getspent_next_nss (pw, ent, buffer, buflen, errnop); } + enum nss_status _nss_compat_getspent_r (struct spwd *pwd, char *buffer, size_t buflen, int *errnop) @@ -634,6 +641,7 @@ _nss_compat_getspent_r (struct spwd *pwd, char *buffer, size_t buflen, return result; } + /* Searches in /etc/passwd and the NIS/NIS+ map for a special user */ static enum nss_status internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent, @@ -776,13 +784,14 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent, return NSS_STATUS_SUCCESS; } + enum nss_status _nss_compat_getspnam_r (const char *name, struct spwd *pwd, char *buffer, size_t buflen, int *errnop) { enum nss_status result; - ent_t ent = {0, TRUE, 0, NULL, {NULL, 0, 0}, - {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}}; + ent_t ent = { false, true, false, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0}, + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0}}; if (name[0] == '-' || name[0] == '+') return NSS_STATUS_NOTFOUND; @@ -804,6 +813,7 @@ _nss_compat_getspnam_r (const char *name, struct spwd *pwd, return result; } + /* Support routines for remembering -@netgroup and -user entries. The names are stored in a single string with `|' as separator. */ static void @@ -850,6 +860,7 @@ blacklist_store_name (const char *name, ent_t *ent) return; } + /* Returns TRUE if ent->blacklist contains name, else FALSE. */ static bool_t in_blacklist (const char *name, int namelen, ent_t *ent) @@ -858,7 +869,7 @@ in_blacklist (const char *name, int namelen, ent_t *ent) char *cp; if (ent->blacklist.data == NULL) - return FALSE; + return false; buf[0] = '|'; cp = stpcpy (&buf[1], name); |