5de29b
commit dd3022d75e6fb8957843d6d84257a5d8457822d5
5de29b
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
5de29b
Date:   Thu Mar 27 19:49:51 2014 +0530
5de29b
5de29b
    Return NULL for wildcard values in getnetgrent from nscd (BZ #16759)
5de29b
    
5de29b
    getnetgrent is supposed to return NULL for values that are wildcards
5de29b
    in the (host, user, domain) triplet.  This works correctly with nscd
5de29b
    disabled, but with it enabled, it returns a blank ("") instead of a
5de29b
    NULL.  This is easily seen with the output of `getent netgroup foonet`
5de29b
    for a netgroup foonet defined as follows in /etc/netgroup:
5de29b
    
5de29b
        foonet (,foo,)
5de29b
    
5de29b
    The output with nscd disabled is:
5de29b
    
5de29b
        foonet ( ,foo,)
5de29b
    
5de29b
    while with nscd enabled, it is:
5de29b
    
5de29b
        foonet (,foo,)
5de29b
    
5de29b
    The extra space with nscd disabled is due to the fact that `getent
5de29b
    netgroup` adds it if the return value from getnetgrent is NULL for
5de29b
    either host or user.
5de29b
12745e
diff --git glibc-2.17-c758a686/inet/getnetgrent_r.c glibc-2.17-c758a686/inet/getnetgrent_r.c
5de29b
index 62cdfda..f6d064d 100644
12745e
--- glibc-2.17-c758a686/inet/getnetgrent_r.c
12745e
+++ glibc-2.17-c758a686/inet/getnetgrent_r.c
5de29b
@@ -235,6 +235,14 @@ endnetgrent (void)
5de29b
   __libc_lock_unlock (lock);
5de29b
 }
5de29b
 
5de29b
+static const char *
5de29b
+get_nonempty_val (const char *in)
5de29b
+{
5de29b
+  if (*in == '\0')
5de29b
+    return NULL;
5de29b
+  return in;
5de29b
+}
5de29b
+
5de29b
 #ifdef USE_NSCD
5de29b
 static enum nss_status
5de29b
 nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen,
5de29b
@@ -243,11 +251,11 @@ nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen,
5de29b
     return NSS_STATUS_UNAVAIL;
5de29b
 
5de29b
   datap->type = triple_val;
5de29b
-  datap->val.triple.host = datap->cursor;
5de29b
+  datap->val.triple.host = get_nonempty_val (datap->cursor);
5de29b
   datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1;
5de29b
-  datap->val.triple.user = datap->cursor;
5de29b
+  datap->val.triple.user = get_nonempty_val (datap->cursor);
5de29b
   datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1;
5de29b
-  datap->val.triple.domain = datap->cursor;
5de29b
+  datap->val.triple.domain = get_nonempty_val (datap->cursor);
5de29b
   datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1;
5de29b
 
5de29b
   return NSS_STATUS_SUCCESS;