1 /* Copyright (C) 1996,2001,2004,2006,2007,2010,2011
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
22 #include <stdio_ext.h>
25 #include <bits/libc-lock.h>
30 /* Path of the file. */
31 static const char default_nss
[] = "/etc/default/nss";
33 /* Flags once read from the file. */
34 static int default_nss_flags
;
36 /* Code to make sure we call 'init' once. */
37 __libc_once_define (static, once
);
39 /* Table of the recognized variables. */
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 { STRNLEN ("ADJUNCT_AS_SHADOW"), NSS_FLAG_ADJUNCT_AS_SHADOW
},
53 #define nvars (sizeof (vars) / sizeof (vars[0]))
59 int saved_errno
= errno
;
60 FILE *fp
= fopen (default_nss
, "rce");
66 __fsetlocking (fp
, FSETLOCKING_BYCALLER
);
68 while (!feof_unlocked (fp
))
70 ssize_t n
= getline (&line
, &linelen
, fp
);
78 with arbitrary white spaces. */
83 /* Recognize comment lines. */
88 for (idx
= 0; idx
< nvars
; ++idx
)
89 if (strncmp (cp
, vars
[idx
].name
, vars
[idx
].len
) == 0)
102 if (strncmp (cp
, "TRUE", 4) != 0)
106 while (isspace (*cp
))
110 default_nss_flags
|= vars
[idx
].flag
;
117 __set_errno (saved_errno
);
122 _nsl_default_nss (void)
124 /* If we have not yet read the file yet do it now. */
125 __libc_once (once
, init
);
127 return default_nss_flags
;