xref: /titanic_44/usr/src/cmd/nscd/getpw.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Routines to handle getpw* calls in nscd
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <assert.h>
34*7c478bd9Sstevel@tonic-gate #include <errno.h>
35*7c478bd9Sstevel@tonic-gate #include <memory.h>
36*7c478bd9Sstevel@tonic-gate #include <signal.h>
37*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
38*7c478bd9Sstevel@tonic-gate #include <stdio.h>
39*7c478bd9Sstevel@tonic-gate #include <string.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/door.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/wait.h>
45*7c478bd9Sstevel@tonic-gate #include <thread.h>
46*7c478bd9Sstevel@tonic-gate #include <unistd.h>
47*7c478bd9Sstevel@tonic-gate #include <nss_common.h>
48*7c478bd9Sstevel@tonic-gate #include <ucred.h>
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #include "getxby_door.h"
51*7c478bd9Sstevel@tonic-gate #include "server_door.h"
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #include "nscd.h"
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate static hash_t *uid_hash;
56*7c478bd9Sstevel@tonic-gate static hash_t *nam_hash;
57*7c478bd9Sstevel@tonic-gate static mutex_t  passwd_lock = DEFAULTMUTEX;
58*7c478bd9Sstevel@tonic-gate static waiter_t passwd_wait;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate static void getpw_invalidate_unlocked(void);
61*7c478bd9Sstevel@tonic-gate static void getpw_namekeepalive(int keep, int interval);
62*7c478bd9Sstevel@tonic-gate static void getpw_uidkeepalive(int keep, int interval);
63*7c478bd9Sstevel@tonic-gate static void update_pw_bucket(nsc_bucket_t **old, nsc_bucket_t *new,
64*7c478bd9Sstevel@tonic-gate     int callnumber);
65*7c478bd9Sstevel@tonic-gate static nsc_bucket_t *fixbuffer(nsc_return_t *in, int maxlen);
66*7c478bd9Sstevel@tonic-gate static void do_findnams(nsc_bucket_t *ptr, int *table, char *name);
67*7c478bd9Sstevel@tonic-gate static void do_finduids(nsc_bucket_t *ptr, int *table, int uid);
68*7c478bd9Sstevel@tonic-gate static void do_invalidate(nsc_bucket_t **ptr, int callnumber);
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate void
71*7c478bd9Sstevel@tonic-gate getpw_init(void)
72*7c478bd9Sstevel@tonic-gate {
73*7c478bd9Sstevel@tonic-gate 	uid_hash = make_ihash(current_admin.passwd.nsc_suggestedsize);
74*7c478bd9Sstevel@tonic-gate 	nam_hash = make_hash(current_admin.passwd.nsc_suggestedsize);
75*7c478bd9Sstevel@tonic-gate }
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate static void
78*7c478bd9Sstevel@tonic-gate do_invalidate(nsc_bucket_t ** ptr, int callnumber)
79*7c478bd9Sstevel@tonic-gate {
80*7c478bd9Sstevel@tonic-gate 	if (*ptr != NULL && *ptr != (nsc_bucket_t *)-1) {
81*7c478bd9Sstevel@tonic-gate 		/* leave pending calls alone */
82*7c478bd9Sstevel@tonic-gate 		update_pw_bucket(ptr, NULL, callnumber);
83*7c478bd9Sstevel@tonic-gate 	}
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate static void
87*7c478bd9Sstevel@tonic-gate do_finduids(nsc_bucket_t *ptr, int *table, int uid)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	/*
91*7c478bd9Sstevel@tonic-gate 	 * be careful with ptr - it may be -1 or NULL.
92*7c478bd9Sstevel@tonic-gate 	 */
93*7c478bd9Sstevel@tonic-gate 	if (ptr != NULL && ptr != (nsc_bucket_t *)-1) {
94*7c478bd9Sstevel@tonic-gate 		insertn(table, ptr->nsc_hits, uid);
95*7c478bd9Sstevel@tonic-gate 	}
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate static void
99*7c478bd9Sstevel@tonic-gate do_findnams(nsc_bucket_t *ptr, int *table, char *name)
100*7c478bd9Sstevel@tonic-gate {
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/*
103*7c478bd9Sstevel@tonic-gate 	 * be careful with ptr - it may be -1 or NULL.
104*7c478bd9Sstevel@tonic-gate 	 */
105*7c478bd9Sstevel@tonic-gate 	if (ptr != NULL && ptr != (nsc_bucket_t *)-1) {
106*7c478bd9Sstevel@tonic-gate 		char *tmp = (char *)insertn(table, ptr->nsc_hits,
107*7c478bd9Sstevel@tonic-gate 			(int)strdup(name));
108*7c478bd9Sstevel@tonic-gate 		if (tmp != (char *)-1)
109*7c478bd9Sstevel@tonic-gate 			free(tmp);
110*7c478bd9Sstevel@tonic-gate 	}
111*7c478bd9Sstevel@tonic-gate }
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate void
116*7c478bd9Sstevel@tonic-gate getpw_revalidate(void)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate 	for (;;) {
119*7c478bd9Sstevel@tonic-gate 		int slp;
120*7c478bd9Sstevel@tonic-gate 		int interval;
121*7c478bd9Sstevel@tonic-gate 		int count;
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 		slp = current_admin.passwd.nsc_pos_ttl;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 		if (slp < 60) {
126*7c478bd9Sstevel@tonic-gate 			slp = 60;
127*7c478bd9Sstevel@tonic-gate 		}
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 		if ((count = current_admin.passwd.nsc_keephot) != 0) {
130*7c478bd9Sstevel@tonic-gate 			interval = (slp / 2)/count;
131*7c478bd9Sstevel@tonic-gate 			if (interval == 0) interval = 1;
132*7c478bd9Sstevel@tonic-gate 			sleep(slp * 2 / 3);
133*7c478bd9Sstevel@tonic-gate 			getpw_uidkeepalive(count, interval);
134*7c478bd9Sstevel@tonic-gate 			getpw_namekeepalive(count, interval);
135*7c478bd9Sstevel@tonic-gate 		} else {
136*7c478bd9Sstevel@tonic-gate 			sleep(slp);
137*7c478bd9Sstevel@tonic-gate 		}
138*7c478bd9Sstevel@tonic-gate 	}
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate static void
142*7c478bd9Sstevel@tonic-gate getpw_uidkeepalive(int keep, int interval)
143*7c478bd9Sstevel@tonic-gate {
144*7c478bd9Sstevel@tonic-gate 	int *table;
145*7c478bd9Sstevel@tonic-gate 	nsc_data_t  ping;
146*7c478bd9Sstevel@tonic-gate 	int i;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	if (!keep)
149*7c478bd9Sstevel@tonic-gate 		return;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	table = maken(keep);
152*7c478bd9Sstevel@tonic-gate 	mutex_lock(&passwd_lock);
153*7c478bd9Sstevel@tonic-gate 	operate_hash(uid_hash, do_finduids, (char *)table);
154*7c478bd9Sstevel@tonic-gate 	mutex_unlock(&passwd_lock);
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= keep; i++) {
157*7c478bd9Sstevel@tonic-gate 	    ping.nsc_call.nsc_callnumber = GETPWUID;
158*7c478bd9Sstevel@tonic-gate 	    if ((ping.nsc_call.nsc_u.uid = table[keep + 1 + i]) == -1)
159*7c478bd9Sstevel@tonic-gate 		continue; /* unused slot in table */
160*7c478bd9Sstevel@tonic-gate 	    launch_update(&ping.nsc_call);
161*7c478bd9Sstevel@tonic-gate 	    sleep(interval);
162*7c478bd9Sstevel@tonic-gate 	}
163*7c478bd9Sstevel@tonic-gate 	free(table);
164*7c478bd9Sstevel@tonic-gate }
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate static void
168*7c478bd9Sstevel@tonic-gate getpw_namekeepalive(int keep, int interval)
169*7c478bd9Sstevel@tonic-gate {
170*7c478bd9Sstevel@tonic-gate 	int *table;
171*7c478bd9Sstevel@tonic-gate 	union {
172*7c478bd9Sstevel@tonic-gate 		nsc_data_t  ping;
173*7c478bd9Sstevel@tonic-gate 		char space[sizeof (nsc_data_t) + NSCDMAXNAMELEN];
174*7c478bd9Sstevel@tonic-gate 	} u;
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 	int i;
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	if (!keep)
179*7c478bd9Sstevel@tonic-gate 		return;
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 	table = maken(keep);
182*7c478bd9Sstevel@tonic-gate 	mutex_lock(&passwd_lock);
183*7c478bd9Sstevel@tonic-gate 	operate_hash(nam_hash, do_findnams, (char *)table);
184*7c478bd9Sstevel@tonic-gate 	mutex_unlock(&passwd_lock);
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= keep; i++) {
187*7c478bd9Sstevel@tonic-gate 		char *tmp;
188*7c478bd9Sstevel@tonic-gate 		u.ping.nsc_call.nsc_callnumber = GETPWNAM;
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 		if ((tmp = (char *)table[keep + 1 + i]) == (char *)-1)
191*7c478bd9Sstevel@tonic-gate 			continue; /* unused slot in table */
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate 		strcpy(u.ping.nsc_call.nsc_u.name, tmp);
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 		launch_update(&u.ping.nsc_call);
196*7c478bd9Sstevel@tonic-gate 		sleep(interval);
197*7c478bd9Sstevel@tonic-gate 	}
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= keep; i++) {
200*7c478bd9Sstevel@tonic-gate 		char *tmp;
201*7c478bd9Sstevel@tonic-gate 		if ((tmp = (char *)table[keep + 1 + i]) != (char *)-1)
202*7c478bd9Sstevel@tonic-gate 			free(tmp);
203*7c478bd9Sstevel@tonic-gate 	}
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	free(table);
206*7c478bd9Sstevel@tonic-gate }
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate /*
212*7c478bd9Sstevel@tonic-gate  *   This routine marks all entries as invalid
213*7c478bd9Sstevel@tonic-gate  *
214*7c478bd9Sstevel@tonic-gate  */
215*7c478bd9Sstevel@tonic-gate void
216*7c478bd9Sstevel@tonic-gate getpw_invalidate(void)
217*7c478bd9Sstevel@tonic-gate {
218*7c478bd9Sstevel@tonic-gate 	mutex_lock(&passwd_lock);
219*7c478bd9Sstevel@tonic-gate 	getpw_invalidate_unlocked();
220*7c478bd9Sstevel@tonic-gate 	mutex_unlock(&passwd_lock);
221*7c478bd9Sstevel@tonic-gate }
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate static void
224*7c478bd9Sstevel@tonic-gate getpw_invalidate_unlocked(void)
225*7c478bd9Sstevel@tonic-gate {
226*7c478bd9Sstevel@tonic-gate 	operate_hash_addr(nam_hash, do_invalidate, (char *)GETPWNAM);
227*7c478bd9Sstevel@tonic-gate 	operate_hash_addr(uid_hash, do_invalidate, (char *)GETPWUID);
228*7c478bd9Sstevel@tonic-gate 	current_admin.passwd.nsc_invalidate_count++;
229*7c478bd9Sstevel@tonic-gate }
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate void
232*7c478bd9Sstevel@tonic-gate getpw_lookup(nsc_return_t *out, int maxsize, nsc_call_t *in, time_t now)
233*7c478bd9Sstevel@tonic-gate {
234*7c478bd9Sstevel@tonic-gate 	int		out_of_date;
235*7c478bd9Sstevel@tonic-gate 	nsc_bucket_t	*retb;
236*7c478bd9Sstevel@tonic-gate 	char 		**bucket;
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate 	static time_t	lastmod;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	int bufferspace = maxsize - sizeof (nsc_return_t);
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 	if (current_admin.passwd.nsc_enabled == 0) {
243*7c478bd9Sstevel@tonic-gate 		out->nsc_return_code = NOSERVER;
244*7c478bd9Sstevel@tonic-gate 		out->nsc_bufferbytesused = sizeof (*out);
245*7c478bd9Sstevel@tonic-gate 		return;
246*7c478bd9Sstevel@tonic-gate 	}
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	mutex_lock(&passwd_lock);
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate 	if (current_admin.passwd.nsc_check_files) {
251*7c478bd9Sstevel@tonic-gate 		struct stat buf;
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 		if (stat("/etc/passwd", &buf) < 0) {
254*7c478bd9Sstevel@tonic-gate 			/*EMPTY*/;
255*7c478bd9Sstevel@tonic-gate 		} else if (lastmod == 0) {
256*7c478bd9Sstevel@tonic-gate 			lastmod = buf.st_mtime;
257*7c478bd9Sstevel@tonic-gate 		} else if (lastmod < buf.st_mtime) {
258*7c478bd9Sstevel@tonic-gate 			getpw_invalidate_unlocked();
259*7c478bd9Sstevel@tonic-gate 			lastmod = buf.st_mtime;
260*7c478bd9Sstevel@tonic-gate 		}
261*7c478bd9Sstevel@tonic-gate 	}
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	if (current_admin.debug_level >= DBG_ALL) {
264*7c478bd9Sstevel@tonic-gate 		if (MASKUPDATEBIT(in->nsc_callnumber) == GETPWUID) {
265*7c478bd9Sstevel@tonic-gate 			logit("getpw_lookup: looking for uid %d\n",
266*7c478bd9Sstevel@tonic-gate 				in->nsc_u.uid);
267*7c478bd9Sstevel@tonic-gate 		} else {
268*7c478bd9Sstevel@tonic-gate 			logit("getpw_lookup: looking for name %s\n",
269*7c478bd9Sstevel@tonic-gate 				in->nsc_u.name);
270*7c478bd9Sstevel@tonic-gate 		}
271*7c478bd9Sstevel@tonic-gate 	}
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	for (;;) {
274*7c478bd9Sstevel@tonic-gate 		if (MASKUPDATEBIT(in->nsc_callnumber) == GETPWUID) {
275*7c478bd9Sstevel@tonic-gate 			bucket = get_hash(uid_hash, (char *)in->nsc_u.uid);
276*7c478bd9Sstevel@tonic-gate 		} else { /* make reasonableness check here  */
277*7c478bd9Sstevel@tonic-gate 			if (strlen(in->nsc_u.name) > NSCDMAXNAMELEN) {
278*7c478bd9Sstevel@tonic-gate 				ucred_t *uc = NULL;
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 				if (door_ucred(&uc) != 0) {
281*7c478bd9Sstevel@tonic-gate 					logit("getpw_lookup: Name too long, "
282*7c478bd9Sstevel@tonic-gate 					    "but no user credential: %s\n",
283*7c478bd9Sstevel@tonic-gate 					    strerror(errno));
284*7c478bd9Sstevel@tonic-gate 				} else {
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 					logit("getpw_lookup: Name too long "
287*7c478bd9Sstevel@tonic-gate 					    "from pid %d uid %d\n",
288*7c478bd9Sstevel@tonic-gate 					    ucred_getpid(uc),
289*7c478bd9Sstevel@tonic-gate 					    ucred_getruid(uc));
290*7c478bd9Sstevel@tonic-gate 					ucred_free(uc);
291*7c478bd9Sstevel@tonic-gate 				}
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate 				out->nsc_errno = NSS_NOTFOUND;
295*7c478bd9Sstevel@tonic-gate 				out->nsc_return_code = NOTFOUND;
296*7c478bd9Sstevel@tonic-gate 				out->nsc_bufferbytesused = sizeof (*out);
297*7c478bd9Sstevel@tonic-gate 				goto getout;
298*7c478bd9Sstevel@tonic-gate 			}
299*7c478bd9Sstevel@tonic-gate 			bucket = get_hash(nam_hash, in->nsc_u.name);
300*7c478bd9Sstevel@tonic-gate 		}
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate 		if (*bucket == (char *)-1) {	/* pending lookup */
303*7c478bd9Sstevel@tonic-gate 			if (get_clearance(in->nsc_callnumber) != 0) {
304*7c478bd9Sstevel@tonic-gate 				/* no threads available */
305*7c478bd9Sstevel@tonic-gate 				out->nsc_return_code = NOSERVER;
306*7c478bd9Sstevel@tonic-gate 				/* cannot process now */
307*7c478bd9Sstevel@tonic-gate 				out->nsc_bufferbytesused = sizeof (*out);
308*7c478bd9Sstevel@tonic-gate 				current_admin.passwd.nsc_throttle_count++;
309*7c478bd9Sstevel@tonic-gate 				goto getout;
310*7c478bd9Sstevel@tonic-gate 			}
311*7c478bd9Sstevel@tonic-gate 			nscd_wait(&passwd_wait, &passwd_lock, bucket);
312*7c478bd9Sstevel@tonic-gate 			release_clearance(in->nsc_callnumber);
313*7c478bd9Sstevel@tonic-gate 			continue; /* go back and relookup hash bucket */
314*7c478bd9Sstevel@tonic-gate 		}
315*7c478bd9Sstevel@tonic-gate 		break;
316*7c478bd9Sstevel@tonic-gate 	}
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	/*
319*7c478bd9Sstevel@tonic-gate 	 * check for no name_service mode
320*7c478bd9Sstevel@tonic-gate 	 */
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate 	if (*bucket == NULL && current_admin.avoid_nameservice) {
323*7c478bd9Sstevel@tonic-gate 		out->nsc_return_code = NOTFOUND;
324*7c478bd9Sstevel@tonic-gate 		out->nsc_bufferbytesused = sizeof (*out);
325*7c478bd9Sstevel@tonic-gate 	} else if (*bucket == NULL ||
326*7c478bd9Sstevel@tonic-gate 	    (in->nsc_callnumber & UPDATEBIT) ||
327*7c478bd9Sstevel@tonic-gate 	    (out_of_date = (!current_admin.avoid_nameservice &&
328*7c478bd9Sstevel@tonic-gate 		(current_admin.passwd.nsc_old_data_ok == 0) &&
329*7c478bd9Sstevel@tonic-gate 		(((nsc_bucket_t *)*bucket)->nsc_timestamp < now)))) {
330*7c478bd9Sstevel@tonic-gate 		/*
331*7c478bd9Sstevel@tonic-gate 		 * time has expired
332*7c478bd9Sstevel@tonic-gate 		 */
333*7c478bd9Sstevel@tonic-gate 		int saved_errno;
334*7c478bd9Sstevel@tonic-gate 		int saved_hits = 0;
335*7c478bd9Sstevel@tonic-gate 		struct passwd *p;
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 		if (get_clearance(in->nsc_callnumber) != 0) {
338*7c478bd9Sstevel@tonic-gate 			/* no threads available */
339*7c478bd9Sstevel@tonic-gate 			out->nsc_return_code = NOSERVER;
340*7c478bd9Sstevel@tonic-gate 			/* cannot process now */
341*7c478bd9Sstevel@tonic-gate 			out->nsc_bufferbytesused = sizeof (*out);
342*7c478bd9Sstevel@tonic-gate 			current_admin.passwd.nsc_throttle_count++;
343*7c478bd9Sstevel@tonic-gate 			goto getout;
344*7c478bd9Sstevel@tonic-gate 		}
345*7c478bd9Sstevel@tonic-gate 		if (*bucket != NULL) {
346*7c478bd9Sstevel@tonic-gate 			saved_hits = ((nsc_bucket_t *)*bucket)->nsc_hits;
347*7c478bd9Sstevel@tonic-gate 		}
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 		/*
350*7c478bd9Sstevel@tonic-gate 		 *  block any threads accessing this bucket if data
351*7c478bd9Sstevel@tonic-gate 		 *  is non-existent or out of date
352*7c478bd9Sstevel@tonic-gate 		 */
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 		if (*bucket == NULL || out_of_date) {
355*7c478bd9Sstevel@tonic-gate 			update_pw_bucket((nsc_bucket_t **)bucket,
356*7c478bd9Sstevel@tonic-gate 					(nsc_bucket_t *)-1,
357*7c478bd9Sstevel@tonic-gate 					in->nsc_callnumber);
358*7c478bd9Sstevel@tonic-gate 		} else {
359*7c478bd9Sstevel@tonic-gate 			/*
360*7c478bd9Sstevel@tonic-gate 			 * if still not -1 bucket we are doing
361*7c478bd9Sstevel@tonic-gate 			 * update... mark to prevent pileups of threads if
362*7c478bd9Sstevel@tonic-gate 			 * the name service is hanging..
363*7c478bd9Sstevel@tonic-gate 			 */
364*7c478bd9Sstevel@tonic-gate 			((nsc_bucket_t *)(*bucket))->nsc_status |=
365*7c478bd9Sstevel@tonic-gate 				ST_UPDATE_PENDING;
366*7c478bd9Sstevel@tonic-gate 			/* cleared by deletion of old data */
367*7c478bd9Sstevel@tonic-gate 		}
368*7c478bd9Sstevel@tonic-gate 		mutex_unlock(&passwd_lock);
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate 		if (MASKUPDATEBIT(in->nsc_callnumber) == GETPWUID) {
371*7c478bd9Sstevel@tonic-gate 			p = _uncached_getpwuid_r(in->nsc_u.uid, &out->nsc_u.pwd,
372*7c478bd9Sstevel@tonic-gate 				out->nsc_u.buff+sizeof (struct passwd),
373*7c478bd9Sstevel@tonic-gate 				bufferspace);
374*7c478bd9Sstevel@tonic-gate 			saved_errno = errno;
375*7c478bd9Sstevel@tonic-gate 		} else {
376*7c478bd9Sstevel@tonic-gate 			p = _uncached_getpwnam_r(in->nsc_u.name,
377*7c478bd9Sstevel@tonic-gate 				&out->nsc_u.pwd,
378*7c478bd9Sstevel@tonic-gate 				out->nsc_u.buff+sizeof (struct passwd),
379*7c478bd9Sstevel@tonic-gate 				bufferspace);
380*7c478bd9Sstevel@tonic-gate 			saved_errno = errno;
381*7c478bd9Sstevel@tonic-gate 		}
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate 		mutex_lock(&passwd_lock);
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate 		release_clearance(in->nsc_callnumber);
386*7c478bd9Sstevel@tonic-gate 
387*7c478bd9Sstevel@tonic-gate 		if (p == NULL) { /* data not found */
388*7c478bd9Sstevel@tonic-gate 			if (current_admin.debug_level >= DBG_CANT_FIND) {
389*7c478bd9Sstevel@tonic-gate 				if (MASKUPDATEBIT(in->nsc_callnumber) ==
390*7c478bd9Sstevel@tonic-gate 					GETPWUID) {
391*7c478bd9Sstevel@tonic-gate 			logit("getpw_lookup: nscd COULDN'T FIND uid %d\n",
392*7c478bd9Sstevel@tonic-gate 					in->nsc_u.uid);
393*7c478bd9Sstevel@tonic-gate 				} else {
394*7c478bd9Sstevel@tonic-gate 		logit("getpw_lookup: nscd COULDN'T FIND passwd name %s\n",
395*7c478bd9Sstevel@tonic-gate 						in->nsc_u.name);
396*7c478bd9Sstevel@tonic-gate 				}
397*7c478bd9Sstevel@tonic-gate 			}
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 			if (!(UPDATEBIT & in->nsc_callnumber))
400*7c478bd9Sstevel@tonic-gate 			    current_admin.passwd.nsc_neg_cache_misses++;
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate 			retb = (nsc_bucket_t *)malloc(sizeof (nsc_bucket_t));
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 			retb->nsc_refcount = 1;
405*7c478bd9Sstevel@tonic-gate 			retb->nsc_data.nsc_bufferbytesused =
406*7c478bd9Sstevel@tonic-gate 				sizeof (nsc_return_t);
407*7c478bd9Sstevel@tonic-gate 			retb->nsc_data.nsc_return_code = NOTFOUND;
408*7c478bd9Sstevel@tonic-gate 			retb->nsc_data.nsc_errno = saved_errno;
409*7c478bd9Sstevel@tonic-gate 			memcpy(out, &retb->nsc_data,
410*7c478bd9Sstevel@tonic-gate 				retb->nsc_data.nsc_bufferbytesused);
411*7c478bd9Sstevel@tonic-gate 			update_pw_bucket((nsc_bucket_t **)bucket, retb,
412*7c478bd9Sstevel@tonic-gate 				in->nsc_callnumber);
413*7c478bd9Sstevel@tonic-gate 			goto getout;
414*7c478bd9Sstevel@tonic-gate 		} else {
415*7c478bd9Sstevel@tonic-gate 			if (current_admin.debug_level >= DBG_ALL) {
416*7c478bd9Sstevel@tonic-gate 				if (MASKUPDATEBIT(in->nsc_callnumber) ==
417*7c478bd9Sstevel@tonic-gate 					GETPWUID) {
418*7c478bd9Sstevel@tonic-gate 				logit("getpw_lookup: nscd FOUND uid %d\n",
419*7c478bd9Sstevel@tonic-gate 						in->nsc_u.uid);
420*7c478bd9Sstevel@tonic-gate 				} else {
421*7c478bd9Sstevel@tonic-gate 			logit("getpw_lookup: nscd FOUND passwd name %s\n",
422*7c478bd9Sstevel@tonic-gate 						in->nsc_u.name);
423*7c478bd9Sstevel@tonic-gate 				}
424*7c478bd9Sstevel@tonic-gate 			}
425*7c478bd9Sstevel@tonic-gate 			if (!(UPDATEBIT & in->nsc_callnumber))
426*7c478bd9Sstevel@tonic-gate 			    current_admin.passwd.nsc_pos_cache_misses++;
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate 			retb = fixbuffer(out, bufferspace);
429*7c478bd9Sstevel@tonic-gate 			update_pw_bucket((nsc_bucket_t **)bucket,
430*7c478bd9Sstevel@tonic-gate 				retb, in->nsc_callnumber);
431*7c478bd9Sstevel@tonic-gate 			if (saved_hits)
432*7c478bd9Sstevel@tonic-gate 				retb->nsc_hits = saved_hits;
433*7c478bd9Sstevel@tonic-gate 		}
434*7c478bd9Sstevel@tonic-gate 	} else { 	/* found entry in cache */
435*7c478bd9Sstevel@tonic-gate 		retb = (nsc_bucket_t *)*bucket;
436*7c478bd9Sstevel@tonic-gate 
437*7c478bd9Sstevel@tonic-gate 		retb->nsc_hits++;
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate 		memcpy(out, &(retb->nsc_data),
440*7c478bd9Sstevel@tonic-gate 			retb->nsc_data.nsc_bufferbytesused);
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate 		if (out->nsc_return_code == SUCCESS) {
443*7c478bd9Sstevel@tonic-gate 			if (!(UPDATEBIT & in->nsc_callnumber))
444*7c478bd9Sstevel@tonic-gate 			    current_admin.passwd.nsc_pos_cache_hits++;
445*7c478bd9Sstevel@tonic-gate 			if (current_admin.debug_level >= DBG_ALL) {
446*7c478bd9Sstevel@tonic-gate 				if (MASKUPDATEBIT(in->nsc_callnumber) ==
447*7c478bd9Sstevel@tonic-gate 					GETPWUID) {
448*7c478bd9Sstevel@tonic-gate 			logit("getpw_lookup: found uid %d in cache\n",
449*7c478bd9Sstevel@tonic-gate 						in->nsc_u.uid);
450*7c478bd9Sstevel@tonic-gate 				} else {
451*7c478bd9Sstevel@tonic-gate 			logit("getpw_lookup: found name %s in cache\n",
452*7c478bd9Sstevel@tonic-gate 						in->nsc_u.name);
453*7c478bd9Sstevel@tonic-gate 				}
454*7c478bd9Sstevel@tonic-gate 			}
455*7c478bd9Sstevel@tonic-gate 		} else {
456*7c478bd9Sstevel@tonic-gate 			if (!(UPDATEBIT & in->nsc_callnumber))
457*7c478bd9Sstevel@tonic-gate 			    current_admin.passwd.nsc_neg_cache_hits++;
458*7c478bd9Sstevel@tonic-gate 			if (current_admin.debug_level >= DBG_ALL) {
459*7c478bd9Sstevel@tonic-gate 				if (MASKUPDATEBIT(in->nsc_callnumber) ==
460*7c478bd9Sstevel@tonic-gate 					GETPWUID) {
461*7c478bd9Sstevel@tonic-gate 		logit("getpw_lookup: %d marked as NOT FOUND in cache.\n",
462*7c478bd9Sstevel@tonic-gate 						in->nsc_u.uid);
463*7c478bd9Sstevel@tonic-gate 				} else {
464*7c478bd9Sstevel@tonic-gate 		logit("getpw_lookup: %s marked as NOT FOUND in cache.\n",
465*7c478bd9Sstevel@tonic-gate 						in->nsc_u.name);
466*7c478bd9Sstevel@tonic-gate 				}
467*7c478bd9Sstevel@tonic-gate 			}
468*7c478bd9Sstevel@tonic-gate 		}
469*7c478bd9Sstevel@tonic-gate 
470*7c478bd9Sstevel@tonic-gate 		if ((retb->nsc_timestamp < now) &&
471*7c478bd9Sstevel@tonic-gate 			!(in->nsc_callnumber & UPDATEBIT) &&
472*7c478bd9Sstevel@tonic-gate 			!(retb->nsc_status & ST_UPDATE_PENDING)) {
473*7c478bd9Sstevel@tonic-gate 			logit("launch update since time = %d\n",
474*7c478bd9Sstevel@tonic-gate 				retb->nsc_timestamp);
475*7c478bd9Sstevel@tonic-gate 			retb->nsc_status |= ST_UPDATE_PENDING;
476*7c478bd9Sstevel@tonic-gate 			/* cleared by deletion of old data */
477*7c478bd9Sstevel@tonic-gate 			launch_update(in);
478*7c478bd9Sstevel@tonic-gate 		}
479*7c478bd9Sstevel@tonic-gate 	}
480*7c478bd9Sstevel@tonic-gate 
481*7c478bd9Sstevel@tonic-gate getout:
482*7c478bd9Sstevel@tonic-gate 
483*7c478bd9Sstevel@tonic-gate 	mutex_unlock(&passwd_lock);
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate 	/*
486*7c478bd9Sstevel@tonic-gate 	 *	secure mode check - blank out passwd if call sucessfull
487*7c478bd9Sstevel@tonic-gate 	 *	and caller != effective id
488*7c478bd9Sstevel@tonic-gate 	 */
489*7c478bd9Sstevel@tonic-gate 	if ((current_admin.passwd.nsc_secure_mode != 0) &&
490*7c478bd9Sstevel@tonic-gate 		(out->nsc_return_code == SUCCESS) &&
491*7c478bd9Sstevel@tonic-gate 		!(UPDATEBIT & in->nsc_callnumber)) {
492*7c478bd9Sstevel@tonic-gate 
493*7c478bd9Sstevel@tonic-gate 		ucred_t *uc = NULL;
494*7c478bd9Sstevel@tonic-gate 
495*7c478bd9Sstevel@tonic-gate 		if (door_ucred(&uc) != 0) {
496*7c478bd9Sstevel@tonic-gate 			perror("door_ucred");
497*7c478bd9Sstevel@tonic-gate 		} else {
498*7c478bd9Sstevel@tonic-gate 			if (ucred_geteuid(uc) != out->nsc_u.pwd.pw_uid) {
499*7c478bd9Sstevel@tonic-gate 				/*
500*7c478bd9Sstevel@tonic-gate 				 *  write *NP* into passwd field if
501*7c478bd9Sstevel@tonic-gate 				 *  not already that way... we fixed
502*7c478bd9Sstevel@tonic-gate 				 *  the buffer code so there's always room.
503*7c478bd9Sstevel@tonic-gate 				 */
504*7c478bd9Sstevel@tonic-gate 				int len;
505*7c478bd9Sstevel@tonic-gate 
506*7c478bd9Sstevel@tonic-gate 				char *foo = out->nsc_u.buff
507*7c478bd9Sstevel@tonic-gate 					+ sizeof (struct passwd)
508*7c478bd9Sstevel@tonic-gate 					+ (int)out->nsc_u.pwd.pw_passwd;
509*7c478bd9Sstevel@tonic-gate 
510*7c478bd9Sstevel@tonic-gate 				len = strlen(foo);
511*7c478bd9Sstevel@tonic-gate 				if (len > 0 &&
512*7c478bd9Sstevel@tonic-gate 				    strcmp(foo, "*NP*") != 0 &&
513*7c478bd9Sstevel@tonic-gate 				    strcmp(foo, "x") != 0) {
514*7c478bd9Sstevel@tonic-gate 					if (len < 5)
515*7c478bd9Sstevel@tonic-gate 						len = 5;
516*7c478bd9Sstevel@tonic-gate 					strncpy(foo, "*NP*", len);
517*7c478bd9Sstevel@tonic-gate 					/*
518*7c478bd9Sstevel@tonic-gate 					 * strncpy will
519*7c478bd9Sstevel@tonic-gate 					 * blank all
520*7c478bd9Sstevel@tonic-gate 					 */
521*7c478bd9Sstevel@tonic-gate 				}
522*7c478bd9Sstevel@tonic-gate 			}
523*7c478bd9Sstevel@tonic-gate 			ucred_free(uc);
524*7c478bd9Sstevel@tonic-gate 		}
525*7c478bd9Sstevel@tonic-gate 	}
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
529*7c478bd9Sstevel@tonic-gate static void
530*7c478bd9Sstevel@tonic-gate update_pw_bucket(nsc_bucket_t **old, nsc_bucket_t *new, int callnumber)
531*7c478bd9Sstevel@tonic-gate {
532*7c478bd9Sstevel@tonic-gate 	if (*old != NULL && *old != (nsc_bucket_t *)-1) {
533*7c478bd9Sstevel@tonic-gate 		/* old data exists */
534*7c478bd9Sstevel@tonic-gate 		free(*old);
535*7c478bd9Sstevel@tonic-gate 		current_admin.passwd.nsc_entries--;
536*7c478bd9Sstevel@tonic-gate 	}
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate 	/*
539*7c478bd9Sstevel@tonic-gate 	 *  we can do this before reseting *old since we're holding the lock
540*7c478bd9Sstevel@tonic-gate 	 */
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate 	else if (*old == (nsc_bucket_t *)-1) {
543*7c478bd9Sstevel@tonic-gate 		nscd_signal(&passwd_wait, (char **)old);
544*7c478bd9Sstevel@tonic-gate 	}
545*7c478bd9Sstevel@tonic-gate 
546*7c478bd9Sstevel@tonic-gate 
547*7c478bd9Sstevel@tonic-gate 
548*7c478bd9Sstevel@tonic-gate 	*old = new;
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate 	if ((new != NULL) &&
551*7c478bd9Sstevel@tonic-gate 		(new != (nsc_bucket_t *)-1)) {
552*7c478bd9Sstevel@tonic-gate 		/* real data, not just update pending or invalidate */
553*7c478bd9Sstevel@tonic-gate 
554*7c478bd9Sstevel@tonic-gate 		new->nsc_hits = 1;
555*7c478bd9Sstevel@tonic-gate 		new->nsc_status = 0;
556*7c478bd9Sstevel@tonic-gate 		new->nsc_refcount = 1;
557*7c478bd9Sstevel@tonic-gate 		current_admin.passwd.nsc_entries++;
558*7c478bd9Sstevel@tonic-gate 
559*7c478bd9Sstevel@tonic-gate 		if (new->nsc_data.nsc_return_code == SUCCESS) {
560*7c478bd9Sstevel@tonic-gate 			new->nsc_timestamp = time(NULL) +
561*7c478bd9Sstevel@tonic-gate 				current_admin.passwd.nsc_pos_ttl;
562*7c478bd9Sstevel@tonic-gate 		} else {
563*7c478bd9Sstevel@tonic-gate 			new->nsc_timestamp = time(NULL) +
564*7c478bd9Sstevel@tonic-gate 				current_admin.passwd.nsc_neg_ttl;
565*7c478bd9Sstevel@tonic-gate 		}
566*7c478bd9Sstevel@tonic-gate 	}
567*7c478bd9Sstevel@tonic-gate }
568*7c478bd9Sstevel@tonic-gate 
569*7c478bd9Sstevel@tonic-gate 
570*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
571*7c478bd9Sstevel@tonic-gate static nsc_bucket_t *
572*7c478bd9Sstevel@tonic-gate fixbuffer(nsc_return_t *in, int maxlen)
573*7c478bd9Sstevel@tonic-gate {
574*7c478bd9Sstevel@tonic-gate 	nsc_bucket_t *retb;
575*7c478bd9Sstevel@tonic-gate 	char *dest;
576*7c478bd9Sstevel@tonic-gate 
577*7c478bd9Sstevel@tonic-gate 	nsc_return_t  *out;
578*7c478bd9Sstevel@tonic-gate 	int offset;
579*7c478bd9Sstevel@tonic-gate 	int strs;
580*7c478bd9Sstevel@tonic-gate 	int pwlen;
581*7c478bd9Sstevel@tonic-gate 
582*7c478bd9Sstevel@tonic-gate 	/*
583*7c478bd9Sstevel@tonic-gate 	 * find out the size of the data block we're going to need
584*7c478bd9Sstevel@tonic-gate 	 */
585*7c478bd9Sstevel@tonic-gate 
586*7c478bd9Sstevel@tonic-gate 	strs = 0;
587*7c478bd9Sstevel@tonic-gate 	strs += 1 + strlen(in->nsc_u.pwd.pw_name);
588*7c478bd9Sstevel@tonic-gate 	pwlen = strlen(in->nsc_u.pwd.pw_passwd);
589*7c478bd9Sstevel@tonic-gate 	if (pwlen < 4)
590*7c478bd9Sstevel@tonic-gate 	    pwlen = 4;
591*7c478bd9Sstevel@tonic-gate 	strs += 1 + pwlen;
592*7c478bd9Sstevel@tonic-gate 	strs += 1 + strlen(in->nsc_u.pwd.pw_age);
593*7c478bd9Sstevel@tonic-gate 	strs += 1 + strlen(in->nsc_u.pwd.pw_comment);
594*7c478bd9Sstevel@tonic-gate 	strs += 1 + strlen(in->nsc_u.pwd.pw_gecos);
595*7c478bd9Sstevel@tonic-gate 	strs += 1 + strlen(in->nsc_u.pwd.pw_dir);
596*7c478bd9Sstevel@tonic-gate 	strs += 1 + strlen(in->nsc_u.pwd.pw_shell);
597*7c478bd9Sstevel@tonic-gate 
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 	/*
600*7c478bd9Sstevel@tonic-gate 	 * allocate it and copy it in
601*7c478bd9Sstevel@tonic-gate 	 * code doesn't assume packing order in original buffer
602*7c478bd9Sstevel@tonic-gate 	 */
603*7c478bd9Sstevel@tonic-gate 
604*7c478bd9Sstevel@tonic-gate 	if ((retb = (nsc_bucket_t *)malloc(sizeof (*retb) + strs)) == NULL) {
605*7c478bd9Sstevel@tonic-gate 		return (NULL);
606*7c478bd9Sstevel@tonic-gate 	}
607*7c478bd9Sstevel@tonic-gate 
608*7c478bd9Sstevel@tonic-gate 	out = &(retb->nsc_data);
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate 
611*7c478bd9Sstevel@tonic-gate 
612*7c478bd9Sstevel@tonic-gate 	out->nsc_bufferbytesused = sizeof (*in) + strs;
613*7c478bd9Sstevel@tonic-gate 	out->nsc_return_code 	= SUCCESS;
614*7c478bd9Sstevel@tonic-gate 	out->nsc_errno 		= 0;
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_uid = in->nsc_u.pwd.pw_uid;
617*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_gid = in->nsc_u.pwd.pw_gid;
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate 	dest = retb->nsc_data.nsc_u.buff + sizeof (struct passwd);
620*7c478bd9Sstevel@tonic-gate 
621*7c478bd9Sstevel@tonic-gate 	offset = (int)dest;
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_name);
624*7c478bd9Sstevel@tonic-gate 	strs = 1 + strlen(in->nsc_u.pwd.pw_name);
625*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_name = dest - offset;
626*7c478bd9Sstevel@tonic-gate 	dest += strs;
627*7c478bd9Sstevel@tonic-gate 
628*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_passwd);
629*7c478bd9Sstevel@tonic-gate 	strs = 1 + pwlen;
630*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_passwd = dest - offset;
631*7c478bd9Sstevel@tonic-gate 	dest += strs;
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_age);
634*7c478bd9Sstevel@tonic-gate 	strs = 1 + strlen(in->nsc_u.pwd.pw_age);
635*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_age = dest - offset;
636*7c478bd9Sstevel@tonic-gate 	dest += strs;
637*7c478bd9Sstevel@tonic-gate 
638*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_comment);
639*7c478bd9Sstevel@tonic-gate 	strs = 1 + strlen(in->nsc_u.pwd.pw_comment);
640*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_comment = dest - offset;
641*7c478bd9Sstevel@tonic-gate 	dest += strs;
642*7c478bd9Sstevel@tonic-gate 
643*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_gecos);
644*7c478bd9Sstevel@tonic-gate 	strs = 1 + strlen(in->nsc_u.pwd.pw_gecos);
645*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_gecos = dest - offset;
646*7c478bd9Sstevel@tonic-gate 	dest += strs;
647*7c478bd9Sstevel@tonic-gate 
648*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_dir);
649*7c478bd9Sstevel@tonic-gate 	strs = 1 + strlen(in->nsc_u.pwd.pw_dir);
650*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_dir = dest - offset;
651*7c478bd9Sstevel@tonic-gate 	dest += strs;
652*7c478bd9Sstevel@tonic-gate 
653*7c478bd9Sstevel@tonic-gate 	strcpy(dest, in->nsc_u.pwd.pw_shell);
654*7c478bd9Sstevel@tonic-gate 	out->nsc_u.pwd.pw_shell = dest - offset;
655*7c478bd9Sstevel@tonic-gate 
656*7c478bd9Sstevel@tonic-gate 	memcpy(in, out, retb->nsc_data.nsc_bufferbytesused);
657*7c478bd9Sstevel@tonic-gate 
658*7c478bd9Sstevel@tonic-gate 
659*7c478bd9Sstevel@tonic-gate 	return (retb);
660*7c478bd9Sstevel@tonic-gate 
661*7c478bd9Sstevel@tonic-gate }
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate void
664*7c478bd9Sstevel@tonic-gate getpw_uid_reaper()
665*7c478bd9Sstevel@tonic-gate {
666*7c478bd9Sstevel@tonic-gate 	nsc_reaper("getpw_uid", uid_hash, &current_admin.passwd, &passwd_lock);
667*7c478bd9Sstevel@tonic-gate }
668*7c478bd9Sstevel@tonic-gate 
669*7c478bd9Sstevel@tonic-gate void
670*7c478bd9Sstevel@tonic-gate getpw_nam_reaper()
671*7c478bd9Sstevel@tonic-gate {
672*7c478bd9Sstevel@tonic-gate 	nsc_reaper("getpw_nam", nam_hash, &current_admin.passwd, &passwd_lock);
673*7c478bd9Sstevel@tonic-gate }
674