1 /* Copyright (C) 1996 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. */
25 #include <libc-lock.h>
26 #include <rpc/key_prot.h>
27 #include <rpcsvc/yp.h>
28 #include <rpcsvc/ypclnt.h>
32 extern int xdecrypt (char *, char *);
34 /* If we found the entry, we give a SUCCESS and an empty key back. */
36 _nss_nis_getpublickey (const char *netname
, char *pkey
)
38 enum nss_status retval
;
39 char *domain
, *result
;
47 return NSS_STATUS_UNAVAIL
;
50 domain
= strchr (netname
, '@');
52 return NSS_STATUS_UNAVAIL
;
55 retval
= yperr2nss (yp_match (domain
, "publickey.byname", netname
,
56 strlen (netname
), &result
, &len
));
58 if (retval
!= NSS_STATUS_SUCCESS
)
60 if (retval
== NSS_STATUS_TRYAGAIN
)
67 char *p
= strchr (result
, ':');
70 strcpy (pkey
, result
);
72 return NSS_STATUS_SUCCESS
;
76 _nss_nis_getsecretkey (const char *netname
, char *skey
, char *passwd
)
78 enum nss_status retval
;
80 char *domain
, *result
;
85 if (netname
== NULL
|| passwd
== NULL
)
88 return NSS_STATUS_UNAVAIL
;
91 domain
= strchr (netname
, '@');
93 return NSS_STATUS_UNAVAIL
;
96 retval
= yperr2nss (yp_match (domain
, "publickey.byname", netname
,
97 strlen (netname
), &result
, &len
));
99 if (retval
!= NSS_STATUS_SUCCESS
)
101 if (retval
== NSS_STATUS_TRYAGAIN
)
102 __set_errno (EAGAIN
);
108 char *p
= strchr (result
, ':');
110 return NSS_STATUS_SUCCESS
;
114 if (!xdecrypt (buf
, passwd
))
115 return NSS_STATUS_SUCCESS
;
117 if (memcmp (buf
, &(buf
[HEXKEYBYTES
]), KEYCHECKSUMSIZE
) != 0)
118 return NSS_STATUS_SUCCESS
;
120 buf
[HEXKEYBYTES
] = 0;
123 return NSS_STATUS_SUCCESS
;
126 /* Parse uid and group information from the passed string.
127 The format of the string passed is uid:gid,grp,grp, ... */
128 static enum nss_status
129 parse_netid_str (const char *s
, uid_t
*uidp
, gid_t
*gidp
, int *gidlenp
,
134 if (!s
|| !isdigit (*s
))
136 syslog (LOG_ERR
, "netname2user: expecting uid '%s'", s
);
137 return NSS_STATUS_NOTFOUND
; /* XXX need a better error */
145 syslog (LOG_ERR
, "netname2user: should not have uid 0");
146 return NSS_STATUS_NOTFOUND
;
149 /* Now get the group list */
153 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'", s
);
154 return NSS_STATUS_NOTFOUND
;
157 if (!p
|| (!isdigit (*p
)))
159 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'.", p
);
160 return NSS_STATUS_NOTFOUND
;
167 while ((p
= strchr (p
, ',')) != NULL
)
170 gidlist
[*gidlenp
++] = atoi (p
);
174 return NSS_STATUS_SUCCESS
;
179 _nss_nis_netname2user (char netname
[MAXNETNAMELEN
+ 1], uid_t
*uidp
,
180 gid_t
*gidp
, int *gidlenp
, gid_t
*gidlist
)
187 domain
= strchr (netname
, '@');
189 return NSS_STATUS_UNAVAIL
;
191 /* Point past the '@' character */
194 yperr
= yp_match (domain
, "netid.byname", netname
, strlen (netname
),
199 break; /* the successful case */
202 return NSS_STATUS_NOTFOUND
;
205 return NSS_STATUS_UNAVAIL
;
212 err
= parse_netid_str (lookup
, uidp
, gidp
, gidlenp
, gidlist
);
217 return NSS_STATUS_NOTFOUND
;
219 return NSS_STATUS_SUCCESS
;