1 /* Copyright (C) 1996-1998,2001,2002,2003,2006 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
,
72 if (__builtin_expect (yp_get_default_domain (&domain
), 0))
73 return NSS_STATUS_UNAVAIL
;
75 /* Get the next entry until we found a correct one. */
86 yperr
= yp_first (domain
, "shadow.byname", &outkey
, &keylen
, &result
,
89 yperr
= yp_next (domain
, "shadow.byname", oldkey
, oldkeylen
, &outkey
,
90 &keylen
, &result
, &len
);
92 if (__builtin_expect (yperr
!= YPERR_SUCCESS
, 0))
94 enum nss_status retval
= yperr2nss (yperr
);
96 if (retval
== NSS_STATUS_TRYAGAIN
)
101 if (__builtin_expect ((size_t) (len
+ 1) > buflen
, 0))
105 return NSS_STATUS_TRYAGAIN
;
108 char *p
= strncpy (buffer
, result
, len
);
114 parse_res
= _nss_files_parse_spent (p
, sp
, (void *) buffer
, buflen
,
116 if (__builtin_expect (parse_res
== -1, 0))
120 return NSS_STATUS_TRYAGAIN
;
130 return NSS_STATUS_SUCCESS
;
134 _nss_nis_getspent_r (struct spwd
*result
, char *buffer
, size_t buflen
,
139 __libc_lock_lock (lock
);
141 status
= internal_nis_getspent_r (result
, buffer
, buflen
, errnop
);
143 __libc_lock_unlock (lock
);
149 _nss_nis_getspnam_r (const char *name
, struct spwd
*sp
,
150 char *buffer
, size_t buflen
, int *errnop
)
155 return NSS_STATUS_UNAVAIL
;
159 if (__builtin_expect (yp_get_default_domain (&domain
), 0))
160 return NSS_STATUS_UNAVAIL
;
164 int yperr
= yp_match (domain
, "shadow.byname", name
, strlen (name
), &result
,
167 if (__builtin_expect (yperr
!= YPERR_SUCCESS
, 0))
169 enum nss_status retval
= yperr2nss (yperr
);
171 if (retval
== NSS_STATUS_TRYAGAIN
)
176 if (__builtin_expect ((size_t) (len
+ 1) > buflen
, 0))
180 return NSS_STATUS_TRYAGAIN
;
183 char *p
= strncpy (buffer
, result
, len
);
189 int parse_res
= _nss_files_parse_spent (p
, sp
, (void *) buffer
, buflen
,
191 if (__builtin_expect (parse_res
< 1, 0))
194 return NSS_STATUS_TRYAGAIN
;
196 return NSS_STATUS_NOTFOUND
;
198 return NSS_STATUS_SUCCESS
;