about summary refs log tree commit diff
path: root/nis/nss_nisplus/nisplus-proto.c
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nss_nisplus/nisplus-proto.c')
-rw-r--r--nis/nss_nisplus/nisplus-proto.c93
1 files changed, 61 insertions, 32 deletions
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
index 2cbd9fe2fa..262276f301 100644
--- a/nis/nss_nisplus/nisplus-proto.c
+++ b/nis/nss_nisplus/nisplus-proto.c
@@ -41,7 +41,7 @@ static u_long tablename_len = 0;
 
 static int
 _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto,
-			     char *buffer, size_t buflen)
+			     char *buffer, size_t buflen, int *errnop)
 {
   char *first_unused = buffer;
   size_t room_left = buflen;
@@ -51,9 +51,10 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto,
   if (result == NULL)
     return 0;
 
-  if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) ||
-      __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ ||
-      strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "protocols_tbl") != 0
+  if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
+      || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
+      || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
+		 "protocols_tbl") != 0
       || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 3)
     return 0;
 
@@ -61,7 +62,7 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto,
   if (NISENTRYLEN (0, 0, result) + 1 > room_left)
     {
     no_more_room:
-      __set_errno (ERANGE);
+      *errnop = ERANGE;
       return -1;
     }
   strncpy (first_unused, NISENTRYVAL (0, 0, result),
@@ -101,7 +102,7 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto,
   proto->p_aliases = (char **) first_unused;
   if (room_left < sizeof (char *))
     goto no_more_room;
-  room_left -= (sizeof (char *));
+  room_left -= sizeof (char *);
   proto->p_aliases[0] = NULL;
 
   i = 0;
@@ -136,7 +137,7 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto,
 }
 
 static enum nss_status
-_nss_create_tablename (void)
+_nss_create_tablename (int *errnop)
 {
   if (tablename_val == NULL)
     {
@@ -147,7 +148,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;
@@ -165,7 +169,10 @@ _nss_nisplus_setprotoent (void)
   result = NULL;
 
   if (tablename_val == NULL)
-    status = _nss_create_tablename ();
+    {
+      int err;
+      status = _nss_create_tablename (&err);
+    }
 
   __libc_lock_unlock (lock);
 
@@ -188,7 +195,7 @@ _nss_nisplus_endprotoent (void)
 
 static enum nss_status
 internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
-				size_t buflen)
+				size_t buflen, int *errnop)
 {
   int parse_res;
 
@@ -201,8 +208,12 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
 	{
 	  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)
@@ -223,11 +234,13 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
 	    }
 	}
 
-      if ((parse_res = _nss_nisplus_parse_protoent (result, proto, buffer,
-						    buflen)) == -1)
+      parse_res = _nss_nisplus_parse_protoent (result, proto, buffer,
+					       buflen, errnop);
+      if (parse_res == -1)
 	{
 	  nis_freeresult (result);
 	  result = saved_res;
+	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
@@ -243,13 +256,13 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
 
 enum nss_status
 _nss_nisplus_getprotoent_r (struct protoent *result, char *buffer,
-			    size_t buflen)
+			    size_t buflen, int *errnop)
 {
   int status;
 
   __libc_lock_lock (lock);
 
-  status = internal_nisplus_getprotoent_r (result, buffer, buflen);
+  status = internal_nisplus_getprotoent_r (result, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);
 
@@ -258,13 +271,17 @@ _nss_nisplus_getprotoent_r (struct protoent *result, char *buffer,
 
 enum nss_status
 _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
-			       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)
     return NSS_STATUS_NOTFOUND;
@@ -280,12 +297,11 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 
       /* If we do not find it, try it as original name. But if the
          database is correct, we should find it in the first case, too */
-      if ((result->status != NIS_SUCCESS &&
-	   result->status != NIS_S_SUCCESS) ||
-	  __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ ||
-	  strcmp (result->objects.objects_val->EN_data.en_type,
-		  "protocols_tbl") != 0 ||
-	  result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
+      if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
+	  || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+	  || strcmp (result->objects.objects_val->EN_data.en_type,
+		     "protocols_tbl") != 0
+	  || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
 	sprintf (buf, "[cname=%s],%s", name, tablename_val);
       else
 	sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result),
@@ -302,12 +318,16 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 	  return status;
 	}
 
-      parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen);
+      parse_res = _nss_nisplus_parse_protoent (result, proto, 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;
 
@@ -317,11 +337,16 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 
 enum nss_status
 _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
-				 char *buffer, size_t buflen)
+				 char *buffer, size_t buflen, int *errnop)
 {
   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;
+    }
+
   {
     int parse_res;
     nis_result *result;
@@ -339,12 +364,16 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
 	return status;
       }
 
-    parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen);
+    parse_res = _nss_nisplus_parse_protoent (result, proto, 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;