1 /* 2 * Copyright (c) 2016 Fujitsu Ltd. 3 * Author: Xiao Yang <yangx.jy (at) cn.fujitsu.com> 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * 13 * You should have received a copy of the GNU General Public License 14 * alone with this program. 15 */ 16 17 /* 18 * Test Name: request_key01 19 * 20 * Description: 21 * The testcase checks basic functionality of the request_key(2). 22 * request_key(2) asks the kernel to find a key which matches the 23 * specified description. If successful, it attaches it to the 24 * nominated keyring and returns its serial number. 25 * 26 */ 27 28 #include "config.h" 29 #include <errno.h> 30 #include <sys/types.h> 31 #ifdef HAVE_KEYUTILS_H 32 # include <keyutils.h> 33 #endif 34 35 #include "tst_test.h" 36 37 #ifdef HAVE_KEYUTILS_H 38 39 static int key; 40 41 static void verify_request_key(void) 42 { 43 44 TEST(request_key("keyring", "ltp", NULL, KEY_REQKEY_DEFL_DEFAULT)); 45 if (TEST_RETURN == -1) { 46 tst_res(TFAIL | TTERRNO, "request_key() failed"); 47 return; 48 } 49 50 if (TEST_RETURN != key) 51 tst_res(TFAIL, "serial number mismatched"); 52 else 53 tst_res(TPASS, "request_key() succeed"); 54 } 55 56 static void setup(void) 57 { 58 key = add_key("keyring", "ltp", NULL, 0, KEY_SPEC_THREAD_KEYRING); 59 if (key == -1) 60 tst_brk(TBROK | TERRNO, "add_key() failed"); 61 } 62 63 static struct tst_test test = { 64 .tid = "request_key01", 65 .setup = setup, 66 .test_all = verify_request_key, 67 }; 68 69 #else 70 71 TST_TEST_TCONF("keyutils.h was missing at compilation"); 72 73 #endif /* HAVE_LINUX_KEYCTL_H */ 74