1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2016 Fujitsu Ltd.
4 * Copyright (c) 2017 Petr Vorel <[email protected]>
5 *
6 * Author: Xiao Yang <[email protected]>
7 */
8
9 /*
10 * Test Name: request_key01
11 *
12 * Description:
13 * The testcase checks basic functionality of the request_key(2).
14 * request_key(2) asks the kernel to find a key which matches the
15 * specified description. If successful, it attaches it to the
16 * nominated keyring and returns its serial number.
17 *
18 */
19
20 #include <errno.h>
21
22 #include "tst_test.h"
23 #include "lapi/keyctl.h"
24
25 static int key;
26
verify_request_key(void)27 static void verify_request_key(void)
28 {
29
30 TEST(request_key("keyring", "ltp", NULL, KEY_REQKEY_DEFL_DEFAULT));
31 if (TST_RET == -1) {
32 tst_res(TFAIL | TTERRNO, "request_key() failed");
33 return;
34 }
35
36 if (TST_RET != key)
37 tst_res(TFAIL, "serial number mismatched");
38 else
39 tst_res(TPASS, "request_key() succeed");
40 }
41
setup(void)42 static void setup(void)
43 {
44 key = add_key("keyring", "ltp", NULL, 0, KEY_SPEC_THREAD_KEYRING);
45 if (key == -1)
46 tst_brk(TBROK | TERRNO, "add_key() failed");
47 }
48
49 static struct tst_test test = {
50 .setup = setup,
51 .test_all = verify_request_key,
52 };
53