1 /* Copyright (C) 1996-1999,2001,2002,2005 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <rpcsvc/yp.h>
27 #include <rpcsvc/ypclnt.h>
28 #include <rpc/key_prot.h>
29 extern int xdecrypt (char *, char *);
33 /* If we haven't found the entry, we give a SUCCESS and an empty key back.
34 Solaris docu says: sizeof (pkey) == HEXKEYBYTES + 1.
37 _nss_nis_getpublickey (const char *netname
, char *pkey
, int *errnop
)
39 enum nss_status retval
;
40 char *domain
, *result
;
48 return NSS_STATUS_UNAVAIL
;
51 domain
= strchr (netname
, '@');
55 return NSS_STATUS_UNAVAIL
;
59 retval
= yperr2nss (yp_match (domain
, "publickey.byname", netname
,
60 strlen (netname
), &result
, &len
));
62 if (retval
!= NSS_STATUS_SUCCESS
)
64 if (retval
== NSS_STATUS_TRYAGAIN
)
71 char *p
= strchr (result
, ':');
74 strncpy (pkey
, result
, HEXKEYBYTES
+ 1);
75 pkey
[HEXKEYBYTES
] = '\0';
77 return NSS_STATUS_SUCCESS
;
81 _nss_nis_getsecretkey (const char *netname
, char *skey
, char *passwd
,
84 enum nss_status retval
;
85 char buf
[2 * (HEXKEYBYTES
+ 1)];
86 char *domain
, *result
;
91 if (netname
== NULL
|| passwd
== NULL
)
94 return NSS_STATUS_UNAVAIL
;
97 domain
= strchr (netname
, '@');
101 return NSS_STATUS_UNAVAIL
;
105 retval
= yperr2nss (yp_match (domain
, "publickey.byname", netname
,
106 strlen (netname
), &result
, &len
));
108 if (retval
!= NSS_STATUS_SUCCESS
)
110 if (retval
== NSS_STATUS_TRYAGAIN
)
117 char *p
= strchr (result
, ':');
119 return NSS_STATUS_SUCCESS
;
122 strncpy (buf
, p
, 2 * (HEXKEYBYTES
+ 1));
123 buf
[2 * HEXKEYBYTES
+ 1] = '\0';
124 if (!xdecrypt (buf
, passwd
))
125 return NSS_STATUS_SUCCESS
;
127 if (memcmp (buf
, &(buf
[HEXKEYBYTES
]), KEYCHECKSUMSIZE
) != 0)
128 return NSS_STATUS_SUCCESS
;
130 buf
[HEXKEYBYTES
] = '\0';
133 return NSS_STATUS_SUCCESS
;
136 /* Parse uid and group information from the passed string.
137 The format of the string passed is uid:gid,grp,grp, ... */
138 static enum nss_status
139 parse_netid_str (const char *s
, uid_t
*uidp
, gid_t
*gidp
, int *gidlenp
,
145 if (!s
|| !isdigit (*s
))
147 syslog (LOG_ERR
, "netname2user: expecting uid '%s'", s
);
148 return NSS_STATUS_NOTFOUND
; /* XXX need a better error */
152 *uidp
= strtoul (s
, NULL
, 10);
156 syslog (LOG_ERR
, "netname2user: should not have uid 0");
157 return NSS_STATUS_NOTFOUND
;
160 /* Now get the group list */
164 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'", s
);
165 return NSS_STATUS_NOTFOUND
;
168 if (!p
|| (!isdigit (*p
)))
170 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'.", p
);
171 return NSS_STATUS_NOTFOUND
;
174 *gidp
= strtoul (p
, &ep
, 10);
178 /* After strtoul() ep should point to the first invalid character.
179 This is the marker "," we search for the next value. */
180 while (ep
!= NULL
&& *ep
== ',')
184 gidlist
[gidlen
++] = strtoul (p
, &ep
, 10);
189 return NSS_STATUS_SUCCESS
;
194 _nss_nis_netname2user (char netname
[MAXNETNAMELEN
+ 1], uid_t
*uidp
,
195 gid_t
*gidp
, int *gidlenp
, gid_t
*gidlist
, int *errnop
)
202 domain
= strchr (netname
, '@');
206 return NSS_STATUS_UNAVAIL
;
209 /* Point past the '@' character */
212 yperr
= yp_match (domain
, "netid.byname", netname
, strlen (netname
),
217 break; /* the successful case */
220 return NSS_STATUS_NOTFOUND
;
223 return NSS_STATUS_UNAVAIL
;
231 err
= parse_netid_str (lookup
, uidp
, gidp
, gidlenp
, gidlist
);
236 return NSS_STATUS_NOTFOUND
;
238 return NSS_STATUS_SUCCESS
;