]>
Commit | Line | Data |
---|---|---|
71170aa0 | 1 | /* Copyright (C) 1996,2001,2004,2006,2007,2010 Free Software Foundation, Inc. |
433f49c4 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
18 | ||
19 | #include <ctype.h> | |
57c9179c | 20 | #include <errno.h> |
433f49c4 UD |
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 | /* Path of the file. */ | |
31 | static const char default_nss[] = "/etc/default/nss"; | |
32 | ||
33 | /* Flags once read from the file. */ | |
34 | static int default_nss_flags; | |
35 | ||
36 | /* Code to make sure we call 'init' once. */ | |
37 | __libc_once_define (static, once); | |
38 | ||
ee821689 UD |
39 | /* Table of the recognized variables. */ |
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 }, | |
4eaa9bb4 | 49 | { STRNLEN ("SERVICES_AUTHORITATIVE"), NSS_FLAG_SERVICES_AUTHORITATIVE }, |
71170aa0 UD |
50 | { STRNLEN ("SETENT_BATCH_READ"), NSS_FLAG_SETENT_BATCH_READ }, |
51 | { STRNLEN ("ADJUNCT_AS_SHADOW"), NSS_FLAG_ADJUNCT_AS_SHADOW }, | |
ee821689 UD |
52 | }; |
53 | #define nvars (sizeof (vars) / sizeof (vars[0])) | |
54 | ||
433f49c4 UD |
55 | |
56 | static void | |
57 | init (void) | |
58 | { | |
57c9179c | 59 | int saved_errno = errno; |
433f49c4 UD |
60 | FILE *fp = fopen (default_nss, "rc"); |
61 | if (fp != NULL) | |
62 | { | |
63 | char *line = NULL; | |
64 | size_t linelen = 0; | |
65 | ||
66 | __fsetlocking (fp, FSETLOCKING_BYCALLER); | |
67 | ||
68 | while (!feof_unlocked (fp)) | |
69 | { | |
70 | ssize_t n = getline (&line, &linelen, fp); | |
71 | if (n <= 0) | |
72 | break; | |
73 | ||
ee821689 | 74 | /* Recognize only |
433f49c4 | 75 | |
ee821689 | 76 | <THE-VARIABLE> = TRUE |
433f49c4 UD |
77 | |
78 | with arbitrary white spaces. */ | |
79 | char *cp = line; | |
80 | while (isspace (*cp)) | |
81 | ++cp; | |
82 | ||
83 | /* Recognize comment lines. */ | |
84 | if (*cp == '#') | |
85 | continue; | |
86 | ||
ee821689 UD |
87 | int idx; |
88 | for (idx = 0; idx < nvars; ++idx) | |
89 | if (strncmp (cp, vars[idx].name, vars[idx].len) == 0) | |
90 | break; | |
91 | if (idx == nvars) | |
433f49c4 UD |
92 | continue; |
93 | ||
ee821689 | 94 | cp += vars[idx].len; |
433f49c4 UD |
95 | while (isspace (*cp)) |
96 | ++cp; | |
97 | if (*cp++ != '=') | |
98 | continue; | |
99 | while (isspace (*cp)) | |
100 | ++cp; | |
101 | ||
102 | if (strncmp (cp, "TRUE", 4) != 0) | |
103 | continue; | |
104 | cp += 4; | |
105 | ||
106 | while (isspace (*cp)) | |
107 | ++cp; | |
108 | ||
109 | if (*cp == '\0') | |
ee821689 | 110 | default_nss_flags |= vars[idx].flag; |
433f49c4 UD |
111 | } |
112 | ||
113 | free (line); | |
114 | ||
115 | fclose (fp); | |
116 | } | |
57c9179c | 117 | __set_errno (saved_errno); |
433f49c4 UD |
118 | } |
119 | ||
120 | ||
121 | int | |
122 | _nsl_default_nss (void) | |
123 | { | |
124 | /* If we have not yet read the file yet do it now. */ | |
125 | __libc_once (once, init); | |
126 | ||
127 | return default_nss_flags; | |
128 | } |