• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Crackerjack Project., 2007
4  * Copyright (c) 2017 Fujitsu Ltd.
5  */
6 
7 /*
8  * Description: This tests the keyctl() syscall
9  *		Manipulate the kernel's key management facility
10  *
11  * Ported by Manas Kumar Nayak maknayak@in.ibm.com>
12  * Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
13  */
14 
15 #include <errno.h>
16 #include <stdint.h>
17 
18 #include "tst_test.h"
19 #include "lapi/keyctl.h"
20 
do_test(void)21 static void do_test(void)
22 {
23 	key_serial_t key;
24 
25 	TEST(keyctl(KEYCTL_GET_KEYRING_ID, KEY_SPEC_USER_SESSION_KEYRING));
26 	if (TST_RET != -1)
27 		tst_res(TPASS, "KEYCTL_GET_KEYRING_ID succeeded");
28 	else
29 		tst_res(TFAIL | TTERRNO, "KEYCTL_GET_KEYRING_ID failed");
30 
31 	for (key = INT32_MAX; key > INT32_MIN; key--) {
32 		TEST(keyctl(KEYCTL_READ, key));
33 		if (TST_RET == -1 && TST_ERR == ENOKEY)
34 			break;
35 	}
36 
37 	TEST(keyctl(KEYCTL_REVOKE, key));
38 	if (TST_RET != -1) {
39 		tst_res(TFAIL, "KEYCTL_REVOKE succeeded unexpectedly");
40 		return;
41 	}
42 
43 	if (TST_ERR != ENOKEY) {
44 		tst_res(TFAIL | TTERRNO, "KEYCTL_REVOKE failed unexpectedly");
45 		return;
46 	}
47 
48 	tst_res(TPASS | TTERRNO, "KEYCTL_REVOKE failed as expected");
49 }
50 
51 static struct tst_test test = {
52 	.test_all = do_test,
53 };
54