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