1 /* Copyright (C) 1996-1998, 2001, 2002, 2003 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 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
24 /* The following is an ugly trick to avoid a prototype declaration for
26 #define _nss_nis_endspent _nss_nis_endspent_XXX
28 #undef _nss_nis_endspent
29 #include <bits/libc-lock.h>
30 #include <rpcsvc/yp.h>
31 #include <rpcsvc/ypclnt.h>
35 /* Get the declaration of the parser function. */
37 #define STRUCTURE spwd
39 #include <nss/nss_files/files-parse.c>
41 /* Protect global state against multiple changers */
42 __libc_lock_define_initialized (static, lock
)
44 static bool_t new_start
= 1;
49 _nss_nis_setspent (int stayopen
)
51 __libc_lock_lock (lock
);
58 __libc_lock_unlock (lock
);
60 return NSS_STATUS_SUCCESS
;
62 /* Make _nss_nis_endspent an alias of _nss_nis_setspent. We do this
63 even though the prototypes don't match. The argument of setspent
64 is not used so this makes no difference. */
65 strong_alias (_nss_nis_setspent
, _nss_nis_endspent
)
67 static enum nss_status
68 internal_nis_getspent_r (struct spwd
*sp
, char *buffer
, size_t buflen
,
71 struct parser_data
*data
= (void *) buffer
;
72 char *domain
, *result
, *outkey
;
73 int len
, keylen
, parse_res
;
75 if (yp_get_default_domain (&domain
))
76 return NSS_STATUS_UNAVAIL
;
78 /* Get the next entry until we found a correct one. */
81 enum nss_status retval
;
85 retval
= yperr2nss (yp_first (domain
, "shadow.byname",
86 &outkey
, &keylen
, &result
, &len
));
88 retval
= yperr2nss ( yp_next (domain
, "shadow.byname",
90 &outkey
, &keylen
, &result
, &len
));
92 if (retval
!= NSS_STATUS_SUCCESS
)
94 if (retval
== NSS_STATUS_TRYAGAIN
)
99 if ((size_t) (len
+ 1) > buflen
)
103 return NSS_STATUS_TRYAGAIN
;
106 p
= strncpy (buffer
, result
, len
);
112 parse_res
= _nss_files_parse_spent (p
, sp
, data
, buflen
, errnop
);
117 return NSS_STATUS_TRYAGAIN
;
127 return NSS_STATUS_SUCCESS
;
131 _nss_nis_getspent_r (struct spwd
*result
, char *buffer
, size_t buflen
,
136 __libc_lock_lock (lock
);
138 status
= internal_nis_getspent_r (result
, buffer
, buflen
, errnop
);
140 __libc_lock_unlock (lock
);
146 _nss_nis_getspnam_r (const char *name
, struct spwd
*sp
,
147 char *buffer
, size_t buflen
, int *errnop
)
149 struct parser_data
*data
= (void *) buffer
;
150 enum nss_status retval
;
151 char *domain
, *result
, *p
;
157 return NSS_STATUS_UNAVAIL
;
160 if (yp_get_default_domain (&domain
))
161 return NSS_STATUS_UNAVAIL
;
163 retval
= yperr2nss (yp_match (domain
, "shadow.byname", name
,
164 strlen (name
), &result
, &len
));
166 if (retval
!= NSS_STATUS_SUCCESS
)
168 if (retval
== NSS_STATUS_TRYAGAIN
)
173 if ((size_t) (len
+ 1) > buflen
)
177 return NSS_STATUS_TRYAGAIN
;
180 p
= strncpy (buffer
, result
, len
);
186 parse_res
= _nss_files_parse_spent (p
, sp
, data
, buflen
, errnop
);
190 return NSS_STATUS_TRYAGAIN
;
192 return NSS_STATUS_NOTFOUND
;
194 return NSS_STATUS_SUCCESS
;