xref: /illumos-gate/usr/src/cmd/ptools/ppriv/ppriv.c (revision 43051d27)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22134a1f4eSCasper H.S. Dik  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
232a12f85aSJeremy Jones  */
242a12f85aSJeremy Jones /*
252a12f85aSJeremy Jones  * Copyright (c) 2013 by Delphix. All rights reserved.
26*43051d27SRobert Mustacchi  * Copyright 2015, Joyent, Inc.
272a12f85aSJeremy Jones  */
282a12f85aSJeremy Jones /*
297c478bd9Sstevel@tonic-gate  * Program to examine or set process privileges.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdio.h>
33004388ebScasper #include <stdio_ext.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <fcntl.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <limits.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <libproc.h>
417c478bd9Sstevel@tonic-gate #include <priv.h>
427c478bd9Sstevel@tonic-gate #include <errno.h>
437c478bd9Sstevel@tonic-gate #include <ctype.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <locale.h>
467c478bd9Sstevel@tonic-gate #include <langinfo.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate static int	look(char *);
497c478bd9Sstevel@tonic-gate static void	perr(char *);
507c478bd9Sstevel@tonic-gate static void	usage(void);
517c478bd9Sstevel@tonic-gate static void	loadprivinfo(void);
527c478bd9Sstevel@tonic-gate static int	parsespec(const char *);
537c478bd9Sstevel@tonic-gate static void	privupdate(prpriv_t *, const char *);
547c478bd9Sstevel@tonic-gate static void	privupdate_self(void);
557c478bd9Sstevel@tonic-gate static int	dumppriv(char **);
567c478bd9Sstevel@tonic-gate static void	flags2str(uint_t);
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static char		*command;
597c478bd9Sstevel@tonic-gate static char		*procname;
607c478bd9Sstevel@tonic-gate static boolean_t	verb = B_FALSE;
617c478bd9Sstevel@tonic-gate static boolean_t	set = B_FALSE;
627c478bd9Sstevel@tonic-gate static boolean_t	exec = B_FALSE;
637c478bd9Sstevel@tonic-gate static boolean_t	Don = B_FALSE;
647c478bd9Sstevel@tonic-gate static boolean_t	Doff = B_FALSE;
657c478bd9Sstevel@tonic-gate static boolean_t	list = B_FALSE;
6645916cd2Sjpk static boolean_t	mac_aware = B_FALSE;
67134a1f4eSCasper H.S. Dik static boolean_t	pfexec = B_FALSE;
68ddf7fe95Scasper static boolean_t	xpol = B_FALSE;
697c478bd9Sstevel@tonic-gate static int		mode = PRIV_STR_PORT;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)727c478bd9Sstevel@tonic-gate main(int argc, char **argv)
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	int rc = 0;
757c478bd9Sstevel@tonic-gate 	int opt;
767c478bd9Sstevel@tonic-gate 	struct rlimit rlim;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
797c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	if ((command = strrchr(argv[0], '/')) != NULL)
827c478bd9Sstevel@tonic-gate 		command++;
837c478bd9Sstevel@tonic-gate 	else
847c478bd9Sstevel@tonic-gate 		command = argv[0];
857c478bd9Sstevel@tonic-gate 
86134a1f4eSCasper H.S. Dik 	while ((opt = getopt(argc, argv, "lDMNPevs:xS")) != EOF) {
877c478bd9Sstevel@tonic-gate 		switch (opt) {
887c478bd9Sstevel@tonic-gate 		case 'l':
897c478bd9Sstevel@tonic-gate 			list = B_TRUE;
907c478bd9Sstevel@tonic-gate 			break;
917c478bd9Sstevel@tonic-gate 		case 'D':
927c478bd9Sstevel@tonic-gate 			set = B_TRUE;
937c478bd9Sstevel@tonic-gate 			Don = B_TRUE;
947c478bd9Sstevel@tonic-gate 			break;
9545916cd2Sjpk 		case 'M':
9645916cd2Sjpk 			mac_aware = B_TRUE;
9745916cd2Sjpk 			break;
987c478bd9Sstevel@tonic-gate 		case 'N':
997c478bd9Sstevel@tonic-gate 			set = B_TRUE;
1007c478bd9Sstevel@tonic-gate 			Doff = B_TRUE;
1017c478bd9Sstevel@tonic-gate 			break;
102134a1f4eSCasper H.S. Dik 		case 'P':
103134a1f4eSCasper H.S. Dik 			set = B_TRUE;
104134a1f4eSCasper H.S. Dik 			pfexec = B_TRUE;
105134a1f4eSCasper H.S. Dik 			break;
1067c478bd9Sstevel@tonic-gate 		case 'e':
1077c478bd9Sstevel@tonic-gate 			exec = B_TRUE;
1087c478bd9Sstevel@tonic-gate 			break;
1097c478bd9Sstevel@tonic-gate 		case 'S':
1107c478bd9Sstevel@tonic-gate 			mode = PRIV_STR_SHORT;
1117c478bd9Sstevel@tonic-gate 			break;
1127c478bd9Sstevel@tonic-gate 		case 'v':
1137c478bd9Sstevel@tonic-gate 			verb = B_TRUE;
1147c478bd9Sstevel@tonic-gate 			mode = PRIV_STR_LIT;
1157c478bd9Sstevel@tonic-gate 			break;
1167c478bd9Sstevel@tonic-gate 		case 's':
1177c478bd9Sstevel@tonic-gate 			set = B_TRUE;
1187c478bd9Sstevel@tonic-gate 			if ((rc = parsespec(optarg)) != 0)
1197c478bd9Sstevel@tonic-gate 				return (rc);
1207c478bd9Sstevel@tonic-gate 			break;
121ddf7fe95Scasper 		case 'x':
122ddf7fe95Scasper 			set = B_TRUE;
123ddf7fe95Scasper 			xpol = B_TRUE;
124ddf7fe95Scasper 			break;
1257c478bd9Sstevel@tonic-gate 		default:
1267c478bd9Sstevel@tonic-gate 			usage();
1277c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 	}
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	argc -= optind;
1327c478bd9Sstevel@tonic-gate 	argv += optind;
1337c478bd9Sstevel@tonic-gate 
13445916cd2Sjpk 	if ((argc < 1 && !list) || Doff && Don || list && (set || exec) ||
13545916cd2Sjpk 	    (mac_aware && !exec))
1367c478bd9Sstevel@tonic-gate 		usage();
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	/*
1397c478bd9Sstevel@tonic-gate 	 * Make sure we'll have enough file descriptors to handle a target
1407c478bd9Sstevel@tonic-gate 	 * that has many many mappings.
1417c478bd9Sstevel@tonic-gate 	 */
1427c478bd9Sstevel@tonic-gate 	if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
1437c478bd9Sstevel@tonic-gate 		rlim.rlim_cur = rlim.rlim_max;
1447c478bd9Sstevel@tonic-gate 		(void) setrlimit(RLIMIT_NOFILE, &rlim);
145004388ebScasper 		(void) enable_extended_FILE_stdio(-1, -1);
1467c478bd9Sstevel@tonic-gate 	}
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	if (exec) {
1497c478bd9Sstevel@tonic-gate 		privupdate_self();
1507c478bd9Sstevel@tonic-gate 		rc = execvp(argv[0], &argv[0]);
1517c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: %s: %s\n", command, argv[0],
152ddf7fe95Scasper 		    strerror(errno));
1537c478bd9Sstevel@tonic-gate 	} else if (list) {
1547c478bd9Sstevel@tonic-gate 		rc = dumppriv(argv);
1557c478bd9Sstevel@tonic-gate 	} else {
1567c478bd9Sstevel@tonic-gate 		while (argc-- > 0)
1577c478bd9Sstevel@tonic-gate 			rc += look(*argv++);
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	return (rc);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate static int
look(char * arg)1647c478bd9Sstevel@tonic-gate look(char *arg)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate 	struct ps_prochandle *Pr;
1677c478bd9Sstevel@tonic-gate 	int gcode;
1687c478bd9Sstevel@tonic-gate 	size_t sz;
1697c478bd9Sstevel@tonic-gate 	void *pdata;
1707c478bd9Sstevel@tonic-gate 	char *x;
1717c478bd9Sstevel@tonic-gate 	int i;
1727c478bd9Sstevel@tonic-gate 	boolean_t nodata;
1732a12f85aSJeremy Jones 	prpriv_t *ppriv;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	procname = arg;		/* for perr() */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if ((Pr = proc_arg_grab(arg, set ? PR_ARG_PIDS : PR_ARG_ANY,
1787c478bd9Sstevel@tonic-gate 	    PGRAB_RETAIN | PGRAB_FORCE | (set ? 0 : PGRAB_RDONLY) |
1797c478bd9Sstevel@tonic-gate 	    PGRAB_NOSTOP, &gcode)) == NULL) {
1807c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: cannot examine %s: %s\n",
1817c478bd9Sstevel@tonic-gate 		    command, arg, Pgrab_error(gcode));
1827c478bd9Sstevel@tonic-gate 		return (1);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1852a12f85aSJeremy Jones 	if (Ppriv(Pr, &ppriv) == -1) {
1867c478bd9Sstevel@tonic-gate 		perr(command);
1877c478bd9Sstevel@tonic-gate 		Prelease(Pr, 0);
1887c478bd9Sstevel@tonic-gate 		return (1);
1897c478bd9Sstevel@tonic-gate 	}
1907c478bd9Sstevel@tonic-gate 	sz = PRIV_PRPRIV_SIZE(ppriv);
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	/*
1937c478bd9Sstevel@tonic-gate 	 * The ppriv fields are unsigned and may overflow, so check them
1947c478bd9Sstevel@tonic-gate 	 * separately.  Size must be word aligned, so check that too.
1957c478bd9Sstevel@tonic-gate 	 * Make sure size is "smallish" too.
1967c478bd9Sstevel@tonic-gate 	 */
1977c478bd9Sstevel@tonic-gate 	if ((sz & 3) || ppriv->pr_nsets == 0 ||
1987c478bd9Sstevel@tonic-gate 	    sz / ppriv->pr_nsets < ppriv->pr_setsize ||
1997c478bd9Sstevel@tonic-gate 	    ppriv->pr_infosize > sz || sz > 1024 * 1024) {
2007c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
201ddf7fe95Scasper 		    "%s: %s: bad PRNOTES section, size = %lx\n",
202ddf7fe95Scasper 		    command, arg, (long)sz);
2037c478bd9Sstevel@tonic-gate 		Prelease(Pr, 0);
204*43051d27SRobert Mustacchi 		Ppriv_free(Pr, ppriv);
2057c478bd9Sstevel@tonic-gate 		return (1);
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	if (set) {
2097c478bd9Sstevel@tonic-gate 		privupdate(ppriv, arg);
2107c478bd9Sstevel@tonic-gate 		if (Psetpriv(Pr, ppriv) != 0) {
2117c478bd9Sstevel@tonic-gate 			perr(command);
2127c478bd9Sstevel@tonic-gate 			Prelease(Pr, 0);
213*43051d27SRobert Mustacchi 			Ppriv_free(Pr, ppriv);
2147c478bd9Sstevel@tonic-gate 			return (1);
2157c478bd9Sstevel@tonic-gate 		}
2167c478bd9Sstevel@tonic-gate 		Prelease(Pr, 0);
217*43051d27SRobert Mustacchi 		Ppriv_free(Pr, ppriv);
2187c478bd9Sstevel@tonic-gate 		return (0);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	if (Pstate(Pr) == PS_DEAD) {
2227c478bd9Sstevel@tonic-gate 		(void) printf("core '%s' of %d:\t%.70s\n",
2237c478bd9Sstevel@tonic-gate 		    arg, (int)Ppsinfo(Pr)->pr_pid, Ppsinfo(Pr)->pr_psargs);
2247c478bd9Sstevel@tonic-gate 		pdata = Pprivinfo(Pr);
2257c478bd9Sstevel@tonic-gate 		nodata = Pstate(Pr) == PS_DEAD && pdata == NULL;
2267c478bd9Sstevel@tonic-gate 	} else {
2277c478bd9Sstevel@tonic-gate 		(void) printf("%d:\t%.70s\n",
2287c478bd9Sstevel@tonic-gate 		    (int)Ppsinfo(Pr)->pr_pid, Ppsinfo(Pr)->pr_psargs);
2297c478bd9Sstevel@tonic-gate 		pdata = NULL;
2307c478bd9Sstevel@tonic-gate 		nodata = B_FALSE;
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	x = (char *)ppriv + sz - ppriv->pr_infosize;
2347c478bd9Sstevel@tonic-gate 	while (x < (char *)ppriv + sz) {
2357c478bd9Sstevel@tonic-gate 		/* LINTED: alignment */
2367c478bd9Sstevel@tonic-gate 		priv_info_t *pi = (priv_info_t *)x;
2377c478bd9Sstevel@tonic-gate 		priv_info_uint_t *pii;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 		switch (pi->priv_info_type) {
2407c478bd9Sstevel@tonic-gate 		case PRIV_INFO_FLAGS:
2417c478bd9Sstevel@tonic-gate 			/* LINTED: alignment */
2427c478bd9Sstevel@tonic-gate 			pii = (priv_info_uint_t *)x;
2437c478bd9Sstevel@tonic-gate 			(void) printf("flags =");
2447c478bd9Sstevel@tonic-gate 			flags2str(pii->val);
2457c478bd9Sstevel@tonic-gate 			(void) putchar('\n');
2467c478bd9Sstevel@tonic-gate 			break;
2477c478bd9Sstevel@tonic-gate 		default:
2487c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: unknown priv_info: %d\n",
249ddf7fe95Scasper 			    arg, pi->priv_info_type);
2507c478bd9Sstevel@tonic-gate 			break;
2517c478bd9Sstevel@tonic-gate 		}
2527c478bd9Sstevel@tonic-gate 		if (pi->priv_info_size > ppriv->pr_infosize ||
2537c478bd9Sstevel@tonic-gate 		    pi->priv_info_size <=  sizeof (priv_info_t) ||
2547c478bd9Sstevel@tonic-gate 		    (pi->priv_info_size & 3) != 0) {
2557c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: bad priv_info_size: %u\n",
256ddf7fe95Scasper 			    arg, pi->priv_info_size);
2577c478bd9Sstevel@tonic-gate 			break;
2587c478bd9Sstevel@tonic-gate 		}
2597c478bd9Sstevel@tonic-gate 		x += pi->priv_info_size;
2607c478bd9Sstevel@tonic-gate 	}
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 	for (i = 0; i < ppriv->pr_nsets; i++) {
2637c478bd9Sstevel@tonic-gate 		extern const char *__priv_getsetbynum(const void *, int);
264ddf7fe95Scasper 		const char *setnm = pdata ? __priv_getsetbynum(pdata, i) :
265ddf7fe95Scasper 		    priv_getsetbynum(i);
266ddf7fe95Scasper 		priv_chunk_t *pc =
267ddf7fe95Scasper 		    (priv_chunk_t *)&ppriv->pr_sets[ppriv->pr_setsize * i];
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 		(void) printf("\t%c: ", setnm && !nodata ? *setnm : '?');
2717c478bd9Sstevel@tonic-gate 		if (!nodata) {
2727c478bd9Sstevel@tonic-gate 			extern char *__priv_set_to_str(void *,
273ddf7fe95Scasper 			    const priv_set_t *, char, int);
2747c478bd9Sstevel@tonic-gate 			priv_set_t *pset = (priv_set_t *)pc;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 			char *s;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 			if (pdata)
2797c478bd9Sstevel@tonic-gate 				s = __priv_set_to_str(pdata, pset, ',', mode);
2807c478bd9Sstevel@tonic-gate 			else
2817c478bd9Sstevel@tonic-gate 				s = priv_set_to_str(pset, ',', mode);
2827c478bd9Sstevel@tonic-gate 			(void) puts(s);
2837c478bd9Sstevel@tonic-gate 			free(s);
2847c478bd9Sstevel@tonic-gate 		} else {
2857c478bd9Sstevel@tonic-gate 			int j;
2867c478bd9Sstevel@tonic-gate 			for (j = 0; j < ppriv->pr_setsize; j++)
2877c478bd9Sstevel@tonic-gate 				(void) printf("%08x", pc[j]);
2887c478bd9Sstevel@tonic-gate 			(void) putchar('\n');
2897c478bd9Sstevel@tonic-gate 		}
2907c478bd9Sstevel@tonic-gate 	}
2917c478bd9Sstevel@tonic-gate 	Prelease(Pr, 0);
292*43051d27SRobert Mustacchi 	Ppriv_free(Pr, ppriv);
2937c478bd9Sstevel@tonic-gate 	return (0);
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate static void
fatal(const char * s)2977c478bd9Sstevel@tonic-gate fatal(const char *s)
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: %s: %s\n", command, s, strerror(errno));
3007c478bd9Sstevel@tonic-gate 	exit(3);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate static void
perr(char * s)3047c478bd9Sstevel@tonic-gate perr(char *s)
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate 	int err = errno;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	if (s != NULL)
3097c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: ", procname);
3107c478bd9Sstevel@tonic-gate 	else
3117c478bd9Sstevel@tonic-gate 		s = procname;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	errno = err;
3147c478bd9Sstevel@tonic-gate 	perror(s);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate static void
usage(void)3187c478bd9Sstevel@tonic-gate usage(void)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
3217c478bd9Sstevel@tonic-gate 	    "usage:\t%s [-v] [-S] [-D|-N] [-s spec] { pid | core } ...\n"
32245916cd2Sjpk 	    "\t%s -e [-D|-N] [-M] [-s spec] cmd [args ...]\n"
3237c478bd9Sstevel@tonic-gate 	    "\t%s -l [-v] [privilege ...]\n"
3247c478bd9Sstevel@tonic-gate 	    "  (report, set or list process privileges)\n", command,
3257c478bd9Sstevel@tonic-gate 	    command, command);
3267c478bd9Sstevel@tonic-gate 	exit(2);
3277c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate  * Parse the privilege bits to add and/or remove from
3327c478bd9Sstevel@tonic-gate  * a privilege set.
3337c478bd9Sstevel@tonic-gate  *
3347c478bd9Sstevel@tonic-gate  * [EPIL][+-=]priv,priv,priv
3357c478bd9Sstevel@tonic-gate  */
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate static int
strindex(char c,const char * str)3387c478bd9Sstevel@tonic-gate strindex(char c, const char *str)
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate 	const char *s;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	if (islower(c))
3437c478bd9Sstevel@tonic-gate 		c = toupper(c);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	s = strchr(str, c);
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	if (s == NULL)
3487c478bd9Sstevel@tonic-gate 		return (-1);
3497c478bd9Sstevel@tonic-gate 	else
3507c478bd9Sstevel@tonic-gate 		return (s - str);
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate static void
badspec(const char * spec)3547c478bd9Sstevel@tonic-gate badspec(const char *spec)
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: bad privilege specification: \"%s\"\n",
357ddf7fe95Scasper 	    command, spec);
3587c478bd9Sstevel@tonic-gate 	exit(3);
3597c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate  * For each set, you can set either add and/or
3647c478bd9Sstevel@tonic-gate  * remove or you can set assign.
3657c478bd9Sstevel@tonic-gate  */
3667c478bd9Sstevel@tonic-gate static priv_set_t **rem, **add, **assign;
3677c478bd9Sstevel@tonic-gate static const priv_impl_info_t *pri = NULL;
3687c478bd9Sstevel@tonic-gate static char *sets;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate static void
loadprivinfo(void)3717c478bd9Sstevel@tonic-gate loadprivinfo(void)
3727c478bd9Sstevel@tonic-gate {
3737c478bd9Sstevel@tonic-gate 	int i;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	if (pri != NULL)
3767c478bd9Sstevel@tonic-gate 		return;
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	pri = getprivimplinfo();
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	if (pri == NULL)
3817c478bd9Sstevel@tonic-gate 		fatal("getprivimplinfo");
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	sets = malloc(pri->priv_nsets + 1);
3847c478bd9Sstevel@tonic-gate 	if (sets == NULL)
3857c478bd9Sstevel@tonic-gate 		fatal("malloc");
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	for (i = 0; i < pri->priv_nsets; i++) {
3887c478bd9Sstevel@tonic-gate 		sets[i] = *priv_getsetbynum(i);
3897c478bd9Sstevel@tonic-gate 		if (islower(sets[i]))
3907c478bd9Sstevel@tonic-gate 			sets[i] = toupper(sets[i]);
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	sets[pri->priv_nsets] = '\0';
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	rem = calloc(pri->priv_nsets, sizeof (priv_set_t *));
3967c478bd9Sstevel@tonic-gate 	add = calloc(pri->priv_nsets, sizeof (priv_set_t *));
3977c478bd9Sstevel@tonic-gate 	assign = calloc(pri->priv_nsets, sizeof (priv_set_t *));
3987c478bd9Sstevel@tonic-gate 	if (rem == NULL || add == NULL || assign == NULL)
3997c478bd9Sstevel@tonic-gate 		fatal("calloc");
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate static int
parsespec(const char * spec)4037c478bd9Sstevel@tonic-gate parsespec(const char *spec)
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate 	char *p;
4067c478bd9Sstevel@tonic-gate 	const char *q;
4077c478bd9Sstevel@tonic-gate 	int count;
4087c478bd9Sstevel@tonic-gate 	priv_set_t ***toupd;
4097c478bd9Sstevel@tonic-gate 	priv_set_t *upd;
4107c478bd9Sstevel@tonic-gate 	int i;
4117c478bd9Sstevel@tonic-gate 	boolean_t freeupd = B_TRUE;
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 	if (pri == NULL)
4147c478bd9Sstevel@tonic-gate 		loadprivinfo();
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	p = strpbrk(spec, "+-=");
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 	if (p == NULL || p - spec > pri->priv_nsets)
4197c478bd9Sstevel@tonic-gate 		badspec(spec);
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	if (p[1] == '\0' || (upd = priv_str_to_set(p + 1, ",", NULL)) == NULL)
4227c478bd9Sstevel@tonic-gate 		badspec(p + 1);
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	count = p - spec;
4257c478bd9Sstevel@tonic-gate 	switch (*p) {
4267c478bd9Sstevel@tonic-gate 	case '+':
4277c478bd9Sstevel@tonic-gate 		toupd = &add;
4287c478bd9Sstevel@tonic-gate 		break;
4297c478bd9Sstevel@tonic-gate 	case '-':
4307c478bd9Sstevel@tonic-gate 		toupd = &rem;
4317c478bd9Sstevel@tonic-gate 		priv_inverse(upd);
4327c478bd9Sstevel@tonic-gate 		break;
4337c478bd9Sstevel@tonic-gate 	case '=':
4347c478bd9Sstevel@tonic-gate 		toupd = &assign;
4357c478bd9Sstevel@tonic-gate 		break;
4367c478bd9Sstevel@tonic-gate 	}
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	/* Update all sets? */
4397c478bd9Sstevel@tonic-gate 	if (count == 0 || *spec == 'a' || *spec == 'A') {
4407c478bd9Sstevel@tonic-gate 		count = pri->priv_nsets;
4417c478bd9Sstevel@tonic-gate 		q = sets;
4427c478bd9Sstevel@tonic-gate 	} else
4437c478bd9Sstevel@tonic-gate 		q = spec;
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	for (i = 0; i < count; i++) {
4467c478bd9Sstevel@tonic-gate 		int ind = strindex(q[i], sets);
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 		if (ind == -1)
4497c478bd9Sstevel@tonic-gate 			badspec(spec);
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 		/* Assign is mutually exclusive with add/remove and itself */
4527c478bd9Sstevel@tonic-gate 		if (((toupd == &rem || toupd == &add) && assign[ind] != NULL) ||
4537c478bd9Sstevel@tonic-gate 		    (toupd == &assign && (assign[ind] != NULL ||
454ddf7fe95Scasper 		    rem[ind] != NULL || add[ind] != NULL))) {
4557c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: conflicting spec: %s\n",
456ddf7fe95Scasper 			    command, spec);
4577c478bd9Sstevel@tonic-gate 			exit(1);
4587c478bd9Sstevel@tonic-gate 		}
4597c478bd9Sstevel@tonic-gate 		if ((*toupd)[ind] != NULL) {
4607c478bd9Sstevel@tonic-gate 			if (*p == '-')
4617c478bd9Sstevel@tonic-gate 				priv_intersect(upd, (*toupd)[ind]);
4627c478bd9Sstevel@tonic-gate 			else
4637c478bd9Sstevel@tonic-gate 				priv_union(upd, (*toupd)[ind]);
4647c478bd9Sstevel@tonic-gate 		} else {
4657c478bd9Sstevel@tonic-gate 			(*toupd)[ind] = upd;
4667c478bd9Sstevel@tonic-gate 			freeupd = B_FALSE;
4677c478bd9Sstevel@tonic-gate 		}
4687c478bd9Sstevel@tonic-gate 	}
4697c478bd9Sstevel@tonic-gate 	if (freeupd)
4707c478bd9Sstevel@tonic-gate 		priv_freeset(upd);
4717c478bd9Sstevel@tonic-gate 	return (0);
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate static void
privupdate(prpriv_t * pr,const char * arg)4757c478bd9Sstevel@tonic-gate privupdate(prpriv_t *pr, const char *arg)
4767c478bd9Sstevel@tonic-gate {
4777c478bd9Sstevel@tonic-gate 	int i;
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	if (sets != NULL) {
4807c478bd9Sstevel@tonic-gate 		for (i = 0; i < pri->priv_nsets; i++) {
4817c478bd9Sstevel@tonic-gate 			priv_set_t *target =
482ddf7fe95Scasper 			    (priv_set_t *)&pr->pr_sets[pr->pr_setsize * i];
4837c478bd9Sstevel@tonic-gate 			if (rem[i] != NULL)
4847c478bd9Sstevel@tonic-gate 				priv_intersect(rem[i], target);
4857c478bd9Sstevel@tonic-gate 			if (add[i] != NULL)
4867c478bd9Sstevel@tonic-gate 				priv_union(add[i], target);
4877c478bd9Sstevel@tonic-gate 			if (assign[i] != NULL)
4887c478bd9Sstevel@tonic-gate 				priv_copyset(assign[i], target);
4897c478bd9Sstevel@tonic-gate 		}
4907c478bd9Sstevel@tonic-gate 	}
4917c478bd9Sstevel@tonic-gate 
492134a1f4eSCasper H.S. Dik 	if (Doff || Don || pfexec || xpol) {
4937c478bd9Sstevel@tonic-gate 		priv_info_uint_t *pii;
4947c478bd9Sstevel@tonic-gate 		int sz = PRIV_PRPRIV_SIZE(pr);
4957c478bd9Sstevel@tonic-gate 		char *x = (char *)pr + PRIV_PRPRIV_INFO_OFFSET(pr);
4967c478bd9Sstevel@tonic-gate 		uint32_t fl = 0;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 		while (x < (char *)pr + sz) {
4997c478bd9Sstevel@tonic-gate 			/* LINTED: alignment */
5007c478bd9Sstevel@tonic-gate 			priv_info_t *pi = (priv_info_t *)x;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 			if (pi->priv_info_type == PRIV_INFO_FLAGS) {
5037c478bd9Sstevel@tonic-gate 				/* LINTED: alignment */
5047c478bd9Sstevel@tonic-gate 				pii = (priv_info_uint_t *)x;
5057c478bd9Sstevel@tonic-gate 				fl = pii->val;
5067c478bd9Sstevel@tonic-gate 				goto done;
5077c478bd9Sstevel@tonic-gate 			}
5087c478bd9Sstevel@tonic-gate 			if (pi->priv_info_size > pr->pr_infosize ||
5097c478bd9Sstevel@tonic-gate 			    pi->priv_info_size <=  sizeof (priv_info_t) ||
5107c478bd9Sstevel@tonic-gate 			    (pi->priv_info_size & 3) != 0)
5117c478bd9Sstevel@tonic-gate 				break;
5127c478bd9Sstevel@tonic-gate 			x += pi->priv_info_size;
5137c478bd9Sstevel@tonic-gate 		}
5147c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
515ddf7fe95Scasper 		    "%s: cannot find privilege flags to set\n", arg);
5167c478bd9Sstevel@tonic-gate 		pr->pr_infosize = 0;
5177c478bd9Sstevel@tonic-gate 		return;
5187c478bd9Sstevel@tonic-gate done:
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 		pr->pr_infosize = sizeof (priv_info_uint_t);
5217c478bd9Sstevel@tonic-gate 		/* LINTED: alignment */
5227c478bd9Sstevel@tonic-gate 		pii = (priv_info_uint_t *)
523ddf7fe95Scasper 		    ((char *)pr + PRIV_PRPRIV_INFO_OFFSET(pr));
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 		if (Don)
5267c478bd9Sstevel@tonic-gate 			fl |= PRIV_DEBUG;
527ddf7fe95Scasper 		if (Doff)
5287c478bd9Sstevel@tonic-gate 			fl &= ~PRIV_DEBUG;
529134a1f4eSCasper H.S. Dik 		if (pfexec)
530134a1f4eSCasper H.S. Dik 			fl |= PRIV_PFEXEC;
531ddf7fe95Scasper 		if (xpol)
532ddf7fe95Scasper 			fl |= PRIV_XPOLICY;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 		pii->info.priv_info_size = sizeof (*pii);
5357c478bd9Sstevel@tonic-gate 		pii->info.priv_info_type = PRIV_INFO_FLAGS;
5367c478bd9Sstevel@tonic-gate 		pii->val = fl;
5377c478bd9Sstevel@tonic-gate 	} else {
5387c478bd9Sstevel@tonic-gate 		pr->pr_infosize = 0;
5397c478bd9Sstevel@tonic-gate 	}
5407c478bd9Sstevel@tonic-gate }
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate static void
privupdate_self(void)5437c478bd9Sstevel@tonic-gate privupdate_self(void)
5447c478bd9Sstevel@tonic-gate {
5457c478bd9Sstevel@tonic-gate 	int set;
5467c478bd9Sstevel@tonic-gate 
54745916cd2Sjpk 	if (mac_aware) {
54845916cd2Sjpk 		if (setpflags(NET_MAC_AWARE, 1) != 0)
54945916cd2Sjpk 			fatal("setpflags(NET_MAC_AWARE)");
55045916cd2Sjpk 		if (setpflags(NET_MAC_AWARE_INHERIT, 1) != 0)
55145916cd2Sjpk 			fatal("setpflags(NET_MAC_AWARE_INHERIT)");
55245916cd2Sjpk 	}
553134a1f4eSCasper H.S. Dik 	if (pfexec) {
554134a1f4eSCasper H.S. Dik 		if (setpflags(PRIV_PFEXEC, 1) != 0)
555134a1f4eSCasper H.S. Dik 			fatal("setpflags(PRIV_PFEXEC)");
556134a1f4eSCasper H.S. Dik 	}
55745916cd2Sjpk 
5587c478bd9Sstevel@tonic-gate 	if (sets != NULL) {
5597c478bd9Sstevel@tonic-gate 		priv_set_t *target = priv_allocset();
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 		if (target == NULL)
5627c478bd9Sstevel@tonic-gate 			fatal("priv_allocet");
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 		set = priv_getsetbyname(PRIV_INHERITABLE);
5657c478bd9Sstevel@tonic-gate 		if (rem[set] != NULL || add[set] != NULL ||
5667c478bd9Sstevel@tonic-gate 		    assign[set] != NULL) {
5677c478bd9Sstevel@tonic-gate 			(void) getppriv(PRIV_INHERITABLE, target);
5687c478bd9Sstevel@tonic-gate 			if (rem[set] != NULL)
5697c478bd9Sstevel@tonic-gate 				priv_intersect(rem[set], target);
5707c478bd9Sstevel@tonic-gate 			if (add[set] != NULL)
5717c478bd9Sstevel@tonic-gate 				priv_union(add[set], target);
5727c478bd9Sstevel@tonic-gate 			if (assign[set] != NULL)
5737c478bd9Sstevel@tonic-gate 				priv_copyset(assign[set], target);
5747c478bd9Sstevel@tonic-gate 			if (setppriv(PRIV_SET, PRIV_INHERITABLE, target) != 0)
5757c478bd9Sstevel@tonic-gate 				fatal("setppriv(Inheritable)");
5767c478bd9Sstevel@tonic-gate 		}
5777c478bd9Sstevel@tonic-gate 		set = priv_getsetbyname(PRIV_LIMIT);
5787c478bd9Sstevel@tonic-gate 		if (rem[set] != NULL || add[set] != NULL ||
5797c478bd9Sstevel@tonic-gate 		    assign[set] != NULL) {
5807c478bd9Sstevel@tonic-gate 			(void) getppriv(PRIV_LIMIT, target);
5817c478bd9Sstevel@tonic-gate 			if (rem[set] != NULL)
5827c478bd9Sstevel@tonic-gate 				priv_intersect(rem[set], target);
5837c478bd9Sstevel@tonic-gate 			if (add[set] != NULL)
5847c478bd9Sstevel@tonic-gate 				priv_union(add[set], target);
5857c478bd9Sstevel@tonic-gate 			if (assign[set] != NULL)
5867c478bd9Sstevel@tonic-gate 				priv_copyset(assign[set], target);
5877c478bd9Sstevel@tonic-gate 			if (setppriv(PRIV_SET, PRIV_LIMIT, target) != 0)
5887c478bd9Sstevel@tonic-gate 				fatal("setppriv(Limit)");
5897c478bd9Sstevel@tonic-gate 		}
5907c478bd9Sstevel@tonic-gate 		priv_freeset(target);
5917c478bd9Sstevel@tonic-gate 	}
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	if (Doff || Don)
5947c478bd9Sstevel@tonic-gate 		(void) setpflags(PRIV_DEBUG, Don ? 1 : 0);
595ddf7fe95Scasper 	if (xpol)
596ddf7fe95Scasper 		(void) setpflags(PRIV_XPOLICY, 1);
597134a1f4eSCasper H.S. Dik 	if (pfexec)
598134a1f4eSCasper H.S. Dik 		(void) setpflags(PRIV_PFEXEC, 1);
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate static int
dopriv(const char * p)6027c478bd9Sstevel@tonic-gate dopriv(const char *p)
6037c478bd9Sstevel@tonic-gate {
6047c478bd9Sstevel@tonic-gate 	(void) puts(p);
6057c478bd9Sstevel@tonic-gate 	if (verb) {
6067c478bd9Sstevel@tonic-gate 		char *text = priv_gettext(p);
6077c478bd9Sstevel@tonic-gate 		char *p, *q;
6087c478bd9Sstevel@tonic-gate 		if (text == NULL)
6097c478bd9Sstevel@tonic-gate 			return (1);
610c8d28497Ssayama 		for (p = text; q = strchr(p, '\n'); p = q + 1) {
611c8d28497Ssayama 			*q = '\0';
612c8d28497Ssayama 			(void) printf("\t%s\n", p);
613c8d28497Ssayama 		}
6147c478bd9Sstevel@tonic-gate 		free(text);
6157c478bd9Sstevel@tonic-gate 	}
6167c478bd9Sstevel@tonic-gate 	return (0);
6177c478bd9Sstevel@tonic-gate }
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate static int
dumppriv(char ** argv)6207c478bd9Sstevel@tonic-gate dumppriv(char **argv)
6217c478bd9Sstevel@tonic-gate {
6227c478bd9Sstevel@tonic-gate 	int rc = 0;
6237c478bd9Sstevel@tonic-gate 	const char *pname;
6247c478bd9Sstevel@tonic-gate 	int i;
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	if (argv[0] == NULL) {
6277c478bd9Sstevel@tonic-gate 		for (i = 0; ((pname = priv_getbynum(i++)) != NULL); )
6287c478bd9Sstevel@tonic-gate 			rc += dopriv(pname);
6297c478bd9Sstevel@tonic-gate 	} else {
6307c478bd9Sstevel@tonic-gate 		for (; *argv; argv++) {
6317c478bd9Sstevel@tonic-gate 			priv_set_t *pset = priv_str_to_set(*argv, ",", NULL);
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 			if (pset == NULL) {
6347c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "%s: %s: bad privilege"
6357c478bd9Sstevel@tonic-gate 				    " list\n", command, *argv);
6367c478bd9Sstevel@tonic-gate 				rc++;
6377c478bd9Sstevel@tonic-gate 				continue;
6387c478bd9Sstevel@tonic-gate 			}
6397c478bd9Sstevel@tonic-gate 			for (i = 0; ((pname = priv_getbynum(i++)) != NULL); )
6407c478bd9Sstevel@tonic-gate 				if (priv_ismember(pset, pname))
6417c478bd9Sstevel@tonic-gate 					rc += dopriv(pname);
6427c478bd9Sstevel@tonic-gate 		}
6437c478bd9Sstevel@tonic-gate 	}
6447c478bd9Sstevel@tonic-gate 	return (rc);
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate static struct {
6487c478bd9Sstevel@tonic-gate 	int flag;
6497c478bd9Sstevel@tonic-gate 	char *name;
6507c478bd9Sstevel@tonic-gate } flags[] = {
6517c478bd9Sstevel@tonic-gate 	{ PRIV_DEBUG, "PRIV_DEBUG" },
6527c478bd9Sstevel@tonic-gate 	{ PRIV_AWARE, "PRIV_AWARE" },
6537c478bd9Sstevel@tonic-gate 	{ PRIV_AWARE_INHERIT, "PRIV_AWARE_INHERIT" },
654982b4ad2SCasper H.S. Dik 	{ PRIV_AWARE_RESET, "PRIV_AWARE_RESET" },
655ddf7fe95Scasper 	{ PRIV_XPOLICY, "PRIV_XPOLICY" },
656134a1f4eSCasper H.S. Dik 	{ PRIV_PFEXEC, "PRIV_PFEXEC" },
657ddf7fe95Scasper 	{ NET_MAC_AWARE, "NET_MAC_AWARE" },
658ddf7fe95Scasper 	{ NET_MAC_AWARE_INHERIT, "NET_MAC_AWARE_INHERIT" },
6597c478bd9Sstevel@tonic-gate };
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate /*
6627c478bd9Sstevel@tonic-gate  * Print flags preceeded by a space.
6637c478bd9Sstevel@tonic-gate  */
6647c478bd9Sstevel@tonic-gate static void
flags2str(uint_t pflags)6657c478bd9Sstevel@tonic-gate flags2str(uint_t pflags)
6667c478bd9Sstevel@tonic-gate {
6677c478bd9Sstevel@tonic-gate 	char c = ' ';
6687c478bd9Sstevel@tonic-gate 	int i;
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 	if (pflags == 0) {
6717c478bd9Sstevel@tonic-gate 		(void) fputs(" <none>", stdout);
6727c478bd9Sstevel@tonic-gate 		return;
6737c478bd9Sstevel@tonic-gate 	}
6747c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (flags)/sizeof (flags[0]) && pflags != 0; i++) {
6757c478bd9Sstevel@tonic-gate 		if ((pflags & flags[i].flag) != 0) {
6767c478bd9Sstevel@tonic-gate 			(void) printf("%c%s", c, flags[i].name);
6777c478bd9Sstevel@tonic-gate 			pflags &= ~flags[i].flag;
6787c478bd9Sstevel@tonic-gate 			c = '|';
6797c478bd9Sstevel@tonic-gate 		}
6807c478bd9Sstevel@tonic-gate 	}
6817c478bd9Sstevel@tonic-gate 	if (pflags != 0)
6827c478bd9Sstevel@tonic-gate 		(void) printf("%c<0x%x>", c, pflags);
6837c478bd9Sstevel@tonic-gate }
684