17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
545916cdjpk * Common Development and Distribution License (the "License").
645916cdjpk * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
22134a1f4Casper H.S. Dik * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bdstevel@tonic-gate */
247c478bdstevel@tonic-gate
257c478bdstevel@tonic-gate#include <sys/param.h>
267c478bdstevel@tonic-gate#include <sys/types.h>
277c478bdstevel@tonic-gate#include <sys/sysmacros.h>
287c478bdstevel@tonic-gate#include <sys/systm.h>
297c478bdstevel@tonic-gate#include <sys/cred_impl.h>
307c478bdstevel@tonic-gate#include <sys/errno.h>
31ddf7fe9casper#include <sys/klpd.h>
327c478bdstevel@tonic-gate#include <sys/proc.h>
337c478bdstevel@tonic-gate#include <sys/priv_impl.h>
347c478bdstevel@tonic-gate#include <sys/policy.h>
357c478bdstevel@tonic-gate#include <sys/ddi.h>
367c478bdstevel@tonic-gate#include <sys/thread.h>
37634e26eCasper H.S. Dik#include <sys/cmn_err.h>
387c478bdstevel@tonic-gate#include <c2/audit.h>
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate/*
417c478bdstevel@tonic-gate * System call support for manipulating privileges.
427c478bdstevel@tonic-gate *
437c478bdstevel@tonic-gate *
447c478bdstevel@tonic-gate * setppriv(2) - set process privilege set
457c478bdstevel@tonic-gate * getppriv(2) - get process privilege set
467c478bdstevel@tonic-gate * getprivimplinfo(2) - get process privilege implementation information
477c478bdstevel@tonic-gate * setpflags(2) - set process (privilege) flags
487c478bdstevel@tonic-gate * getpflags(2) - get process (privilege) flags
497c478bdstevel@tonic-gate */
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate/*
527c478bdstevel@tonic-gate * setppriv (priv_op_t, priv_ptype_t, priv_set_t)
537c478bdstevel@tonic-gate */
547c478bdstevel@tonic-gatestatic int
557c478bdstevel@tonic-gatesetppriv(priv_op_t op, priv_ptype_t type, priv_set_t *in_pset)
567c478bdstevel@tonic-gate{
577c478bdstevel@tonic-gate	priv_set_t	pset, *target;
587c478bdstevel@tonic-gate	cred_t		*cr, *pcr;
597c478bdstevel@tonic-gate	proc_t		*p;
60ddf7fe9casper	boolean_t	donocd = B_FALSE;
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate	if (!PRIV_VALIDSET(type) || !PRIV_VALIDOP(op))
637c478bdstevel@tonic-gate		return (set_errno(EINVAL));
647c478bdstevel@tonic-gate
657c478bdstevel@tonic-gate	if (copyin(in_pset, &pset, sizeof (priv_set_t)))
667c478bdstevel@tonic-gate		return (set_errno(EFAULT));
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate	p = ttoproc(curthread);
697c478bdstevel@tonic-gate	cr = cralloc();
707c478bdstevel@tonic-gate	mutex_enter(&p->p_crlock);
717c478bdstevel@tonic-gate
72ddf7fe9casperretry:
737c478bdstevel@tonic-gate	pcr = p->p_cred;
747c478bdstevel@tonic-gate
75005d3feMarek Pospisil	if (AU_AUDITING())
767c478bdstevel@tonic-gate		audit_setppriv(op, type, &pset, pcr);
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate	/*
797c478bdstevel@tonic-gate	 * Filter out unallowed request (bad op and bad type)
807c478bdstevel@tonic-gate	 */
817c478bdstevel@tonic-gate	switch (op) {
827c478bdstevel@tonic-gate	case PRIV_ON:
837c478bdstevel@tonic-gate	case PRIV_SET:
847c478bdstevel@tonic-gate		/*
857c478bdstevel@tonic-gate		 * Turning on privileges; the limit set cannot grow,
867c478bdstevel@tonic-gate		 * other sets can but only as long as they remain subsets
877c478bdstevel@tonic-gate		 * of P.  Only immediately after exec holds that P <= L.
887c478bdstevel@tonic-gate		 */
89ddf7fe9casper		if (type == PRIV_LIMIT &&
90ddf7fe9casper		    !priv_issubset(&pset, &CR_LPRIV(pcr))) {
9105db633casper			mutex_exit(&p->p_crlock);
927c478bdstevel@tonic-gate			crfree(cr);
937c478bdstevel@tonic-gate			return (set_errno(EPERM));
947c478bdstevel@tonic-gate		}
95ddf7fe9casper		if (!priv_issubset(&pset, &CR_OPPRIV(pcr)) &&
96ddf7fe9casper		    !priv_issubset(&pset, priv_getset(pcr, type))) {
97ddf7fe9casper			mutex_exit(&p->p_crlock);
98ddf7fe9casper			/* Policy override should not grow beyond L either */
99ddf7fe9casper			if (type != PRIV_INHERITABLE ||
100ddf7fe9casper			    !priv_issubset(&pset, &CR_LPRIV(pcr)) ||
101ddf7fe9casper			    secpolicy_require_privs(CRED(), &pset) != 0) {
102ddf7fe9casper				crfree(cr);
103ddf7fe9casper				return (set_errno(EPERM));
104ddf7fe9casper			}
105ddf7fe9casper			mutex_enter(&p->p_crlock);
106ddf7fe9casper			if (pcr != p->p_cred)
107ddf7fe9casper				goto retry;
108ddf7fe9casper			donocd = B_TRUE;
109ddf7fe9casper		}
1107c478bdstevel@tonic-gate		break;
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gate	case PRIV_OFF:
1137c478bdstevel@tonic-gate		/* PRIV_OFF is always allowed */
1147c478bdstevel@tonic-gate		break;
1157c478bdstevel@tonic-gate	}
1167c478bdstevel@tonic-gate
1177c478bdstevel@tonic-gate	/*
1187c478bdstevel@tonic-gate	 * OK! everything is cool.
1197c478bdstevel@tonic-gate	 * Do cred COW.
1207c478bdstevel@tonic-gate	 */
1217c478bdstevel@tonic-gate	crcopy_to(pcr, cr);
1227c478bdstevel@tonic-gate
1237c478bdstevel@tonic-gate	/*
1247c478bdstevel@tonic-gate	 * If we change the effective, permitted or limit set, we attain
1257c478bdstevel@tonic-gate	 * "privilege awareness".
1267c478bdstevel@tonic-gate	 */
1277c478bdstevel@tonic-gate	if (type != PRIV_INHERITABLE)
1287c478bdstevel@tonic-gate		priv_set_PA(cr);
1297c478bdstevel@tonic-gate
1307c478bdstevel@tonic-gate	target = &(CR_PRIVS(cr)->crprivs[type]);
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gate	switch (op) {
1337c478bdstevel@tonic-gate	case PRIV_ON:
1347c478bdstevel@tonic-gate		priv_union(&pset, target);
1357c478bdstevel@tonic-gate		break;
1367c478bdstevel@tonic-gate	case PRIV_OFF:
1377c478bdstevel@tonic-gate		priv_inverse(&pset);
1387c478bdstevel@tonic-gate		priv_intersect(target, &pset);
1397c478bdstevel@tonic-gate
1407c478bdstevel@tonic-gate		/*
1417c478bdstevel@tonic-gate		 * Fall-thru to set target and change other process
1427c478bdstevel@tonic-gate		 * privilege sets.
1437c478bdstevel@tonic-gate		 */
1447c478bdstevel@tonic-gate		/*FALLTHRU*/
1457c478bdstevel@tonic-gate
1467c478bdstevel@tonic-gate	case PRIV_SET:
1477c478bdstevel@tonic-gate		*target = pset;
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gate		/*
1507c478bdstevel@tonic-gate		 * Take privileges no longer permitted out
1517c478bdstevel@tonic-gate		 * of other effective sets as well.
1527c478bdstevel@tonic-gate		 * Limit set is enforced at exec() time.
1537c478bdstevel@tonic-gate		 */
1547c478bdstevel@tonic-gate		if (type == PRIV_PERMITTED)
1557c478bdstevel@tonic-gate			priv_intersect(&pset, &CR_EPRIV(cr));
1567c478bdstevel@tonic-gate		break;
1577c478bdstevel@tonic-gate	}
1587c478bdstevel@tonic-gate
1597c478bdstevel@tonic-gate	/*
1607c478bdstevel@tonic-gate	 * When we give up privileges not in the inheritable set,
1617c478bdstevel@tonic-gate	 * set SNOCD if not already set; first we compute the
1627c478bdstevel@tonic-gate	 * privileges removed from P using Diff = (~P') & P
1637c478bdstevel@tonic-gate	 * and then we check whether the removed privileges are
1647c478bdstevel@tonic-gate	 * a subset of I.  If we retain uid 0, all privileges
1657c478bdstevel@tonic-gate	 * are required anyway so don't set SNOCD.
1667c478bdstevel@tonic-gate	 */
1677c478bdstevel@tonic-gate	if (type == PRIV_PERMITTED && (p->p_flag & SNOCD) == 0 &&
1687c478bdstevel@tonic-gate	    cr->cr_uid != 0 && cr->cr_ruid != 0 && cr->cr_suid != 0) {
1697c478bdstevel@tonic-gate		priv_set_t diff = CR_OPPRIV(cr);
1707c478bdstevel@tonic-gate		priv_inverse(&diff);
1717c478bdstevel@tonic-gate		priv_intersect(&CR_OPPRIV(pcr), &diff);
1727c478bdstevel@tonic-gate		donocd = !priv_issubset(&diff, &CR_IPRIV(cr));
1737c478bdstevel@tonic-gate	}
1747c478bdstevel@tonic-gate
1757c478bdstevel@tonic-gate	p->p_cred = cr;
1767c478bdstevel@tonic-gate	mutex_exit(&p->p_crlock);
1777c478bdstevel@tonic-gate
1787c478bdstevel@tonic-gate	if (donocd) {
1797c478bdstevel@tonic-gate		mutex_enter(&p->p_lock);
1807c478bdstevel@tonic-gate		p->p_flag |= SNOCD;
1817c478bdstevel@tonic-gate		mutex_exit(&p->p_lock);
1827c478bdstevel@tonic-gate	}
1837c478bdstevel@tonic-gate
184634e26eCasper H.S. Dik	/*
185634e26eCasper H.S. Dik	 * The basic_test privilege should not be removed from E;
186634e26eCasper H.S. Dik	 * if that has happened, then some programmer typically set the E/P to
187634e26eCasper H.S. Dik	 * empty. That is not portable.
188634e26eCasper H.S. Dik	 */
189d93c0b4Casper H.S. Dik	if ((type == PRIV_EFFECTIVE || type == PRIV_PERMITTED) &&
190634e26eCasper H.S. Dik	    priv_basic_test >= 0 && !PRIV_ISASSERT(target, priv_basic_test)) {
191634e26eCasper H.S. Dik		proc_t *p = curproc;
192634e26eCasper H.S. Dik		pid_t pid = p->p_pid;
193634e26eCasper H.S. Dik		char *fn = PTOU(p)->u_comm;
194634e26eCasper H.S. Dik
195634e26eCasper H.S. Dik		cmn_err(CE_WARN, "%s[%d]: setppriv: basic_test privilege "
196634e26eCasper H.S. Dik		    "removed from E/P", fn, pid);
197634e26eCasper H.S. Dik	}
198634e26eCasper H.S. Dik
1997c478bdstevel@tonic-gate	crset(p, cr);		/* broadcast to process threads */
2007c478bdstevel@tonic-gate
2017c478bdstevel@tonic-gate	return (0);
2027c478bdstevel@tonic-gate}
2037c478bdstevel@tonic-gate
2047c478bdstevel@tonic-gate/*
2057c478bdstevel@tonic-gate * getppriv (priv_ptype_t, priv_set_t *)
2067c478bdstevel@tonic-gate */
2077c478bdstevel@tonic-gatestatic int
2087c478bdstevel@tonic-gategetppriv(priv_ptype_t type, priv_set_t *pset)
2097c478bdstevel@tonic-gate{
2107c478bdstevel@tonic-gate	if (!PRIV_VALIDSET(type))
2117c478bdstevel@tonic-gate		return (set_errno(EINVAL));
2127c478bdstevel@tonic-gate
2137c478bdstevel@tonic-gate	if (copyout(priv_getset(CRED(), type), pset, sizeof (priv_set_t)) != 0)
2147c478bdstevel@tonic-gate		return (set_errno(EFAULT));
2157c478bdstevel@tonic-gate
2167c478bdstevel@tonic-gate	return (0);
2177c478bdstevel@tonic-gate}
2187c478bdstevel@tonic-gate
2197c478bdstevel@tonic-gatestatic int
2207c478bdstevel@tonic-gategetprivimplinfo(void *buf, size_t bufsize)
2217c478bdstevel@tonic-gate{
2227c478bdstevel@tonic-gate	int err;
2237c478bdstevel@tonic-gate
2247c478bdstevel@tonic-gate	err = copyout(priv_hold_implinfo(), buf, min(bufsize, privinfosize));
2257c478bdstevel@tonic-gate
2267c478bdstevel@tonic-gate	priv_release_implinfo();
2277c478bdstevel@tonic-gate
2287c478bdstevel@tonic-gate	if (err)
2297c478bdstevel@tonic-gate		return (set_errno(EFAULT));
2307c478bdstevel@tonic-gate
2317c478bdstevel@tonic-gate	return (0);
2327c478bdstevel@tonic-gate}
2337c478bdstevel@tonic-gate
2347c478bdstevel@tonic-gate/*
23545916cdjpk * Set process flags in the given target cred.  If NULL is specified, then
23645916cdjpk * CRED() is used; otherwise the cred is assumed to be modifiable (i.e. newly
23745916cdjpk * crdup'ed, or equivalent).  Some flags are set in the proc rather than cred;
23845916cdjpk * for these, curproc is always used.
2397c478bdstevel@tonic-gate *
2407c478bdstevel@tonic-gate * For now we cheat: the flags are actually bit masks so we can simplify
2417c478bdstevel@tonic-gate * some; we do make sure that the arguments are valid, though.
2427c478bdstevel@tonic-gate */
2437c478bdstevel@tonic-gate
24445916cdjpkint
24545916cdjpksetpflags(uint_t flag, uint_t val, cred_t *tcr)
2467c478bdstevel@tonic-gate{
2477c478bdstevel@tonic-gate	cred_t *cr, *pcr;
2487c478bdstevel@tonic-gate	proc_t *p = curproc;
2497c478bdstevel@tonic-gate	uint_t newflags;
25045916cdjpk	boolean_t use_curcred = (tcr == NULL);
2517c478bdstevel@tonic-gate
2527c478bdstevel@tonic-gate	if (val > 1 || (flag != PRIV_DEBUG && flag != PRIV_AWARE &&
25345916cdjpk	    flag != NET_MAC_AWARE && flag != NET_MAC_AWARE_INHERIT &&
254982b4adCasper H.S. Dik	    flag != __PROC_PROTECT && flag != PRIV_XPOLICY &&
255134a1f4Casper H.S. Dik	    flag != PRIV_AWARE_RESET && flag != PRIV_PFEXEC)) {
25645916cdjpk		return (EINVAL);
2577c478bdstevel@tonic-gate	}
2587c478bdstevel@tonic-gate
2597c478bdstevel@tonic-gate	if (flag == __PROC_PROTECT) {
2607c478bdstevel@tonic-gate		mutex_enter(&p->p_lock);
2617c478bdstevel@tonic-gate		if (val == 0)
2627c478bdstevel@tonic-gate			p->p_flag &= ~SNOCD;
2637c478bdstevel@tonic-gate		else
2647c478bdstevel@tonic-gate			p->p_flag |= SNOCD;
2657c478bdstevel@tonic-gate		mutex_exit(&p->p_lock);
2667c478bdstevel@tonic-gate		return (0);
2677c478bdstevel@tonic-gate	}
2687c478bdstevel@tonic-gate
26945916cdjpk	if (use_curcred) {
27045916cdjpk		cr = cralloc();
27145916cdjpk		mutex_enter(&p->p_crlock);
27245916cdjpk		pcr = p->p_cred;
27345916cdjpk	} else {
27445916cdjpk		cr = pcr = tcr;
27545916cdjpk	}
2767c478bdstevel@tonic-gate
2777c478bdstevel@tonic-gate	newflags = CR_FLAGS(pcr);
2787c478bdstevel@tonic-gate
279982b4adCasper H.S. Dik	if (val != 0) {
280982b4adCasper H.S. Dik		if (flag == PRIV_AWARE)
281982b4adCasper H.S. Dik			newflags &= ~PRIV_AWARE_RESET;
2827c478bdstevel@tonic-gate		newflags |= flag;
283982b4adCasper H.S. Dik	} else {
2847c478bdstevel@tonic-gate		newflags &= ~flag;
285982b4adCasper H.S. Dik	}
2867c478bdstevel@tonic-gate
2877c478bdstevel@tonic-gate	/* No change */
2887c478bdstevel@tonic-gate	if (CR_FLAGS(pcr) == newflags) {
28945916cdjpk		if (use_curcred) {
29045916cdjpk			mutex_exit(&p->p_crlock);
29145916cdjpk			crfree(cr);
29245916cdjpk		}
2937c478bdstevel@tonic-gate		return (0);
2947c478bdstevel@tonic-gate	}
2957c478bdstevel@tonic-gate
29645916cdjpk	/*
29797bedc9gfaden	 * Setting either the NET_MAC_AWARE or NET_MAC_AWARE_INHERIT
29897bedc9gfaden	 * flags is a restricted operation.
29997bedc9gfaden	 *
30097bedc9gfaden	 * When invoked via the PRIVSYS_SETPFLAGS syscall
30197bedc9gfaden	 * we require that the current cred has the net_mac_aware
30297bedc9gfaden	 * privilege in its effective set.
30397bedc9gfaden	 *
30497bedc9gfaden	 * When called from within the kernel by label-aware
30597bedc9gfaden	 * services such as NFS, we don't require a privilege check.
30697bedc9gfaden	 *
30745916cdjpk	 */
30845916cdjpk	if ((flag == NET_MAC_AWARE || flag == NET_MAC_AWARE_INHERIT) &&
30945916cdjpk	    (val == 1) && use_curcred) {
31097bedc9gfaden		if (secpolicy_net_mac_aware(pcr) != 0) {
31145916cdjpk			mutex_exit(&p->p_crlock);
31245916cdjpk			crfree(cr);
31345916cdjpk			return (EPERM);
31445916cdjpk		}
31545916cdjpk	}
31645916cdjpk
3177c478bdstevel@tonic-gate	/* Trying to unset PA; if we can't, return an error */
3187c478bdstevel@tonic-gate	if (flag == PRIV_AWARE && val == 0 && !priv_can_clear_PA(pcr)) {
31945916cdjpk		if (use_curcred) {
32045916cdjpk			mutex_exit(&p->p_crlock);
32145916cdjpk			crfree(cr);
32245916cdjpk		}
32345916cdjpk		return (EPERM);
3247c478bdstevel@tonic-gate	}
3257c478bdstevel@tonic-gate
3267c478bdstevel@tonic-gate	/* Committed to changing the flag */
32745916cdjpk	if (use_curcred)
32845916cdjpk		crcopy_to(pcr, cr);
3297c478bdstevel@tonic-gate	if (flag == PRIV_AWARE) {
3307c478bdstevel@tonic-gate		if (val != 0)
3317c478bdstevel@tonic-gate			priv_set_PA(cr);
3327c478bdstevel@tonic-gate		else
3337c478bdstevel@tonic-gate			priv_adjust_PA(cr);
3347c478bdstevel@tonic-gate	} else {
3357c478bdstevel@tonic-gate		CR_FLAGS(cr) = newflags;
3367c478bdstevel@tonic-gate	}
3377c478bdstevel@tonic-gate
338ddf7fe9casper	/*
339ddf7fe9casper	 * Unsetting the flag has as side effect getting rid of
340ddf7fe9casper	 * the per-credential policy.
341ddf7fe9casper	 */
342ddf7fe9casper	if (flag == PRIV_XPOLICY && val == 0)
343ddf7fe9casper		crsetcrklpd(cr, NULL);
344ddf7fe9casper
34545916cdjpk	if (use_curcred) {
34645916cdjpk		p->p_cred = cr;
34745916cdjpk		mutex_exit(&p->p_crlock);
34845916cdjpk		crset(p, cr);
34945916cdjpk	}
3507c478bdstevel@tonic-gate
3517c478bdstevel@tonic-gate	return (0);
3527c478bdstevel@tonic-gate}
3537c478bdstevel@tonic-gate
3547c478bdstevel@tonic-gate/*
3557c478bdstevel@tonic-gate * Getpflags.  Currently only implements single bit flags.
3567c478bdstevel@tonic-gate */
35745916cdjpkuint_t
35845916cdjpkgetpflags(uint_t flag, const cred_t *cr)
3597c478bdstevel@tonic-gate{
36045916cdjpk	if (flag != PRIV_DEBUG && flag != PRIV_AWARE &&
361ddf7fe9casper	    flag != NET_MAC_AWARE && flag != NET_MAC_AWARE_INHERIT &&
362134a1f4Casper H.S. Dik	    flag != PRIV_XPOLICY && flag != PRIV_PFEXEC &&
363134a1f4Casper H.S. Dik	    flag != PRIV_AWARE_RESET)
36445916cdjpk		return ((uint_t)-1);
3657c478bdstevel@tonic-gate
36645916cdjpk	return ((CR_FLAGS(cr) & flag) != 0);
3677c478bdstevel@tonic-gate}
3687c478bdstevel@tonic-gate
3697c478bdstevel@tonic-gate/*
3707c478bdstevel@tonic-gate * Privilege system call entry point
3717c478bdstevel@tonic-gate */
3727c478bdstevel@tonic-gateint
373ddf7fe9casperprivsys(int code, priv_op_t op, priv_ptype_t type, void *buf, size_t bufsize,
374ddf7fe9casper    int itype)
3757c478bdstevel@tonic-gate{
37645916cdjpk	int retv;
377f48205bcasper	extern int issetugid(void);
37845916cdjpk
3797c478bdstevel@tonic-gate	switch (code) {
3807c478bdstevel@tonic-gate	case PRIVSYS_SETPPRIV:
3817c478bdstevel@tonic-gate		if (bufsize < sizeof (priv_set_t))
3827c478bdstevel@tonic-gate			return (set_errno(ENOMEM));
3837c478bdstevel@tonic-gate		return (setppriv(op, type, buf));
3847c478bdstevel@tonic-gate	case PRIVSYS_GETPPRIV:
3857c478bdstevel@tonic-gate		if (bufsize < sizeof (priv_set_t))
3867c478bdstevel@tonic-gate			return (set_errno(ENOMEM));
3877c478bdstevel@tonic-gate		return (getppriv(type, buf));
3887c478bdstevel@tonic-gate	case PRIVSYS_GETIMPLINFO:
3897c478bdstevel@tonic-gate		return (getprivimplinfo(buf, bufsize));
3907c478bdstevel@tonic-gate	case PRIVSYS_SETPFLAGS:
39145916cdjpk		retv = setpflags((uint_t)op, (uint_t)type, NULL);
39245916cdjpk		return (retv != 0 ? set_errno(retv) : 0);
3937c478bdstevel@tonic-gate	case PRIVSYS_GETPFLAGS:
39445916cdjpk		retv = (int)getpflags((uint_t)op, CRED());
39545916cdjpk		return (retv == -1 ? set_errno(EINVAL) : retv);
396f48205bcasper	case PRIVSYS_ISSETUGID:
397f48205bcasper		return (issetugid());
398ddf7fe9casper	case PRIVSYS_KLPD_REG:
399ddf7fe9casper		if (bufsize < sizeof (priv_set_t))
400ddf7fe9casper			return (set_errno(ENOMEM));
401ddf7fe9casper		return ((int)klpd_reg((int)op, (idtype_t)itype, (id_t)type,
402ddf7fe9casper		    buf));
403ddf7fe9casper	case PRIVSYS_KLPD_UNREG:
404ddf7fe9casper		return ((int)klpd_unreg((int)op, (idtype_t)itype, (id_t)type));
405134a1f4Casper H.S. Dik	case PRIVSYS_PFEXEC_REG:
406134a1f4Casper H.S. Dik		return ((int)pfexec_reg((int)op));
407134a1f4Casper H.S. Dik	case PRIVSYS_PFEXEC_UNREG:
408134a1f4Casper H.S. Dik		return ((int)pfexec_unreg((int)op));
4097c478bdstevel@tonic-gate	}
4107c478bdstevel@tonic-gate	return (set_errno(EINVAL));
4117c478bdstevel@tonic-gate}
4127c478bdstevel@tonic-gate
4137c478bdstevel@tonic-gate#ifdef _SYSCALL32_IMPL
4147c478bdstevel@tonic-gateint
415ddf7fe9casperprivsys32(int code, priv_op_t op, priv_ptype_t type, caddr32_t buf,
416ddf7fe9casper    size32_t bufsize, int itype)
4177c478bdstevel@tonic-gate{
418ddf7fe9casper	return (privsys(code, op, type, (void *)(uintptr_t)buf,
419ddf7fe9casper	    (size_t)bufsize, itype));
4207c478bdstevel@tonic-gate}
4217c478bdstevel@tonic-gate#endif
422