1 /* $NetBSD: getpwent.c,v 1.81 2012/09/08 15:15:06 dholland Exp $ */
4 * Copyright (c) 1997-2000, 2004-2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1988, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * Portions Copyright (c) 1994, 1995, Jason Downs. All rights reserved.
64 * Redistribution and use in source and binary forms, with or without
65 * modification, are permitted provided that the following conditions
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 * 2. Redistributions in binary form must reproduce the above copyright
70 * notice, this list of conditions and the following disclaimer in the
71 * documentation and/or other materials provided with the distribution.
73 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
74 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
75 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
77 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
79 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
80 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
81 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
82 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
86 #include <sys/cdefs.h>
87 #if defined(LIBC_SCCS) && !defined(lint)
89 static char sccsid
[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95";
91 __RCSID("$NetBSD: getpwent.c,v 1.81 2012/09/08 15:15:06 dholland Exp $");
93 #endif /* LIBC_SCCS and not lint */
95 #include "namespace.h"
96 #include "reentrant.h"
98 #include <sys/param.h>
105 #include <netgroup.h>
106 #include <nsswitch.h>
120 #include <machine/param.h>
122 #include <rpcsvc/yp_prot.h>
123 #include <rpcsvc/ypclnt.h>
126 #include "pw_private.h"
128 #define _PASSWD_COMPAT /* "passwd" defaults to compat, so always provide it */
131 __weak_alias(endpwent
,_endpwent
)
132 __weak_alias(setpassent
,_setpassent
)
133 __weak_alias(setpwent
,_setpwent
)
137 static mutex_t _pwmutex
= MUTEX_INITIALIZER
;
140 const char __yp_token
[] = "__YP!"; /* Let pwd_mkdb pull this in. */
144 * The pwd.db lookup techniques and data extraction code here must be kept
145 * in sync with that in `pwd_mkdb'.
148 #if defined(YP) || defined(HESIOD)
151 * Parses entry using pw_scan(3) (without the trailing \n)
152 * after copying to buf, and fills in pw with corresponding values.
153 * If old is non-zero, entry is in _PASSWORD_OLDFMT.
154 * Returns 1 if parsed successfully, 0 on parse failure.
157 _pw_parse(const char *entry
, struct passwd
*pw
, char *buf
, size_t buflen
,
162 _DIAGASSERT(entry
!= NULL
);
163 _DIAGASSERT(pw
!= NULL
);
164 _DIAGASSERT(buf
!= NULL
);
166 if (strlcpy(buf
, entry
, buflen
) >= buflen
)
168 flags
= _PASSWORD_NOWARN
;
170 flags
|= _PASSWORD_OLDFMT
;
171 return __pw_scan(buf
, pw
, &flags
);
173 #endif /* YP || HESIOD */
177 * if *db is NULL, dbopen(3) /etc/spwd.db or /etc/pwd.db (depending
178 * upon permissions, etc)
181 _pw_opendb(DB
**db
, int *version
)
187 const char *dbfile
= NULL
;
189 _DIAGASSERT(db
!= NULL
);
190 _DIAGASSERT(version
!= NULL
);
191 if (*db
!= NULL
) /* open *db */
194 if (geteuid() == 0) {
195 dbfile
= _PATH_SMP_DB
;
196 *db
= dbopen(dbfile
, O_RDONLY
, 0, DB_HASH
, NULL
);
199 dbfile
= _PATH_MP_DB
;
200 *db
= dbopen(dbfile
, O_RDONLY
, 0, DB_HASH
, NULL
);
205 syslog(LOG_ERR
, "%s: %m", dbfile
);
211 key
.data
= __UNCONST("VERSION");
212 key
.size
= strlen((char *)key
.data
) + 1;
213 switch ((*(*db
)->get
)(*db
, &key
, &value
, 0)) {
215 if (sizeof(*version
) != value
.size
)
217 (void)memcpy(version
, value
.data
, value
.size
);
220 *version
= 0; /* not found */
223 return NS_UNAVAIL
; /* error in db routines */
232 * Lookup key in *db, filling in pw
233 * with the result, allocating memory from buffer (size buflen).
234 * (The caller may point key.data to buffer on entry; the contents
235 * of key.data will be invalid on exit.)
238 _pw_getkey(DB
*db
, DBT
*key
,
239 struct passwd
*pw
, char *buffer
, size_t buflen
, int *pwflags
,
245 _DIAGASSERT(db
!= NULL
);
246 _DIAGASSERT(key
!= NULL
);
247 _DIAGASSERT(pw
!= NULL
);
248 _DIAGASSERT(buffer
!= NULL
);
249 /* pwflags may be NULL (if we don't care about them */
251 if (db
== NULL
) /* this shouldn't happen */
254 switch ((db
->get
)(db
, key
, &data
, 0)) {
258 return NS_NOTFOUND
; /* not found */
260 return NS_UNAVAIL
; /* error in db routines */
265 p
= (char *)data
.data
;
266 if (data
.size
> buflen
) {
272 * THE DECODING BELOW MUST MATCH THAT IN pwd_mkdb.
275 #define MACRO(a) do { a } while (/*CONSTCOND*/0)
276 #define EXPAND(e) MACRO(e = t; while ((*t++ = *p++));)
277 #define SCALAR(v) MACRO(memmove(&(v), p, sizeof v); p += sizeof v;)
279 EXPAND(pw
->pw_passwd
);
287 SCALAR(pw
->pw_change
);
288 EXPAND(pw
->pw_class
);
289 EXPAND(pw
->pw_gecos
);
291 EXPAND(pw
->pw_shell
);
297 SCALAR(pw
->pw_expire
);
299 /* See if there's any data left. If so, read in flags. */
300 if (data
.size
> (size_t) (p
- (char *)data
.data
)) {
302 } else { /* default */
303 *pwflags
= _PASSWORD_NOUID
|_PASSWORD_NOGID
;
312 * Obtain want bytes from buffer (of size buflen) and return a pointer
313 * to the available memory after adjusting buffer/buflen.
314 * Returns NULL if there is insufficient space.
317 _pw_memfrombuf(size_t want
, char **buffer
, size_t *buflen
)
321 if (want
> *buflen
) {
333 * Copy the contents of frompw to pw; memory for strings
334 * and arrays will be allocated from buf (of size buflen).
335 * If proto != NULL, use various fields in proto in preference to frompw.
336 * Returns 1 if copied successfully, 0 on copy failure.
337 * NOTE: frompw must not use buf for its own pointers.
340 _pw_copy(const struct passwd
*frompw
, struct passwd
*pw
,
341 char *buf
, size_t buflen
, const struct passwd
*protopw
, int protoflags
)
346 _DIAGASSERT(frompw
!= NULL
);
347 _DIAGASSERT(pw
!= NULL
);
348 _DIAGASSERT(buf
!= NULL
);
349 /* protopw may be NULL */
351 useproto
= protopw
&& protopw
->pw_name
;
353 #define COPYSTR(to, from) \
355 count = strlen((from)); \
356 (to) = _pw_memfrombuf(count+1, &buf, &buflen); \
359 memmove((to), (from), count); \
361 } while (0) /* LINTED */
363 #define COPYFIELD(field) COPYSTR(pw->field, frompw->field)
365 #define COPYPROTOFIELD(field) COPYSTR(pw->field, \
366 (useproto && *protopw->field ? protopw->field : frompw->field))
370 #ifdef PW_OVERRIDE_PASSWD
371 COPYPROTOFIELD(pw_passwd
);
373 COPYFIELD(pw_passwd
);
376 if (useproto
&& !(protoflags
& _PASSWORD_NOUID
))
377 pw
->pw_uid
= protopw
->pw_uid
;
379 pw
->pw_uid
= frompw
->pw_uid
;
381 if (useproto
&& !(protoflags
& _PASSWORD_NOGID
))
382 pw
->pw_gid
= protopw
->pw_gid
;
384 pw
->pw_gid
= frompw
->pw_gid
;
386 pw
->pw_change
= frompw
->pw_change
;
388 COPYPROTOFIELD(pw_gecos
);
389 COPYPROTOFIELD(pw_dir
);
390 COPYPROTOFIELD(pw_shell
);
394 #undef COPYPROTOFIELD
404 /* state shared between files methods */
406 int stayopen
; /* see getpassent(3) */
407 DB
*db
; /* passwd file handle */
408 int keynum
; /* key counter, -1 if no more */
412 static struct files_state _files_state
;
413 /* storage for non _r functions */
414 static struct passwd _files_passwd
;
415 static char _files_passwdbuf
[_GETPW_R_SIZE_MAX
];
418 _files_start(struct files_state
*state
)
422 _DIAGASSERT(state
!= NULL
);
425 rv
= _pw_opendb(&state
->db
, &state
->version
);
426 if (rv
!= NS_SUCCESS
)
432 _files_end(struct files_state
*state
)
435 _DIAGASSERT(state
!= NULL
);
439 (void)(state
->db
->close
)(state
->db
);
447 * Search state->db for the next desired entry.
448 * If search is _PW_KEYBYNUM, look for state->keynum.
449 * If search is _PW_KEYBYNAME, look for name.
450 * If search is _PW_KEYBYUID, look for uid.
451 * Sets *retval to the errno if the result is not NS_SUCCESS
455 _files_pwscan(int *retval
, struct passwd
*pw
, char *buffer
, size_t buflen
,
456 struct files_state
*state
, int search
, const char *name
, uid_t uid
)
463 _DIAGASSERT(retval
!= NULL
);
464 _DIAGASSERT(pw
!= NULL
);
465 _DIAGASSERT(buffer
!= NULL
);
466 _DIAGASSERT(state
!= NULL
);
467 /* name is NULL to indicate searching for uid */
471 if (state
->db
== NULL
) { /* only start if file not open yet */
472 rv
= _files_start(state
);
473 if (rv
!= NS_SUCCESS
)
474 goto filespwscan_out
;
477 for (;;) { /* search for a match */
480 if (state
->keynum
== -1)
481 return NS_NOTFOUND
; /* no more records */
483 from
= &state
->keynum
;
484 fromlen
= sizeof(state
->keynum
);
488 fromlen
= strlen(name
);
492 fromlen
= sizeof(uid
);
498 if (buflen
<= fromlen
) { /* buffer too small */
502 buffer
[0] = search
; /* setup key */
503 memmove(buffer
+ 1, from
, fromlen
);
504 key
.size
= fromlen
+ 1;
505 key
.data
= (u_char
*)buffer
;
508 rv
= _pw_getkey(state
->db
, &key
, pw
, buffer
, buflen
, NULL
,
510 if (rv
!= NS_SUCCESS
) /* no match */
512 if (pw
->pw_name
[0] == '+' || pw
->pw_name
[0] == '-') {
513 /* if a compat line */
514 if (search
== _PW_KEYBYNUM
)
515 continue; /* read next if pwent */
516 rv
= NS_NOTFOUND
; /* don't match if pw{nam,uid} */
522 if (rv
== NS_NOTFOUND
&& search
== _PW_KEYBYNUM
)
523 state
->keynum
= -1; /* flag `no more records' */
525 if (rv
== NS_SUCCESS
) {
526 if ((search
== _PW_KEYBYUID
&& pw
->pw_uid
!= uid
) ||
527 (search
== _PW_KEYBYNAME
&& strcmp(pw
->pw_name
, name
) != 0))
532 if (rv
!= NS_SUCCESS
&& rv
!= NS_NOTFOUND
)
539 _files_setpwent(void *nsrv
, void *nscb
, va_list ap
)
542 _files_state
.stayopen
= 0;
543 return _files_start(&_files_state
);
548 _files_setpassent(void *nsrv
, void *nscb
, va_list ap
)
550 int *retval
= va_arg(ap
, int *);
551 int stayopen
= va_arg(ap
, int);
555 _files_state
.stayopen
= stayopen
;
556 rv
= _files_start(&_files_state
);
557 *retval
= (rv
== NS_SUCCESS
);
563 _files_endpwent(void *nsrv
, void *nscb
, va_list ap
)
566 _files_state
.stayopen
= 0;
567 return _files_end(&_files_state
);
572 _files_getpwent(void *nsrv
, void *nscb
, va_list ap
)
574 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
578 _DIAGASSERT(retval
!= NULL
);
581 rv
= _files_pwscan(&rerror
, &_files_passwd
,
582 _files_passwdbuf
, sizeof(_files_passwdbuf
),
583 &_files_state
, _PW_KEYBYNUM
, NULL
, 0);
584 if (rv
== NS_SUCCESS
)
585 *retval
= &_files_passwd
;
591 _files_getpwent_r(void *nsrv
, void *nscb
, va_list ap
)
593 int *retval
= va_arg(ap
, int *);
594 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
595 char *buffer
= va_arg(ap
, char *);
596 size_t buflen
= va_arg(ap
, size_t);
597 struct passwd
**result
= va_arg(ap
, struct passwd
**);
601 _DIAGASSERT(retval
!= NULL
);
602 _DIAGASSERT(pw
!= NULL
);
603 _DIAGASSERT(buffer
!= NULL
);
604 _DIAGASSERT(result
!= NULL
);
606 rv
= _files_pwscan(retval
, pw
, buffer
, buflen
, &_files_state
,
607 _PW_KEYBYNUM
, NULL
, 0);
608 if (rv
== NS_SUCCESS
)
617 _files_getpwnam(void *nsrv
, void *nscb
, va_list ap
)
619 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
620 const char *name
= va_arg(ap
, const char *);
624 _DIAGASSERT(retval
!= NULL
);
627 rv
= _files_start(&_files_state
);
628 if (rv
!= NS_SUCCESS
)
630 rv
= _files_pwscan(&rerror
, &_files_passwd
,
631 _files_passwdbuf
, sizeof(_files_passwdbuf
),
632 &_files_state
, _PW_KEYBYNAME
, name
, 0);
633 if (!_files_state
.stayopen
)
634 _files_end(&_files_state
);
635 if (rv
== NS_SUCCESS
)
636 *retval
= &_files_passwd
;
642 _files_getpwnam_r(void *nsrv
, void *nscb
, va_list ap
)
644 int *retval
= va_arg(ap
, int *);
645 const char *name
= va_arg(ap
, const char *);
646 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
647 char *buffer
= va_arg(ap
, char *);
648 size_t buflen
= va_arg(ap
, size_t);
649 struct passwd
**result
= va_arg(ap
, struct passwd
**);
651 struct files_state state
;
654 _DIAGASSERT(retval
!= NULL
);
655 _DIAGASSERT(pw
!= NULL
);
656 _DIAGASSERT(buffer
!= NULL
);
657 _DIAGASSERT(result
!= NULL
);
660 memset(&state
, 0, sizeof(state
));
661 rv
= _files_pwscan(retval
, pw
, buffer
, buflen
, &state
,
662 _PW_KEYBYNAME
, name
, 0);
664 if (rv
== NS_SUCCESS
)
671 _files_getpwuid(void *nsrv
, void *nscb
, va_list ap
)
673 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
674 uid_t uid
= va_arg(ap
, uid_t
);
678 _DIAGASSERT(retval
!= NULL
);
681 rv
= _files_start(&_files_state
);
682 if (rv
!= NS_SUCCESS
)
684 rv
= _files_pwscan(&rerror
, &_files_passwd
,
685 _files_passwdbuf
, sizeof(_files_passwdbuf
),
686 &_files_state
, _PW_KEYBYUID
, NULL
, uid
);
687 if (!_files_state
.stayopen
)
688 _files_end(&_files_state
);
689 if (rv
== NS_SUCCESS
)
690 *retval
= &_files_passwd
;
696 _files_getpwuid_r(void *nsrv
, void *nscb
, va_list ap
)
698 int *retval
= va_arg(ap
, int *);
699 uid_t uid
= va_arg(ap
, uid_t
);
700 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
701 char *buffer
= va_arg(ap
, char *);
702 size_t buflen
= va_arg(ap
, size_t);
703 struct passwd
**result
= va_arg(ap
, struct passwd
**);
705 struct files_state state
;
708 _DIAGASSERT(retval
!= NULL
);
709 _DIAGASSERT(pw
!= NULL
);
710 _DIAGASSERT(buffer
!= NULL
);
711 _DIAGASSERT(result
!= NULL
);
714 memset(&state
, 0, sizeof(state
));
715 rv
= _files_pwscan(retval
, pw
, buffer
, buflen
, &state
,
716 _PW_KEYBYUID
, NULL
, uid
);
718 if (rv
== NS_SUCCESS
)
729 /* state shared between dns methods */
731 int stayopen
; /* see getpassent(3) */
732 void *context
; /* Hesiod context */
733 int num
; /* passwd index, -1 if no more */
736 static struct dns_state _dns_state
;
737 /* storage for non _r functions */
738 static struct passwd _dns_passwd
;
739 static char _dns_passwdbuf
[_GETPW_R_SIZE_MAX
];
742 _dns_start(struct dns_state
*state
)
745 _DIAGASSERT(state
!= NULL
);
748 if (state
->context
== NULL
) { /* setup Hesiod */
749 if (hesiod_init(&state
->context
) == -1)
757 _dns_end(struct dns_state
*state
)
760 _DIAGASSERT(state
!= NULL
);
763 if (state
->context
) {
764 hesiod_end(state
->context
);
765 state
->context
= NULL
;
772 * Look for the Hesiod name provided in buffer in the NULL-terminated
774 * and decode into pw/buffer/buflen.
777 _dns_pwscan(int *retval
, struct passwd
*pw
, char *buffer
, size_t buflen
,
778 struct dns_state
*state
, const char **zones
)
780 const char **curzone
;
784 _DIAGASSERT(retval
!= NULL
);
785 _DIAGASSERT(pw
!= NULL
);
786 _DIAGASSERT(buffer
!= NULL
);
787 _DIAGASSERT(state
!= NULL
);
788 _DIAGASSERT(zones
!= NULL
);
792 if (state
->context
== NULL
) { /* only start if Hesiod not setup */
793 rv
= _dns_start(state
);
794 if (rv
!= NS_SUCCESS
)
801 for (curzone
= zones
; *curzone
; curzone
++) { /* search zones */
802 hp
= hesiod_resolve(state
->context
, buffer
, *curzone
);
805 if (errno
!= ENOENT
) {
810 if (*curzone
== NULL
)
813 if ((ep
= strchr(hp
[0], '\n')) != NULL
)
814 *ep
= '\0'; /* clear trailing \n */
815 if (_pw_parse(hp
[0], pw
, buffer
, buflen
, 1)) /* validate line */
821 if (rv
!= NS_SUCCESS
&& rv
!= NS_NOTFOUND
)
824 hesiod_free_list(state
->context
, hp
);
830 _dns_setpwent(void *nsrv
, void *nscb
, va_list ap
)
833 _dns_state
.stayopen
= 0;
834 return _dns_start(&_dns_state
);
839 _dns_setpassent(void *nsrv
, void *nscb
, va_list ap
)
841 int *retval
= va_arg(ap
, int *);
842 int stayopen
= va_arg(ap
, int);
846 _dns_state
.stayopen
= stayopen
;
847 rv
= _dns_start(&_dns_state
);
848 *retval
= (rv
== NS_SUCCESS
);
854 _dns_endpwent(void *nsrv
, void *nscb
, va_list ap
)
857 _dns_state
.stayopen
= 0;
858 return _dns_end(&_dns_state
);
863 _dns_getpwent(void *nsrv
, void *nscb
, va_list ap
)
865 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
870 _DIAGASSERT(retval
!= NULL
);
874 if (_dns_state
.num
== -1) /* exhausted search */
877 if (_dns_state
.context
== NULL
) {
878 /* only start if Hesiod not setup */
879 rv
= _dns_start(&_dns_state
);
880 if (rv
!= NS_SUCCESS
)
888 /* find passwd-NNN */
889 snprintf(_dns_passwdbuf
, sizeof(_dns_passwdbuf
),
890 "passwd-%u", _dns_state
.num
);
893 hp
= hesiod_resolve(_dns_state
.context
, _dns_passwdbuf
, "passwd");
900 if ((ep
= strchr(hp
[0], '\n')) != NULL
)
901 *ep
= '\0'; /* clear trailing \n */
903 if (_pw_parse(hp
[0], &_dns_passwd
,
904 _dns_passwdbuf
, sizeof(_dns_passwdbuf
), 1))
906 else { /* dodgy entry, try again */
907 hesiod_free_list(_dns_state
.context
, hp
);
913 hesiod_free_list(_dns_state
.context
, hp
);
914 if (rv
== NS_SUCCESS
)
915 *retval
= &_dns_passwd
;
921 _dns_getpwent_r(void *nsrv
, void *nscb
, va_list ap
)
923 int *retval
= va_arg(ap
, int *);
924 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
925 char *buffer
= va_arg(ap
, char *);
926 size_t buflen
= va_arg(ap
, size_t);
927 struct passwd
**result
= va_arg(ap
, struct passwd
**);
932 _DIAGASSERT(retval
!= NULL
);
933 _DIAGASSERT(pw
!= NULL
);
934 _DIAGASSERT(buffer
!= NULL
);
935 _DIAGASSERT(result
!= NULL
);
939 if (_dns_state
.num
== -1) /* exhausted search */
942 if (_dns_state
.context
== NULL
) {
943 /* only start if Hesiod not setup */
944 rv
= _dns_start(&_dns_state
);
945 if (rv
!= NS_SUCCESS
)
953 /* find passwd-NNN */
954 snprintf(buffer
, buflen
, "passwd-%u", _dns_state
.num
);
957 hp
= hesiod_resolve(_dns_state
.context
, buffer
, "passwd");
964 if ((ep
= strchr(hp
[0], '\n')) != NULL
)
965 *ep
= '\0'; /* clear trailing \n */
967 if (_pw_parse(hp
[0], pw
, buffer
, buflen
, 1))
969 else { /* dodgy entry, try again */
970 hesiod_free_list(_dns_state
.context
, hp
);
976 hesiod_free_list(_dns_state
.context
, hp
);
977 if (rv
== NS_SUCCESS
)
984 static const char *_dns_uid_zones
[] = {
992 _dns_getpwuid(void *nsrv
, void *nscb
, va_list ap
)
994 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
995 uid_t uid
= va_arg(ap
, uid_t
);
999 _DIAGASSERT(retval
!= NULL
);
1002 rv
= _dns_start(&_dns_state
);
1003 if (rv
!= NS_SUCCESS
)
1005 snprintf(_dns_passwdbuf
, sizeof(_dns_passwdbuf
),
1006 "%u", (unsigned int)uid
);
1007 rv
= _dns_pwscan(&rerror
, &_dns_passwd
,
1008 _dns_passwdbuf
, sizeof(_dns_passwdbuf
),
1009 &_dns_state
, _dns_uid_zones
);
1010 if (!_dns_state
.stayopen
)
1011 _dns_end(&_dns_state
);
1012 if (rv
== NS_SUCCESS
&& uid
== _dns_passwd
.pw_uid
)
1013 *retval
= &_dns_passwd
;
1019 _dns_getpwuid_r(void *nsrv
, void *nscb
, va_list ap
)
1021 int *retval
= va_arg(ap
, int *);
1022 uid_t uid
= va_arg(ap
, uid_t
);
1023 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
1024 char *buffer
= va_arg(ap
, char *);
1025 size_t buflen
= va_arg(ap
, size_t);
1026 struct passwd
**result
= va_arg(ap
, struct passwd
**);
1028 struct dns_state state
;
1031 _DIAGASSERT(retval
!= NULL
);
1032 _DIAGASSERT(pw
!= NULL
);
1033 _DIAGASSERT(buffer
!= NULL
);
1034 _DIAGASSERT(result
!= NULL
);
1037 memset(&state
, 0, sizeof(state
));
1038 snprintf(buffer
, buflen
, "%u", (unsigned int)uid
);
1039 rv
= _dns_pwscan(retval
, pw
, buffer
, buflen
, &state
, _dns_uid_zones
);
1041 if (rv
!= NS_SUCCESS
)
1043 if (uid
== pw
->pw_uid
) {
1050 static const char *_dns_nam_zones
[] = {
1057 _dns_getpwnam(void *nsrv
, void *nscb
, va_list ap
)
1059 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
1060 const char *name
= va_arg(ap
, const char *);
1064 _DIAGASSERT(retval
!= NULL
);
1067 rv
= _dns_start(&_dns_state
);
1068 if (rv
!= NS_SUCCESS
)
1070 snprintf(_dns_passwdbuf
, sizeof(_dns_passwdbuf
), "%s", name
);
1071 rv
= _dns_pwscan(&rerror
, &_dns_passwd
,
1072 _dns_passwdbuf
, sizeof(_dns_passwdbuf
),
1073 &_dns_state
, _dns_nam_zones
);
1074 if (!_dns_state
.stayopen
)
1075 _dns_end(&_dns_state
);
1076 if (rv
== NS_SUCCESS
&& strcmp(name
, _dns_passwd
.pw_name
) == 0)
1077 *retval
= &_dns_passwd
;
1083 _dns_getpwnam_r(void *nsrv
, void *nscb
, va_list ap
)
1085 int *retval
= va_arg(ap
, int *);
1086 const char *name
= va_arg(ap
, const char *);
1087 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
1088 char *buffer
= va_arg(ap
, char *);
1089 size_t buflen
= va_arg(ap
, size_t);
1090 struct passwd
**result
= va_arg(ap
, struct passwd
**);
1092 struct dns_state state
;
1095 _DIAGASSERT(retval
!= NULL
);
1096 _DIAGASSERT(pw
!= NULL
);
1097 _DIAGASSERT(buffer
!= NULL
);
1098 _DIAGASSERT(result
!= NULL
);
1101 memset(&state
, 0, sizeof(state
));
1102 snprintf(buffer
, buflen
, "%s", name
);
1103 rv
= _dns_pwscan(retval
, pw
, buffer
, buflen
, &state
, _dns_nam_zones
);
1105 if (rv
!= NS_SUCCESS
)
1107 if (strcmp(name
, pw
->pw_name
) == 0) {
1121 /* state shared between nis methods */
1123 int stayopen
; /* see getpassent(3) */
1124 char *domain
; /* NIS domain */
1125 int done
; /* non-zero if search exhausted */
1126 char *current
; /* current first/next match */
1127 int currentlen
; /* length of _nis_current */
1128 enum { /* shadow map type */
1129 NISMAP_UNKNOWN
= 0, /* unknown ... */
1130 NISMAP_NONE
, /* none: use "passwd.by*" */
1131 NISMAP_ADJUNCT
, /* pw_passwd from "passwd.adjunct.*" */
1132 NISMAP_MASTER
/* all from "master.passwd.by*" */
1136 static struct nis_state _nis_state
;
1137 /* storage for non _r functions */
1138 static struct passwd _nis_passwd
;
1139 static char _nis_passwdbuf
[_GETPW_R_SIZE_MAX
];
1141 static const char __nis_pw_n_1
[] = "master.passwd.byname";
1142 static const char __nis_pw_n_2
[] = "passwd.byname";
1143 static const char __nis_pw_u_1
[] = "master.passwd.byuid";
1144 static const char __nis_pw_u_2
[] = "passwd.byuid";
1146 static const char * const __nis_pw_n_map
[4] = { __nis_pw_n_2
, __nis_pw_n_2
, __nis_pw_n_2
, __nis_pw_n_1
};
1147 static const char * const __nis_pw_u_map
[4] = { __nis_pw_u_2
, __nis_pw_u_2
, __nis_pw_u_2
, __nis_pw_u_1
};
1149 /* macros for deciding which NIS maps to use. */
1150 #define PASSWD_BYNAME(x) ((x)->maptype == NISMAP_MASTER ? __nis_pw_n_1 : __nis_pw_n_2)
1151 #define PASSWD_BYUID(x) ((x)->maptype == NISMAP_MASTER ? __nis_pw_u_1 : __nis_pw_u_2)
1154 _nis_start(struct nis_state
*state
)
1157 _DIAGASSERT(state
!= NULL
);
1160 if (state
->current
) {
1161 free(state
->current
);
1162 state
->current
= NULL
;
1164 if (state
->domain
== NULL
) { /* setup NIS */
1165 switch (yp_get_default_domain(&state
->domain
)) {
1175 /* determine where to get pw_passwd from */
1176 if (state
->maptype
== NISMAP_UNKNOWN
) {
1179 state
->maptype
= NISMAP_NONE
; /* default to no adjunct */
1180 if (geteuid() != 0) /* non-root can't use adjunct */
1183 /* look for "master.passwd.*" */
1184 r
= yp_order(state
->domain
, "master.passwd.byname", &order
);
1186 state
->maptype
= NISMAP_MASTER
;
1190 /* master.passwd doesn't exist, try passwd.adjunct */
1191 if (r
== YPERR_MAP
) {
1192 r
= yp_order(state
->domain
, "passwd.adjunct.byname",
1195 state
->maptype
= NISMAP_ADJUNCT
;
1202 _nis_end(struct nis_state
*state
)
1205 _DIAGASSERT(state
!= NULL
);
1208 state
->domain
= NULL
;
1211 free(state
->current
);
1212 state
->current
= NULL
;
1213 state
->maptype
= NISMAP_UNKNOWN
;
1219 * wrapper to _pw_parse that obtains the real password from the
1220 * "passwd.adjunct.byname" NIS map if the maptype is NISMAP_ADJUNCT.
1223 _nis_parse(const char *entry
, struct passwd
*pw
, char *buf
, size_t buflen
,
1224 struct nis_state
*state
)
1228 _DIAGASSERT(entry
!= NULL
);
1229 _DIAGASSERT(pw
!= NULL
);
1230 _DIAGASSERT(buf
!= NULL
);
1231 _DIAGASSERT(state
!= NULL
);
1233 elen
= strlen(entry
) + 1;
1236 if (! _pw_parse(entry
, pw
, buf
, buflen
,
1237 !(state
->maptype
== NISMAP_MASTER
)))
1240 if ((state
->maptype
== NISMAP_ADJUNCT
) &&
1241 (strstr(pw
->pw_passwd
, "##") != NULL
)) {
1245 if (yp_match(state
->domain
, "passwd.adjunct.byname",
1246 pw
->pw_name
, (int)strlen(pw
->pw_name
),
1247 &data
, &datalen
) == 0) {
1249 /* skip name to get password */
1251 if (strsep(&ep
, ":") != NULL
&&
1252 (bp
= strsep(&ep
, ":")) != NULL
) {
1253 /* store new pw_passwd after entry */
1254 if (strlcpy(buf
+ elen
, bp
, buflen
- elen
) >=
1259 pw
->pw_passwd
= &buf
[elen
];
1271 * Look for the yp key provided in buffer from map,
1272 * and decode into pw/buffer/buflen.
1275 _nis_pwscan(int *retval
, struct passwd
*pw
, char *buffer
, size_t buflen
,
1276 struct nis_state
*state
, const char * const *map_arr
, size_t nmaps
)
1279 int nisr
, rv
, datalen
;
1281 _DIAGASSERT(retval
!= NULL
);
1282 _DIAGASSERT(pw
!= NULL
);
1283 _DIAGASSERT(buffer
!= NULL
);
1284 _DIAGASSERT(state
!= NULL
);
1285 _DIAGASSERT(map_arr
!= NULL
);
1289 if (state
->domain
== NULL
) { /* only start if NIS not setup */
1290 rv
= _nis_start(state
);
1291 if (rv
!= NS_SUCCESS
)
1297 _DIAGASSERT(state
->maptype
!= NISMAP_UNKNOWN
&&
1298 (unsigned)state
->maptype
< nmaps
);
1301 nisr
= yp_match(state
->domain
, map_arr
[state
->maptype
], buffer
, (int)strlen(buffer
),
1305 data
[datalen
] = '\0'; /* clear trailing \n */
1306 if (_nis_parse(data
, pw
, buffer
, buflen
, state
))
1307 rv
= NS_SUCCESS
; /* validate line */
1318 if (rv
!= NS_SUCCESS
&& rv
!= NS_NOTFOUND
)
1327 _nis_setpwent(void *nsrv
, void *nscb
, va_list ap
)
1330 _nis_state
.stayopen
= 0;
1331 return _nis_start(&_nis_state
);
1336 _nis_setpassent(void *nsrv
, void *nscb
, va_list ap
)
1338 int *retval
= va_arg(ap
, int *);
1339 int stayopen
= va_arg(ap
, int);
1343 _nis_state
.stayopen
= stayopen
;
1344 rv
= _nis_start(&_nis_state
);
1345 *retval
= (rv
== NS_SUCCESS
);
1351 _nis_endpwent(void *nsrv
, void *nscb
, va_list ap
)
1354 return _nis_end(&_nis_state
);
1360 _nis_getpwent(void *nsrv
, void *nscb
, va_list ap
)
1362 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
1365 int keylen
, datalen
, rv
, nisr
;
1367 _DIAGASSERT(retval
!= NULL
);
1371 if (_nis_state
.done
) /* exhausted search */
1373 if (_nis_state
.domain
== NULL
) {
1374 /* only start if NIS not setup */
1375 rv
= _nis_start(&_nis_state
);
1376 if (rv
!= NS_SUCCESS
)
1385 if (_nis_state
.current
) { /* already searching */
1386 nisr
= yp_next(_nis_state
.domain
, PASSWD_BYNAME(&_nis_state
),
1387 _nis_state
.current
, _nis_state
.currentlen
,
1388 &key
, &keylen
, &data
, &datalen
);
1389 free(_nis_state
.current
);
1390 _nis_state
.current
= NULL
;
1393 _nis_state
.current
= key
;
1394 _nis_state
.currentlen
= keylen
;
1398 _nis_state
.done
= 1;
1404 } else { /* new search */
1405 if (yp_first(_nis_state
.domain
, PASSWD_BYNAME(&_nis_state
),
1406 &_nis_state
.current
, &_nis_state
.currentlen
,
1413 data
[datalen
] = '\0'; /* clear trailing \n */
1415 if (_nis_parse(data
, &_nis_passwd
,
1416 _nis_passwdbuf
, sizeof(_nis_passwdbuf
), &_nis_state
))
1418 else { /* dodgy entry, try again */
1420 goto next_nis_entry
;
1428 if (rv
== NS_SUCCESS
)
1429 *retval
= &_nis_passwd
;
1435 _nis_getpwent_r(void *nsrv
, void *nscb
, va_list ap
)
1437 int *retval
= va_arg(ap
, int *);
1438 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
1439 char *buffer
= va_arg(ap
, char *);
1440 size_t buflen
= va_arg(ap
, size_t);
1441 struct passwd
**result
= va_arg(ap
, struct passwd
**);
1444 int keylen
, datalen
, rv
, nisr
;
1446 _DIAGASSERT(retval
!= NULL
);
1447 _DIAGASSERT(pw
!= NULL
);
1448 _DIAGASSERT(buffer
!= NULL
);
1449 _DIAGASSERT(result
!= NULL
);
1453 if (_nis_state
.done
) /* exhausted search */
1455 if (_nis_state
.domain
== NULL
) {
1456 /* only start if NIS not setup */
1457 rv
= _nis_start(&_nis_state
);
1458 if (rv
!= NS_SUCCESS
)
1467 if (_nis_state
.current
) { /* already searching */
1468 nisr
= yp_next(_nis_state
.domain
, PASSWD_BYNAME(&_nis_state
),
1469 _nis_state
.current
, _nis_state
.currentlen
,
1470 &key
, &keylen
, &data
, &datalen
);
1471 free(_nis_state
.current
);
1472 _nis_state
.current
= NULL
;
1475 _nis_state
.current
= key
;
1476 _nis_state
.currentlen
= keylen
;
1480 _nis_state
.done
= 1;
1486 } else { /* new search */
1487 if (yp_first(_nis_state
.domain
, PASSWD_BYNAME(&_nis_state
),
1488 &_nis_state
.current
, &_nis_state
.currentlen
,
1495 data
[datalen
] = '\0'; /* clear trailing \n */
1497 if (_nis_parse(data
, pw
, buffer
, buflen
, &_nis_state
))
1499 else { /* dodgy entry, try again */
1503 goto next_nis_entry
;
1511 if (rv
== NS_SUCCESS
)
1520 _nis_getpwuid(void *nsrv
, void *nscb
, va_list ap
)
1522 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
1523 uid_t uid
= va_arg(ap
, uid_t
);
1527 _DIAGASSERT(retval
!= NULL
);
1530 rv
= _nis_start(&_nis_state
);
1531 if (rv
!= NS_SUCCESS
)
1533 snprintf(_nis_passwdbuf
, sizeof(_nis_passwdbuf
), "%u", (unsigned int)uid
);
1534 rv
= _nis_pwscan(&rerror
, &_nis_passwd
,
1535 _nis_passwdbuf
, sizeof(_nis_passwdbuf
),
1536 &_nis_state
, __nis_pw_u_map
, __arraycount(__nis_pw_u_map
));
1537 if (!_nis_state
.stayopen
)
1538 _nis_end(&_nis_state
);
1539 if (rv
== NS_SUCCESS
&& uid
== _nis_passwd
.pw_uid
)
1540 *retval
= &_nis_passwd
;
1546 _nis_getpwuid_r(void *nsrv
, void *nscb
, va_list ap
)
1548 int *retval
= va_arg(ap
, int *);
1549 uid_t uid
= va_arg(ap
, uid_t
);
1550 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
1551 char *buffer
= va_arg(ap
, char *);
1552 size_t buflen
= va_arg(ap
, size_t);
1553 struct passwd
**result
= va_arg(ap
, struct passwd
**);
1555 struct nis_state state
;
1558 _DIAGASSERT(retval
!= NULL
);
1559 _DIAGASSERT(pw
!= NULL
);
1560 _DIAGASSERT(buffer
!= NULL
);
1561 _DIAGASSERT(result
!= NULL
);
1564 snprintf(buffer
, buflen
, "%u", (unsigned int)uid
);
1565 /* remark: we run under a global mutex inside of this module ... */
1566 if (_nis_state
.stayopen
)
1567 { /* use global state only if stayopen is set - otherwise we would blow up getpwent_r() ... */
1568 rv
= _nis_pwscan(retval
, pw
, buffer
, buflen
,
1569 &_nis_state
, __nis_pw_u_map
, __arraycount(__nis_pw_u_map
));
1572 { /* keep old semantic if no stayopen set - no need to call _nis_start() here - _nis_pwscan() will do it for us ... */
1573 /* use same way as in getgrent.c ... */
1574 memset(&state
, 0, sizeof(state
));
1575 rv
= _nis_pwscan(retval
, pw
, buffer
, buflen
,
1576 &state
, __nis_pw_u_map
, __arraycount(__nis_pw_u_map
));
1579 if (rv
!= NS_SUCCESS
)
1581 if (uid
== pw
->pw_uid
) {
1590 _nis_getpwnam(void *nsrv
, void *nscb
, va_list ap
)
1592 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
1593 const char *name
= va_arg(ap
, const char *);
1597 _DIAGASSERT(retval
!= NULL
);
1600 rv
= _nis_start(&_nis_state
);
1601 if (rv
!= NS_SUCCESS
)
1603 snprintf(_nis_passwdbuf
, sizeof(_nis_passwdbuf
), "%s", name
);
1604 rv
= _nis_pwscan(&rerror
, &_nis_passwd
,
1605 _nis_passwdbuf
, sizeof(_nis_passwdbuf
),
1606 &_nis_state
, __nis_pw_n_map
, __arraycount(__nis_pw_n_map
));
1607 if (!_nis_state
.stayopen
)
1608 _nis_end(&_nis_state
);
1609 if (rv
== NS_SUCCESS
&& strcmp(name
, _nis_passwd
.pw_name
) == 0)
1610 *retval
= &_nis_passwd
;
1616 _nis_getpwnam_r(void *nsrv
, void *nscb
, va_list ap
)
1618 int *retval
= va_arg(ap
, int *);
1619 const char *name
= va_arg(ap
, const char *);
1620 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
1621 char *buffer
= va_arg(ap
, char *);
1622 size_t buflen
= va_arg(ap
, size_t);
1623 struct passwd
**result
= va_arg(ap
, struct passwd
**);
1625 struct nis_state state
;
1628 _DIAGASSERT(retval
!= NULL
);
1629 _DIAGASSERT(pw
!= NULL
);
1630 _DIAGASSERT(buffer
!= NULL
);
1631 _DIAGASSERT(result
!= NULL
);
1634 snprintf(buffer
, buflen
, "%s", name
);
1635 /* remark: we run under a global mutex inside of this module ... */
1636 if (_nis_state
.stayopen
)
1637 { /* use global state only if stayopen is set - otherwise we would blow up getpwent_r() ... */
1638 rv
= _nis_pwscan(retval
, pw
, buffer
, buflen
,
1639 &_nis_state
, __nis_pw_n_map
, __arraycount(__nis_pw_n_map
));
1642 { /* keep old semantic if no stayopen set - no need to call _nis_start() here - _nis_pwscan() will do it for us ... */
1643 /* use same way as in getgrent.c ... */
1644 memset(&state
, 0, sizeof(state
));
1645 rv
= _nis_pwscan(retval
, pw
, buffer
, buflen
,
1646 &state
, __nis_pw_n_map
, __arraycount(__nis_pw_n_map
));
1649 if (rv
!= NS_SUCCESS
)
1651 if (strcmp(name
, pw
->pw_name
) == 0) {
1661 #ifdef _PASSWD_COMPAT
1666 /* state shared between compat methods */
1668 struct compat_state
{
1669 int stayopen
; /* see getpassent(3) */
1670 DB
*db
; /* passwd DB */
1671 int keynum
; /* key counter, -1 if no more */
1672 enum { /* current compat mode */
1673 COMPAT_NOTOKEN
= 0, /* no compat token present */
1674 COMPAT_NONE
, /* parsing normal pwd.db line */
1675 COMPAT_FULL
, /* parsing `+' entries */
1676 COMPAT_USER
, /* parsing `+name' entries */
1677 COMPAT_NETGROUP
/* parsing `+@netgroup' entries */
1679 char *user
; /* COMPAT_USER "+name" */
1680 DB
*exclude
; /* compat exclude DB */
1681 struct passwd proto
; /* proto passwd entry */
1682 char protobuf
[_GETPW_R_SIZE_MAX
];
1683 /* buffer for proto ptrs */
1684 int protoflags
; /* proto passwd flags */
1688 static struct compat_state _compat_state
;
1689 /* storage for non _r functions */
1690 static struct passwd _compat_passwd
;
1691 static char _compat_passwdbuf
[_GETPW_R_SIZE_MAX
];
1694 _compat_start(struct compat_state
*state
)
1698 _DIAGASSERT(state
!= NULL
);
1701 if (state
->db
== NULL
) { /* not open yet */
1704 char bf
[MAXLOGNAME
];
1706 rv
= _pw_opendb(&state
->db
, &state
->version
);
1707 if (rv
!= NS_SUCCESS
)
1710 state
->mode
= COMPAT_NOTOKEN
;
1713 * Determine if the "compat" token is present in pwd.db;
1714 * either "__YP!" or PW_KEYBYNAME+"+".
1715 * Only works if pwd_mkdb installs the token.
1717 key
.data
= (u_char
*)__UNCONST(__yp_token
);
1718 key
.size
= strlen(__yp_token
);
1720 bf
[0] = _PW_KEYBYNAME
; /* Pre-token database support. */
1722 pkey
.data
= (u_char
*)bf
;
1725 if ((state
->db
->get
)(state
->db
, &key
, &data
, 0) == 0
1726 || (state
->db
->get
)(state
->db
, &pkey
, &pdata
, 0) == 0)
1727 state
->mode
= COMPAT_NONE
;
1733 _compat_end(struct compat_state
*state
)
1736 _DIAGASSERT(state
!= NULL
);
1740 (void)(state
->db
->close
)(state
->db
);
1743 state
->mode
= COMPAT_NOTOKEN
;
1747 if (state
->exclude
!= NULL
)
1748 (void)(state
->exclude
->close
)(state
->exclude
);
1749 state
->exclude
= NULL
;
1750 state
->proto
.pw_name
= NULL
;
1751 state
->protoflags
= 0;
1756 * _compat_add_exclude
1757 * add the name to the exclude list in state->exclude.
1760 _compat_add_exclude(struct compat_state
*state
, const char *name
)
1764 _DIAGASSERT(state
!= NULL
);
1765 _DIAGASSERT(name
!= NULL
);
1767 /* initialize the exclusion table if needed */
1768 if (state
->exclude
== NULL
) {
1769 state
->exclude
= dbopen(NULL
, O_RDWR
, 600, DB_HASH
, NULL
);
1770 if (state
->exclude
== NULL
)
1774 key
.size
= strlen(name
); /* set up the key */
1775 key
.data
= (u_char
*)__UNCONST(name
);
1777 data
.data
= NULL
; /* data is nothing */
1781 if ((state
->exclude
->put
)(state
->exclude
, &key
, &data
, 0) == -1)
1788 * _compat_is_excluded
1789 * test if a name is on the compat mode exclude list
1792 _compat_is_excluded(struct compat_state
*state
, const char *name
)
1796 _DIAGASSERT(state
!= NULL
);
1797 _DIAGASSERT(name
!= NULL
);
1799 if (state
->exclude
== NULL
)
1800 return 0; /* nothing excluded */
1802 key
.size
= strlen(name
); /* set up the key */
1803 key
.data
= (u_char
*)__UNCONST(name
);
1805 if ((state
->exclude
->get
)(state
->exclude
, &key
, &data
, 0) == 0)
1806 return 1; /* is excluded */
1814 * log an error if "files" or "compat" is specified in
1815 * passwd_compat database
1819 _passwdcompat_bad(void *nsrv
, void *nscb
, va_list ap
)
1823 _DIAGASSERT(nsrv
!= NULL
);
1824 _DIAGASSERT(nscb
!= NULL
);
1828 "nsswitch.conf passwd_compat database can't use '%s'",
1836 * _passwdcompat_setpassent
1837 * Call setpassent for all passwd_compat sources.
1840 _passwdcompat_setpassent(int stayopen
)
1842 static const ns_dtab dtab
[] = {
1843 NS_FILES_CB(_passwdcompat_bad
, "files")
1844 NS_DNS_CB(_dns_setpassent
, NULL
)
1845 NS_NIS_CB(_nis_setpassent
, NULL
)
1846 NS_COMPAT_CB(_passwdcompat_bad
, "compat")
1852 rv
= nsdispatch(NULL
, dtab
, NSDB_PASSWD_COMPAT
, "setpassent",
1853 __nsdefaultnis_forceall
, &result
, stayopen
);
1858 * _passwdcompat_endpwent
1859 * Call endpwent for all passwd_compat sources.
1862 _passwdcompat_endpwent(void)
1864 static const ns_dtab dtab
[] = {
1865 NS_FILES_CB(_passwdcompat_bad
, "files")
1866 NS_DNS_CB(_dns_endpwent
, NULL
)
1867 NS_NIS_CB(_nis_endpwent
, NULL
)
1868 NS_COMPAT_CB(_passwdcompat_bad
, "compat")
1872 return nsdispatch(NULL
, dtab
, NSDB_PASSWD_COMPAT
, "endpwent",
1873 __nsdefaultnis_forceall
);
1877 * _passwdcompat_pwscan
1878 * When a name lookup in compat mode is required (e.g., `+name', or a
1879 * name in `+@netgroup'), look it up in the 'passwd_compat' nsswitch
1881 * Fail if passwd_compat contains files or compat.
1884 _passwdcompat_pwscan(struct passwd
*pw
, char *buffer
, size_t buflen
,
1885 int search
, const char *name
, uid_t uid
)
1887 static const ns_dtab compatentdtab
[] = {
1888 NS_FILES_CB(_passwdcompat_bad
, "files")
1889 NS_DNS_CB(_dns_getpwent_r
, NULL
)
1890 NS_NIS_CB(_nis_getpwent_r
, NULL
)
1891 NS_COMPAT_CB(_passwdcompat_bad
, "compat")
1894 static const ns_dtab compatuiddtab
[] = {
1895 NS_FILES_CB(_passwdcompat_bad
, "files")
1896 NS_DNS_CB(_dns_getpwuid_r
, NULL
)
1897 NS_NIS_CB(_nis_getpwuid_r
, NULL
)
1898 NS_COMPAT_CB(_passwdcompat_bad
, "compat")
1901 static const ns_dtab compatnamdtab
[] = {
1902 NS_FILES_CB(_passwdcompat_bad
, "files")
1903 NS_DNS_CB(_dns_getpwnam_r
, NULL
)
1904 NS_NIS_CB(_nis_getpwnam_r
, NULL
)
1905 NS_COMPAT_CB(_passwdcompat_bad
, "compat")
1914 rv
= nsdispatch(NULL
, compatentdtab
,
1915 NSDB_PASSWD_COMPAT
, "getpwent_r", __nsdefaultnis
,
1916 &crv
, pw
, buffer
, buflen
, &cpw
);
1919 _DIAGASSERT(name
!= NULL
);
1920 rv
= nsdispatch(NULL
, compatnamdtab
,
1921 NSDB_PASSWD_COMPAT
, "getpwnam_r", __nsdefaultnis
,
1922 &crv
, name
, pw
, buffer
, buflen
, &cpw
);
1925 rv
= nsdispatch(NULL
, compatuiddtab
,
1926 NSDB_PASSWD_COMPAT
, "getpwuid_r", __nsdefaultnis
,
1927 &crv
, uid
, pw
, buffer
, buflen
, &cpw
);
1938 * Search state->db for the next desired entry.
1939 * If search is _PW_KEYBYNUM, look for state->keynum.
1940 * If search is _PW_KEYBYNAME, look for name.
1941 * If search is _PW_KEYBYUID, look for uid.
1942 * Sets *retval to the errno if the result is not NS_SUCCESS
1946 _compat_pwscan(int *retval
, struct passwd
*pw
, char *buffer
, size_t buflen
,
1947 struct compat_state
*state
, int search
, const char *name
, uid_t uid
)
1951 const char *user
, *host
, *dom
;
1955 _DIAGASSERT(retval
!= NULL
);
1956 _DIAGASSERT(pw
!= NULL
);
1957 _DIAGASSERT(buffer
!= NULL
);
1958 _DIAGASSERT(state
!= NULL
);
1959 /* name may be NULL */
1963 if (state
->db
== NULL
) {
1964 rv
= _compat_start(state
);
1965 if (rv
!= NS_SUCCESS
)
1968 if (buflen
<= 1) { /* buffer too small */
1973 for (;;) { /* loop over pwd.db */
1975 if (state
->mode
!= COMPAT_NOTOKEN
&&
1976 state
->mode
!= COMPAT_NONE
) {
1977 /* doing a compat lookup */
1979 char cbuf
[_GETPW_R_SIZE_MAX
];
1981 switch (state
->mode
) {
1984 /* get next user or lookup by key */
1985 rv
= _passwdcompat_pwscan(&cpw
,
1986 cbuf
, sizeof(cbuf
), search
, name
, uid
);
1987 if (rv
!= NS_SUCCESS
)
1988 state
->mode
= COMPAT_NONE
;
1991 case COMPAT_NETGROUP
:
1992 /* XXXREENTRANT: getnetgrent is not thread safe */
1993 /* get next user from netgroup */
1994 r
= getnetgrent(&host
, &user
, &dom
);
1995 if (r
== 0) { /* end of group */
1997 state
->mode
= COMPAT_NONE
;
2000 if (!user
|| !*user
)
2002 rv
= _passwdcompat_pwscan(&cpw
,
2004 _PW_KEYBYNAME
, user
, 0);
2008 /* get specific user */
2009 if (state
->user
== NULL
) {
2010 state
->mode
= COMPAT_NONE
;
2013 rv
= _passwdcompat_pwscan(&cpw
,
2015 _PW_KEYBYNAME
, state
->user
, 0);
2018 state
->mode
= COMPAT_NONE
;
2021 case COMPAT_NOTOKEN
:
2026 if (rv
!= NS_SUCCESS
) /* if not matched, next loop */
2029 /* copy cpw to pw, applying prototype */
2030 if (! _pw_copy(&cpw
, pw
, buffer
, buflen
,
2031 &state
->proto
, state
->protoflags
)) {
2036 if (_compat_is_excluded(state
, pw
->pw_name
))
2037 continue; /* excluded; next loop */
2039 if ((search
== _PW_KEYBYNAME
2040 && strcmp(pw
->pw_name
, name
) != 0)
2041 || (search
== _PW_KEYBYUID
&& pw
->pw_uid
!= uid
)) {
2042 continue; /* not specific; next loop */
2045 break; /* exit loop if found */
2046 } else { /* not a compat line */
2047 state
->proto
.pw_name
= NULL
;
2048 /* clear prototype */
2051 if (state
->mode
== COMPAT_NOTOKEN
) {
2052 /* no compat token; do direct lookup */
2055 if (state
->keynum
== -1) /* no more records */
2058 from
= &state
->keynum
;
2059 fromlen
= sizeof(state
->keynum
);
2063 fromlen
= strlen(name
);
2067 fromlen
= sizeof(uid
);
2074 /* compat token; do line by line */
2075 if (state
->keynum
== -1) /* no more records */
2078 from
= &state
->keynum
;
2079 fromlen
= sizeof(state
->keynum
);
2080 buffer
[0] = _PW_KEYBYNUM
;
2083 if (buflen
<= fromlen
) { /* buffer too small */
2087 memmove(buffer
+ 1, from
, fromlen
); /* setup key */
2088 key
.size
= fromlen
+ 1;
2089 key
.data
= (u_char
*)buffer
;
2091 rv
= _pw_getkey(state
->db
, &key
, pw
, buffer
, buflen
, &pwflags
,
2093 if (rv
!= NS_SUCCESS
) /* stop on error */
2096 if (state
->mode
== COMPAT_NOTOKEN
)
2097 break; /* stop if no compat token */
2099 if (pw
->pw_name
[0] == '+') {
2100 /* compat inclusion */
2101 switch(pw
->pw_name
[1]) {
2102 case '\0': /* `+' */
2103 state
->mode
= COMPAT_FULL
;
2104 /* reset passwd_compat search */
2105 /* XXXREENTRANT: setpassent is not thread safe ? */
2106 (void) _passwdcompat_setpassent(_compat_state
.stayopen
);
2108 case '@': /* `+@netgroup' */
2109 state
->mode
= COMPAT_NETGROUP
;
2110 /* reset netgroup search */
2111 /* XXXREENTRANT: setnetgrent is not thread safe */
2112 setnetgrent(pw
->pw_name
+ 2);
2114 default: /* `+name' */
2115 state
->mode
= COMPAT_USER
;
2118 state
->user
= strdup(pw
->pw_name
+ 1);
2121 /* save the prototype */
2122 state
->protoflags
= pwflags
;
2123 if (! _pw_copy(pw
, &state
->proto
, state
->protobuf
,
2124 sizeof(state
->protobuf
), NULL
, 0)) {
2128 continue; /* loop again after inclusion */
2129 } else if (pw
->pw_name
[0] == '-') {
2130 /* compat exclusion */
2132 switch(pw
->pw_name
[1]) {
2133 case '\0': /* `-' */
2135 case '@': /* `-@netgroup' */
2136 /* XXXREENTRANT: {set,get,end}netgrent is not thread safe */
2137 setnetgrent(pw
->pw_name
+ 2);
2138 while (getnetgrent(&host
, &user
, &dom
)) {
2139 if (!user
|| !*user
)
2141 if (! _compat_add_exclude(state
,user
)) {
2148 default: /* `-name' */
2149 if (! _compat_add_exclude(state
,
2155 if (rv
!= NS_SUCCESS
) /* exclusion failure */
2157 continue; /* loop again after exclusion */
2159 if (search
== _PW_KEYBYNUM
||
2160 (search
== _PW_KEYBYUID
&& pw
->pw_uid
== uid
) ||
2161 (search
== _PW_KEYBYNAME
&& strcmp(pw
->pw_name
, name
) == 0))
2162 break; /* token mode match found */
2165 if (rv
== NS_NOTFOUND
&&
2166 (search
== _PW_KEYBYNUM
|| state
->mode
!= COMPAT_NOTOKEN
))
2167 state
->keynum
= -1; /* flag `no more records' */
2169 if (rv
== NS_SUCCESS
) {
2170 if ((search
== _PW_KEYBYNAME
&& strcmp(pw
->pw_name
, name
) != 0)
2171 || (search
== _PW_KEYBYUID
&& pw
->pw_uid
!= uid
))
2175 if (rv
!= NS_SUCCESS
&& rv
!= NS_NOTFOUND
)
2182 _compat_setpwent(void *nsrv
, void *nscb
, va_list ap
)
2185 /* force passwd_compat setpwent() */
2186 (void) _passwdcompat_setpassent(0);
2188 /* reset state, keep db open */
2189 _compat_state
.stayopen
= 0;
2190 return _compat_start(&_compat_state
);
2195 _compat_setpassent(void *nsrv
, void *nscb
, va_list ap
)
2197 int *retval
= va_arg(ap
, int *);
2198 int stayopen
= va_arg(ap
, int);
2202 /* force passwd_compat setpassent() */
2203 (void) _passwdcompat_setpassent(stayopen
);
2205 _compat_state
.stayopen
= stayopen
;
2206 rv
= _compat_start(&_compat_state
);
2207 *retval
= (rv
== NS_SUCCESS
);
2213 _compat_endpwent(void *nsrv
, void *nscb
, va_list ap
)
2216 /* force passwd_compat endpwent() */
2217 (void) _passwdcompat_endpwent();
2219 /* reset state, close db */
2220 _compat_state
.stayopen
= 0;
2221 return _compat_end(&_compat_state
);
2227 _compat_getpwent(void *nsrv
, void *nscb
, va_list ap
)
2229 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
2233 _DIAGASSERT(retval
!= NULL
);
2236 rv
= _compat_pwscan(&rerror
, &_compat_passwd
,
2237 _compat_passwdbuf
, sizeof(_compat_passwdbuf
),
2238 &_compat_state
, _PW_KEYBYNUM
, NULL
, 0);
2239 if (rv
== NS_SUCCESS
)
2240 *retval
= &_compat_passwd
;
2246 _compat_getpwent_r(void *nsrv
, void *nscb
, va_list ap
)
2248 int *retval
= va_arg(ap
, int *);
2249 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
2250 char *buffer
= va_arg(ap
, char *);
2251 size_t buflen
= va_arg(ap
, size_t);
2252 struct passwd
**result
= va_arg(ap
, struct passwd
**);
2256 _DIAGASSERT(retval
!= NULL
);
2257 _DIAGASSERT(pw
!= NULL
);
2258 _DIAGASSERT(buffer
!= NULL
);
2259 _DIAGASSERT(result
!= NULL
);
2261 rv
= _compat_pwscan(retval
, pw
, buffer
, buflen
, &_compat_state
,
2262 _PW_KEYBYNUM
, NULL
, 0);
2263 if (rv
== NS_SUCCESS
)
2273 _compat_getpwnam(void *nsrv
, void *nscb
, va_list ap
)
2275 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
2276 const char *name
= va_arg(ap
, const char *);
2280 _DIAGASSERT(retval
!= NULL
);
2283 rv
= _compat_start(&_compat_state
);
2284 if (rv
!= NS_SUCCESS
)
2286 rv
= _compat_pwscan(&rerror
, &_compat_passwd
,
2287 _compat_passwdbuf
, sizeof(_compat_passwdbuf
),
2288 &_compat_state
, _PW_KEYBYNAME
, name
, 0);
2289 if (!_compat_state
.stayopen
)
2290 _compat_end(&_compat_state
);
2291 if (rv
== NS_SUCCESS
)
2292 *retval
= &_compat_passwd
;
2298 _compat_getpwnam_r(void *nsrv
, void *nscb
, va_list ap
)
2300 int *retval
= va_arg(ap
, int *);
2301 const char *name
= va_arg(ap
, const char *);
2302 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
2303 char *buffer
= va_arg(ap
, char *);
2304 size_t buflen
= va_arg(ap
, size_t);
2305 struct passwd
**result
= va_arg(ap
, struct passwd
**);
2307 struct compat_state state
;
2310 _DIAGASSERT(retval
!= NULL
);
2311 _DIAGASSERT(pw
!= NULL
);
2312 _DIAGASSERT(buffer
!= NULL
);
2313 _DIAGASSERT(result
!= NULL
);
2316 memset(&state
, 0, sizeof(state
));
2317 rv
= _compat_pwscan(retval
, pw
, buffer
, buflen
, &state
,
2318 _PW_KEYBYNAME
, name
, 0);
2319 _compat_end(&state
);
2320 if (rv
== NS_SUCCESS
)
2327 _compat_getpwuid(void *nsrv
, void *nscb
, va_list ap
)
2329 struct passwd
**retval
= va_arg(ap
, struct passwd
**);
2330 uid_t uid
= va_arg(ap
, uid_t
);
2334 _DIAGASSERT(retval
!= NULL
);
2337 rv
= _compat_start(&_compat_state
);
2338 if (rv
!= NS_SUCCESS
)
2340 rv
= _compat_pwscan(&rerror
, &_compat_passwd
,
2341 _compat_passwdbuf
, sizeof(_compat_passwdbuf
),
2342 &_compat_state
, _PW_KEYBYUID
, NULL
, uid
);
2343 if (!_compat_state
.stayopen
)
2344 _compat_end(&_compat_state
);
2345 if (rv
== NS_SUCCESS
)
2346 *retval
= &_compat_passwd
;
2352 _compat_getpwuid_r(void *nsrv
, void *nscb
, va_list ap
)
2354 int *retval
= va_arg(ap
, int *);
2355 uid_t uid
= va_arg(ap
, uid_t
);
2356 struct passwd
*pw
= va_arg(ap
, struct passwd
*);
2357 char *buffer
= va_arg(ap
, char *);
2358 size_t buflen
= va_arg(ap
, size_t);
2359 struct passwd
**result
= va_arg(ap
, struct passwd
**);
2361 struct compat_state state
;
2364 _DIAGASSERT(retval
!= NULL
);
2365 _DIAGASSERT(pw
!= NULL
);
2366 _DIAGASSERT(buffer
!= NULL
);
2367 _DIAGASSERT(result
!= NULL
);
2370 memset(&state
, 0, sizeof(state
));
2371 rv
= _compat_pwscan(retval
, pw
, buffer
, buflen
, &state
,
2372 _PW_KEYBYUID
, NULL
, uid
);
2373 _compat_end(&state
);
2374 if (rv
== NS_SUCCESS
)
2379 #endif /* _PASSWD_COMPAT */
2390 struct passwd
*retval
;
2392 static const ns_dtab dtab
[] = {
2393 NS_FILES_CB(_files_getpwent
, NULL
)
2394 NS_DNS_CB(_dns_getpwent
, NULL
)
2395 NS_NIS_CB(_nis_getpwent
, NULL
)
2396 NS_COMPAT_CB(_compat_getpwent
, NULL
)
2400 mutex_lock(&_pwmutex
);
2401 r
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "getpwent", __nsdefaultcompat
,
2403 mutex_unlock(&_pwmutex
);
2404 return (r
== NS_SUCCESS
) ? retval
: NULL
;
2408 getpwent_r(struct passwd
*pwd
, char *buffer
, size_t buflen
,
2409 struct passwd
**result
)
2413 static const ns_dtab dtab
[] = {
2414 NS_FILES_CB(_files_getpwent_r
, NULL
)
2415 NS_DNS_CB(_dns_getpwent_r
, NULL
)
2416 NS_NIS_CB(_nis_getpwent_r
, NULL
)
2417 NS_COMPAT_CB(_compat_getpwent_r
, NULL
)
2421 _DIAGASSERT(pwd
!= NULL
);
2422 _DIAGASSERT(buffer
!= NULL
);
2423 _DIAGASSERT(result
!= NULL
);
2427 mutex_lock(&_pwmutex
);
2428 r
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "getpwent_r", __nsdefaultcompat
,
2429 &retval
, pwd
, buffer
, buflen
, result
);
2430 mutex_unlock(&_pwmutex
);
2442 getpwnam(const char *name
)
2445 struct passwd
*retval
;
2447 static const ns_dtab dtab
[] = {
2448 NS_FILES_CB(_files_getpwnam
, NULL
)
2449 NS_DNS_CB(_dns_getpwnam
, NULL
)
2450 NS_NIS_CB(_nis_getpwnam
, NULL
)
2451 NS_COMPAT_CB(_compat_getpwnam
, NULL
)
2455 mutex_lock(&_pwmutex
);
2456 rv
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "getpwnam", __nsdefaultcompat
,
2458 mutex_unlock(&_pwmutex
);
2459 return (rv
== NS_SUCCESS
) ? retval
: NULL
;
2463 getpwnam_r(const char *name
, struct passwd
*pwd
, char *buffer
, size_t buflen
,
2464 struct passwd
**result
)
2468 static const ns_dtab dtab
[] = {
2469 NS_FILES_CB(_files_getpwnam_r
, NULL
)
2470 NS_DNS_CB(_dns_getpwnam_r
, NULL
)
2471 NS_NIS_CB(_nis_getpwnam_r
, NULL
)
2472 NS_COMPAT_CB(_compat_getpwnam_r
, NULL
)
2476 _DIAGASSERT(name
!= NULL
);
2477 _DIAGASSERT(pwd
!= NULL
);
2478 _DIAGASSERT(buffer
!= NULL
);
2479 _DIAGASSERT(result
!= NULL
);
2483 mutex_lock(&_pwmutex
);
2484 r
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "getpwnam_r", __nsdefaultcompat
,
2485 &retval
, name
, pwd
, buffer
, buflen
, result
);
2486 mutex_unlock(&_pwmutex
);
2500 struct passwd
*retval
;
2502 static const ns_dtab dtab
[] = {
2503 NS_FILES_CB(_files_getpwuid
, NULL
)
2504 NS_DNS_CB(_dns_getpwuid
, NULL
)
2505 NS_NIS_CB(_nis_getpwuid
, NULL
)
2506 NS_COMPAT_CB(_compat_getpwuid
, NULL
)
2510 mutex_lock(&_pwmutex
);
2511 rv
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "getpwuid", __nsdefaultcompat
,
2513 mutex_unlock(&_pwmutex
);
2514 return (rv
== NS_SUCCESS
) ? retval
: NULL
;
2518 getpwuid_r(uid_t uid
, struct passwd
*pwd
, char *buffer
, size_t buflen
,
2519 struct passwd
**result
)
2523 static const ns_dtab dtab
[] = {
2524 NS_FILES_CB(_files_getpwuid_r
, NULL
)
2525 NS_DNS_CB(_dns_getpwuid_r
, NULL
)
2526 NS_NIS_CB(_nis_getpwuid_r
, NULL
)
2527 NS_COMPAT_CB(_compat_getpwuid_r
, NULL
)
2531 _DIAGASSERT(pwd
!= NULL
);
2532 _DIAGASSERT(buffer
!= NULL
);
2533 _DIAGASSERT(result
!= NULL
);
2537 mutex_lock(&_pwmutex
);
2538 r
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "getpwuid_r", __nsdefaultcompat
,
2539 &retval
, uid
, pwd
, buffer
, buflen
, result
);
2540 mutex_unlock(&_pwmutex
);
2553 static const ns_dtab dtab
[] = {
2554 NS_FILES_CB(_files_endpwent
, NULL
)
2555 NS_DNS_CB(_dns_endpwent
, NULL
)
2556 NS_NIS_CB(_nis_endpwent
, NULL
)
2557 NS_COMPAT_CB(_compat_endpwent
, NULL
)
2561 mutex_lock(&_pwmutex
);
2562 /* force all endpwent() methods */
2563 (void) nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "endpwent",
2564 __nsdefaultcompat_forceall
);
2565 mutex_unlock(&_pwmutex
);
2570 setpassent(int stayopen
)
2572 static const ns_dtab dtab
[] = {
2573 NS_FILES_CB(_files_setpassent
, NULL
)
2574 NS_DNS_CB(_dns_setpassent
, NULL
)
2575 NS_NIS_CB(_nis_setpassent
, NULL
)
2576 NS_COMPAT_CB(_compat_setpassent
, NULL
)
2581 mutex_lock(&_pwmutex
);
2582 /* force all setpassent() methods */
2583 rv
= nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "setpassent",
2584 __nsdefaultcompat_forceall
, &retval
, stayopen
);
2585 mutex_unlock(&_pwmutex
);
2586 return (rv
== NS_SUCCESS
) ? retval
: 0;
2592 static const ns_dtab dtab
[] = {
2593 NS_FILES_CB(_files_setpwent
, NULL
)
2594 NS_DNS_CB(_dns_setpwent
, NULL
)
2595 NS_NIS_CB(_nis_setpwent
, NULL
)
2596 NS_COMPAT_CB(_compat_setpwent
, NULL
)
2600 mutex_lock(&_pwmutex
);
2601 /* force all setpwent() methods */
2602 (void) nsdispatch(NULL
, dtab
, NSDB_PASSWD
, "setpwent",
2603 __nsdefaultcompat_forceall
);
2604 mutex_unlock(&_pwmutex
);