blob: 09b37d2652b34047a8f787f85b1050760275149f [file] [log] [blame]
robbiewa5d67cb2003-01-01 20:44:12 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiewa5d67cb2003-01-01 20:44:12 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiewa5d67cb2003-01-01 20:44:12 +000019 * TEST IDENTIFIER : capset01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiewa5d67cb2003-01-01 20:44:12 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiewa5d67cb2003-01-01 20:44:12 +000023 * TEST TITLE : Basic test for capset(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiewa5d67cb2003-01-01 20:44:12 +000025 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiewa5d67cb2003-01-01 20:44:12 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiewa5d67cb2003-01-01 20:44:12 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the capset(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
robbiewa5d67cb2003-01-01 20:44:12 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
40 * call capget() to save the current capability data
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
robbiewa5d67cb2003-01-01 20:44:12 +000042 * Test:
43 * Loop if the proper options are given.
44 * call capset() with the saved data
45 * if return value == 0
46 * Test passed
47 * Otherwise
48 * Test failed
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
robbiewa5d67cb2003-01-01 20:44:12 +000050 * Cleanup:
51 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000052 *
robbiewa5d67cb2003-01-01 20:44:12 +000053 * USAGE: <for command-line>
54 * capset01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
55 * where, -c n : Run n copies concurrently.
56 * -e : Turn on errno logging.
57 * -h : Show help screen
58 * -f : Turn off functional testing
59 * -i n : Execute test n times.
60 * -I x : Execute test for x seconds.
61 * -p : Pause for SIGUSR1 before starting
62 * -P x : Pause for x seconds between iterations.
63 * -t : Turn on syscall timing.
robbiew74f956b2005-01-17 22:15:33 +000064 *
65 * CHANGES:
66 * 2005/01/01: add an hint to a possible solution when test fails
67 * - Ricky Ng-Adam <rngadam@yahoo.com>
robbiewa5d67cb2003-01-01 20:44:12 +000068 ****************************************************************/
robbiewdd799e92003-03-25 17:16:44 +000069#include <unistd.h>
robbiewa5d67cb2003-01-01 20:44:12 +000070#include <errno.h>
robbiewa5d67cb2003-01-01 20:44:12 +000071#include "test.h"
72#include "usctest.h"
Garrett Cooper795ce692010-12-17 11:03:31 -080073#include "linux_syscall_numbers.h"
74
robbiewe7757592003-10-01 17:23:49 +000075/**************************************************************************/
robbiewe7757592003-10-01 17:23:49 +000076/* */
77/* Some archs do not have the manpage documented sys/capability.h file, */
robbiew04a8ba52003-10-02 17:38:04 +000078/* and require the use of the line below */
79
80#include <linux/capability.h>
81
82/* If you are having issues with including this file and have the sys/ */
83/* version, then you may want to try switching to it. -Robbie W. */
robbiewe7757592003-10-01 17:23:49 +000084/**************************************************************************/
85
robbiewa5d67cb2003-01-01 20:44:12 +000086static void setup();
87static void cleanup();
88
89char *TCID = "capset01"; /* Test program identifier. */
90int TST_TOTAL = 1; /* Total number of test cases. */
subrata_modakf938ae72010-01-07 11:27:24 +000091static int exp_enos[] = { EFAULT, EINVAL, EPERM, 0 };
robbiewa5d67cb2003-01-01 20:44:12 +000092
subrata_modak56207ce2009-03-23 13:35:39 +000093static struct __user_cap_header_struct header; /* cap_user_header_t is a pointer
94 to __user_cap_header_struct */
robbiewa5d67cb2003-01-01 20:44:12 +000095
subrata_modak56207ce2009-03-23 13:35:39 +000096static struct __user_cap_data_struct data; /* cap_user_data_t is a pointer to
97 __user_cap_data_struct */
robbiewa5d67cb2003-01-01 20:44:12 +000098
subrata_modak56207ce2009-03-23 13:35:39 +000099int main(int ac, char **av)
robbiewa5d67cb2003-01-01 20:44:12 +0000100{
101
Garrett Cooper795ce692010-12-17 11:03:31 -0800102 int lc;
103 char *msg;
robbiewa5d67cb2003-01-01 20:44:12 +0000104
Garrett Cooper53740502010-12-16 00:04:01 -0800105 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800106 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewa5d67cb2003-01-01 20:44:12 +0000107
robbiewa5d67cb2003-01-01 20:44:12 +0000108 setup();
109
robbiewa5d67cb2003-01-01 20:44:12 +0000110 for (lc = 0; TEST_LOOPING(lc); lc++) {
111
robbiewa5d67cb2003-01-01 20:44:12 +0000112 Tst_count = 0;
113
Jan Stancek359980f2013-02-15 10:16:05 +0100114 TEST(ltp_syscall(__NR_capset, &header, &data));
robbiewa5d67cb2003-01-01 20:44:12 +0000115
116 if (TEST_RETURN == 0) {
vapier72d58562009-08-28 11:24:25 +0000117 tst_resm(TPASS, "capset() returned %ld", TEST_RETURN);
robbiewa5d67cb2003-01-01 20:44:12 +0000118 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119 tst_resm(TFAIL | TTERRNO,
120 "Test Failed, capset() returned %ld"
robbiew74f956b2005-01-17 22:15:33 +0000121 " Maybe you need to do `modprobe capability`?",
vapier72d58562009-08-28 11:24:25 +0000122 TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000123 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800124 }
robbiewa5d67cb2003-01-01 20:44:12 +0000125
robbiewa5d67cb2003-01-01 20:44:12 +0000126 cleanup();
127
Garrett Cooper795ce692010-12-17 11:03:31 -0800128 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800129}
robbiewa5d67cb2003-01-01 20:44:12 +0000130
subrata_modak56207ce2009-03-23 13:35:39 +0000131void setup()
robbiewa5d67cb2003-01-01 20:44:12 +0000132{
Garrett Cooper2c282152010-12-16 00:55:50 -0800133
robbiewa5d67cb2003-01-01 20:44:12 +0000134 tst_sig(NOFORK, DEF_HANDLER, cleanup);
135
Wanlong Gao354ebb42012-12-07 10:10:04 +0800136 TEST_EXP_ENOS(exp_enos);
subrata_modakf938ae72010-01-07 11:27:24 +0000137
robbiewa5d67cb2003-01-01 20:44:12 +0000138 TEST_PAUSE;
139
robbiewa5d67cb2003-01-01 20:44:12 +0000140 header.version = _LINUX_CAPABILITY_VERSION;
141 header.pid = 0;
Jan Stancek359980f2013-02-15 10:16:05 +0100142 if (ltp_syscall(__NR_capget, &header, &data) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800143 tst_brkm(TBROK | TERRNO, NULL, "capget() failed");
Garrett Cooper2c282152010-12-16 00:55:50 -0800144}
robbiewa5d67cb2003-01-01 20:44:12 +0000145
subrata_modak56207ce2009-03-23 13:35:39 +0000146void cleanup()
robbiewa5d67cb2003-01-01 20:44:12 +0000147{
robbiewa5d67cb2003-01-01 20:44:12 +0000148 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700149}