1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
5 *
6 * CHANGES:
7 * 2005/01/01: add an hint to a possible solution when test fails
8 * - Ricky Ng-Adam <rngadam@yahoo.com>
9 */
10 #include <sys/types.h>
11 #include <unistd.h>
12 #include "tst_test.h"
13 #include "lapi/syscalls.h"
14 #include <linux/capability.h>
15
16 static pid_t pid;
17 static struct __user_cap_header_struct *header;
18 static struct __user_cap_data_struct *data;
19 static struct tcase {
20 int version;
21 char *message;
22 } tcases[] = {
23 {0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"},
24 {0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"},
25 {0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"},
26 };
27
verify_capset(unsigned int n)28 static void verify_capset(unsigned int n)
29 {
30 struct tcase *tc = &tcases[n];
31
32 tst_res(TINFO, "%s", tc->message);
33 header->version = tc->version;
34 header->pid = pid;
35
36 if (tst_syscall(__NR_capget, header, data) == -1) {
37 tst_res(TFAIL | TTERRNO, "capget() failed");
38 return;
39 }
40
41 TEST(tst_syscall(__NR_capset, header, data));
42 if (TST_RET == 0)
43 tst_res(TPASS, "capset() returned %ld", TST_RET);
44 else
45 tst_res(TFAIL | TTERRNO, "Test Failed, capset() returned %ld", TST_RET);
46 }
47
setup(void)48 static void setup(void)
49 {
50 pid = getpid();
51 }
52
53 static struct tst_test test = {
54 .setup = setup,
55 .tcnt = ARRAY_SIZE(tcases),
56 .test = verify_capset,
57 .bufs = (struct tst_buffers []) {
58 {&header, .size = sizeof(*header)},
59 {&data, .size = 2 * sizeof(*data)},
60 {},
61 }
62 };
63