summary refs log tree commit diff
path: root/nis/nss_nisplus/nisplus-spwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nss_nisplus/nisplus-spwd.c')
-rw-r--r--nis/nss_nisplus/nisplus-spwd.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/nis/nss_nisplus/nisplus-spwd.c b/nis/nss_nisplus/nisplus-spwd.c
index 1b3f68325e..54bbc32f3c 100644
--- a/nis/nss_nisplus/nisplus-spwd.c
+++ b/nis/nss_nisplus/nisplus-spwd.c
@@ -34,7 +34,7 @@ static nis_name tablename_val = NULL;
 static u_long tablename_len = 0;
 
 static enum nss_status
-_nss_create_tablename (void)
+_nss_create_tablename (int *errnop)
 {
   if (tablename_val == NULL)
     {
@@ -45,7 +45,10 @@ _nss_create_tablename (void)
       p = __stpcpy (p, nis_local_directory ());
       tablename_val = __strdup (buf);
       if (tablename_val == NULL)
-        return NSS_STATUS_TRYAGAIN;
+	{
+	  *errnop = errno;
+	  return NSS_STATUS_TRYAGAIN;
+	}
       tablename_len = strlen (tablename_val);
     }
   return NSS_STATUS_SUCCESS;
@@ -55,6 +58,7 @@ enum nss_status
 _nss_nisplus_setspent (void)
 {
   enum nss_status status = NSS_STATUS_SUCCESS;
+  int err;
 
   __libc_lock_lock (lock);
 
@@ -63,7 +67,7 @@ _nss_nisplus_setspent (void)
   result = NULL;
 
   if (tablename_val == NULL)
-    status = _nss_create_tablename ();
+    status = _nss_create_tablename (&err);
 
   __libc_lock_unlock (lock);
 
@@ -85,7 +89,8 @@ _nss_nisplus_endspent (void)
 }
 
 static enum nss_status
-internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
+internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
+			     int *errnop)
 {
   int parse_res;
 
@@ -99,8 +104,12 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
 	  saved_res = NULL;
 
           if (tablename_val == NULL)
-            if (_nss_create_tablename () != NSS_STATUS_SUCCESS)
-              return NSS_STATUS_UNAVAIL;
+	    {
+	      enum nss_status status = _nss_create_tablename (errnop);
+
+	      if (status != NSS_STATUS_SUCCESS)
+		return status;
+	    }
 
 	  result = nis_first_entry (tablename_val);
 	  if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
@@ -120,11 +129,13 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
 	    }
 	}
 
-      if ((parse_res = _nss_nisplus_parse_spent (result, sp, buffer,
-						 buflen)) == -1)
+      parse_res = _nss_nisplus_parse_spent (result, sp, buffer,
+					    buflen, errnop);
+      if (parse_res == -1)
 	{
 	  nis_freeresult (result);
 	  result = saved_res;
+	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
@@ -138,13 +149,14 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
 }
 
 enum nss_status
-_nss_nisplus_getspent_r (struct spwd *result, char *buffer, size_t buflen)
+_nss_nisplus_getspent_r (struct spwd *result, char *buffer, size_t buflen,
+			 int *errnop)
 {
   int status;
 
   __libc_lock_lock (lock);
 
-  status = internal_nisplus_getspent_r (result, buffer, buflen);
+  status = internal_nisplus_getspent_r (result, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);
 
@@ -153,13 +165,17 @@ _nss_nisplus_getspent_r (struct spwd *result, char *buffer, size_t buflen)
 
 enum nss_status
 _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
-		     char *buffer, size_t buflen)
+		     char *buffer, size_t buflen, int *errnop)
 {
   int parse_res;
 
   if (tablename_val == NULL)
-    if (_nss_create_tablename () != NSS_STATUS_SUCCESS)
-      return NSS_STATUS_UNAVAIL;
+    {
+      enum nss_status status = _nss_create_tablename (errnop);
+
+      if (status != NSS_STATUS_SUCCESS)
+	return status;
+    }
 
   if (name == NULL || strlen (name) > 8)
     return NSS_STATUS_NOTFOUND;
@@ -180,11 +196,15 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
 	  return status;
 	}
 
-      parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen);
+      parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen,
+					    errnop);
       nis_freeresult (result);
 
       if (parse_res == -1)
-	return NSS_STATUS_TRYAGAIN;
+	{
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
 
       if (parse_res)
 	return NSS_STATUS_SUCCESS;