diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-12 01:09:41 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-10-12 01:09:41 +0000 |
commit | b49bfcb8f0dcb84e532ba4cd4631318bc503245e (patch) | |
tree | acb9cff934a953665142b6e8821d628608a7e498 /tests/libcap_launch_test.c | |
parent | 2c67aea5a983378eec08b22d5879145e797dc4b3 (diff) | |
parent | e61c65778b22599546e46eee12f857dd1c28f89e (diff) | |
download | libcap-b49bfcb8f0dcb84e532ba4cd4631318bc503245e.tar.gz |
Snap for 9163570 from e61c65778b22599546e46eee12f857dd1c28f89e to udc-releaseandroid-vts-14.0_r4android-vts-14.0_r3android-vts-14.0_r2android-vts-14.0_r1android-security-14.0.0_r9android-security-14.0.0_r8android-security-14.0.0_r7android-security-14.0.0_r6android-security-14.0.0_r5android-security-14.0.0_r4android-security-14.0.0_r3android-security-14.0.0_r2android-security-14.0.0_r1android-platform-14.0.0_r8android-platform-14.0.0_r7android-platform-14.0.0_r6android-platform-14.0.0_r5android-platform-14.0.0_r4android-platform-14.0.0_r3android-platform-14.0.0_r2android-platform-14.0.0_r1android-cts-14.0_r4android-cts-14.0_r3android-cts-14.0_r2android-cts-14.0_r1android-14.0.0_r28android-14.0.0_r2android-14.0.0_r15android-14.0.0_r14android-14.0.0_r13android-14.0.0_r1android14-tests-releaseandroid14-security-releaseandroid14-s2-releaseandroid14-s1-releaseandroid14-releaseandroid14-platform-releaseandroid14-gsi
Change-Id: Id045070ed233aea5d1e3fd32ad8174e5018f3d80
Diffstat (limited to 'tests/libcap_launch_test.c')
-rw-r--r-- | tests/libcap_launch_test.c | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/tests/libcap_launch_test.c b/tests/libcap_launch_test.c index bba38c6..f45b2b7 100644 --- a/tests/libcap_launch_test.c +++ b/tests/libcap_launch_test.c @@ -24,7 +24,9 @@ struct test_case_s { const char **envp; const char *iab; cap_mode_t mode; + int launch_abort; int result; + int (*callback_fn)(void *detail); }; #ifdef WITH_PTHREADS @@ -32,6 +34,17 @@ struct test_case_s { #else /* WITH_PTHREADS */ #endif /* WITH_PTHREADS */ +/* + * clean_out drops all process capabilities. + */ +static int clean_out(void *data) { + cap_t empty; + empty = cap_init(); + cap_set_proc(empty); + cap_free(empty); + return 0; +} + int main(int argc, char **argv) { static struct test_case_s vs[] = { { @@ -39,13 +52,32 @@ int main(int argc, char **argv) { .result = 0 }, { + .args = { "../progs/tcapsh-static", "--", "-c", "echo hello" }, + .callback_fn = &clean_out, + .result = 0 + }, + { + .callback_fn = &clean_out, + .result = 0 + }, + { .args = { "../progs/tcapsh-static", "--is-uid=123" }, .result = 256 }, { + .args = { "/", "won't", "work" }, + .launch_abort = 1, + }, + { .args = { "../progs/tcapsh-static", "--is-uid=123" }, + .uid = 123, .result = 0, + }, + { + .args = { "../progs/tcapsh-static", "--is-uid=123" }, + .callback_fn = &clean_out, .uid = 123, + .launch_abort = 1, }, { .args = { "../progs/tcapsh-static", "--is-gid=123" }, @@ -91,8 +123,16 @@ int main(int argc, char **argv) { for (i=0; vs[i].pass_on != NO_MORE; i++) { const struct test_case_s *v = &vs[i]; printf("[%d] test should %s\n", i, - v->result ? "generate error" : "work"); - cap_launch_t attr = cap_new_launcher(v->args[0], v->args, v->envp); + v->result || v->launch_abort ? "generate error" : "work"); + cap_launch_t attr; + if (v->args[0] != NULL) { + attr = cap_new_launcher(v->args[0], v->args, v->envp); + if (v->callback_fn != NULL) { + cap_launcher_callback(attr, v->callback_fn); + } + } else { + attr = cap_func_launcher(v->callback_fn); + } if (v->chroot) { cap_launcher_set_chroot(attr, v->chroot); } @@ -125,28 +165,30 @@ int main(int argc, char **argv) { pid_t child = cap_launch(attr, NULL); if (child <= 0) { - fprintf(stderr, "[%d] failed to launch", i); - perror(":"); - success = 0; + fprintf(stderr, "[%d] failed to launch: ", i); + perror(""); + if (!v->launch_abort) { + success = 0; + } continue; } if (cap_free(attr)) { - fprintf(stderr, "[%d] failed to free launcher", i); - perror(":"); + fprintf(stderr, "[%d] failed to free launcher: ", i); + perror(""); success = 0; } int result; int ret = waitpid(child, &result, 0); if (ret != child) { - fprintf(stderr, "[%d] failed to wait", i); - perror(":"); + fprintf(stderr, "[%d] failed to wait: ", i); + perror(""); success = 0; continue; } if (result != v->result) { - fprintf(stderr, "[%d] bad result: got=%d want=%d", i, result, + fprintf(stderr, "[%d] bad result: got=%d want=%d: ", i, result, v->result); - perror(":"); + perror(""); success = 0; continue; } @@ -164,10 +206,10 @@ int main(int argc, char **argv) { cap_free(final); cap_free(orig); - if (success) { - printf("cap_launch_test: PASSED\n"); - } else { + if (!success) { printf("cap_launch_test: FAILED\n"); exit(1); } + printf("cap_launch_test: PASSED\n"); + exit(0); } |