xref: /aosp_15_r20/external/ltp/lib/newlib_tests/tst_capability02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later */
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2019 Richard Palethorpe <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
7*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
8*49cdfc7eSAndroid Build Coastguard Worker 
9*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
10*49cdfc7eSAndroid Build Coastguard Worker #include "tst_capability.h"
11*49cdfc7eSAndroid Build Coastguard Worker #include "tst_safe_net.h"
12*49cdfc7eSAndroid Build Coastguard Worker 
13*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/socket.h"
14*49cdfc7eSAndroid Build Coastguard Worker 
run(void)15*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
16*49cdfc7eSAndroid Build Coastguard Worker {
17*49cdfc7eSAndroid Build Coastguard Worker 	TEST(socket(AF_INET, SOCK_RAW, 1));
18*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET > -1) {
19*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS, "Created raw socket");
20*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_CLOSE(TST_RET);
21*49cdfc7eSAndroid Build Coastguard Worker 	} else {
22*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL | TTERRNO, "Didn't create raw socket");
23*49cdfc7eSAndroid Build Coastguard Worker 	}
24*49cdfc7eSAndroid Build Coastguard Worker }
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
27*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
28*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
29*49cdfc7eSAndroid Build Coastguard Worker 	.caps = (struct tst_cap []) {
30*49cdfc7eSAndroid Build Coastguard Worker 		TST_CAP(TST_CAP_REQ, CAP_NET_RAW),
31*49cdfc7eSAndroid Build Coastguard Worker 		TST_CAP(TST_CAP_DROP, CAP_AUDIT_READ), /* 64bit capability */
32*49cdfc7eSAndroid Build Coastguard Worker 		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
33*49cdfc7eSAndroid Build Coastguard Worker 		{}
34*49cdfc7eSAndroid Build Coastguard Worker 	},
35*49cdfc7eSAndroid Build Coastguard Worker };
36