xref: /netbsd/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c (revision d6aaec91)
1*d6aaec91Ssevan /*	$NetBSD: pcnfsd_v2.c,v 1.14 2018/01/23 21:06:25 sevan Exp $	*/
2457d5a17Sgwr 
382b75dfdSjtc /* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_v2.c 1.2 91/12/18 13:26:13 SMI */
482b75dfdSjtc /*
582b75dfdSjtc **=====================================================================
682b75dfdSjtc ** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
782b75dfdSjtc **	@(#)pcnfsd_v2.c	1.2	12/18/91
882b75dfdSjtc **=====================================================================
982b75dfdSjtc */
1082b75dfdSjtc /*
1182b75dfdSjtc **=====================================================================
1282b75dfdSjtc **             I N C L U D E   F I L E   S E C T I O N                *
1382b75dfdSjtc **                                                                    *
1482b75dfdSjtc ** If your port requires different include files, add a suitable      *
1582b75dfdSjtc ** #define in the customization section, and make the inclusion or    *
1682b75dfdSjtc ** exclusion of the files conditional on this.                        *
1782b75dfdSjtc **=====================================================================
1882b75dfdSjtc */
1982b75dfdSjtc 
2082b75dfdSjtc #include <sys/file.h>
2182b75dfdSjtc #include <sys/ioctl.h>
22736ba086Slukem #include <sys/stat.h>
23736ba086Slukem 
24736ba086Slukem #include <grp.h>
2582b75dfdSjtc #include <netdb.h>
26736ba086Slukem #include <pwd.h>
27736ba086Slukem #include <signal.h>
28736ba086Slukem #include <stdio.h>
29736ba086Slukem #include <stdlib.h>
3082b75dfdSjtc #include <string.h>
31736ba086Slukem #include <unistd.h>
3282b75dfdSjtc 
3382b75dfdSjtc #ifdef USE_YP
3482b75dfdSjtc #include <rpcsvc/ypclnt.h>
3582b75dfdSjtc #endif
3682b75dfdSjtc 
3782b75dfdSjtc #ifndef SYSV
3882b75dfdSjtc #include <sys/wait.h>
3982b75dfdSjtc #endif
4082b75dfdSjtc 
4182b75dfdSjtc #ifdef ISC_2_0
4282b75dfdSjtc #include <sys/fcntl.h>
4382b75dfdSjtc #endif
4482b75dfdSjtc 
4582b75dfdSjtc #ifdef SHADOW_SUPPORT
4682b75dfdSjtc #include <shadow.h>
4782b75dfdSjtc #endif
4882b75dfdSjtc 
49736ba086Slukem #include "common.h"
50736ba086Slukem #include "pcnfsd.h"
51736ba086Slukem #include "extern.h"
5282b75dfdSjtc 
5382b75dfdSjtc /*
5482b75dfdSjtc **=====================================================================
558d3f7ee6Sgwr **                      C O D E   S E C T I O N                       *
568d3f7ee6Sgwr **=====================================================================
5782b75dfdSjtc */
5882b75dfdSjtc 
5982b75dfdSjtc 
6082b75dfdSjtc static char no_comment[] = "No comment";
6182b75dfdSjtc static char not_supported[] = "Not supported";
6282b75dfdSjtc static char pcnfsd_version[] = "@(#)pcnfsd_v2.c	1.2 - rpc.pcnfsd V2.0 (c) 1991 Sun Technology Enterprises, Inc.";
6382b75dfdSjtc 
6482b75dfdSjtc /*ARGSUSED*/
65736ba086Slukem void   *
pcnfsd2_null_2_svc(void * arg,struct svc_req * req)66*d6aaec91Ssevan pcnfsd2_null_2_svc(void *arg, struct svc_req *req)
6782b75dfdSjtc {
6882b75dfdSjtc 	static char dummy;
6982b75dfdSjtc 	return ((void *) &dummy);
7082b75dfdSjtc }
7182b75dfdSjtc 
72736ba086Slukem v2_auth_results *
pcnfsd2_auth_2_svc(v2_auth_args * arg,struct svc_req * req)73*d6aaec91Ssevan pcnfsd2_auth_2_svc(v2_auth_args *arg, struct svc_req *req)
7482b75dfdSjtc {
7582b75dfdSjtc 	static v2_auth_results r;
7682b75dfdSjtc 
7782b75dfdSjtc 	char    uname[32];
7882b75dfdSjtc 	char    pw[64];
7982b75dfdSjtc 	int     c1, c2;
8082b75dfdSjtc 	struct passwd *p;
8182b75dfdSjtc 	static u_int extra_gids[EXTRAGIDLEN];
8282b75dfdSjtc 	static char home[256];
8382b75dfdSjtc #ifdef USE_YP
8482b75dfdSjtc 	char   *yphome;
8582b75dfdSjtc 	char   *cp;
8682b75dfdSjtc #endif				/* USE_YP */
8782b75dfdSjtc 
8882b75dfdSjtc 
8982b75dfdSjtc 	r.stat = AUTH_RES_FAIL;	/* assume failure */
9082b75dfdSjtc 	r.uid = (int) -2;
9182b75dfdSjtc 	r.gid = (int) -2;
9282b75dfdSjtc 	r.cm = &no_comment[0];
9382b75dfdSjtc 	r.gids.gids_len = 0;
9482b75dfdSjtc 	r.gids.gids_val = &extra_gids[0];
9582b75dfdSjtc 	home[0] = '\0';
9682b75dfdSjtc 	r.home = &home[0];
9782b75dfdSjtc 	r.def_umask = umask(0);
9882b75dfdSjtc 	(void) umask(r.def_umask);	/* or use 022 */
9982b75dfdSjtc 
10082b75dfdSjtc 	scramble(arg->id, uname);
10182b75dfdSjtc 	scramble(arg->pw, pw);
10282b75dfdSjtc 
10382b75dfdSjtc #ifdef USER_CACHE
10482b75dfdSjtc 	if (check_cache(uname, pw, &r.uid, &r.gid)) {
10582b75dfdSjtc 		r.stat = AUTH_RES_OK;
10682b75dfdSjtc #ifdef WTMP
10782b75dfdSjtc 		wlogin(uname, req);
10882b75dfdSjtc #endif
10982b75dfdSjtc 		fillin_extra_groups
11082b75dfdSjtc 		    (uname, r.gid, &r.gids.gids_len, extra_gids);
11182b75dfdSjtc #ifdef USE_YP
11282b75dfdSjtc 		yphome = find_entry(uname, "auto.home");
11382b75dfdSjtc 		if (yphome) {
1145d573dd9Sitojun 			strlcpy(home, yphome, sizeof(home));
11582b75dfdSjtc 			free(yphome);
11682b75dfdSjtc 			cp = strchr(home, ':');
11782b75dfdSjtc 			cp++;
11882b75dfdSjtc 			cp = strchr(cp, ':');
11982b75dfdSjtc 			if (cp)
12082b75dfdSjtc 				*cp = '/';
12182b75dfdSjtc 		}
12282b75dfdSjtc #endif
12382b75dfdSjtc 		return (&r);
12482b75dfdSjtc 	}
12582b75dfdSjtc #endif
12682b75dfdSjtc 
12782b75dfdSjtc 	p = get_password(uname);
1284a1b3429Splunky 	if (p == NULL)
12982b75dfdSjtc 		return (&r);
13082b75dfdSjtc 
13182b75dfdSjtc 	c1 = strlen(pw);
13282b75dfdSjtc 	c2 = strlen(p->pw_passwd);
13382b75dfdSjtc 	if ((c1 && !c2) || (c2 && !c1) ||
134736ba086Slukem 	    (strcmp(p->pw_passwd, crypt(pw, p->pw_passwd)))) {
13582b75dfdSjtc 		return (&r);
13682b75dfdSjtc 	}
13782b75dfdSjtc 	r.stat = AUTH_RES_OK;
13882b75dfdSjtc 	r.uid = p->pw_uid;
13982b75dfdSjtc 	r.gid = p->pw_gid;
14082b75dfdSjtc #ifdef WTMP
14182b75dfdSjtc 	wlogin(uname, req);
14282b75dfdSjtc #endif
14382b75dfdSjtc 	fillin_extra_groups(uname, r.gid, &r.gids.gids_len, extra_gids);
14482b75dfdSjtc 
14582b75dfdSjtc #ifdef USE_YP
14682b75dfdSjtc 	yphome = find_entry(uname, "auto.home");
14782b75dfdSjtc 	if (yphome) {
1485d573dd9Sitojun 		strlcpy(home, yphome, sizeof(home));
14982b75dfdSjtc 		free(yphome);
15082b75dfdSjtc 		cp = strchr(home, ':');
15182b75dfdSjtc 		cp++;
15282b75dfdSjtc 		cp = strchr(cp, ':');
15382b75dfdSjtc 		if (cp)
15482b75dfdSjtc 			*cp = '/';
15582b75dfdSjtc 	}
15682b75dfdSjtc #endif
15782b75dfdSjtc 
15882b75dfdSjtc #ifdef USER_CACHE
15982b75dfdSjtc 	add_cache_entry(p);
16082b75dfdSjtc #endif
16182b75dfdSjtc 
16282b75dfdSjtc 	return (&r);
16382b75dfdSjtc 
16482b75dfdSjtc }
16582b75dfdSjtc 
166736ba086Slukem v2_pr_init_results *
pcnfsd2_pr_init_2_svc(v2_pr_init_args * arg,struct svc_req * req)167*d6aaec91Ssevan pcnfsd2_pr_init_2_svc(v2_pr_init_args *arg, struct svc_req *req)
16882b75dfdSjtc {
16982b75dfdSjtc 	static v2_pr_init_results res;
17082b75dfdSjtc 
17182b75dfdSjtc 	res.stat =
17282b75dfdSjtc 	    (pirstat) pr_init(arg->system, arg->pn, &res.dir);
17382b75dfdSjtc 	res.cm = &no_comment[0];
17482b75dfdSjtc 
17582b75dfdSjtc 
17682b75dfdSjtc 	return (&res);
17782b75dfdSjtc }
17882b75dfdSjtc 
179736ba086Slukem v2_pr_start_results *
pcnfsd2_pr_start_2_svc(v2_pr_start_args * arg,struct svc_req * req)180*d6aaec91Ssevan pcnfsd2_pr_start_2_svc(v2_pr_start_args *arg, struct svc_req *req)
18182b75dfdSjtc {
18282b75dfdSjtc 	static v2_pr_start_results res;
18382b75dfdSjtc 
18482b75dfdSjtc 	res.stat =
18582b75dfdSjtc 	    (psrstat) pr_start2(arg->system, arg->pn, arg->user,
18682b75dfdSjtc 	    arg->file, arg->opts, &res.id);
18782b75dfdSjtc 	res.cm = &no_comment[0];
18882b75dfdSjtc 
18982b75dfdSjtc 	return (&res);
19082b75dfdSjtc }
19182b75dfdSjtc /*ARGSUSED*/
192736ba086Slukem v2_pr_list_results *
pcnfsd2_pr_list_2_svc(void * arg,struct svc_req * req)193*d6aaec91Ssevan pcnfsd2_pr_list_2_svc(void *arg, struct svc_req *req)
19482b75dfdSjtc {
19582b75dfdSjtc 	static v2_pr_list_results res;
19682b75dfdSjtc 
19782b75dfdSjtc 	if (printers == NULL)
19882b75dfdSjtc 		(void) build_pr_list();
19982b75dfdSjtc 	res.cm = &no_comment[0];
20082b75dfdSjtc 	res.printers = printers;
20182b75dfdSjtc 
20282b75dfdSjtc 	return (&res);
20382b75dfdSjtc }
20482b75dfdSjtc 
205736ba086Slukem v2_pr_queue_results *
pcnfsd2_pr_queue_2_svc(v2_pr_queue_args * arg,struct svc_req * req)206*d6aaec91Ssevan pcnfsd2_pr_queue_2_svc(v2_pr_queue_args *arg, struct svc_req *req)
20782b75dfdSjtc {
20882b75dfdSjtc 	static v2_pr_queue_results res;
20982b75dfdSjtc 
21082b75dfdSjtc 	res.stat = build_pr_queue(arg->pn, arg->user,
21182b75dfdSjtc 	    arg->just_mine, &res.qlen, &res.qshown);
21282b75dfdSjtc 	res.cm = &no_comment[0];
21382b75dfdSjtc 	res.just_yours = arg->just_mine;
21482b75dfdSjtc 	res.jobs = queue;
21582b75dfdSjtc 
21682b75dfdSjtc 
21782b75dfdSjtc 	return (&res);
21882b75dfdSjtc }
21982b75dfdSjtc 
220736ba086Slukem v2_pr_status_results *
pcnfsd2_pr_status_2_svc(v2_pr_status_args * arg,struct svc_req * req)221*d6aaec91Ssevan pcnfsd2_pr_status_2_svc(v2_pr_status_args *arg, struct svc_req *req)
22282b75dfdSjtc {
22382b75dfdSjtc 	static v2_pr_status_results res;
22482b75dfdSjtc 	static char status[128];
22582b75dfdSjtc 
22682b75dfdSjtc 	res.stat = get_pr_status(arg->pn, &res.avail, &res.printing,
227e6e73c33Sapb 	    &res.qlen, &res.needs_operator, &status[0], sizeof(status));
22882b75dfdSjtc 	res.status = &status[0];
22982b75dfdSjtc 	res.cm = &no_comment[0];
23082b75dfdSjtc 
23182b75dfdSjtc 	return (&res);
23282b75dfdSjtc }
23382b75dfdSjtc 
234736ba086Slukem v2_pr_cancel_results *
pcnfsd2_pr_cancel_2_svc(v2_pr_cancel_args * arg,struct svc_req * req)235*d6aaec91Ssevan pcnfsd2_pr_cancel_2_svc(v2_pr_cancel_args *arg, struct svc_req *req)
23682b75dfdSjtc {
23782b75dfdSjtc 	static v2_pr_cancel_results res;
23882b75dfdSjtc 
23982b75dfdSjtc 	res.stat = pr_cancel(arg->pn, arg->user, arg->id);
24082b75dfdSjtc 	res.cm = &no_comment[0];
24182b75dfdSjtc 
24282b75dfdSjtc 	return (&res);
24382b75dfdSjtc }
24482b75dfdSjtc /*ARGSUSED*/
245736ba086Slukem v2_pr_requeue_results *
pcnfsd2_pr_requeue_2_svc(v2_pr_requeue_args * arg,struct svc_req * req)246*d6aaec91Ssevan pcnfsd2_pr_requeue_2_svc(v2_pr_requeue_args *arg, struct svc_req *req)
24782b75dfdSjtc {
24882b75dfdSjtc 	static v2_pr_requeue_results res;
24982b75dfdSjtc 	res.stat = PC_RES_FAIL;
25082b75dfdSjtc 	res.cm = &not_supported[0];
25182b75dfdSjtc 
25282b75dfdSjtc 	return (&res);
25382b75dfdSjtc }
25482b75dfdSjtc /*ARGSUSED*/
255736ba086Slukem v2_pr_hold_results *
pcnfsd2_pr_hold_2_svc(v2_pr_hold_args * arg,struct svc_req * req)256*d6aaec91Ssevan pcnfsd2_pr_hold_2_svc(v2_pr_hold_args *arg, struct svc_req *req)
25782b75dfdSjtc {
25882b75dfdSjtc 	static v2_pr_hold_results res;
25982b75dfdSjtc 
26082b75dfdSjtc 	res.stat = PC_RES_FAIL;
26182b75dfdSjtc 	res.cm = &not_supported[0];
26282b75dfdSjtc 
26382b75dfdSjtc 	return (&res);
26482b75dfdSjtc }
26582b75dfdSjtc /*ARGSUSED*/
266736ba086Slukem v2_pr_release_results *
pcnfsd2_pr_release_2_svc(v2_pr_release_args * arg,struct svc_req * req)267*d6aaec91Ssevan pcnfsd2_pr_release_2_svc(v2_pr_release_args *arg, struct svc_req *req)
26882b75dfdSjtc {
26982b75dfdSjtc 	static v2_pr_release_results res;
27082b75dfdSjtc 
27182b75dfdSjtc 	res.stat = PC_RES_FAIL;
27282b75dfdSjtc 	res.cm = &not_supported[0];
27382b75dfdSjtc 
27482b75dfdSjtc 	return (&res);
27582b75dfdSjtc }
27682b75dfdSjtc /*ARGSUSED*/
277736ba086Slukem v2_pr_admin_results *
pcnfsd2_pr_admin_2_svc(v2_pr_admin_args * arg,struct svc_req * req)278*d6aaec91Ssevan pcnfsd2_pr_admin_2_svc(v2_pr_admin_args *arg, struct svc_req *req)
27982b75dfdSjtc {
28082b75dfdSjtc 	static v2_pr_admin_results res;
28182b75dfdSjtc /*
28282b75dfdSjtc ** The default action for admin is to fail.
28382b75dfdSjtc ** If someone wishes to implement an administration
28482b75dfdSjtc ** mechanism, and isn't worried about the security
28582b75dfdSjtc ** holes, go right ahead.
28682b75dfdSjtc */
28782b75dfdSjtc 
28882b75dfdSjtc 	res.cm = &not_supported[0];
28982b75dfdSjtc 	res.stat = PI_RES_FAIL;
29082b75dfdSjtc 
29182b75dfdSjtc 	return (&res);
29282b75dfdSjtc }
29382b75dfdSjtc 
29482b75dfdSjtc void
free_mapreq_results(mapreq_res p)295*d6aaec91Ssevan free_mapreq_results(mapreq_res p)
29682b75dfdSjtc {
29782b75dfdSjtc 	if (p->mapreq_next)
29882b75dfdSjtc 		free_mapreq_results(p->mapreq_next);	/* recurse */
29982b75dfdSjtc 	if (p->name)
30082b75dfdSjtc 		(void) free(p->name);
30182b75dfdSjtc 	(void) free(p);
30282b75dfdSjtc 	return;
30382b75dfdSjtc }
30482b75dfdSjtc 
305*d6aaec91Ssevan static char *my_strdup(const char *);
306736ba086Slukem 
30782b75dfdSjtc static char *
my_strdup(const char * s)308*d6aaec91Ssevan my_strdup(const char *s)
30982b75dfdSjtc {
310ea9931eeSjoerg 	size_t len;
31182b75dfdSjtc 	char   *r;
312ea9931eeSjoerg 	len = strlen(s);
313ea9931eeSjoerg 	r = (char *) grab(len + 1);
314ea9931eeSjoerg 	memcpy(r, s, len + 1);
31582b75dfdSjtc 	return (r);
31682b75dfdSjtc }
31782b75dfdSjtc 
318736ba086Slukem v2_mapid_results *
pcnfsd2_mapid_2_svc(v2_mapid_args * arg,struct svc_req * req)319*d6aaec91Ssevan pcnfsd2_mapid_2_svc(v2_mapid_args *arg, struct svc_req *req)
32082b75dfdSjtc {
32182b75dfdSjtc 	static v2_mapid_results res;
32282b75dfdSjtc 	struct passwd *p_passwd;
32382b75dfdSjtc 	struct group *p_group;
32482b75dfdSjtc 
32582b75dfdSjtc 	mapreq_arg a;
32682b75dfdSjtc 	mapreq_res next_r;
32782b75dfdSjtc 	mapreq_res last_r = NULL;
32882b75dfdSjtc 
32982b75dfdSjtc 
33082b75dfdSjtc 	if (res.res_list) {
33182b75dfdSjtc 		free_mapreq_results(res.res_list);
33282b75dfdSjtc 		res.res_list = NULL;
33382b75dfdSjtc 	}
33482b75dfdSjtc 	a = arg->req_list;
33582b75dfdSjtc 	while (a) {
33682b75dfdSjtc 		next_r = (struct mapreq_res_item *)
33782b75dfdSjtc 		    grab(sizeof(struct mapreq_res_item));
33882b75dfdSjtc 		next_r->stat = MAP_RES_UNKNOWN;
33982b75dfdSjtc 		next_r->req = a->req;
34082b75dfdSjtc 		next_r->id = a->id;
34182b75dfdSjtc 		next_r->name = NULL;
34282b75dfdSjtc 		next_r->mapreq_next = NULL;
34382b75dfdSjtc 
34482b75dfdSjtc 		if (last_r == NULL)
34582b75dfdSjtc 			res.res_list = next_r;
34682b75dfdSjtc 		else
34782b75dfdSjtc 			last_r->mapreq_next = next_r;
34882b75dfdSjtc 		last_r = next_r;
34982b75dfdSjtc 		switch (a->req) {
35082b75dfdSjtc 		case MAP_REQ_UID:
35182b75dfdSjtc 			p_passwd = getpwuid((uid_t) a->id);
35282b75dfdSjtc 			if (p_passwd) {
35382b75dfdSjtc 				next_r->name = my_strdup(p_passwd->pw_name);
35482b75dfdSjtc 				next_r->stat = MAP_RES_OK;
35582b75dfdSjtc 			}
35682b75dfdSjtc 			break;
35782b75dfdSjtc 		case MAP_REQ_GID:
35882b75dfdSjtc 			p_group = getgrgid((gid_t) a->id);
35982b75dfdSjtc 			if (p_group) {
36082b75dfdSjtc 				next_r->name = my_strdup(p_group->gr_name);
36182b75dfdSjtc 				next_r->stat = MAP_RES_OK;
36282b75dfdSjtc 			}
36382b75dfdSjtc 			break;
36482b75dfdSjtc 		case MAP_REQ_UNAME:
36582b75dfdSjtc 			next_r->name = my_strdup(a->name);
36682b75dfdSjtc 			p_passwd = getpwnam(a->name);
36782b75dfdSjtc 			if (p_passwd) {
36882b75dfdSjtc 				next_r->id = p_passwd->pw_uid;
36982b75dfdSjtc 				next_r->stat = MAP_RES_OK;
37082b75dfdSjtc 			}
37182b75dfdSjtc 			break;
37282b75dfdSjtc 		case MAP_REQ_GNAME:
37382b75dfdSjtc 			next_r->name = my_strdup(a->name);
37482b75dfdSjtc 			p_group = getgrnam(a->name);
37582b75dfdSjtc 			if (p_group) {
37682b75dfdSjtc 				next_r->id = p_group->gr_gid;
37782b75dfdSjtc 				next_r->stat = MAP_RES_OK;
37882b75dfdSjtc 			}
37982b75dfdSjtc 			break;
38082b75dfdSjtc 		}
38182b75dfdSjtc 		if (next_r->name == NULL)
38282b75dfdSjtc 			next_r->name = my_strdup("");
38382b75dfdSjtc 		a = a->mapreq_next;
38482b75dfdSjtc 	}
38582b75dfdSjtc 
38682b75dfdSjtc 	res.cm = &no_comment[0];
38782b75dfdSjtc 
38882b75dfdSjtc 	return (&res);
38982b75dfdSjtc }
39082b75dfdSjtc 
39182b75dfdSjtc 
39282b75dfdSjtc /*ARGSUSED*/
393736ba086Slukem v2_alert_results *
pcnfsd2_alert_2_svc(v2_alert_args * arg,struct svc_req * req)394*d6aaec91Ssevan pcnfsd2_alert_2_svc(v2_alert_args *arg, struct svc_req *req)
39582b75dfdSjtc {
39682b75dfdSjtc 	static v2_alert_results res;
39782b75dfdSjtc 
39882b75dfdSjtc 	res.stat = ALERT_RES_FAIL;
39982b75dfdSjtc 	res.cm = &not_supported[0];
40082b75dfdSjtc 
40182b75dfdSjtc 	return (&res);
40282b75dfdSjtc }
40382b75dfdSjtc /*ARGSUSED*/
404736ba086Slukem v2_info_results *
pcnfsd2_info_2_svc(v2_info_args * arg,struct svc_req * req)405*d6aaec91Ssevan pcnfsd2_info_2_svc(v2_info_args *arg, struct svc_req *req)
40682b75dfdSjtc {
40782b75dfdSjtc 	static v2_info_results res;
40882b75dfdSjtc 	static int facilities[FACILITIESMAX];
40982b75dfdSjtc 	static int onetime = 1;
41082b75dfdSjtc 
41182b75dfdSjtc #define UNSUPPORTED -1
41282b75dfdSjtc #define QUICK 100
41382b75dfdSjtc #define SLOW 2000
41482b75dfdSjtc 
41582b75dfdSjtc 	if (onetime) {
41682b75dfdSjtc 		onetime = 0;
41782b75dfdSjtc 		facilities[PCNFSD2_NULL] = QUICK;
41882b75dfdSjtc 		facilities[PCNFSD2_INFO] = QUICK;
41982b75dfdSjtc 		facilities[PCNFSD2_PR_INIT] = QUICK;
42082b75dfdSjtc 		facilities[PCNFSD2_PR_START] = SLOW;
42182b75dfdSjtc 		facilities[PCNFSD2_PR_LIST] = QUICK;	/* except first time */
42282b75dfdSjtc 		facilities[PCNFSD2_PR_QUEUE] = SLOW;
42382b75dfdSjtc 		facilities[PCNFSD2_PR_STATUS] = SLOW;
42482b75dfdSjtc 		facilities[PCNFSD2_PR_CANCEL] = SLOW;
42582b75dfdSjtc 		facilities[PCNFSD2_PR_ADMIN] = UNSUPPORTED;
42682b75dfdSjtc 		facilities[PCNFSD2_PR_REQUEUE] = UNSUPPORTED;
42782b75dfdSjtc 		facilities[PCNFSD2_PR_HOLD] = UNSUPPORTED;
42882b75dfdSjtc 		facilities[PCNFSD2_PR_RELEASE] = UNSUPPORTED;
42982b75dfdSjtc 		facilities[PCNFSD2_MAPID] = QUICK;
43082b75dfdSjtc 		facilities[PCNFSD2_AUTH] = QUICK;
43182b75dfdSjtc 		facilities[PCNFSD2_ALERT] = QUICK;
43282b75dfdSjtc 	}
43382b75dfdSjtc 	res.facilities.facilities_len = PCNFSD2_ALERT + 1;
43482b75dfdSjtc 	res.facilities.facilities_val = facilities;
43582b75dfdSjtc 
43682b75dfdSjtc 	res.vers = &pcnfsd_version[0];
43782b75dfdSjtc 	res.cm = &no_comment[0];
43882b75dfdSjtc 
43982b75dfdSjtc 	return (&res);
44082b75dfdSjtc }
44182b75dfdSjtc 
44282b75dfdSjtc 
44382b75dfdSjtc 
44482b75dfdSjtc void
fillin_extra_groups(char * uname,gid_t main_gid,int * len,gid_t extra_gids[EXTRAGIDLEN])445*d6aaec91Ssevan fillin_extra_groups(char *uname, gid_t main_gid, int *len, gid_t extra_gids[EXTRAGIDLEN])
44682b75dfdSjtc {
44782b75dfdSjtc 	struct group *grp;
4482e9ada3aSmycroft 	__aconst char *__aconst *members;
44982b75dfdSjtc 	int     n = 0;
45082b75dfdSjtc 
45182b75dfdSjtc 	setgrent();
45282b75dfdSjtc 
45382b75dfdSjtc 	while (n < EXTRAGIDLEN) {
45482b75dfdSjtc 		grp = getgrent();
45582b75dfdSjtc 		if (grp == NULL)
45682b75dfdSjtc 			break;
45782b75dfdSjtc 		if (grp->gr_gid == main_gid)
45882b75dfdSjtc 			continue;
45982b75dfdSjtc 		for (members = grp->gr_mem; members && *members; members++) {
46082b75dfdSjtc 			if (!strcmp(*members, uname)) {
46182b75dfdSjtc 				extra_gids[n++] = grp->gr_gid;
46282b75dfdSjtc 				break;
46382b75dfdSjtc 			}
46482b75dfdSjtc 		}
46582b75dfdSjtc 	}
46682b75dfdSjtc 	endgrent();
46782b75dfdSjtc 	*len = n;
46882b75dfdSjtc }
46982b75dfdSjtc 
47082b75dfdSjtc #ifdef USE_YP
47182b75dfdSjtc /* the following is from rpcsvc/yp_prot.h */
47282b75dfdSjtc #define YPMAXDOMAIN 64
473736ba086Slukem 
47482b75dfdSjtc /*
47582b75dfdSjtc  * find_entry returns NULL on any error (printing a message) and
47682b75dfdSjtc  * otherwise returns a pointer to the malloc'd result. The caller
47782b75dfdSjtc  * is responsible for free()ing the result string.
47882b75dfdSjtc  */
47982b75dfdSjtc char   *
find_entry(const char * key,const char * map)480*d6aaec91Ssevan find_entry(const char *key, const char *map)
48182b75dfdSjtc {
48282b75dfdSjtc 	int     err;
48382b75dfdSjtc 	char   *val = NULL;
48482b75dfdSjtc 	char   *cp;
48582b75dfdSjtc 	int     len = 0;
48682b75dfdSjtc 	static char domain[YPMAXDOMAIN + 1];
48782b75dfdSjtc 
48882b75dfdSjtc 	if (getdomainname(domain, YPMAXDOMAIN)) {
48982b75dfdSjtc 		msg_out("rpc.pcnfsd: getdomainname failed");
49082b75dfdSjtc 		return (NULL);
49182b75dfdSjtc 	}
492736ba086Slukem 	if ((err = yp_bind(domain)) != 0) {
493e69420e4Sgwr #ifdef	DEBUG
49482b75dfdSjtc 		msg_out("rpc.pcnfsd: yp_bind failed");
495e69420e4Sgwr #endif
49682b75dfdSjtc 		return (NULL);
49782b75dfdSjtc 	}
49882b75dfdSjtc 	err = yp_match(domain, map, key, strlen(key), &val, &len);
49982b75dfdSjtc 
50082b75dfdSjtc 	if (err) {
50182b75dfdSjtc 		msg_out("rpc.pcnfsd: yp_match failed");
502b6572fdcSlukem 		if (val)
503b6572fdcSlukem 			free(val);
50482b75dfdSjtc 		return (NULL);
50582b75dfdSjtc 	}
506736ba086Slukem 	if ((cp = strchr(val, '\n')) != NULL)
50782b75dfdSjtc 		*cp = '\0';	/* in case we get an extra NL at the end */
50882b75dfdSjtc 	return (val);
50982b75dfdSjtc }
51082b75dfdSjtc #endif
511