freebsd-dev/sbin
Pawel Jakub Dawidek 7008be5bd7 Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.

The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.

The structure definition looks like this:

	struct cap_rights {
		uint64_t	cr_rights[CAP_RIGHTS_VERSION + 2];
	};

The initial CAP_RIGHTS_VERSION is 0.

The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.

The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.

To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.

	#define	CAP_PDKILL	CAPRIGHT(1, 0x0000000000000800ULL)

We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:

	#define	CAP_LOOKUP	CAPRIGHT(0, 0x0000000000000400ULL)
	#define	CAP_FCHMOD	CAPRIGHT(0, 0x0000000000002000ULL)

	#define	CAP_FCHMODAT	(CAP_FCHMOD | CAP_LOOKUP)

There is new API to manage the new cap_rights_t structure:

	cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
	void cap_rights_set(cap_rights_t *rights, ...);
	void cap_rights_clear(cap_rights_t *rights, ...);
	bool cap_rights_is_set(const cap_rights_t *rights, ...);

	bool cap_rights_is_valid(const cap_rights_t *rights);
	void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
	void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
	bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);

Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:

	cap_rights_t rights;

	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);

There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:

	#define	cap_rights_set(rights, ...)				\
		__cap_rights_set((rights), __VA_ARGS__, 0ULL)
	void __cap_rights_set(cap_rights_t *rights, ...);

Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:

	cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);

Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.

This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.

Sponsored by:	The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
..
adjkerntz Revert r253748,253749 2013-07-28 18:44:17 +00:00
atm In sbin/atm/atmconfig/diag.c, fix a few warnings about format strings 2011-12-17 00:26:45 +00:00
badsect Add missing static keywords for global variables to tools in sbin/. 2011-11-04 13:36:02 +00:00
bsdlabel It seems that libdisk(3) incorrectly sets d_secperunit value. 2012-04-11 06:35:13 +00:00
camcontrol Add missing newlines to Fibre Channel attributes output. 2013-08-27 06:50:46 +00:00
ccdconfig Cross-reference gvinum(8) instead of vinum(8). 2013-03-16 22:02:47 +00:00
clri Switch the default WARNS level for sbin/ to 6. 2009-10-19 16:00:24 +00:00
comcontrol A number of places in the source tree still reference cuad.* after 2012-12-08 22:16:36 +00:00
conscontrol Changed "conscontrol unset" to accept an existing virtual 2011-04-18 20:28:07 +00:00
ddb remove duplicate semicolons where possible. 2012-10-22 03:00:37 +00:00
devd Correct the printf format specifier for total_events. 2013-07-08 21:10:30 +00:00
devfs Clarify how "hide" and "unhide" commands work on directories. 2013-07-12 06:03:25 +00:00
dhclient Change the cap_rights_t type from uint64_t to a structure that we can extend 2013-09-05 00:09:56 +00:00
dmesg Move the check whether the clear flag is set. This has 2 advantages 2013-06-11 17:46:32 +00:00
dump Mark non-returning function as such 2012-11-29 05:16:50 +00:00
dumpfs When running the -m option to generate a newfs(8) command suitable for 2013-05-16 20:07:08 +00:00
dumpon Adapt to the fact that minidumps are now on by default. 2013-04-30 07:22:03 +00:00
etherswitchcfg Typo in strtol(3). 2013-08-30 10:01:19 +00:00
fdisk VMware environment is frequent nowadays. Add VMFS id. 2012-04-16 17:30:19 +00:00
fdisk_pc98 Change <sys/diskpc98.h> to not redefine the same symbols that are 2013-08-07 00:00:48 +00:00
ffsinfo Cross-reference gvinum(8) instead of vinum(8). 2013-03-16 22:02:47 +00:00
fsck Make fsck and fsck_msdosfs WARNS=6 clean 2012-10-21 12:01:19 +00:00
fsck_ffs Fix the zeroing loop. I must have been drunk when I wrote this... 2013-08-20 07:19:58 +00:00
fsck_msdosfs Print a newline after the error message. 2012-11-03 09:18:37 +00:00
fsdb Revert 248634 and 248643 (e.g., restoring 248625 and 248639). 2013-03-23 20:00:02 +00:00
fsirand Fix sbin/ build with a 64-bit ino_t. 2012-09-27 23:31:06 +00:00
gbde Add the Clang specific -Wmissing-variable-declarations to WARNS=6. 2013-04-19 19:45:00 +00:00
geom Note NULL encryption method for GELI 2013-08-05 10:38:34 +00:00
ggate Fix warnings found by -Wmising-variable-declarations. 2012-10-19 05:43:38 +00:00
growfs Allow the use of lowercase 'yes' 2013-05-08 18:55:38 +00:00
gvinum Remove reference to vinum(4). The manual page was removed in r248370. 2013-03-16 21:50:06 +00:00
hastctl Make hastctl(1) ('list' command) output a worker pid. 2013-07-01 18:41:07 +00:00
hastd Change the cap_rights_t type from uint64_t to a structure that we can extend 2013-09-05 00:09:56 +00:00
ifconfig Fix a typo (s/error/errno/). 2013-07-03 09:50:59 +00:00
init init: Set kernel login class and CPU mask on new processes. 2013-08-13 18:51:26 +00:00
ipf Link ipfilter(4) and ipfilter(5) to the build to stop the wrong man page 2012-08-28 12:33:54 +00:00
ipfw Remove duplicated parapgraph. 2013-07-24 08:36:29 +00:00
iscontrol Move the old iSCSI initiator source to a more appropriate place 2013-08-22 14:02:34 +00:00
kldconfig Raise WARNS for various tools where possible. 2010-01-17 21:56:27 +00:00
kldload Remove contractions. 2013-04-11 18:46:41 +00:00
kldstat In printfile(), exit the process instead of only printing the warning. 2010-11-13 16:49:07 +00:00
kldunload Switch the default WARNS level for sbin/ to 6. 2009-10-19 16:00:24 +00:00
ldconfig Add a comment about why aout support is still here: We need it for 2013-03-19 16:57:04 +00:00
mca Fix a variety of compile errors with gcc48 and clang 2012-05-31 08:22:02 +00:00
md5 Add the Clang specific -Wmissing-variable-declarations to WARNS=6. 2013-04-19 19:45:00 +00:00
mdconfig Resolve fflag with realpath(). 2013-07-31 07:06:58 +00:00
mdmfs Remove trailing whitespace per mdoc lint warning 2012-03-29 05:02:12 +00:00
mknod Fix some more warnings found by clang. 2010-11-22 20:10:48 +00:00
mksnap_ffs Note that a UFS filesystem can have up to 20 active snapshots. 2011-02-15 07:25:54 +00:00
mount Minor mdoc fixes. 2013-07-18 05:46:33 +00:00
mount_cd9660 Update the manual page to reflect reality. With r138509 and r152355, 2013-03-05 23:05:43 +00:00
mount_fusefs Fix warnings found by -Wmising-variable-declarations. 2012-10-19 05:43:38 +00:00
mount_msdosfs GC unused variables. Prefer NULL over 0 for pointers. 2013-03-05 22:41:35 +00:00
mount_nfs Document the "gssname" and "allgssname" mount options added by the 2013-07-09 01:31:36 +00:00
mount_nullfs GC unused variables. Prefer NULL over 0 for pointers. 2013-03-05 22:41:35 +00:00
mount_udf Use build_iovec() to make it less cryptic. This also fixes warnings. 2013-03-06 00:36:33 +00:00
mount_unionfs GC unused variables. Prefer NULL over 0 for pointers. 2013-03-05 22:41:35 +00:00
nandfs mdoc: remove superfluous paragraph macro. 2012-05-17 11:29:22 +00:00
natd remove duplicate semicolons where possible. 2012-10-22 03:00:37 +00:00
newfs Remove contractions. 2013-04-11 18:46:41 +00:00
newfs_msdos newfs_msdos: cosmetical cleanups 2013-01-19 03:34:02 +00:00
newfs_nandfs Unbreak the build of newfs_nandfs. 2013-04-21 22:36:14 +00:00
nfsiod - Display current settings when run without options. 2009-12-26 08:36:02 +00:00
nos-tun nos-tun(8): make WARNS=3 clean 2010-03-10 18:51:13 +00:00
nvmecontrol Add message when nvd disks are attached and detached. 2013-07-19 21:40:57 +00:00
pfctl - Get rid of #ifdef __FreeBSD__. 2012-09-29 16:42:01 +00:00
pflogd pflogd does not depend on libutil 2013-01-01 18:28:21 +00:00
ping Check the return error of set[ug]id. While this can never fail in the 2012-10-22 03:31:22 +00:00
ping6 Remove EOL whitespace. 2013-05-08 21:04:19 +00:00
quotacheck Fix sbin/ build with a 64-bit ino_t. 2012-09-27 23:31:06 +00:00
rcorder Fix warnings found by -Wmising-variable-declarations. 2012-10-19 05:43:38 +00:00
reboot Add a new gptboot(8) man page. Factor out the redundant information 2013-07-01 22:38:36 +00:00
recoverdisk Fix 'SEE ALSO' list. 2013-07-12 09:20:55 +00:00
resolvconf Add resolvconf(8) which manages resolv.conf. 2011-03-18 12:18:52 +00:00
restore Check the return error of set[e][ug]id. While this can never fail in the 2012-10-22 03:07:05 +00:00
route Fix boundary check of sockaddr array. 2013-08-01 04:50:46 +00:00
routed mdoc sweep 2013-05-13 18:13:50 +00:00
rtsol Add dump.c to the rtsol build. It is needed now that sec2str is non-static 2011-06-08 21:59:07 +00:00
savecore With rotating kernel dumps the higest dump number is not necessarily the 2012-12-16 23:09:27 +00:00
sconfig Switch the default WARNS level for sbin/ to 6. 2009-10-19 16:00:24 +00:00
setkey Correct prefix for "locally installed things" 2013-01-16 05:03:46 +00:00
shutdown Add simple example. 2013-03-19 21:40:14 +00:00
spppcontrol mdoc: order prologue macros consistently by Dd/Dt/Os 2010-04-14 19:08:06 +00:00
sunlabel mdoc: fix column names, indentation, column separation within each row, and 2012-04-07 09:05:30 +00:00
swapon Make two buffer variables static for now. It is not safe to 2013-07-31 07:09:35 +00:00
sysctl Use the right format string for line buffer. 2013-01-13 04:28:44 +00:00
tunefs Constify string pointers. 2013-05-16 21:04:56 +00:00
umount Fix memory leak in umount.c 2012-11-15 15:06:21 +00:00
Makefile Remove all legacy ATA code parts, not used since options ATA_CAM enabled in 2013-04-04 07:12:24 +00:00
Makefile.amd64 Integrate nvmecontrol(8) into the amd64 and i386 builds. 2012-09-17 21:41:38 +00:00
Makefile.arm MF tbemd: Move to using Makefile.arch to select what to build. 2010-09-13 02:25:21 +00:00
Makefile.i386 Integrate nvmecontrol(8) into the amd64 and i386 builds. 2012-09-17 21:41:38 +00:00
Makefile.ia64 MF tbemd: Move to using Makefile.arch to select what to build. 2010-09-13 02:25:21 +00:00
Makefile.inc Switch the default WARNS level for sbin/ to 6. 2009-10-19 16:00:24 +00:00
Makefile.mips MF tbemd: Move to using Makefile.arch to select what to build. 2010-09-13 02:25:21 +00:00
Makefile.pc98 MF tbemd: Move to using Makefile.arch to select what to build. 2010-09-13 02:25:21 +00:00
Makefile.sparc64 MF tbemd: Move to using Makefile.arch to select what to build. 2010-09-13 02:25:21 +00:00