freebsd-dev/lib
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
..
atf
bind Update Bind to 9.9.3-P2 2013-08-22 08:15:03 +00:00
clang Upgrade our copy of llvm/clang to 3.3 release. 2013-06-12 18:48:53 +00:00
csu Add a makefle that recurses into the right architecture-specific 2013-05-21 17:47:53 +00:00
libalias
libarchive MFV r248590,248594: 2013-03-22 13:36:03 +00:00
libauditd
libbegemot
libblocksruntime
libbluetooth
libbsm
libbsnmp
libbz2
libc Change the cap_rights_t type from uint64_t to a structure that we can extend 2013-09-05 00:09:56 +00:00
libc++ Add a c++/v1/tr1 include directory containing symlinks to all of the standard 2013-09-04 15:02:14 +00:00
libcalendar
libcam Fix a typo: XPORT_SPI should be tested against transport, nor protocol. 2013-06-03 21:52:19 +00:00
libcom_err
libcompat
libcompiler_rt Unconditionally compile the __sync_* atomics support functions into compiler-rt 2013-08-31 08:50:45 +00:00
libcrypt
libcxxrt Add several missing symbols to libcxxrt's symbol version map, and remove 2013-02-03 20:40:41 +00:00
libdevinfo
libdevstat
libdwarf When decoding SLEB128, make sure sign extension is performed for 2013-06-30 21:06:47 +00:00
libedit libedit: Revert r247683 to fix buildworld. 2013-03-03 14:42:15 +00:00
libefi
libelf Add support to the ARM platform specific section types. 2013-08-31 18:13:20 +00:00
libexecinfo Don't install private libexecinfo headers 2013-09-03 13:31:43 +00:00
libexpat Update base system libexpat to 2.1.0. 2013-02-26 00:58:44 +00:00
libfetch Even though it doesn't really make sense in the context of a CONNECT 2013-08-22 07:43:36 +00:00
libgeom Since there's no defined schema for the XML that's generated by the 2013-07-19 06:42:15 +00:00
libgpib
libgssapi
libiconv
libiconv_compat Turn off warns for this do-nothing file. clang noticed. 2013-08-13 08:12:57 +00:00
libiconv_modules As a followup to r252547, propate const down the call stack. 2013-07-03 18:27:45 +00:00
libipsec Improve compatibility with recent flex from flex.sourceforge.net. 2013-05-03 23:51:32 +00:00
libipx
libjail
libkiconv The iconv in libc did two things - implement the standard APIs, the GNU 2013-08-13 07:15:01 +00:00
libkse
libkvm In r227839, when removing libkvm dependency on procfs(5), 2013-07-10 19:44:43 +00:00
libldns Clean up. 2013-04-14 00:59:56 +00:00
liblzma
libmagic
libmandoc
libmd
libmemstat Refine UMA bucket allocation to reduce space consumption and improve 2013-06-18 04:50:20 +00:00
libmilter
libmp
libnandfs
libnetbsd
libnetgraph Fix for quite a special case when userland emulates a netgraph node, and 2013-03-11 13:05:11 +00:00
libngatm
libopie
libpam Make the PAM password strength checking module WARNS=2 safe. 2013-08-27 15:50:26 +00:00
libpcap MFV: libpcap 1.4.0. 2013-05-30 08:02:00 +00:00
libpmc Always install pmc.foo(3) manpages. 2013-05-03 08:20:10 +00:00
libproc Fix the return value when we found a symbol in .dynstr. This nasty bug was 2013-08-10 07:39:15 +00:00
libprocstat Change the cap_rights_t type from uint64_t to a structure that we can extend 2013-09-05 00:09:56 +00:00
libradius mdoc sweep. 2013-05-12 22:22:12 +00:00
librpcsec_gss
librpcsvc
librt Convert this piece of code to use C11 atomics. 2013-06-30 08:59:33 +00:00
librtld_db
libsbuf Add sbuf_start_section and sbuf_end_section to the libsbuf symbol map. 2013-04-11 19:50:10 +00:00
libsdp
libsm Since clang 3.2 now has an option to suppress warnings about implicitly 2013-02-16 20:17:31 +00:00
libsmb
libsmdb
libsmutil
libstand Move pos++ out of the complicated equation, introduced at r240780. 2013-07-01 17:23:13 +00:00
libstdbuf
libstdthreads
libtacplus mdoc sweep. 2013-05-12 22:22:12 +00:00
libtelnet
libthr The SUSv4tc1 requires that pthread_setcancelstate() shall be not a 2013-06-19 04:47:41 +00:00
libthread_db Ensure we set all fpu registers to zero by using the address and size of 2013-08-17 14:42:40 +00:00
libufs
libugidfw
libulog
libusb Add pkgconf files for libusb. 2013-07-25 03:54:08 +00:00
libusbhid
libutil The round of expand_number() cleanups. 2013-08-30 11:21:52 +00:00
libvgl
libvmmapi Remove deprecated APIs to get the total and free memory available to vmm.ko. 2013-04-25 20:42:21 +00:00
libwrap
liby
libyaml Add a stub manpage modeled over the libexpat one to explain to users not to use 2013-03-05 13:06:40 +00:00
libypclnt
libz MFV: Update zlib to 1.2.8. 2013-05-05 06:20:49 +00:00
msun * Whitespace. 2013-08-28 16:59:55 +00:00
ncurses Convert old make variable modifiers :U and :L to bmake :tu and :tl. 2013-06-02 11:44:23 +00:00
Makefile Connect libexecinfo to the build 2013-09-03 15:22:04 +00:00
Makefile.inc