olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1039970.patch

51f0aa
commit 9a3c6a6ff602c88d7155139a7d7d0000b7b7e946
51f0aa
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
51f0aa
Date:   Thu Jan 2 10:05:27 2014 +0530
51f0aa
51f0aa
    Fix return code from getent netgroup when the netgroup is not found (bz #16366)
51f0aa
ce426f
diff -pruN glibc-2.17-c758a686/nscd/netgroupcache.c glibc-2.17-c758a686/nscd/netgroupcache.c
ce426f
--- glibc-2.17-c758a686/nscd/netgroupcache.c	2013-12-03 20:41:12.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/nscd/netgroupcache.c	2013-12-19 08:36:52.253000000 -0500
ce426f
@@ -65,6 +65,55 @@ struct dataset
ce426f
   char strdata[0];
ce426f
 };
ce426f
 
ce426f
+/* Sends a notfound message and prepares a notfound dataset to write to the
ce426f
+   cache.  Returns true if there was enough memory to allocate the dataset and
ce426f
+   returns the dataset in DATASETP, total bytes to write in TOTALP and the
ce426f
+   timeout in TIMEOUTP.  KEY_COPY is set to point to the copy of the key in the
ce426f
+   dataset. */
ce426f
+static bool
ce426f
+do_notfound (struct database_dyn *db, int fd, request_header *req,
ce426f
+	       const char *key, struct dataset **datasetp, ssize_t *totalp,
ce426f
+	       time_t *timeoutp, char **key_copy)
ce426f
+{
ce426f
+  struct dataset *dataset;
ce426f
+  ssize_t total;
ce426f
+  time_t timeout;
ce426f
+  bool cacheable = false;
ce426f
+
ce426f
+  total = sizeof (notfound);
ce426f
+  timeout = time (NULL) + db->negtimeout;
ce426f
+
ce426f
+  if (fd != -1)
ce426f
+    TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));
ce426f
+
ce426f
+  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);
ce426f
+  /* If we cannot permanently store the result, so be it.  */
ce426f
+  if (dataset != NULL)
ce426f
+    {
ce426f
+      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
ce426f
+      dataset->head.recsize = total;
ce426f
+      dataset->head.notfound = true;
ce426f
+      dataset->head.nreloads = 0;
ce426f
+      dataset->head.usable = true;
ce426f
+
ce426f
+      /* Compute the timeout time.  */
ce426f
+      timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
ce426f
+      dataset->head.ttl = db->negtimeout;
ce426f
+
ce426f
+      /* This is the reply.  */
ce426f
+      memcpy (&dataset->resp, &notfound, total);
ce426f
+
ce426f
+      /* Copy the key data.  */
ce426f
+      memcpy (dataset->strdata, key, req->key_len);
ce426f
+      *key_copy = dataset->strdata;
ce426f
+
ce426f
+      cacheable = true;
ce426f
+    }
ce426f
+  *timeoutp = timeout;
ce426f
+  *totalp = total;
ce426f
+  *datasetp = dataset;
ce426f
+  return cacheable;
ce426f
+}
ce426f
 
ce426f
 static time_t
ce426f
 addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
ce426f
@@ -84,6 +133,7 @@ addgetnetgrentX (struct database_dyn *db
ce426f
   struct dataset *dataset;
ce426f
   bool cacheable = false;
ce426f
   ssize_t total;
ce426f
+  bool found = false;
ce426f
 
ce426f
   char *key_copy = NULL;
ce426f
   struct __netgrent data;
ce426f
@@ -103,35 +153,8 @@ addgetnetgrentX (struct database_dyn *db
ce426f
       && __nss_database_lookup ("netgroup", NULL, NULL, &netgroup_database))
ce426f
     {
ce426f
       /* No such service.  */
ce426f
-      total = sizeof (notfound);
ce426f
-      timeout = time (NULL) + db->negtimeout;
ce426f
-
ce426f
-      if (fd != -1)
ce426f
-	TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));
ce426f
-
ce426f
-      dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);
ce426f
-      /* If we cannot permanently store the result, so be it.  */
ce426f
-      if (dataset != NULL)
ce426f
-	{
ce426f
-	  dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
ce426f
-	  dataset->head.recsize = total;
ce426f
-	  dataset->head.notfound = true;
ce426f
-	  dataset->head.nreloads = 0;
ce426f
-	  dataset->head.usable = true;
ce426f
-
ce426f
-	  /* Compute the timeout time.  */
ce426f
-	  timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
ce426f
-	  dataset->head.ttl = db->negtimeout;
ce426f
-
ce426f
-	  /* This is the reply.  */
ce426f
-	  memcpy (&dataset->resp, &notfound, total);
ce426f
-
ce426f
-	  /* Copy the key data.  */
ce426f
-	  memcpy (dataset->strdata, key, req->key_len);
ce426f
-
ce426f
-	  cacheable = true;
ce426f
-	}
ce426f
-
ce426f
+      cacheable = do_notfound (db, fd, req, key, &dataset, &total, &timeout,
ce426f
+			       &key_copy);
ce426f
       goto writeout;
ce426f
     }
ce426f
 
ce426f
@@ -167,6 +190,7 @@ addgetnetgrentX (struct database_dyn *db
ce426f
 
ce426f
 	  if (status == NSS_STATUS_SUCCESS)
ce426f
 	    {
ce426f
+	      found = true;
ce426f
 	      union
ce426f
 	      {
ce426f
 		enum nss_status (*f) (struct __netgrent *, char *, size_t,
ce426f
@@ -325,6 +349,15 @@ addgetnetgrentX (struct database_dyn *db
ce426f
 	}
ce426f
     }
ce426f
 
ce426f
+  /* No results.  Return a failure and write out a notfound record in the
ce426f
+     cache.  */
ce426f
+  if (!found)
ce426f
+    {
ce426f
+      cacheable = do_notfound (db, fd, req, key, &dataset, &total, &timeout,
ce426f
+			       &key_copy);
ce426f
+      goto writeout;
ce426f
+    }
ce426f
+
ce426f
   total = buffilled;
ce426f
 
ce426f
   /* Fill in the dataset.  */