blob: bb8328cfba6f3cf5869f7a43d9dac69fbef99c70 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
subrata_modak56207ce2009-03-23 13:35:39 +00002 *
Mike Frysingera25f89e2013-04-27 02:35:01 -04003 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * Test Name: getresgid01
22 *
23 * Test Description:
24 * Verify that getresgid() will be successful to get the real, effective
25 * and saved user id of the calling process.
26 *
27 * Expected Result:
28 * getresgid() should return with 0 value and the real/effective/saved
29 * user ids should be equal to that of calling process.
30 *
31 * Algorithm:
32 * Setup:
33 * Setup signal handling.
34 * Pause for SIGUSR1 if option specified.
35 *
36 * Test:
37 * Loop if the proper options are given.
38 * Execute system call
39 * Check return code, if system call failed (return=-1)
subrata_modak56207ce2009-03-23 13:35:39 +000040 * Log the errno and Issue a FAIL message.
plars865695b2001-08-27 22:15:12 +000041 * Otherwise,
subrata_modak56207ce2009-03-23 13:35:39 +000042 * Verify the Functionality of system call
plars865695b2001-08-27 22:15:12 +000043 * if successful,
subrata_modak56207ce2009-03-23 13:35:39 +000044 * Issue Functionality-Pass message.
plars865695b2001-08-27 22:15:12 +000045 * Otherwise,
46 * Issue Functionality-Fail message.
47 * Cleanup:
48 * Print errno log and/or timing stats if options given
49 *
50 * Usage: <for command-line>
51 * getresgid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
52 * where, -c n : Run n copies concurrently.
53 * -f : Turn off functionality Testing.
54 * -i n : Execute test n times.
55 * -I x : Execute test for x seconds.
56 * -P x : Pause for x seconds between iterations.
57 * -t : Turn on syscall timing.
58 *
59 * HISTORY
60 * 07/2001 Ported by Wayne Boyer
61 *
62 * RESTRICTIONS:
63 * None.
64 *
65 */
robbiew96d23372003-03-26 20:40:04 +000066
plars865695b2001-08-27 22:15:12 +000067#include <stdio.h>
68#include <unistd.h>
69#include <sys/types.h>
70#include <errno.h>
71#include <fcntl.h>
72#include <string.h>
73#include <signal.h>
74
75#include "test.h"
plars865695b2001-08-27 22:15:12 +000076
subrata_modak56207ce2009-03-23 13:35:39 +000077extern int getresgid(gid_t *, gid_t *, gid_t *);
robbiew96d23372003-03-26 20:40:04 +000078
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020079char *TCID = "getresgid01";
80int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000081gid_t pr_gid, pe_gid, ps_gid; /* calling process real/effective/saved gid */
82
83void setup(); /* Main setup function of test */
84void cleanup(); /* cleanup function for the test */
85
subrata_modak56207ce2009-03-23 13:35:39 +000086int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000087{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020088 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020089 const char *msg;
plars865695b2001-08-27 22:15:12 +000090 gid_t real_gid, /* real/eff./saved user id from getresgid() */
subrata_modak56207ce2009-03-23 13:35:39 +000091 eff_gid, sav_gid;
92
Garrett Cooper45e285d2010-11-22 12:19:25 -080093 msg = parse_opts(ac, av, NULL, NULL);
94 if (msg != NULL) {
plars865695b2001-08-27 22:15:12 +000095 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080096
plars865695b2001-08-27 22:15:12 +000097 }
98
plars865695b2001-08-27 22:15:12 +000099 setup();
100
plars865695b2001-08-27 22:15:12 +0000101 for (lc = 0; TEST_LOOPING(lc); lc++) {
Garrett Cooper2c282152010-12-16 00:55:50 -0800102
Caspar Zhangd59a6592013-03-07 14:59:12 +0800103 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000104
subrata_modak4bb656a2009-02-26 12:02:09 +0000105 /*
plars865695b2001-08-27 22:15:12 +0000106 * Call getresgid() to get the real/effective/saved
107 * user id's of the calling process.
108 */
109 TEST(getresgid(&real_gid, &eff_gid, &sav_gid));
110
plars865695b2001-08-27 22:15:12 +0000111 if (TEST_RETURN == -1) {
112 tst_resm(TFAIL, "getresgid() Failed, errno=%d : %s",
113 TEST_ERRNO, strerror(TEST_ERRNO));
114 continue;
115 }
116 /*
Cyril Hrubise38b9612014-06-02 17:20:57 +0200117 * Verify the real/effective/saved gid values returned
118 * by getresgid with the expected values.
plars865695b2001-08-27 22:15:12 +0000119 */
Cyril Hrubise38b9612014-06-02 17:20:57 +0200120 if ((real_gid != pr_gid) || (eff_gid != pe_gid) ||
121 (sav_gid != ps_gid)) {
122 tst_resm(TFAIL, "real:%d, effective:%d, "
123 "saved-user:%d ids differ",
124 real_gid, eff_gid, sav_gid);
plars865695b2001-08-27 22:15:12 +0000125 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200126 tst_resm(TPASS, "Functionality of getresgid() "
127 "successful");
plars865695b2001-08-27 22:15:12 +0000128 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800129 }
plars865695b2001-08-27 22:15:12 +0000130
plars865695b2001-08-27 22:15:12 +0000131 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800132 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800133}
plars865695b2001-08-27 22:15:12 +0000134
135/*
136 * setup() - performs all ONE TIME setup for this test.
137 * Get the real/effective/saved user id of the calling process.
138 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400139void setup(void)
plars865695b2001-08-27 22:15:12 +0000140{
Garrett Cooper2c282152010-12-16 00:55:50 -0800141
plars865695b2001-08-27 22:15:12 +0000142 tst_sig(NOFORK, DEF_HANDLER, cleanup);
143
plars865695b2001-08-27 22:15:12 +0000144 TEST_PAUSE;
145
146 /* Real user-id of the calling process */
147 pr_gid = getgid();
148
149 /* Effective user-id of the calling process */
150 pe_gid = getegid();
151
152 /* Saved user-id of the calling process */
153 ps_gid = getegid();
154
155}
156
plars865695b2001-08-27 22:15:12 +0000157/*
158 * cleanup() - performs all ONE TIME cleanup for this test at
159 * completion or premature exit.
160 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400161void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000162{
plars865695b2001-08-27 22:15:12 +0000163
Chris Dearmanec6edca2012-10-17 19:54:01 -0700164}