1 /* Copyright (C) 1996-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
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, see
17 <http://www.gnu.org/licenses/>. */
25 #include <rpcsvc/yp.h>
26 #include <rpcsvc/ypclnt.h>
27 #include <rpc/key_prot.h>
28 extern int xdecrypt (char *, char *);
32 /* If we haven't found the entry, we give a SUCCESS and an empty key back.
33 Solaris docu says: sizeof (pkey) == HEXKEYBYTES + 1.
36 _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
43 return NSS_STATUS_UNAVAIL;
46 char *domain = strchr (netname, '@');
50 return NSS_STATUS_UNAVAIL;
56 int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
59 if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
61 enum nss_status retval = yperr2nss (yperr);
63 if (retval == NSS_STATUS_TRYAGAIN)
70 char *p = strchr (result, ':');
73 strncpy (pkey, result, HEXKEYBYTES + 1);
74 pkey[HEXKEYBYTES] = '\0';
77 return NSS_STATUS_SUCCESS;
81 _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
86 if (netname == NULL || passwd == NULL)
89 return NSS_STATUS_UNAVAIL;
92 char *domain = strchr (netname, '@');
96 return NSS_STATUS_UNAVAIL;
102 int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
105 if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
107 enum nss_status retval = yperr2nss (yperr);
109 if (retval == NSS_STATUS_TRYAGAIN)
116 char *p = strchr (result, ':');
119 char buf[2 * (HEXKEYBYTES + 1)];
122 strncpy (buf, p, 2 * (HEXKEYBYTES + 1));
123 buf[2 * HEXKEYBYTES + 1] = '\0';
124 if (xdecrypt (buf, passwd)
125 && memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) == 0)
127 buf[HEXKEYBYTES] = '\0';
134 return NSS_STATUS_SUCCESS;
137 /* Parse uid and group information from the passed string.
138 The format of the string passed is uid:gid,grp,grp, ... */
139 static enum nss_status
140 parse_netid_str (const char *s, uid_t *uidp, gid_t *gidp, int *gidlenp,
146 if (!s || !isdigit (*s))
148 syslog (LOG_ERR, "netname2user: expecting uid '%s'", s);
149 return NSS_STATUS_NOTFOUND; /* XXX need a better error */
153 *uidp = strtoul (s, NULL, 10);
157 syslog (LOG_ERR, "netname2user: should not have uid 0");
158 return NSS_STATUS_NOTFOUND;
161 /* Now get the group list */
165 syslog (LOG_ERR, "netname2user: missing group id list in '%s'", s);
166 return NSS_STATUS_NOTFOUND;
169 if (!p || (!isdigit (*p)))
171 syslog (LOG_ERR, "netname2user: missing group id list in '%s'.", p);
172 return NSS_STATUS_NOTFOUND;
175 *gidp = strtoul (p, &ep, 10);
179 /* After strtoul() ep should point to the first invalid character.
180 This is the marker "," we search for the next value. */
181 while (ep != NULL && *ep == ',')
185 gidlist[gidlen++] = strtoul (p, &ep, 10);
190 return NSS_STATUS_SUCCESS;
195 _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
196 gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop)
198 char *domain = strchr (netname, '@');
202 return NSS_STATUS_UNAVAIL;
205 /* Point past the '@' character */
209 int yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
214 break; /* the successful case */
217 return NSS_STATUS_NOTFOUND;
220 return NSS_STATUS_UNAVAIL;
224 return NSS_STATUS_NOTFOUND;
229 enum nss_status err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);