xref: /illumos-gate/usr/src/uts/common/sys/policy.h (revision 2b24ab6b)
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
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * 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 /*
22f53eecf5SJames Carlson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_POLICY_H
277c478bd9Sstevel@tonic-gate #define	_SYS_POLICY_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/cred.h>
317c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
327c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef _KERNEL
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef _IN_PORT_T
417c478bd9Sstevel@tonic-gate #define	_IN_PORT_T
427c478bd9Sstevel@tonic-gate typedef uint16_t in_port_t;
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Policy routines; in case we check privileges in-line.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * priv_policy
497c478bd9Sstevel@tonic-gate  *		privilege debugging
507c478bd9Sstevel@tonic-gate  *		audits success & failure
517c478bd9Sstevel@tonic-gate  *		returns 0 on success, error on failure
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * priv_policy_choice
547c478bd9Sstevel@tonic-gate  *		determines extend of operation
557c478bd9Sstevel@tonic-gate  *		audit on success
567c478bd9Sstevel@tonic-gate  * 		returns a boolean_t indicating success (B_TRUE) or failure.
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * priv_policy_only
597c478bd9Sstevel@tonic-gate  *		when auditing is in appropriate (interrupt context)
607c478bd9Sstevel@tonic-gate  *		to determine context of operation
617c478bd9Sstevel@tonic-gate  * 		returns a boolean_t indicating success (B_TRUE) or failure.
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate int priv_policy(const cred_t *, int, boolean_t, int, const char *);
657c478bd9Sstevel@tonic-gate boolean_t priv_policy_only(const cred_t *, int, boolean_t);
667c478bd9Sstevel@tonic-gate boolean_t priv_policy_choice(const cred_t *, int, boolean_t);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate struct kipc_perm;
697c478bd9Sstevel@tonic-gate struct vfs;
707c478bd9Sstevel@tonic-gate struct proc;
71ddf7fe95Scasper struct priv_set;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate int secpolicy_acct(const cred_t *);
74ddf7fe95Scasper int secpolicy_require_privs(const cred_t *, const struct priv_set *);
757c478bd9Sstevel@tonic-gate int secpolicy_allow_setid(const cred_t *, uid_t, boolean_t);
767c478bd9Sstevel@tonic-gate int secpolicy_audit_config(const cred_t *);
777c478bd9Sstevel@tonic-gate int secpolicy_audit_getattr(const cred_t *);
787c478bd9Sstevel@tonic-gate int secpolicy_audit_modify(const cred_t *);
797c478bd9Sstevel@tonic-gate int secpolicy_blacklist(const cred_t *);
807c478bd9Sstevel@tonic-gate int secpolicy_chroot(const cred_t *);
817c478bd9Sstevel@tonic-gate int secpolicy_clock_highres(const cred_t *);
827c478bd9Sstevel@tonic-gate int secpolicy_console(const cred_t *);
837b209c2cSacruz int secpolicy_contract_identity(const cred_t *);
847c478bd9Sstevel@tonic-gate int secpolicy_contract_observer(const cred_t *, struct contract *);
857c478bd9Sstevel@tonic-gate boolean_t secpolicy_contract_observer_choice(const cred_t *);
867c478bd9Sstevel@tonic-gate int secpolicy_contract_event(const cred_t *);
877c478bd9Sstevel@tonic-gate boolean_t secpolicy_contract_event_choice(const cred_t *);
887c478bd9Sstevel@tonic-gate int secpolicy_coreadm(const cred_t *);
897c478bd9Sstevel@tonic-gate int secpolicy_cpc_cpu(const cred_t *);
907c478bd9Sstevel@tonic-gate int secpolicy_dispadm(const cred_t *);
917aec1d6eScindi int secpolicy_error_inject(const cred_t *);
927c478bd9Sstevel@tonic-gate int secpolicy_excl_open(const cred_t *);
937c478bd9Sstevel@tonic-gate int secpolicy_fs_mount(cred_t *, vnode_t *, struct vfs *);
947c478bd9Sstevel@tonic-gate int secpolicy_fs_unmount(cred_t *, struct vfs *);
957c478bd9Sstevel@tonic-gate int secpolicy_fs_config(const cred_t *, const struct vfs *);
967c478bd9Sstevel@tonic-gate int secpolicy_fs_linkdir(const cred_t *, const struct vfs *);
977c478bd9Sstevel@tonic-gate int secpolicy_fs_minfree(const cred_t *, const struct vfs *);
987c478bd9Sstevel@tonic-gate int secpolicy_fs_quota(const cred_t *, const struct vfs *);
99f48205beScasper int secpolicy_idmap(const cred_t *);
100f4b3ec61Sdh int secpolicy_ip(const cred_t *, int, boolean_t);
101f4b3ec61Sdh int secpolicy_ip_config(const cred_t *, boolean_t);
102eae72b5bSSebastien Roy int secpolicy_dl_config(const cred_t *);
103*2b24ab6bSSebastien Roy int secpolicy_iptun_config(const cred_t *);
1047c478bd9Sstevel@tonic-gate int secpolicy_ipc_access(const cred_t *, const struct kipc_perm *, mode_t);
1057c478bd9Sstevel@tonic-gate int secpolicy_ipc_config(const cred_t *);
1067c478bd9Sstevel@tonic-gate int secpolicy_ipc_owner(const cred_t *, const struct kipc_perm *);
1077c478bd9Sstevel@tonic-gate int secpolicy_kmdb(const cred_t *);
1087c478bd9Sstevel@tonic-gate int secpolicy_lock_memory(const cred_t *);
1097c478bd9Sstevel@tonic-gate int secpolicy_modctl(const cred_t *, int);
1107c478bd9Sstevel@tonic-gate int secpolicy_net(const cred_t *, int, boolean_t);
11145916cd2Sjpk int secpolicy_net_bindmlp(const cred_t *);
1127c478bd9Sstevel@tonic-gate int secpolicy_net_config(const cred_t *, boolean_t);
1137c478bd9Sstevel@tonic-gate int secpolicy_net_icmpaccess(const cred_t *);
11445916cd2Sjpk int secpolicy_net_mac_aware(const cred_t *);
115ddf7fe95Scasper int secpolicy_net_privaddr(const cred_t *, in_port_t, int proto);
1167c478bd9Sstevel@tonic-gate int secpolicy_net_rawaccess(const cred_t *);
11745916cd2Sjpk boolean_t secpolicy_net_reply_equal(const cred_t *);
1187c478bd9Sstevel@tonic-gate int secpolicy_newproc(const cred_t *);
1197c478bd9Sstevel@tonic-gate int secpolicy_nfs(const cred_t *);
1207c478bd9Sstevel@tonic-gate int secpolicy_pcfs_modify_bootpartition(const cred_t *);
1217c478bd9Sstevel@tonic-gate int secpolicy_ponline(const cred_t *);
1227c478bd9Sstevel@tonic-gate int secpolicy_pool(const cred_t *);
1237c478bd9Sstevel@tonic-gate int secpolicy_power_mgmt(const cred_t *);
124f53eecf5SJames Carlson int secpolicy_ppp_config(const cred_t *);
1257c478bd9Sstevel@tonic-gate int secpolicy_proc_access(const cred_t *);
1267c478bd9Sstevel@tonic-gate int secpolicy_proc_excl_open(const cred_t *);
1277c478bd9Sstevel@tonic-gate int secpolicy_proc_owner(const cred_t *, const cred_t *, int);
1287c478bd9Sstevel@tonic-gate int secpolicy_proc_zone(const cred_t *);
1297c478bd9Sstevel@tonic-gate int secpolicy_pset(const cred_t *);
1307c478bd9Sstevel@tonic-gate int secpolicy_rctlsys(const cred_t *, boolean_t);
1317c478bd9Sstevel@tonic-gate int secpolicy_resource(const cred_t *);
1321c7cef2bSStan Studzinski int secpolicy_resource_anon_mem(const cred_t *);
1337c478bd9Sstevel@tonic-gate int secpolicy_rpcmod_open(const cred_t *);
1347c478bd9Sstevel@tonic-gate int secpolicy_rsm_access(const cred_t *, uid_t, mode_t);
1357c478bd9Sstevel@tonic-gate int secpolicy_setpriority(const cred_t *);
1367c478bd9Sstevel@tonic-gate int secpolicy_settime(const cred_t *);
137da6c28aaSamw int secpolicy_smb(const cred_t *);
1384bff34e3Sthurlow int secpolicy_smbfs_login(const cred_t *, uid_t);
1397c478bd9Sstevel@tonic-gate int secpolicy_spec_open(const cred_t *, struct vnode *, int);
1407c478bd9Sstevel@tonic-gate int secpolicy_sti(const cred_t *);
1417c478bd9Sstevel@tonic-gate int secpolicy_swapctl(const cred_t *);
1427c478bd9Sstevel@tonic-gate int secpolicy_sys_config(const cred_t *, boolean_t);
1437c478bd9Sstevel@tonic-gate int secpolicy_zone_admin(const cred_t *, boolean_t);
1447c478bd9Sstevel@tonic-gate int secpolicy_zone_config(const cred_t *);
1457c478bd9Sstevel@tonic-gate int secpolicy_sys_devices(const cred_t *);
1467c478bd9Sstevel@tonic-gate int secpolicy_systeminfo(const cred_t *);
1477c478bd9Sstevel@tonic-gate int secpolicy_tasksys(const cred_t *);
1487c478bd9Sstevel@tonic-gate int secpolicy_vnode_access(const cred_t *, vnode_t *, uid_t, mode_t);
149e02bc683SMark Shellenbaum int secpolicy_vnode_chown(const cred_t *, uid_t);
1507c478bd9Sstevel@tonic-gate int secpolicy_vnode_create_gid(const cred_t *);
1517c478bd9Sstevel@tonic-gate int secpolicy_vnode_owner(const cred_t *, uid_t);
1527c478bd9Sstevel@tonic-gate int secpolicy_vnode_remove(const cred_t *);
1537c478bd9Sstevel@tonic-gate int secpolicy_vnode_setdac(const cred_t *, uid_t);
1547c478bd9Sstevel@tonic-gate int secpolicy_vnode_setid_retain(const cred_t *, boolean_t);
1557c478bd9Sstevel@tonic-gate int secpolicy_vnode_setids_setgids(const cred_t *, gid_t);
1567c478bd9Sstevel@tonic-gate int secpolicy_vnode_stky_modify(const cred_t *);
157911106dfSjm int secpolicy_vscan(const cred_t *);
158ea8dc4b6Seschrock int secpolicy_zinject(const cred_t *);
159fa9e4066Sahrens int secpolicy_zfs(const cred_t *);
1602449e17fSsherrym int secpolicy_ucode_update(const cred_t *);
161e6bdcbd5Sdh int secpolicy_sadopen(const cred_t *);
16213f9f30eSmarks void secpolicy_setid_clear(vattr_t *, cred_t *);
163ecd6cf80Smarks void secpolicy_fs_mount_clearopts(cred_t *, struct vfs *);
164f92daba9Smarks int secpolicy_setid_setsticky_clear(vnode_t *, vattr_t *,
165f92daba9Smarks     const vattr_t *, cred_t *);
166da6c28aaSamw int secpolicy_xvattr(xvattr_t *, uid_t, cred_t *, vtype_t);
167b26a64aeSjohnlev int secpolicy_xvm_control(const cred_t *);
1687c478bd9Sstevel@tonic-gate 
169ddf7fe95Scasper int secpolicy_basic_exec(const cred_t *, vnode_t *);
1707c478bd9Sstevel@tonic-gate int secpolicy_basic_fork(const cred_t *);
171ddf7fe95Scasper int secpolicy_basic_link(const cred_t *);
1727c478bd9Sstevel@tonic-gate int secpolicy_basic_proc(const cred_t *);
1737c478bd9Sstevel@tonic-gate int secpolicy_basic_procinfo(const cred_t *, struct proc *, struct proc *);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate int secpolicy_gart_access(const cred_t *);
1767c478bd9Sstevel@tonic-gate int secpolicy_gart_map(const cred_t *);
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate  * This function to be called from xxfs_setattr().
1797c478bd9Sstevel@tonic-gate  * Must be called with the node's attributes read-write locked.
1807c478bd9Sstevel@tonic-gate  *
1817c478bd9Sstevel@tonic-gate  *		cred_t *		- acting credentials
1827c478bd9Sstevel@tonic-gate  *		struct vnode *		- vnode we're operating on
1837c478bd9Sstevel@tonic-gate  *		struct vattr *va	- new attributes, va_mask may be
1847c478bd9Sstevel@tonic-gate  *					  changed on return from a call
1857c478bd9Sstevel@tonic-gate  *		struct vattr *oldva	- old attributes, need include owner
1867c478bd9Sstevel@tonic-gate  *					  and mode only
1877c478bd9Sstevel@tonic-gate  *		int flags		- setattr flags
1887c478bd9Sstevel@tonic-gate  *		int iaccess(void *node, int mode, cred_t *cr)
1897c478bd9Sstevel@tonic-gate  *					- non-locking internal access function
1907c478bd9Sstevel@tonic-gate  *						mode be checked
1917c478bd9Sstevel@tonic-gate  *						w/ VREAD|VWRITE|VEXEC, not fs
1927c478bd9Sstevel@tonic-gate  *						internal mode encoding.
1937c478bd9Sstevel@tonic-gate  *
1947c478bd9Sstevel@tonic-gate  *		void *node		- internal node (inode, tmpnode) to
1957c478bd9Sstevel@tonic-gate  *					  pass as arg to iaccess
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate int secpolicy_vnode_setattr(cred_t *, struct vnode *, struct vattr *,
1987c478bd9Sstevel@tonic-gate     const struct vattr *, int, int (void *, int, cred_t *), void *);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * Test privilege. Audit success or failure, allow privilege debugging.
2027c478bd9Sstevel@tonic-gate  * Returns 0 for success, err for failure.
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate #define	PRIV_POLICY(cred, priv, all, err, reason) \
2057c478bd9Sstevel@tonic-gate 		priv_policy((cred), (priv), (all), (err), (reason))
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * Test privilege. Audit success only, no privilege debugging.
2097c478bd9Sstevel@tonic-gate  * Returns 1 for success, and 0 for failure.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate #define	PRIV_POLICY_CHOICE(cred, priv, all) \
2127c478bd9Sstevel@tonic-gate 		priv_policy_choice((cred), (priv), (all))
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate  * Test privilege. No priv_debugging, no auditing.
2167c478bd9Sstevel@tonic-gate  * Returns 1 for success, and 0 for failure.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate #define	PRIV_POLICY_ONLY(cred, priv, all) \
2207c478bd9Sstevel@tonic-gate 		priv_policy_only((cred), (priv), (all))
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #endif
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate #endif
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #endif	/* _SYS_POLICY_H */
230