Blame SOURCES/glibc-rh1039970.patch

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