libcasper: fix cap_rights_init usage

Capability rights passed to cap_rights_* are not simple bitmaks and
cannot be ORed together in general (although it will work for certain
subsets of rights).

PR:		277057
Fixes:		faaf43b2a7 ("fileargs: add tests")
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 3733d82c4d)
(cherry picked from commit be83aa2a01)
This commit is contained in:
Ed Maste 2024-02-14 19:42:48 -05:00
parent 8a17cc127b
commit ec44cc4e28

View File

@ -281,7 +281,7 @@ ATF_TC_BODY(fileargs__open_read, tc)
prepare_files(MAX_FILES, true);
cap_rights_init(&rights, CAP_READ | CAP_FCNTL);
cap_rights_init(&rights, CAP_READ, CAP_FCNTL);
cap_rights_init(&norights, CAP_WRITE);
fa = fileargs_init(MAX_FILES, files, O_RDONLY, 0, &rights,
FA_OPEN);
@ -326,7 +326,7 @@ ATF_TC_BODY(fileargs__open_write, tc)
prepare_files(MAX_FILES, true);
cap_rights_init(&rights, CAP_WRITE | CAP_FCNTL);
cap_rights_init(&rights, CAP_WRITE, CAP_FCNTL);
cap_rights_init(&norights, CAP_READ);
fa = fileargs_init(MAX_FILES, files, O_WRONLY, 0, &rights,
FA_OPEN);
@ -371,7 +371,7 @@ ATF_TC_BODY(fileargs__open_create, tc)
prepare_files(MAX_FILES, false);
cap_rights_init(&rights, CAP_WRITE | CAP_FCNTL | CAP_READ);
cap_rights_init(&rights, CAP_WRITE, CAP_FCNTL, CAP_READ);
cap_rights_init(&norights, CAP_FCHMOD);
fa = fileargs_init(MAX_FILES, files, O_RDWR | O_CREAT, 666,
&rights, FA_OPEN);
@ -448,7 +448,7 @@ ATF_TC_BODY(fileargs__fopen_read, tc)
prepare_files(MAX_FILES, true);
cap_rights_init(&rights, CAP_READ | CAP_FCNTL);
cap_rights_init(&rights, CAP_READ, CAP_FCNTL);
cap_rights_init(&norights, CAP_WRITE);
fa = fileargs_init(MAX_FILES, files, O_RDONLY, 0, &rights,
FA_OPEN);
@ -496,7 +496,7 @@ ATF_TC_BODY(fileargs__fopen_write, tc)
prepare_files(MAX_FILES, true);
cap_rights_init(&rights, CAP_WRITE | CAP_FCNTL);
cap_rights_init(&rights, CAP_WRITE, CAP_FCNTL);
cap_rights_init(&norights, CAP_READ);
fa = fileargs_init(MAX_FILES, files, O_WRONLY, 0, &rights,
FA_OPEN);
@ -544,7 +544,7 @@ ATF_TC_BODY(fileargs__fopen_create, tc)
prepare_files(MAX_FILES, false);
cap_rights_init(&rights, CAP_READ | CAP_WRITE | CAP_FCNTL);
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FCNTL);
fa = fileargs_init(MAX_FILES, files, O_RDWR | O_CREAT, 0, &rights,
FA_OPEN);
ATF_REQUIRE(fa != NULL);
@ -646,7 +646,7 @@ ATF_TC_BODY(fileargs__open_lstat, tc)
prepare_files(MAX_FILES, true);
cap_rights_init(&rights, CAP_READ | CAP_FCNTL);
cap_rights_init(&rights, CAP_READ, CAP_FCNTL);
cap_rights_init(&norights, CAP_WRITE);
fa = fileargs_init(MAX_FILES, files, O_RDONLY, 0, &rights,
FA_OPEN | FA_LSTAT);
@ -692,7 +692,7 @@ ATF_TC_BODY(fileargs__open_realpath, tc)
prepare_files(MAX_FILES, true);
cap_rights_init(&rights, CAP_READ | CAP_FCNTL);
cap_rights_init(&rights, CAP_READ, CAP_FCNTL);
cap_rights_init(&norights, CAP_WRITE);
fa = fileargs_init(MAX_FILES, files, O_RDONLY, 0, &rights,
FA_OPEN | FA_REALPATH);