1 /* Copyright (C) 1996, 2001, 2004, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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
21 #include <stdio_ext.h>
24 #include <bits/libc-lock.h>
29 /* Path of the file. */
30 static const char default_nss
[] = "/etc/default/nss";
32 /* Flags once read from the file. */
33 static int default_nss_flags
;
35 /* Code to make sure we call 'init' once. */
36 __libc_once_define (static, once
);
42 FILE *fp
= fopen (default_nss
, "rc");
48 __fsetlocking (fp
, FSETLOCKING_BYCALLER
);
50 while (!feof_unlocked (fp
))
52 ssize_t n
= getline (&line
, &linelen
, fp
);
56 /* There currently are only two variables we expect, so
57 simplify the parsing. Recognize only
59 NETID_AUTHORITATIVE = TRUE
60 SERVICES_AUTHORITATIVE = TRUE
62 with arbitrary white spaces. */
67 /* Recognize comment lines. */
71 static const char netid_authoritative
[] = "NETID_AUTHORITATIVE";
72 static const char services_authoritative
[]
73 = "SERVICES_AUTHORITATIVE";
75 if (strncmp (cp
, netid_authoritative
,
76 flag_len
= sizeof (netid_authoritative
) - 1) != 0
77 && strncmp (cp
, services_authoritative
,
78 flag_len
= sizeof (services_authoritative
) - 1)
90 if (strncmp (cp
, "TRUE", 4) != 0)
98 default_nss_flags
|= (flag_len
== sizeof (netid_authoritative
) - 1
99 ? NSS_FLAG_NETID_AUTHORITATIVE
100 : NSS_FLAG_SERVICES_AUTHORITATIVE
);
111 _nsl_default_nss (void)
113 /* If we have not yet read the file yet do it now. */
114 __libc_once (once
, init
);
116 return default_nss_flags
;