about summary refs log tree commit diff
path: root/nis/nss_compat/compat-spwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nss_compat/compat-spwd.c')
-rw-r--r--nis/nss_compat/compat-spwd.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
index 5c820a5f65..d1de3f75b0 100644
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.c
@@ -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,11 +214,7 @@ internal_setspent (ent_t *ent, int stayopen)
   give_spwd_free (&ent->pwd);
 
   if (status == NSS_STATUS_SUCCESS && nss_setspent)
-    {
-      status = nss_setspent (stayopen);
-      if (status == NSS_STATUS_UNAVAIL)
-        status = NSS_STATUS_SUCCESS;
-    }
+    ent->setent_status = nss_setspent (stayopen);
 
   return status;
 }
@@ -255,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)
     {
@@ -298,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)
@@ -325,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;
 	}
@@ -400,6 +402,7 @@ 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,
@@ -440,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)
@@ -520,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,
@@ -577,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);
@@ -613,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)
@@ -636,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,
@@ -778,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;
@@ -806,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
@@ -852,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)
@@ -860,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);