xref: /netbsd/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c (revision 5d573dd9)
1*5d573dd9Sitojun /*	$NetBSD: pcnfsd_v2.c,v 1.9 2003/07/16 08:22:01 itojun 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   *
66736ba086Slukem pcnfsd2_null_2_svc(arg, req)
6782b75dfdSjtc 	void   *arg;
6882b75dfdSjtc 	struct svc_req *req;
6982b75dfdSjtc {
7082b75dfdSjtc 	static char dummy;
7182b75dfdSjtc 	return ((void *) &dummy);
7282b75dfdSjtc }
7382b75dfdSjtc 
74736ba086Slukem v2_auth_results *
75736ba086Slukem pcnfsd2_auth_2_svc(arg, req)
7682b75dfdSjtc 	v2_auth_args *arg;
7782b75dfdSjtc 	struct svc_req *req;
7882b75dfdSjtc {
7982b75dfdSjtc 	static v2_auth_results r;
8082b75dfdSjtc 
8182b75dfdSjtc 	char    uname[32];
8282b75dfdSjtc 	char    pw[64];
8382b75dfdSjtc 	int     c1, c2;
8482b75dfdSjtc 	struct passwd *p;
8582b75dfdSjtc 	static u_int extra_gids[EXTRAGIDLEN];
8682b75dfdSjtc 	static char home[256];
8782b75dfdSjtc #ifdef USE_YP
8882b75dfdSjtc 	char   *yphome;
8982b75dfdSjtc 	char   *cp;
9082b75dfdSjtc #endif				/* USE_YP */
9182b75dfdSjtc 
9282b75dfdSjtc 
9382b75dfdSjtc 	r.stat = AUTH_RES_FAIL;	/* assume failure */
9482b75dfdSjtc 	r.uid = (int) -2;
9582b75dfdSjtc 	r.gid = (int) -2;
9682b75dfdSjtc 	r.cm = &no_comment[0];
9782b75dfdSjtc 	r.gids.gids_len = 0;
9882b75dfdSjtc 	r.gids.gids_val = &extra_gids[0];
9982b75dfdSjtc 	home[0] = '\0';
10082b75dfdSjtc 	r.home = &home[0];
10182b75dfdSjtc 	r.def_umask = umask(0);
10282b75dfdSjtc 	(void) umask(r.def_umask);	/* or use 022 */
10382b75dfdSjtc 
10482b75dfdSjtc 	scramble(arg->id, uname);
10582b75dfdSjtc 	scramble(arg->pw, pw);
10682b75dfdSjtc 
10782b75dfdSjtc #ifdef USER_CACHE
10882b75dfdSjtc 	if (check_cache(uname, pw, &r.uid, &r.gid)) {
10982b75dfdSjtc 		r.stat = AUTH_RES_OK;
11082b75dfdSjtc #ifdef WTMP
11182b75dfdSjtc 		wlogin(uname, req);
11282b75dfdSjtc #endif
11382b75dfdSjtc 		fillin_extra_groups
11482b75dfdSjtc 		    (uname, r.gid, &r.gids.gids_len, extra_gids);
11582b75dfdSjtc #ifdef USE_YP
11682b75dfdSjtc 		yphome = find_entry(uname, "auto.home");
11782b75dfdSjtc 		if (yphome) {
118*5d573dd9Sitojun 			strlcpy(home, yphome, sizeof(home));
11982b75dfdSjtc 			free(yphome);
12082b75dfdSjtc 			cp = strchr(home, ':');
12182b75dfdSjtc 			cp++;
12282b75dfdSjtc 			cp = strchr(cp, ':');
12382b75dfdSjtc 			if (cp)
12482b75dfdSjtc 				*cp = '/';
12582b75dfdSjtc 		}
12682b75dfdSjtc #endif
12782b75dfdSjtc 		return (&r);
12882b75dfdSjtc 	}
12982b75dfdSjtc #endif
13082b75dfdSjtc 
13182b75dfdSjtc 	p = get_password(uname);
13282b75dfdSjtc 	if (p == (struct passwd *) NULL)
13382b75dfdSjtc 		return (&r);
13482b75dfdSjtc 
13582b75dfdSjtc 	c1 = strlen(pw);
13682b75dfdSjtc 	c2 = strlen(p->pw_passwd);
13782b75dfdSjtc 	if ((c1 && !c2) || (c2 && !c1) ||
138736ba086Slukem 	    (strcmp(p->pw_passwd, crypt(pw, p->pw_passwd)))) {
13982b75dfdSjtc 		return (&r);
14082b75dfdSjtc 	}
14182b75dfdSjtc 	r.stat = AUTH_RES_OK;
14282b75dfdSjtc 	r.uid = p->pw_uid;
14382b75dfdSjtc 	r.gid = p->pw_gid;
14482b75dfdSjtc #ifdef WTMP
14582b75dfdSjtc 	wlogin(uname, req);
14682b75dfdSjtc #endif
14782b75dfdSjtc 	fillin_extra_groups(uname, r.gid, &r.gids.gids_len, extra_gids);
14882b75dfdSjtc 
14982b75dfdSjtc #ifdef USE_YP
15082b75dfdSjtc 	yphome = find_entry(uname, "auto.home");
15182b75dfdSjtc 	if (yphome) {
152*5d573dd9Sitojun 		strlcpy(home, yphome, sizeof(home));
15382b75dfdSjtc 		free(yphome);
15482b75dfdSjtc 		cp = strchr(home, ':');
15582b75dfdSjtc 		cp++;
15682b75dfdSjtc 		cp = strchr(cp, ':');
15782b75dfdSjtc 		if (cp)
15882b75dfdSjtc 			*cp = '/';
15982b75dfdSjtc 	}
16082b75dfdSjtc #endif
16182b75dfdSjtc 
16282b75dfdSjtc #ifdef USER_CACHE
16382b75dfdSjtc 	add_cache_entry(p);
16482b75dfdSjtc #endif
16582b75dfdSjtc 
16682b75dfdSjtc 	return (&r);
16782b75dfdSjtc 
16882b75dfdSjtc }
16982b75dfdSjtc 
170736ba086Slukem v2_pr_init_results *
171736ba086Slukem pcnfsd2_pr_init_2_svc(arg, req)
17282b75dfdSjtc 	v2_pr_init_args *arg;
17382b75dfdSjtc 	struct svc_req *req;
17482b75dfdSjtc {
17582b75dfdSjtc 	static v2_pr_init_results res;
17682b75dfdSjtc 
17782b75dfdSjtc 	res.stat =
17882b75dfdSjtc 	    (pirstat) pr_init(arg->system, arg->pn, &res.dir);
17982b75dfdSjtc 	res.cm = &no_comment[0];
18082b75dfdSjtc 
18182b75dfdSjtc 
18282b75dfdSjtc 	return (&res);
18382b75dfdSjtc }
18482b75dfdSjtc 
185736ba086Slukem v2_pr_start_results *
186736ba086Slukem pcnfsd2_pr_start_2_svc(arg, req)
18782b75dfdSjtc 	v2_pr_start_args *arg;
18882b75dfdSjtc 	struct svc_req *req;
18982b75dfdSjtc {
19082b75dfdSjtc 	static v2_pr_start_results res;
19182b75dfdSjtc 
19282b75dfdSjtc 	res.stat =
19382b75dfdSjtc 	    (psrstat) pr_start2(arg->system, arg->pn, arg->user,
19482b75dfdSjtc 	    arg->file, arg->opts, &res.id);
19582b75dfdSjtc 	res.cm = &no_comment[0];
19682b75dfdSjtc 
19782b75dfdSjtc 	return (&res);
19882b75dfdSjtc }
19982b75dfdSjtc /*ARGSUSED*/
200736ba086Slukem v2_pr_list_results *
201736ba086Slukem pcnfsd2_pr_list_2_svc(arg, req)
20282b75dfdSjtc 	void   *arg;
20382b75dfdSjtc 	struct svc_req *req;
20482b75dfdSjtc {
20582b75dfdSjtc 	static v2_pr_list_results res;
20682b75dfdSjtc 
20782b75dfdSjtc 	if (printers == NULL)
20882b75dfdSjtc 		(void) build_pr_list();
20982b75dfdSjtc 	res.cm = &no_comment[0];
21082b75dfdSjtc 	res.printers = printers;
21182b75dfdSjtc 
21282b75dfdSjtc 	return (&res);
21382b75dfdSjtc }
21482b75dfdSjtc 
215736ba086Slukem v2_pr_queue_results *
216736ba086Slukem pcnfsd2_pr_queue_2_svc(arg, req)
21782b75dfdSjtc 	v2_pr_queue_args *arg;
21882b75dfdSjtc 	struct svc_req *req;
21982b75dfdSjtc {
22082b75dfdSjtc 	static v2_pr_queue_results res;
22182b75dfdSjtc 
22282b75dfdSjtc 	res.stat = build_pr_queue(arg->pn, arg->user,
22382b75dfdSjtc 	    arg->just_mine, &res.qlen, &res.qshown);
22482b75dfdSjtc 	res.cm = &no_comment[0];
22582b75dfdSjtc 	res.just_yours = arg->just_mine;
22682b75dfdSjtc 	res.jobs = queue;
22782b75dfdSjtc 
22882b75dfdSjtc 
22982b75dfdSjtc 	return (&res);
23082b75dfdSjtc }
23182b75dfdSjtc 
232736ba086Slukem v2_pr_status_results *
233736ba086Slukem pcnfsd2_pr_status_2_svc(arg, req)
23482b75dfdSjtc 	v2_pr_status_args *arg;
23582b75dfdSjtc 	struct svc_req *req;
23682b75dfdSjtc {
23782b75dfdSjtc 	static v2_pr_status_results res;
23882b75dfdSjtc 	static char status[128];
23982b75dfdSjtc 
24082b75dfdSjtc 	res.stat = get_pr_status(arg->pn, &res.avail, &res.printing,
24182b75dfdSjtc 	    &res.qlen, &res.needs_operator, &status[0]);
24282b75dfdSjtc 	res.status = &status[0];
24382b75dfdSjtc 	res.cm = &no_comment[0];
24482b75dfdSjtc 
24582b75dfdSjtc 	return (&res);
24682b75dfdSjtc }
24782b75dfdSjtc 
248736ba086Slukem v2_pr_cancel_results *
249736ba086Slukem pcnfsd2_pr_cancel_2_svc(arg, req)
25082b75dfdSjtc 	v2_pr_cancel_args *arg;
25182b75dfdSjtc 	struct svc_req *req;
25282b75dfdSjtc {
25382b75dfdSjtc 	static v2_pr_cancel_results res;
25482b75dfdSjtc 
25582b75dfdSjtc 	res.stat = pr_cancel(arg->pn, arg->user, arg->id);
25682b75dfdSjtc 	res.cm = &no_comment[0];
25782b75dfdSjtc 
25882b75dfdSjtc 	return (&res);
25982b75dfdSjtc }
26082b75dfdSjtc /*ARGSUSED*/
261736ba086Slukem v2_pr_requeue_results *
262736ba086Slukem pcnfsd2_pr_requeue_2_svc(arg, req)
26382b75dfdSjtc 	v2_pr_requeue_args *arg;
26482b75dfdSjtc 	struct svc_req *req;
26582b75dfdSjtc {
26682b75dfdSjtc 	static v2_pr_requeue_results res;
26782b75dfdSjtc 	res.stat = PC_RES_FAIL;
26882b75dfdSjtc 	res.cm = &not_supported[0];
26982b75dfdSjtc 
27082b75dfdSjtc 	return (&res);
27182b75dfdSjtc }
27282b75dfdSjtc /*ARGSUSED*/
273736ba086Slukem v2_pr_hold_results *
274736ba086Slukem pcnfsd2_pr_hold_2_svc(arg, req)
27582b75dfdSjtc 	v2_pr_hold_args *arg;
27682b75dfdSjtc 	struct svc_req *req;
27782b75dfdSjtc {
27882b75dfdSjtc 	static v2_pr_hold_results res;
27982b75dfdSjtc 
28082b75dfdSjtc 	res.stat = PC_RES_FAIL;
28182b75dfdSjtc 	res.cm = &not_supported[0];
28282b75dfdSjtc 
28382b75dfdSjtc 	return (&res);
28482b75dfdSjtc }
28582b75dfdSjtc /*ARGSUSED*/
286736ba086Slukem v2_pr_release_results *
287736ba086Slukem pcnfsd2_pr_release_2_svc(arg, req)
28882b75dfdSjtc 	v2_pr_release_args *arg;
28982b75dfdSjtc 	struct svc_req *req;
29082b75dfdSjtc {
29182b75dfdSjtc 	static v2_pr_release_results res;
29282b75dfdSjtc 
29382b75dfdSjtc 	res.stat = PC_RES_FAIL;
29482b75dfdSjtc 	res.cm = &not_supported[0];
29582b75dfdSjtc 
29682b75dfdSjtc 	return (&res);
29782b75dfdSjtc }
29882b75dfdSjtc /*ARGSUSED*/
299736ba086Slukem v2_pr_admin_results *
300736ba086Slukem pcnfsd2_pr_admin_2_svc(arg, req)
30182b75dfdSjtc 	v2_pr_admin_args *arg;
30282b75dfdSjtc 	struct svc_req *req;
30382b75dfdSjtc {
30482b75dfdSjtc 	static v2_pr_admin_results res;
30582b75dfdSjtc /*
30682b75dfdSjtc ** The default action for admin is to fail.
30782b75dfdSjtc ** If someone wishes to implement an administration
30882b75dfdSjtc ** mechanism, and isn't worried about the security
30982b75dfdSjtc ** holes, go right ahead.
31082b75dfdSjtc */
31182b75dfdSjtc 
31282b75dfdSjtc 	res.cm = &not_supported[0];
31382b75dfdSjtc 	res.stat = PI_RES_FAIL;
31482b75dfdSjtc 
31582b75dfdSjtc 	return (&res);
31682b75dfdSjtc }
31782b75dfdSjtc 
31882b75dfdSjtc void
31982b75dfdSjtc free_mapreq_results(p)
32082b75dfdSjtc 	mapreq_res p;
32182b75dfdSjtc {
32282b75dfdSjtc 	if (p->mapreq_next)
32382b75dfdSjtc 		free_mapreq_results(p->mapreq_next);	/* recurse */
32482b75dfdSjtc 	if (p->name)
32582b75dfdSjtc 		(void) free(p->name);
32682b75dfdSjtc 	(void) free(p);
32782b75dfdSjtc 	return;
32882b75dfdSjtc }
32982b75dfdSjtc 
3301f86e583Smycroft static char *my_strdup __P((const char *));
331736ba086Slukem 
33282b75dfdSjtc static char *
33382b75dfdSjtc my_strdup(s)
3341f86e583Smycroft 	const char   *s;
33582b75dfdSjtc {
33682b75dfdSjtc 	char   *r;
33782b75dfdSjtc 	r = (char *) grab(strlen(s) + 1);
338*5d573dd9Sitojun 	strlcpy(r, s, strlen(s) + 1);
33982b75dfdSjtc 	return (r);
34082b75dfdSjtc }
34182b75dfdSjtc 
342736ba086Slukem v2_mapid_results *
343736ba086Slukem pcnfsd2_mapid_2_svc(arg, req)
34482b75dfdSjtc 	v2_mapid_args *arg;
34582b75dfdSjtc 	struct svc_req *req;
34682b75dfdSjtc {
34782b75dfdSjtc 	static v2_mapid_results res;
34882b75dfdSjtc 	struct passwd *p_passwd;
34982b75dfdSjtc 	struct group *p_group;
35082b75dfdSjtc 
35182b75dfdSjtc 	mapreq_arg a;
35282b75dfdSjtc 	mapreq_res next_r;
35382b75dfdSjtc 	mapreq_res last_r = NULL;
35482b75dfdSjtc 
35582b75dfdSjtc 
35682b75dfdSjtc 	if (res.res_list) {
35782b75dfdSjtc 		free_mapreq_results(res.res_list);
35882b75dfdSjtc 		res.res_list = NULL;
35982b75dfdSjtc 	}
36082b75dfdSjtc 	a = arg->req_list;
36182b75dfdSjtc 	while (a) {
36282b75dfdSjtc 		next_r = (struct mapreq_res_item *)
36382b75dfdSjtc 		    grab(sizeof(struct mapreq_res_item));
36482b75dfdSjtc 		next_r->stat = MAP_RES_UNKNOWN;
36582b75dfdSjtc 		next_r->req = a->req;
36682b75dfdSjtc 		next_r->id = a->id;
36782b75dfdSjtc 		next_r->name = NULL;
36882b75dfdSjtc 		next_r->mapreq_next = NULL;
36982b75dfdSjtc 
37082b75dfdSjtc 		if (last_r == NULL)
37182b75dfdSjtc 			res.res_list = next_r;
37282b75dfdSjtc 		else
37382b75dfdSjtc 			last_r->mapreq_next = next_r;
37482b75dfdSjtc 		last_r = next_r;
37582b75dfdSjtc 		switch (a->req) {
37682b75dfdSjtc 		case MAP_REQ_UID:
37782b75dfdSjtc 			p_passwd = getpwuid((uid_t) a->id);
37882b75dfdSjtc 			if (p_passwd) {
37982b75dfdSjtc 				next_r->name = my_strdup(p_passwd->pw_name);
38082b75dfdSjtc 				next_r->stat = MAP_RES_OK;
38182b75dfdSjtc 			}
38282b75dfdSjtc 			break;
38382b75dfdSjtc 		case MAP_REQ_GID:
38482b75dfdSjtc 			p_group = getgrgid((gid_t) a->id);
38582b75dfdSjtc 			if (p_group) {
38682b75dfdSjtc 				next_r->name = my_strdup(p_group->gr_name);
38782b75dfdSjtc 				next_r->stat = MAP_RES_OK;
38882b75dfdSjtc 			}
38982b75dfdSjtc 			break;
39082b75dfdSjtc 		case MAP_REQ_UNAME:
39182b75dfdSjtc 			next_r->name = my_strdup(a->name);
39282b75dfdSjtc 			p_passwd = getpwnam(a->name);
39382b75dfdSjtc 			if (p_passwd) {
39482b75dfdSjtc 				next_r->id = p_passwd->pw_uid;
39582b75dfdSjtc 				next_r->stat = MAP_RES_OK;
39682b75dfdSjtc 			}
39782b75dfdSjtc 			break;
39882b75dfdSjtc 		case MAP_REQ_GNAME:
39982b75dfdSjtc 			next_r->name = my_strdup(a->name);
40082b75dfdSjtc 			p_group = getgrnam(a->name);
40182b75dfdSjtc 			if (p_group) {
40282b75dfdSjtc 				next_r->id = p_group->gr_gid;
40382b75dfdSjtc 				next_r->stat = MAP_RES_OK;
40482b75dfdSjtc 			}
40582b75dfdSjtc 			break;
40682b75dfdSjtc 		}
40782b75dfdSjtc 		if (next_r->name == NULL)
40882b75dfdSjtc 			next_r->name = my_strdup("");
40982b75dfdSjtc 		a = a->mapreq_next;
41082b75dfdSjtc 	}
41182b75dfdSjtc 
41282b75dfdSjtc 	res.cm = &no_comment[0];
41382b75dfdSjtc 
41482b75dfdSjtc 	return (&res);
41582b75dfdSjtc }
41682b75dfdSjtc 
41782b75dfdSjtc 
41882b75dfdSjtc /*ARGSUSED*/
419736ba086Slukem v2_alert_results *
420736ba086Slukem pcnfsd2_alert_2_svc(arg, req)
42182b75dfdSjtc 	v2_alert_args *arg;
42282b75dfdSjtc 	struct svc_req *req;
42382b75dfdSjtc {
42482b75dfdSjtc 	static v2_alert_results res;
42582b75dfdSjtc 
42682b75dfdSjtc 	res.stat = ALERT_RES_FAIL;
42782b75dfdSjtc 	res.cm = &not_supported[0];
42882b75dfdSjtc 
42982b75dfdSjtc 	return (&res);
43082b75dfdSjtc }
43182b75dfdSjtc /*ARGSUSED*/
432736ba086Slukem v2_info_results *
433736ba086Slukem pcnfsd2_info_2_svc(arg, req)
43482b75dfdSjtc 	v2_info_args *arg;
43582b75dfdSjtc 	struct svc_req *req;
43682b75dfdSjtc {
43782b75dfdSjtc 	static v2_info_results res;
43882b75dfdSjtc 	static int facilities[FACILITIESMAX];
43982b75dfdSjtc 	static int onetime = 1;
44082b75dfdSjtc 
44182b75dfdSjtc #define UNSUPPORTED -1
44282b75dfdSjtc #define QUICK 100
44382b75dfdSjtc #define SLOW 2000
44482b75dfdSjtc 
44582b75dfdSjtc 	if (onetime) {
44682b75dfdSjtc 		onetime = 0;
44782b75dfdSjtc 		facilities[PCNFSD2_NULL] = QUICK;
44882b75dfdSjtc 		facilities[PCNFSD2_INFO] = QUICK;
44982b75dfdSjtc 		facilities[PCNFSD2_PR_INIT] = QUICK;
45082b75dfdSjtc 		facilities[PCNFSD2_PR_START] = SLOW;
45182b75dfdSjtc 		facilities[PCNFSD2_PR_LIST] = QUICK;	/* except first time */
45282b75dfdSjtc 		facilities[PCNFSD2_PR_QUEUE] = SLOW;
45382b75dfdSjtc 		facilities[PCNFSD2_PR_STATUS] = SLOW;
45482b75dfdSjtc 		facilities[PCNFSD2_PR_CANCEL] = SLOW;
45582b75dfdSjtc 		facilities[PCNFSD2_PR_ADMIN] = UNSUPPORTED;
45682b75dfdSjtc 		facilities[PCNFSD2_PR_REQUEUE] = UNSUPPORTED;
45782b75dfdSjtc 		facilities[PCNFSD2_PR_HOLD] = UNSUPPORTED;
45882b75dfdSjtc 		facilities[PCNFSD2_PR_RELEASE] = UNSUPPORTED;
45982b75dfdSjtc 		facilities[PCNFSD2_MAPID] = QUICK;
46082b75dfdSjtc 		facilities[PCNFSD2_AUTH] = QUICK;
46182b75dfdSjtc 		facilities[PCNFSD2_ALERT] = QUICK;
46282b75dfdSjtc 	}
46382b75dfdSjtc 	res.facilities.facilities_len = PCNFSD2_ALERT + 1;
46482b75dfdSjtc 	res.facilities.facilities_val = facilities;
46582b75dfdSjtc 
46682b75dfdSjtc 	res.vers = &pcnfsd_version[0];
46782b75dfdSjtc 	res.cm = &no_comment[0];
46882b75dfdSjtc 
46982b75dfdSjtc 	return (&res);
47082b75dfdSjtc }
47182b75dfdSjtc 
47282b75dfdSjtc 
47382b75dfdSjtc 
47482b75dfdSjtc void
47582b75dfdSjtc fillin_extra_groups(uname, main_gid, len, extra_gids)
47682b75dfdSjtc 	char   *uname;
477736ba086Slukem 	gid_t   main_gid;
47882b75dfdSjtc 	int    *len;
479736ba086Slukem 	gid_t   extra_gids[EXTRAGIDLEN];
48082b75dfdSjtc {
48182b75dfdSjtc 	struct group *grp;
4822e9ada3aSmycroft 	__aconst char *__aconst *members;
48382b75dfdSjtc 	int     n = 0;
48482b75dfdSjtc 
48582b75dfdSjtc 	setgrent();
48682b75dfdSjtc 
48782b75dfdSjtc 	while (n < EXTRAGIDLEN) {
48882b75dfdSjtc 		grp = getgrent();
48982b75dfdSjtc 		if (grp == NULL)
49082b75dfdSjtc 			break;
49182b75dfdSjtc 		if (grp->gr_gid == main_gid)
49282b75dfdSjtc 			continue;
49382b75dfdSjtc 		for (members = grp->gr_mem; members && *members; members++) {
49482b75dfdSjtc 			if (!strcmp(*members, uname)) {
49582b75dfdSjtc 				extra_gids[n++] = grp->gr_gid;
49682b75dfdSjtc 				break;
49782b75dfdSjtc 			}
49882b75dfdSjtc 		}
49982b75dfdSjtc 	}
50082b75dfdSjtc 	endgrent();
50182b75dfdSjtc 	*len = n;
50282b75dfdSjtc }
50382b75dfdSjtc 
50482b75dfdSjtc #ifdef USE_YP
50582b75dfdSjtc /* the following is from rpcsvc/yp_prot.h */
50682b75dfdSjtc #define YPMAXDOMAIN 64
507736ba086Slukem 
50882b75dfdSjtc /*
50982b75dfdSjtc  * find_entry returns NULL on any error (printing a message) and
51082b75dfdSjtc  * otherwise returns a pointer to the malloc'd result. The caller
51182b75dfdSjtc  * is responsible for free()ing the result string.
51282b75dfdSjtc  */
51382b75dfdSjtc char   *
51482b75dfdSjtc find_entry(key, map)
51582b75dfdSjtc 	char   *key;
51682b75dfdSjtc 	char   *map;
51782b75dfdSjtc {
51882b75dfdSjtc 	int     err;
51982b75dfdSjtc 	char   *val = NULL;
52082b75dfdSjtc 	char   *cp;
52182b75dfdSjtc 	int     len = 0;
52282b75dfdSjtc 	static char domain[YPMAXDOMAIN + 1];
52382b75dfdSjtc 
52482b75dfdSjtc 	if (getdomainname(domain, YPMAXDOMAIN)) {
52582b75dfdSjtc 		msg_out("rpc.pcnfsd: getdomainname failed");
52682b75dfdSjtc 		return (NULL);
52782b75dfdSjtc 	}
528736ba086Slukem 	if ((err = yp_bind(domain)) != 0) {
529e69420e4Sgwr #ifdef	DEBUG
53082b75dfdSjtc 		msg_out("rpc.pcnfsd: yp_bind failed");
531e69420e4Sgwr #endif
53282b75dfdSjtc 		return (NULL);
53382b75dfdSjtc 	}
53482b75dfdSjtc 	err = yp_match(domain, map, key, strlen(key), &val, &len);
53582b75dfdSjtc 
53682b75dfdSjtc 	if (err) {
53782b75dfdSjtc 		msg_out("rpc.pcnfsd: yp_match failed");
538b6572fdcSlukem 		if (val)
539b6572fdcSlukem 			free(val);
54082b75dfdSjtc 		return (NULL);
54182b75dfdSjtc 	}
542736ba086Slukem 	if ((cp = strchr(val, '\n')) != NULL)
54382b75dfdSjtc 		*cp = '\0';	/* in case we get an extra NL at the end */
54482b75dfdSjtc 	return (val);
54582b75dfdSjtc }
54682b75dfdSjtc #endif
547