1 /* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
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
, '@');
53 return NSS_STATUS_UNAVAIL
;
56 retval
= yperr2nss (yp_match (domain
, "publickey.byname", netname
,
57 strlen (netname
), &result
, &len
));
59 if (retval
!= NSS_STATUS_SUCCESS
)
61 if (retval
== NSS_STATUS_NOTFOUND
)
63 else if (retval
== NSS_STATUS_TRYAGAIN
)
70 char *p
= strchr (result
, ':');
73 strncpy (pkey
, result
, HEXKEYBYTES
+ 1);
74 pkey
[HEXKEYBYTES
] = '\0';
76 return NSS_STATUS_SUCCESS
;
80 _nss_nis_getsecretkey (const char *netname
, char *skey
, char *passwd
,
83 enum nss_status retval
;
84 char buf
[2 * (HEXKEYBYTES
+ 1)];
85 char *domain
, *result
;
90 if (netname
== NULL
|| passwd
== NULL
)
93 return NSS_STATUS_UNAVAIL
;
96 domain
= strchr (netname
, '@');
98 return NSS_STATUS_UNAVAIL
;
101 retval
= yperr2nss (yp_match (domain
, "publickey.byname", netname
,
102 strlen (netname
), &result
, &len
));
104 if (retval
!= NSS_STATUS_SUCCESS
)
106 if (retval
== NSS_STATUS_NOTFOUND
)
108 else if (retval
== NSS_STATUS_TRYAGAIN
)
115 char *p
= strchr (result
, ':');
117 return NSS_STATUS_SUCCESS
;
120 strncpy (buf
, p
, 2 * (HEXKEYBYTES
+ 1));
121 buf
[2 * (HEXKEYBYTES
+ 1)] = '\0';
122 if (!xdecrypt (buf
, passwd
))
123 return NSS_STATUS_SUCCESS
;
125 if (memcmp (buf
, &(buf
[HEXKEYBYTES
]), KEYCHECKSUMSIZE
) != 0)
126 return NSS_STATUS_SUCCESS
;
128 buf
[HEXKEYBYTES
] = '\0';
131 return NSS_STATUS_SUCCESS
;
134 /* Parse uid and group information from the passed string.
135 The format of the string passed is uid:gid,grp,grp, ... */
136 static enum nss_status
137 parse_netid_str (const char *s
, uid_t
*uidp
, gid_t
*gidp
, int *gidlenp
,
143 if (!s
|| !isdigit (*s
))
145 syslog (LOG_ERR
, "netname2user: expecting uid '%s'", s
);
146 return NSS_STATUS_NOTFOUND
; /* XXX need a better error */
154 syslog (LOG_ERR
, "netname2user: should not have uid 0");
155 return NSS_STATUS_NOTFOUND
;
158 /* Now get the group list */
162 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'", s
);
163 return NSS_STATUS_NOTFOUND
;
166 if (!p
|| (!isdigit (*p
)))
168 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'.", p
);
169 return NSS_STATUS_NOTFOUND
;
176 while ((p
= strchr (p
, ',')) != NULL
)
179 gidlist
[gidlen
++] = atoi (p
);
184 return NSS_STATUS_SUCCESS
;
189 _nss_nis_netname2user (char netname
[MAXNETNAMELEN
+ 1], uid_t
*uidp
,
190 gid_t
*gidp
, int *gidlenp
, gid_t
*gidlist
, int *errnop
)
197 domain
= strchr (netname
, '@');
199 return NSS_STATUS_UNAVAIL
;
201 /* Point past the '@' character */
204 yperr
= yp_match (domain
, "netid.byname", netname
, strlen (netname
),
209 break; /* the successful case */
212 return NSS_STATUS_NOTFOUND
;
215 return NSS_STATUS_UNAVAIL
;
222 err
= parse_netid_str (lookup
, uidp
, gidp
, gidlenp
, gidlist
);
227 return NSS_STATUS_NOTFOUND
;
229 return NSS_STATUS_SUCCESS
;