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, "LINUX_CAPABILITY_VERSION_1"},
24 {0x20071026, "LINUX_CAPABILITY_VERSION_2"},
25 {0x20080522, "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 header->version = tc->version;
33 header->pid = pid;
34
35 TEST(tst_syscall(__NR_capget, header, data));
36 if (TST_RET == -1)
37 tst_brk(TFAIL | TTERRNO, "capget() failed");
38
39 TST_EXP_PASS(tst_syscall(__NR_capset, header, data),
40 "capset() with %s", tc->message);
41 }
42
setup(void)43 static void setup(void)
44 {
45 pid = getpid();
46 }
47
48 static struct tst_test test = {
49 .setup = setup,
50 .tcnt = ARRAY_SIZE(tcases),
51 .test = verify_capset,
52 .bufs = (struct tst_buffers []) {
53 {&header, .size = sizeof(*header)},
54 {&data, .size = 2 * sizeof(*data)},
55 {},
56 }
57 };
58