]>
Commit | Line | Data |
---|---|---|
bb330e25 AF |
1 | commit dd3022d75e6fb8957843d6d84257a5d8457822d5 |
2 | Author: Siddhesh Poyarekar <siddhesh@redhat.com> | |
3 | Date: Thu Mar 27 19:49:51 2014 +0530 | |
4 | ||
5 | Return NULL for wildcard values in getnetgrent from nscd (BZ #16759) | |
6 | ||
7 | getnetgrent is supposed to return NULL for values that are wildcards | |
8 | in the (host, user, domain) triplet. This works correctly with nscd | |
9 | disabled, but with it enabled, it returns a blank ("") instead of a | |
10 | NULL. This is easily seen with the output of `getent netgroup foonet` | |
11 | for a netgroup foonet defined as follows in /etc/netgroup: | |
12 | ||
13 | foonet (,foo,) | |
14 | ||
15 | The output with nscd disabled is: | |
16 | ||
17 | foonet ( ,foo,) | |
18 | ||
19 | while with nscd enabled, it is: | |
20 | ||
21 | foonet (,foo,) | |
22 | ||
23 | The extra space with nscd disabled is due to the fact that `getent | |
24 | netgroup` adds it if the return value from getnetgrent is NULL for | |
25 | either host or user. | |
26 | ||
27 | diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c | |
28 | index 62cdfda..f6d064d 100644 | |
29 | --- a/inet/getnetgrent_r.c | |
30 | +++ b/inet/getnetgrent_r.c | |
31 | @@ -235,6 +235,14 @@ endnetgrent (void) | |
32 | libc_hidden_proto (internal_getnetgrent_r) | |
33 | ||
34 | ||
35 | +static const char * | |
36 | +get_nonempty_val (const char *in) | |
37 | +{ | |
38 | + if (*in == '\0') | |
39 | + return NULL; | |
40 | + return in; | |
41 | +} | |
42 | + | |
43 | static enum nss_status | |
44 | nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen, | |
45 | int *errnop) | |
46 | @@ -243,11 +251,11 @@ nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen, | |
47 | return NSS_STATUS_UNAVAIL; | |
48 | ||
49 | datap->type = triple_val; | |
50 | - datap->val.triple.host = datap->cursor; | |
51 | + datap->val.triple.host = get_nonempty_val (datap->cursor); | |
52 | datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1; | |
53 | - datap->val.triple.user = datap->cursor; | |
54 | + datap->val.triple.user = get_nonempty_val (datap->cursor); | |
55 | datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1; | |
56 | - datap->val.triple.domain = datap->cursor; | |
57 | + datap->val.triple.domain = get_nonempty_val (datap->cursor); | |
58 | datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1; | |
59 | ||
60 | return NSS_STATUS_SUCCESS; |