• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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
13  * with this program; if not, write the Free Software Foundation, Inc.,
14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  */
17 /**********************************************************
18  *
19  *    TEST IDENTIFIER	: capset01
20  *
21  *    EXECUTED BY	: anyone
22  *
23  *    TEST TITLE	: Basic test for capset(2)
24  *
25  *    TEST CASE TOTAL	: 1
26  *
27  *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
28  *
29  *    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.
36  *
37  * 	Setup:
38  * 	  Setup signal handling.
39  *	  Pause for SIGUSR1 if option specified.
40  *	  call capget() to save the current capability data
41  *
42  * 	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
49  *
50  * 	Cleanup:
51  * 	  Print errno log and/or timing stats if options given
52  *
53  * 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.
64  *
65  * CHANGES:
66  *  2005/01/01: add an hint to a possible solution when test fails
67  *              - Ricky Ng-Adam <rngadam@yahoo.com>
68  ****************************************************************/
69 #include <unistd.h>
70 #include <errno.h>
71 #include "test.h"
72 #include "lapi/syscalls.h"
73 
74 /**************************************************************************/
75 /*                                                                        */
76 /*   Some archs do not have the manpage documented sys/capability.h file, */
77 /*   and require the use of the line below                                */
78 
79 #include <linux/capability.h>
80 
81 /*   If you are having issues with including this file and have the sys/  */
82 /*   version, then you may want to try switching to it. -Robbie W.        */
83 /**************************************************************************/
84 
85 static void setup();
86 static void cleanup();
87 
88 char *TCID = "capset01";
89 int TST_TOTAL = 1;
90 
91 static struct __user_cap_header_struct header;	/* cap_user_header_t is a pointer
92 						   to __user_cap_header_struct */
93 
94 static struct __user_cap_data_struct data;	/* cap_user_data_t is a pointer to
95 						   __user_cap_data_struct */
96 
main(int ac,char ** av)97 int main(int ac, char **av)
98 {
99 
100 	int lc;
101 
102 	tst_parse_opts(ac, av, NULL, NULL);
103 
104 	setup();
105 
106 	for (lc = 0; TEST_LOOPING(lc); lc++) {
107 
108 		tst_count = 0;
109 
110 		TEST(ltp_syscall(__NR_capset, &header, &data));
111 
112 		if (TEST_RETURN == 0) {
113 			tst_resm(TPASS, "capset() returned %ld", TEST_RETURN);
114 		} else {
115 			tst_resm(TFAIL | TTERRNO,
116 				 "Test Failed, capset() returned %ld"
117 				 " Maybe you need to do `modprobe capability`?",
118 				 TEST_RETURN);
119 		}
120 	}
121 
122 	cleanup();
123 
124 	tst_exit();
125 }
126 
setup(void)127 void setup(void)
128 {
129 
130 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
131 
132 	TEST_PAUSE;
133 
134 	header.version = _LINUX_CAPABILITY_VERSION;
135 	header.pid = 0;
136 	if (ltp_syscall(__NR_capget, &header, &data) == -1)
137 		tst_brkm(TBROK | TERRNO, NULL, "capget() failed");
138 }
139 
cleanup(void)140 void cleanup(void)
141 {
142 }
143