about 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.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/nis/nss_nisplus/nisplus-spwd.c b/nis/nss_nisplus/nisplus-spwd.c
index 81bde4e689..c7f1e2a567 100644
--- a/nis/nss_nisplus/nisplus-spwd.c
+++ b/nis/nss_nisplus/nisplus-spwd.c
@@ -93,8 +93,12 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
   /* Get the next entry until we found a correct one. */
   do
     {
+      nis_result *saved_res;
+
       if (result == NULL)
 	{
+	  saved_res = NULL;
+
           if (tablename_val == NULL)
             if (_nss_create_tablename () != NSS_STATUS_SUCCESS)
               return NSS_STATUS_UNAVAIL;
@@ -107,14 +111,28 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
 	{
 	  nis_result *res;
 
+	  saved_res = result;
 	  res = nis_next_entry (tablename_val, &result->cookie);
-	  nis_freeresult (result);
 	  result = res;
 	  if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
-	    return niserr2nss (result->status);
+	    {
+	      nis_freeresult (saved_res);
+	      return niserr2nss (result->status);
+	    }
 	}
 
-      parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen);
+      if ((parse_res = _nss_nisplus_parse_spent (result, sp, buffer,
+						 buflen)) == -1)
+	{
+	  nis_freeresult (result);
+	  result = saved_res;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+      else
+	{
+	  if (saved_res)
+	    nis_freeresult (saved_res);
+	}
     } while (!parse_res);
 
   return NSS_STATUS_SUCCESS;
@@ -164,15 +182,14 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
 	}
 
       parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen);
-
       nis_freeresult (result);
 
+      if (parse_res == -1)
+	return NSS_STATUS_TRYAGAIN;
+
       if (parse_res)
 	return NSS_STATUS_SUCCESS;
 
-      if (!parse_res && errno == ERANGE)
-	return NSS_STATUS_TRYAGAIN;
-      else
-	return NSS_STATUS_NOTFOUND;
+      return NSS_STATUS_NOTFOUND;
     }
 }