]>
git.ipfire.org Git - thirdparty/glibc.git/blob - nis/nss_nis/nis-spwd.c
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 <rpcsvc/yp.h>
27 #include <rpcsvc/ypclnt.h>
31 /* Protect global state against multiple changers */
32 __libc_lock_define_initialized (static, lock
)
34 static bool_t new_start
= 1;
35 static char *oldkey
= NULL
;
36 static int oldkeylen
= 0;
39 _nss_nis_setspent (void)
41 __libc_lock_lock (lock
);
51 __libc_lock_unlock (lock
);
53 return NSS_STATUS_SUCCESS
;
57 _nss_nis_endspent (void)
59 __libc_lock_lock (lock
);
69 __libc_lock_unlock (lock
);
71 return NSS_STATUS_SUCCESS
;
74 static enum nss_status
75 internal_nis_getspent_r (struct spwd
*sp
, char *buffer
, size_t buflen
)
77 char *domain
, *result
, *outkey
;
78 int len
, keylen
, parse_res
;
80 if (yp_get_default_domain (&domain
))
81 return NSS_STATUS_UNAVAIL
;
83 /* Get the next entry until we found a correct one. */
86 enum nss_status retval
;
90 retval
= yperr2nss (yp_first (domain
, "shadow.byname",
91 &outkey
, &keylen
, &result
, &len
));
93 retval
= yperr2nss ( yp_next (domain
, "shadow.byname",
95 &outkey
, &keylen
, &result
, &len
));
97 if (retval
!= NSS_STATUS_SUCCESS
)
99 if (retval
== NSS_STATUS_TRYAGAIN
)
100 __set_errno (EAGAIN
);
104 if ((size_t) (len
+ 1) > buflen
)
107 __set_errno (ERANGE
);
108 return NSS_STATUS_TRYAGAIN
;
111 p
= strncpy (buffer
, result
, len
);
117 parse_res
= _nss_files_parse_spent (p
, sp
, buffer
, buflen
);
118 if (!parse_res
&& errno
== ERANGE
)
119 return NSS_STATUS_TRYAGAIN
;
128 return NSS_STATUS_SUCCESS
;
132 _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
);
140 __libc_lock_unlock (lock
);
146 _nss_nis_getspnam_r (const char *name
, struct spwd
*sp
,
147 char *buffer
, size_t buflen
)
149 enum nss_status retval
;
150 char *domain
, *result
, *p
;
155 __set_errno (EINVAL
);
156 return NSS_STATUS_UNAVAIL
;
159 if (yp_get_default_domain (&domain
))
160 return NSS_STATUS_UNAVAIL
;
162 retval
= yperr2nss (yp_match (domain
, "shadow.byname", name
,
163 strlen (name
), &result
, &len
));
165 if (retval
!= NSS_STATUS_SUCCESS
)
167 if (retval
== NSS_STATUS_TRYAGAIN
)
168 __set_errno (EAGAIN
);
172 if ((size_t) (len
+ 1) > buflen
)
175 __set_errno (ERANGE
);
176 return NSS_STATUS_TRYAGAIN
;
179 p
= strncpy (buffer
, result
, len
);
185 parse_res
= _nss_files_parse_spent (p
, sp
, buffer
, buflen
);
190 return NSS_STATUS_TRYAGAIN
;
192 return NSS_STATUS_NOTFOUND
;
195 return NSS_STATUS_SUCCESS
;