(tests): Add tst-sigset2.
[glibc/history.git] / nis / nss-default.c
blob3287e68b8660dbae3d1b29972017adcb8c662582
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
17 02111-1307 USA. */
19 #include <ctype.h>
20 #include <stdio.h>
21 #include <stdio_ext.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <bits/libc-lock.h>
26 #include <libnsl.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);
39 static void
40 init (void)
42 FILE *fp = fopen (default_nss, "rc");
43 if (fp != NULL)
45 char *line = NULL;
46 size_t linelen = 0;
48 __fsetlocking (fp, FSETLOCKING_BYCALLER);
50 while (!feof_unlocked (fp))
52 ssize_t n = getline (&line, &linelen, fp);
53 if (n <= 0)
54 break;
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. */
63 char *cp = line;
64 while (isspace (*cp))
65 ++cp;
67 /* Recognize comment lines. */
68 if (*cp == '#')
69 continue;
71 static const char netid_authoritative[] = "NETID_AUTHORITATIVE";
72 static const char services_authoritative[]
73 = "SERVICES_AUTHORITATIVE";
74 size_t flag_len;
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)
79 != 0)
80 continue;
82 cp += flag_len;
83 while (isspace (*cp))
84 ++cp;
85 if (*cp++ != '=')
86 continue;
87 while (isspace (*cp))
88 ++cp;
90 if (strncmp (cp, "TRUE", 4) != 0)
91 continue;
92 cp += 4;
94 while (isspace (*cp))
95 ++cp;
97 if (*cp == '\0')
98 default_nss_flags |= (flag_len == sizeof (netid_authoritative) - 1
99 ? NSS_FLAG_NETID_AUTHORITATIVE
100 : NSS_FLAG_SERVICES_AUTHORITATIVE);
103 free (line);
105 fclose (fp);
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;