1 /* Copyright (C) 1996-1999,2001,2002,2005,2006 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
)
44 return NSS_STATUS_UNAVAIL
;
47 char *domain
= strchr (netname
, '@');
51 return NSS_STATUS_UNAVAIL
;
57 int yperr
= yp_match (domain
, "publickey.byname", netname
, strlen (netname
),
60 if (__builtin_expect (yperr
!= YPERR_SUCCESS
, 0))
62 enum nss_status retval
= yperr2nss (yperr
);
64 if (retval
== NSS_STATUS_TRYAGAIN
)
71 char *p
= strchr (result
, ':');
74 strncpy (pkey
, result
, HEXKEYBYTES
+ 1);
75 pkey
[HEXKEYBYTES
] = '\0';
78 return NSS_STATUS_SUCCESS
;
82 _nss_nis_getsecretkey (const char *netname
, char *skey
, char *passwd
,
87 if (netname
== NULL
|| passwd
== NULL
)
90 return NSS_STATUS_UNAVAIL
;
93 char *domain
= strchr (netname
, '@');
97 return NSS_STATUS_UNAVAIL
;
103 int yperr
= yp_match (domain
, "publickey.byname", netname
, strlen (netname
),
106 if (__builtin_expect (yperr
!= YPERR_SUCCESS
, 0))
108 enum nss_status retval
= yperr2nss (yperr
);
110 if (retval
== NSS_STATUS_TRYAGAIN
)
117 char *p
= strchr (result
, ':');
120 char buf
[2 * (HEXKEYBYTES
+ 1)];
123 strncpy (buf
, p
, 2 * (HEXKEYBYTES
+ 1));
124 buf
[2 * HEXKEYBYTES
+ 1] = '\0';
125 if (xdecrypt (buf
, passwd
)
126 && memcmp (buf
, &(buf
[HEXKEYBYTES
]), KEYCHECKSUMSIZE
) == 0)
128 buf
[HEXKEYBYTES
] = '\0';
135 return NSS_STATUS_SUCCESS
;
138 /* Parse uid and group information from the passed string.
139 The format of the string passed is uid:gid,grp,grp, ... */
140 static enum nss_status
141 parse_netid_str (const char *s
, uid_t
*uidp
, gid_t
*gidp
, int *gidlenp
,
147 if (!s
|| !isdigit (*s
))
149 syslog (LOG_ERR
, "netname2user: expecting uid '%s'", s
);
150 return NSS_STATUS_NOTFOUND
; /* XXX need a better error */
154 *uidp
= strtoul (s
, NULL
, 10);
158 syslog (LOG_ERR
, "netname2user: should not have uid 0");
159 return NSS_STATUS_NOTFOUND
;
162 /* Now get the group list */
166 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'", s
);
167 return NSS_STATUS_NOTFOUND
;
170 if (!p
|| (!isdigit (*p
)))
172 syslog (LOG_ERR
, "netname2user: missing group id list in '%s'.", p
);
173 return NSS_STATUS_NOTFOUND
;
176 *gidp
= strtoul (p
, &ep
, 10);
180 /* After strtoul() ep should point to the first invalid character.
181 This is the marker "," we search for the next value. */
182 while (ep
!= NULL
&& *ep
== ',')
186 gidlist
[gidlen
++] = strtoul (p
, &ep
, 10);
191 return NSS_STATUS_SUCCESS
;
196 _nss_nis_netname2user (char netname
[MAXNETNAMELEN
+ 1], uid_t
*uidp
,
197 gid_t
*gidp
, int *gidlenp
, gid_t
*gidlist
, int *errnop
)
199 char *domain
= strchr (netname
, '@');
203 return NSS_STATUS_UNAVAIL
;
206 /* Point past the '@' character */
210 int yperr
= yp_match (domain
, "netid.byname", netname
, strlen (netname
),
215 break; /* the successful case */
218 return NSS_STATUS_NOTFOUND
;
221 return NSS_STATUS_UNAVAIL
;
225 return NSS_STATUS_NOTFOUND
;
230 enum nss_status err
= parse_netid_str (lookup
, uidp
, gidp
, gidlenp
, gidlist
);