1 /****************************************************************************** 2 * Copyright (c) Crackerjack Project., 2007 * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * 12 * the GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the Free Software Foundation, * 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 17 * * 18 ******************************************************************************/ 19 20 /* 21 * Basic test for the add_key() syscall. 22 * 23 * History: Porting from Crackerjack to LTP is done by 24 * Manas Kumar Nayak maknayak (at) in.ibm.com> 25 */ 26 27 #include "config.h" 28 #ifdef HAVE_LINUX_KEYCTL_H 29 # include <linux/keyctl.h> 30 #endif 31 #include "tst_test.h" 32 #include "linux_syscall_numbers.h" 33 34 #ifdef HAVE_LINUX_KEYCTL_H 35 struct tcase { 36 char *type; 37 char *desc; 38 void *payload; 39 int plen; 40 int exp_errno; 41 } tcases[] = { 42 {"user", "firstkey", NULL, 1, EINVAL} 43 }; 44 #endif /* HAVE_LINUX_KEYCTL_H */ 45 46 static void verify_add_key(unsigned int i) 47 { 48 #ifdef HAVE_LINUX_KEYCTL_H 49 TEST(tst_syscall(__NR_add_key, tcases[i].type, tcases[i].desc, 50 tcases[i].payload, tcases[i].plen, 51 KEY_SPEC_USER_KEYRING)); 52 53 if (TEST_RETURN != -1) { 54 tst_res(TFAIL, "add_key() passed unexpectedly"); 55 return; 56 } 57 58 if (TEST_ERRNO == tcases[i].exp_errno) { 59 tst_res(TPASS | TTERRNO, "add_key() failed expectedly"); 60 return; 61 } 62 63 tst_res(TFAIL | TTERRNO, 64 "add_key() failed unexpectedly, expected %s", 65 tst_strerrno(tcases[i].exp_errno)); 66 #else 67 tst_brk(TCONF, "linux/keyctl.h was missing upon compilation."); 68 #endif /* HAVE_LINUX_KEYCTL_H */ 69 } 70 71 static struct tst_test test = { 72 .tid = "add_key01", 73 .tcnt = ARRAY_SIZE(tcases), 74 .test = verify_add_key, 75 }; 76