1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19: #include <ctype.h>
20: #include <errno.h>
21: #include <stdio.h>
22: #include <stdio_ext.h>
23: #include <stdlib.h>
24: #include <string.h>
25: #include <bits/libc-lock.h>
26:
27: #include <libnsl.h>
28:
29:
30:
31: static const char default_nss[] = "/etc/default/nss";
32:
33:
34: static int default_nss_flags;
35:
36:
37: __libc_once_define (static, once);
38:
39:
40: static const struct
41: {
42: char name[23];
43: unsigned int len;
44: int flag;
45: } vars[] =
46: {
47: #define STRNLEN(s) s, sizeof (s) - 1
48: { STRNLEN ("NETID_AUTHORITATIVE"), NSS_FLAG_NETID_AUTHORITATIVE },
49: { STRNLEN ("SERVICES_AUTHORITATIVE"), NSS_FLAG_SERVICES_AUTHORITATIVE },
50: { STRNLEN ("SETENT_BATCH_READ"), NSS_FLAG_SETENT_BATCH_READ }
51: };
52: #define nvars (sizeof (vars) / sizeof (vars[0]))
53:
54:
55: static void
56: init (void)
57: {
58: int saved_errno = errno;
59: FILE *fp = fopen (default_nss, "rc");
60: if (fp != NULL)
61: {
62: char *line = NULL;
63: size_t linelen = 0;
64:
65: __fsetlocking (fp, FSETLOCKING_BYCALLER);
66:
67: while (!feof_unlocked (fp))
68: {
69: ssize_t n = getline (&line, &linelen, fp);
70: if (n <= 0)
71: break;
72:
73:
74:
75:
76:
77:
78: char *cp = line;
79: while (isspace (*cp))
80: ++cp;
81:
82:
83: if (*cp == '#')
84: continue;
85:
86: int idx;
87: for (idx = 0; idx < nvars; ++idx)
88: if (strncmp (cp, vars[idx].name, vars[idx].len) == 0)
89: break;
90: if (idx == nvars)
91: continue;
92:
93: cp += vars[idx].len;
94: while (isspace (*cp))
95: ++cp;
96: if (*cp++ != '=')
97: continue;
98: while (isspace (*cp))
99: ++cp;
100:
101: if (strncmp (cp, "TRUE", 4) != 0)
102: continue;
103: cp += 4;
104:
105: while (isspace (*cp))
106: ++cp;
107:
108: if (*cp == '\0')
109: default_nss_flags |= vars[idx].flag;
110: }
111:
112: free (line);
113:
114: fclose (fp);
115: }
116: __set_errno (saved_errno);
117: }
118:
119:
120: int
121: _nsl_default_nss (void)
122: {
123:
124: __libc_once (once, init);
125:
126: return default_nss_flags;
127: }