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