(INTERNAL_SYSCALL): Add LOAD_REGS_##nr. (LOAD_ARGS_0, LOAD_ARGS_1, LOAD_ARGS_2, LOAD_...
[glibc.git] / nis / nss-nis.c
blob59129a894388ca123fafedb6a39aacea26b7248e
1 /* Copyright (C) 1996, 2001, 2004 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 <string.h>
23 #include <rpcsvc/ypclnt.h>
25 #include "nss-nis.h"
26 #include "nsswitch.h"
29 /* Convert YP error number to NSS error number. */
30 const enum nss_status __yperr2nss_tab[] =
32 [YPERR_SUCCESS] = NSS_STATUS_SUCCESS,
33 [YPERR_BADARGS] = NSS_STATUS_UNAVAIL,
34 [YPERR_RPC] = NSS_STATUS_UNAVAIL,
35 [YPERR_DOMAIN] = NSS_STATUS_UNAVAIL,
36 [YPERR_MAP] = NSS_STATUS_UNAVAIL,
37 [YPERR_KEY] = NSS_STATUS_NOTFOUND,
38 [YPERR_YPERR] = NSS_STATUS_UNAVAIL,
39 [YPERR_RESRC] = NSS_STATUS_TRYAGAIN,
40 [YPERR_NOMORE] = NSS_STATUS_NOTFOUND,
41 [YPERR_PMAP] = NSS_STATUS_UNAVAIL,
42 [YPERR_YPBIND] = NSS_STATUS_UNAVAIL,
43 [YPERR_YPSERV] = NSS_STATUS_UNAVAIL,
44 [YPERR_NODOM] = NSS_STATUS_UNAVAIL,
45 [YPERR_BADDB] = NSS_STATUS_UNAVAIL,
46 [YPERR_VERS] = NSS_STATUS_UNAVAIL,
47 [YPERR_ACCESS] = NSS_STATUS_UNAVAIL,
48 [YPERR_BUSY] = NSS_STATUS_TRYAGAIN
50 const unsigned int __yperr2nss_count = (sizeof (__yperr2nss_tab)
51 / sizeof (__yperr2nss_tab[0]));
53 int _nis_default_nss_flags;
55 static const char default_nss[] = "/etc/default/nss";
57 int
58 _nis_check_default_nss (void)
60 FILE *fp = fopen (default_nss, "rc");
61 int flags = NSS_FLAG_SET;
62 if (fp != NULL)
64 char *line = NULL;
65 size_t linelen = 0;
67 __fsetlocking (fp, FSETLOCKING_BYCALLER);
69 while (!feof_unlocked (fp))
71 ssize_t n = getline (&line, &linelen, fp);
72 if (n <= 0)
73 break;
75 /* There currently are only two variables we expect, so
76 simplify the parsing. Recognize only
78 NETID_AUTHORITATIVE = TRUE
79 SERVICES_AUTHORITATIVE = TRUE
81 with arbitrary white spaces. */
82 char *cp = line;
83 while (isspace (*cp))
84 ++cp;
86 /* Recognize comment lines. */
87 if (*cp == '#')
88 continue;
90 static const char netid_authoritative[] = "NETID_AUTHORITATIVE";
91 static const char services_authoritative[]
92 = "SERVICES_AUTHORITATIVE";
93 size_t flag_len;
94 if (strncmp (cp, netid_authoritative,
95 flag_len = sizeof (netid_authoritative) - 1) != 0
96 && strncmp (cp, services_authoritative,
97 flag_len = sizeof (services_authoritative) - 1)
98 != 0)
99 continue;
101 cp += flag_len;
102 while (isspace (*cp))
103 ++cp;
104 if (*cp++ != '=')
105 continue;
106 while (isspace (*cp))
107 ++cp;
109 if (strncmp (cp, "TRUE", 4) != 0)
110 continue;
111 cp += 4;
113 while (isspace (*cp))
114 ++cp;
116 if (*cp == '\0')
117 flags |= flag_len == sizeof (netid_authoritative) - 1
118 ? NSS_FLAG_NETID_AUTHORITATIVE
119 : NSS_FLAG_SERVICES_AUTHORITATIVE;
122 free (line);
124 fclose (fp);
127 _nis_default_nss_flags = flags;
128 return flags;