capsicum_helpers: Add LOOKUP flag

Add a helper routine for opening a directory that is restricted to being
used for opening relative files as stdio streams.

I think this will really help basic adaptation of multi-file programs to
Capsicum. Rather than having each program initialize a rights object and
ioctl/fcntl arrays for their root fd for relative opens, consolidate in the
logical place.

Reviewed by:	oshogbo@
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8743
This commit is contained in:
Conrad Meyer 2016-12-16 01:37:44 +00:00
parent 6e183b4b25
commit 6a1c4d1efc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310135

View File

@ -41,6 +41,7 @@
#define CAPH_IGNORE_EBADF 0x0001
#define CAPH_READ 0x0002
#define CAPH_WRITE 0x0004
#define CAPH_LOOKUP 0x0008
static __inline int
caph_limit_stream(int fd, int flags)
@ -54,6 +55,8 @@ caph_limit_stream(int fd, int flags)
cap_rights_set(&rights, CAP_READ);
if ((flags & CAPH_WRITE) != 0)
cap_rights_set(&rights, CAP_WRITE);
if ((flags & CAPH_LOOKUP) != 0)
cap_rights_set(&rights, CAP_LOOKUP);
if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) {
if (errno == EBADF && (flags & CAPH_IGNORE_EBADF) != 0)