ce426f
commit fbd6b5a4052316f7eb03c4617eebfaafc59dcc06
ce426f
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
ce426f
Date:   Thu Mar 27 07:15:22 2014 +0530
ce426f
ce426f
    Fix nscd lookup for innetgr when netgroup has wildcards (BZ #16758)
ce426f
    
ce426f
    nscd works correctly when the request in innetgr is a wildcard,
ce426f
    i.e. when one or more of host, user or domain parameters is NULL.
ce426f
    However, it does not work when the the triplet in the netgroup
ce426f
    definition has a wildcard.  This is easy to reproduce for a triplet
ce426f
    defined as follows:
ce426f
    
ce426f
        foonet (,foo,)
ce426f
    
ce426f
    Here, an innetgr call that looks like this:
ce426f
    
ce426f
        innetgr ("foonet", "foohost", "foo", NULL);
ce426f
    
ce426f
    should succeed and so should:
ce426f
    
ce426f
        innetgr ("foonet", NULL, "foo", "foodomain");
ce426f
    
ce426f
    It does succeed with nscd disabled, but not with nscd enabled.  This
ce426f
    fix adds this additional check for all three parts of the triplet so
ce426f
    that it gives the correct result.
ce426f
    
ce426f
    	[BZ #16758]
ce426f
    	* nscd/netgroupcache.c (addinnetgrX): Succeed if triplet has
ce426f
    	blank values.
ce426f
ce426f
diff --git glibc-2.17-c758a686/nscd/netgroupcache.c glibc-2.17-c758a686/nscd/netgroupcache.c
ce426f
index 5ba1e1f..5d15aa4 100644
ce426f
--- glibc-2.17-c758a686/nscd/netgroupcache.c
ce426f
+++ glibc-2.17-c758a686/nscd/netgroupcache.c
ce426f
@@ -560,15 +560,19 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
ce426f
 	{
ce426f
 	  bool success = true;
ce426f
 
ce426f
-	  if (host != NULL)
ce426f
+	  /* For the host, user and domain in each triplet, we assume success
ce426f
+	     if the value is blank because that is how the wildcard entry to
ce426f
+	     match anything is stored in the netgroup cache.  */
ce426f
+	  if (host != NULL && *triplets != '\0')
ce426f
 	    success = strcmp (host, triplets) == 0;
ce426f
 	  triplets = (const char *) rawmemchr (triplets, '\0') + 1;
ce426f
 
ce426f
-	  if (success && user != NULL)
ce426f
+	  if (success && user != NULL && *triplets != '\0')
ce426f
 	    success = strcmp (user, triplets) == 0;
ce426f
 	  triplets = (const char *) rawmemchr (triplets, '\0') + 1;
ce426f
 
ce426f
-	  if (success && (domain == NULL || strcmp (domain, triplets) == 0))
ce426f
+	  if (success && (domain == NULL || *triplets == '\0'
ce426f
+			  || strcmp (domain, triplets) == 0))
ce426f
 	    {
ce426f
 	      dataset->resp.result = 1;
ce426f
 	      break;