blob: ce87ee9fc3dcf985112349959095555f281f8829 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
subrata_modak4f41ee32008-09-22 06:52:57 +000022 * getegid02.c
plars865695b2001-08-27 22:15:12 +000023 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of getegid().
26 *
27 * ALGORITHM
28 * call setup
29 * loop if that option was specified
30 * Execute getegid() call using TEST macro
31 * if not expected value
32 * break remaining tests and cleanup
33 * if STD_FUNCTIONAL_TEST
34 * Execute geteuid() call
35 * Execute getpwduid() call
36 * if the passwd entry is NULL
37 * break the remaining tests and cleanup
38 * else if pwent->pw_gid != TEST_RETURN
39 * print failure message
40 * else
41 * print pass message
42 * else
43 * print pass message
44 * call cleanup
45 *
46 * USAGE: <for command-line>
subrata_modak4f41ee32008-09-22 06:52:57 +000047 * getegid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
plars865695b2001-08-27 22:15:12 +000048 * where, -c n : Run n copies concurrently.
49 * -f : Turn off functionality Testing.
50 * -i n : Execute test n times.
51 * -I x : Execute test for x seconds.
52 * -P x : Pause for x seconds between iterations.
53 * -t : Turn on syscall timing.
54 *
55 * HISTORY
56 * 07/2001 Ported by Wayne Boyer
57 *
58 * RESTRICTIONS
59 * none
60 */
61
62#include <pwd.h>
63#include <errno.h>
64
65#include "test.h"
66#include "usctest.h"
67
subrata_modak153f98c2008-09-19 10:09:58 +000068#include "compat_16.h"
69
plars865695b2001-08-27 22:15:12 +000070void cleanup(void);
71void setup(void);
72
subrata_modak4f41ee32008-09-22 06:52:57 +000073TCID_DEFINE(getegid02);
plars865695b2001-08-27 22:15:12 +000074int TST_TOTAL = 1;
75extern int Tst_count;
76
plars74948ad2002-11-14 16:16:14 +000077int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000078{
subrata_modak56207ce2009-03-23 13:35:39 +000079 int lc; /* loop counter */
80 char *msg; /* message returned from parse_opts */
plars865695b2001-08-27 22:15:12 +000081 int euid;
82 struct passwd *pwent;
83
84 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -080085 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
plars865695b2001-08-27 22:15:12 +000086 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +000087 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +000088
subrata_modak56207ce2009-03-23 13:35:39 +000089 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000090
91 /* The following loop checks looping state if -i option given */
92 for (lc = 0; TEST_LOOPING(lc); lc++) {
93
94 /* reset Tst_count in case we are looping */
95 Tst_count = 0;
96
subrata_modak153f98c2008-09-19 10:09:58 +000097 TEST(GETEGID());
plars865695b2001-08-27 22:15:12 +000098
99 if (TEST_RETURN < 0) {
100 tst_brkm(TBROK, cleanup, "This should never happen");
101 }
102
103 if (STD_FUNCTIONAL_TEST) {
104 euid = geteuid();
105
106 pwent = getpwuid(euid);
107
108 if (pwent == NULL) {
109 tst_brkm(TBROK, cleanup, "geteuid() returned "
110 "unexpected value %d", euid);
subrata_modak153f98c2008-09-19 10:09:58 +0000111 } else if (!GID_SIZE_CHECK(pwent->pw_gid)) {
subrata_modak56207ce2009-03-23 13:35:39 +0000112 tst_brkm(TBROK,
subrata_modak4bb656a2009-02-26 12:02:09 +0000113 cleanup,
subrata_modak153f98c2008-09-19 10:09:58 +0000114 "gid for euid %d is too large for testing getegid16",
115 euid);
plars865695b2001-08-27 22:15:12 +0000116 } else {
117 if (pwent->pw_gid != TEST_RETURN) {
118 tst_resm(TFAIL, "getegid() return value"
subrata_modak358c3ee2009-10-26 14:55:46 +0000119 " %ld unexpected - expected %d",
subrata_modak56207ce2009-03-23 13:35:39 +0000120 TEST_RETURN, pwent->pw_gid);
plars865695b2001-08-27 22:15:12 +0000121 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +0000122 tst_resm(TPASS, "effective group id %ld "
plars865695b2001-08-27 22:15:12 +0000123 "is correct", TEST_RETURN);
124 }
125 }
126 } else {
127 tst_resm(TPASS, "call succeeded");
128 }
129 }
130 cleanup();
131
subrata_modak56207ce2009-03-23 13:35:39 +0000132 /*NOTREACHED*/ return 0;
plars865695b2001-08-27 22:15:12 +0000133}
134
plars865695b2001-08-27 22:15:12 +0000135/*
136 * setup() - performs all ONE TIME setup for this test
137 */
subrata_modak56207ce2009-03-23 13:35:39 +0000138void setup()
plars865695b2001-08-27 22:15:12 +0000139{
140 /* capture signals */
141 tst_sig(NOFORK, DEF_HANDLER, cleanup);
142
143 /* Pause if that option was specified */
144 TEST_PAUSE;
145}
146
147/*
148 * cleanup() - performs all the ONE TIME cleanup for this test at completion
subrata_modak56207ce2009-03-23 13:35:39 +0000149 * or premature exit.
plars865695b2001-08-27 22:15:12 +0000150 */
subrata_modak56207ce2009-03-23 13:35:39 +0000151void cleanup()
plars865695b2001-08-27 22:15:12 +0000152{
153 /*
154 * print timing status if that option was specified.
155 * print errno log if that option was specified
156 */
157 TEST_CLEANUP;
158
159 /* exit with return code appropriate for results */
160 tst_exit();
161}