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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <stdio_ext.h>
26 #include <bits/libc-lock.h>
31 /* Path of the file. */
32 static const char default_nss
[] = "/etc/default/nss";
34 /* Flags once read from the file. */
35 static int default_nss_flags
;
37 /* Code to make sure we call 'init' once. */
38 __libc_once_define (static, once
);
40 /* Table of the recognized variables. */
48 #define STRNLEN(s) s, sizeof (s) - 1
49 { STRNLEN ("NETID_AUTHORITATIVE"), NSS_FLAG_NETID_AUTHORITATIVE
},
50 { STRNLEN ("SERVICES_AUTHORITATIVE"), NSS_FLAG_SERVICES_AUTHORITATIVE
},
51 { STRNLEN ("SETENT_BATCH_READ"), NSS_FLAG_SETENT_BATCH_READ
},
52 { STRNLEN ("ADJUNCT_AS_SHADOW"), NSS_FLAG_ADJUNCT_AS_SHADOW
},
54 #define nvars (sizeof (vars) / sizeof (vars[0]))
60 int saved_errno
= errno
;
61 FILE *fp
= fopen (default_nss
, "rce");
67 __fsetlocking (fp
, FSETLOCKING_BYCALLER
);
69 while (!feof_unlocked (fp
))
71 ssize_t n
= getline (&line
, &linelen
, fp
);
79 with arbitrary white spaces. */
84 /* Recognize comment lines. */
89 for (idx
= 0; idx
< nvars
; ++idx
)
90 if (strncmp (cp
, vars
[idx
].name
, vars
[idx
].len
) == 0)
100 while (isspace (*cp
))
103 if (strncmp (cp
, "TRUE", 4) != 0)
107 while (isspace (*cp
))
111 default_nss_flags
|= vars
[idx
].flag
;
118 __set_errno (saved_errno
);
123 _nsl_default_nss (void)
125 /* If we have not yet read the file yet do it now. */
126 __libc_once (once
, init
);
128 return default_nss_flags
;