Update.
[glibc.git] / nis / nss-nis.c
blob40370bae3b7de300fa17c545c625e3850cba5220
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 <stdlib.h>
23 #include <string.h>
24 #include <rpcsvc/ypclnt.h>
26 #include "nss-nis.h"
27 #include "nsswitch.h"
30 /* Convert YP error number to NSS error number. */
31 const enum nss_status __yperr2nss_tab[] =
33 [YPERR_SUCCESS] = NSS_STATUS_SUCCESS,
34 [YPERR_BADARGS] = NSS_STATUS_UNAVAIL,
35 [YPERR_RPC] = NSS_STATUS_UNAVAIL,
36 [YPERR_DOMAIN] = NSS_STATUS_UNAVAIL,
37 [YPERR_MAP] = NSS_STATUS_UNAVAIL,
38 [YPERR_KEY] = NSS_STATUS_NOTFOUND,
39 [YPERR_YPERR] = NSS_STATUS_UNAVAIL,
40 [YPERR_RESRC] = NSS_STATUS_TRYAGAIN,
41 [YPERR_NOMORE] = NSS_STATUS_NOTFOUND,
42 [YPERR_PMAP] = NSS_STATUS_UNAVAIL,
43 [YPERR_YPBIND] = NSS_STATUS_UNAVAIL,
44 [YPERR_YPSERV] = NSS_STATUS_UNAVAIL,
45 [YPERR_NODOM] = NSS_STATUS_UNAVAIL,
46 [YPERR_BADDB] = NSS_STATUS_UNAVAIL,
47 [YPERR_VERS] = NSS_STATUS_UNAVAIL,
48 [YPERR_ACCESS] = NSS_STATUS_UNAVAIL,
49 [YPERR_BUSY] = NSS_STATUS_TRYAGAIN
51 const unsigned int __yperr2nss_count = (sizeof (__yperr2nss_tab)
52 / sizeof (__yperr2nss_tab[0]));
54 int _nis_default_nss_flags;
56 static const char default_nss[] = "/etc/default/nss";
58 int
59 _nis_check_default_nss (void)
61 FILE *fp = fopen (default_nss, "rc");
62 int flags = NSS_FLAG_SET;
63 if (fp != NULL)
65 char *line = NULL;
66 size_t linelen = 0;
68 __fsetlocking (fp, FSETLOCKING_BYCALLER);
70 while (!feof_unlocked (fp))
72 ssize_t n = getline (&line, &linelen, fp);
73 if (n <= 0)
74 break;
76 /* There currently are only two variables we expect, so
77 simplify the parsing. Recognize only
79 NETID_AUTHORITATIVE = TRUE
80 SERVICES_AUTHORITATIVE = TRUE
82 with arbitrary white spaces. */
83 char *cp = line;
84 while (isspace (*cp))
85 ++cp;
87 /* Recognize comment lines. */
88 if (*cp == '#')
89 continue;
91 static const char netid_authoritative[] = "NETID_AUTHORITATIVE";
92 static const char services_authoritative[]
93 = "SERVICES_AUTHORITATIVE";
94 size_t flag_len;
95 if (strncmp (cp, netid_authoritative,
96 flag_len = sizeof (netid_authoritative) - 1) != 0
97 && strncmp (cp, services_authoritative,
98 flag_len = sizeof (services_authoritative) - 1)
99 != 0)
100 continue;
102 cp += flag_len;
103 while (isspace (*cp))
104 ++cp;
105 if (*cp++ != '=')
106 continue;
107 while (isspace (*cp))
108 ++cp;
110 if (strncmp (cp, "TRUE", 4) != 0)
111 continue;
112 cp += 4;
114 while (isspace (*cp))
115 ++cp;
117 if (*cp == '\0')
118 flags |= flag_len == sizeof (netid_authoritative) - 1
119 ? NSS_FLAG_NETID_AUTHORITATIVE
120 : NSS_FLAG_SERVICES_AUTHORITATIVE;
123 free (line);
125 fclose (fp);
128 _nis_default_nss_flags = flags;
129 return flags;