4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996,1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid
[] = "Id: getpwent.c,v 1.3 2005/04/27 04:56:26 sra Exp";
26 #include "port_before.h"
28 #if !defined(WANT_IRS_PW) || defined(__BIND_NOSTATIC)
29 static int __bind_irs_pw_unneeded
;
32 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <arpa/nameser.h>
45 #include "port_after.h"
51 static struct net_data
* init(void);
57 struct net_data
*net_data
= init();
59 return (getpwent_p(net_data
));
63 getpwnam(const char *name
) {
64 struct net_data
*net_data
= init();
66 return (getpwnam_p(name
, net_data
));
71 struct net_data
*net_data
= init();
73 return (getpwuid_p(uid
, net_data
));
77 setpassent(int stayopen
) {
78 struct net_data
*net_data
= init();
80 return (setpassent_p(stayopen
, net_data
));
86 struct net_data
*net_data
= init();
93 struct net_data
*net_data
= init();
95 return (setpwent_p(net_data
));
101 struct net_data
*net_data
= init();
103 endpwent_p(net_data
);
106 /* Shared private. */
109 getpwent_p(struct net_data
*net_data
) {
112 if (!net_data
|| !(pw
= net_data
->pw
))
114 net_data
->pw_last
= (*pw
->next
)(pw
);
115 return (net_data
->pw_last
);
119 getpwnam_p(const char *name
, struct net_data
*net_data
) {
122 if (!net_data
|| !(pw
= net_data
->pw
))
124 if (net_data
->pw_stayopen
&& net_data
->pw_last
&&
125 !strcmp(net_data
->pw_last
->pw_name
, name
))
126 return (net_data
->pw_last
);
127 net_data
->pw_last
= (*pw
->byname
)(pw
, name
);
128 if (!net_data
->pw_stayopen
)
130 return (net_data
->pw_last
);
134 getpwuid_p(uid_t uid
, struct net_data
*net_data
) {
137 if (!net_data
|| !(pw
= net_data
->pw
))
139 if (net_data
->pw_stayopen
&& net_data
->pw_last
&&
140 net_data
->pw_last
->pw_uid
== uid
)
141 return (net_data
->pw_last
);
142 net_data
->pw_last
= (*pw
->byuid
)(pw
, uid
);
143 if (!net_data
->pw_stayopen
)
145 return (net_data
->pw_last
);
149 setpassent_p(int stayopen
, struct net_data
*net_data
) {
152 if (!net_data
|| !(pw
= net_data
->pw
))
155 net_data
->pw_stayopen
= (stayopen
!= 0);
157 net_data_minimize(net_data
);
163 setpwent_p(struct net_data
*net_data
) {
164 (void) setpassent_p(0, net_data
);
168 setpwent_p(struct net_data
*net_data
) {
169 return (setpassent_p(0, net_data
));
174 endpwent_p(struct net_data
*net_data
) {
177 if ((net_data
!= NULL
) && ((pw
= net_data
->pw
) != NULL
))
183 static struct net_data
*
185 struct net_data
*net_data
;
186 if (!(net_data
= net_data_init(NULL
)))
189 net_data
->pw
= (*net_data
->irs
->pw_map
)(net_data
->irs
);
191 if (!net_data
->pw
|| !net_data
->res
) {
196 (*net_data
->pw
->res_set
)(net_data
->pw
, net_data
->res
, NULL
);
202 #endif /* WANT_IRS_PW */