1/*
2 * Copyright (c) Crackerjack Project., 2007
3 * Copyright (c) 2017 Fujitsu Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY;  without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program, if not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * Description: This tests the keyctl() syscall
21 *		Manipulate the kernel's key management facility
22 *
23 * Ported by Manas Kumar Nayak maknayak@in.ibm.com>
24 * Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
25 */
26
27#include <errno.h>
28#include <stdint.h>
29
30#include "tst_test.h"
31#include "lapi/keyctl.h"
32
33static void do_test(void)
34{
35	key_serial_t key;
36
37	TEST(keyctl(KEYCTL_GET_KEYRING_ID, KEY_SPEC_USER_SESSION_KEYRING));
38	if (TEST_RETURN != -1)
39		tst_res(TPASS, "KEYCTL_GET_KEYRING_ID succeeded");
40	else
41		tst_res(TFAIL | TTERRNO, "KEYCTL_GET_KEYRING_ID failed");
42
43	for (key = INT32_MAX; key > INT32_MIN; key--) {
44		TEST(keyctl(KEYCTL_READ, key));
45		if (TEST_RETURN == -1 && TEST_ERRNO == ENOKEY)
46			break;
47	}
48
49	TEST(keyctl(KEYCTL_REVOKE, key));
50	if (TEST_RETURN != -1) {
51		tst_res(TFAIL, "KEYCTL_REVOKE succeeded unexpectedly");
52		return;
53	}
54
55	if (TEST_ERRNO != ENOKEY) {
56		tst_res(TFAIL | TTERRNO, "KEYCTL_REVOKE failed unexpectedly");
57		return;
58	}
59
60	tst_res(TPASS | TTERRNO, "KEYCTL_REVOKE failed as expected");
61}
62
63static struct tst_test test = {
64	.test_all = do_test,
65};
66