blob: bf2f28d604aeecccfad5b7cfda7fee98b087a812 [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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * getuid02.c
23 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of the geteuid() system call.
26 *
27 * USAGE: <for command-line>
28 * getuid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
29 * where, -c n : Run n copies concurrently.
30 * -f : Turn off functionality Testing.
31 * -i n : Execute test n times.
32 * -I x : Execute test for x seconds.
33 * -P x : Pause for x seconds between iterations.
34 * -t : Turn on syscall timing.
35 *
36 * HISTORY
37 * 07/2001 Ported by Wayne Boyer
38 *
39 * RESTRICTIONS
40 * None
41 */
42
43#include <pwd.h>
44#include <errno.h>
Garrett Coopere8530df2010-12-21 11:37:57 -080045#include "test.h"
46#include "usctest.h"
subrata_modak493f24f2009-10-15 14:30:34 +000047#include "compat_16.h"
plars865695b2001-08-27 22:15:12 +000048
subrata_modak493f24f2009-10-15 14:30:34 +000049TCID_DEFINE(getuid02);
plars865695b2001-08-27 22:15:12 +000050int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000051
52void setup(void);
53void cleanup(void);
54
robbiew96d23372003-03-26 20:40:04 +000055int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000056{
Garrett Cooper60fa8012010-11-22 13:50:58 -080057 struct passwd *pwent;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020058 int lc;
subrata_modak56207ce2009-03-23 13:35:39 +000059 char *msg; /* message returned by parse_opts */
plars865695b2001-08-27 22:15:12 +000060
Garrett Cooper53740502010-12-16 00:04:01 -080061 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080062 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000063
64 setup();
65
plars865695b2001-08-27 22:15:12 +000066 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +000067 Tst_count = 0;
68
subrata_modak493f24f2009-10-15 14:30:34 +000069 TEST(GETEUID());
plars865695b2001-08-27 22:15:12 +000070
Garrett Cooper27408da2010-12-19 02:31:31 -080071 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080072 tst_brkm(TBROK | TTERRNO, cleanup, "geteuid* failed");
plars865695b2001-08-27 22:15:12 +000073
74 if (STD_FUNCTIONAL_TEST) {
75
76 pwent = getpwuid(TEST_RETURN);
Garrett Cooper27408da2010-12-19 02:31:31 -080077 if (pwent == NULL)
Wanlong Gao354ebb42012-12-07 10:10:04 +080078 tst_resm(TFAIL | TERRNO, "getpwuid failed");
Garrett Cooper27408da2010-12-19 02:31:31 -080079 else if (!UID_SIZE_CHECK(pwent->pw_uid))
80 tst_brkm(TBROK, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 "uid = %ld is too large for testing "
82 "via geteuid16", TEST_RETURN);
Garrett Cooper27408da2010-12-19 02:31:31 -080083 else {
84 if (pwent->pw_uid != TEST_RETURN)
85 tst_resm(TFAIL, "getpwuid value, %d, "
86 "does not match geteuid "
subrata_modak358c3ee2009-10-26 14:55:46 +000087 "value, %ld", pwent->pw_uid,
plars865695b2001-08-27 22:15:12 +000088 TEST_RETURN);
Garrett Cooper27408da2010-12-19 02:31:31 -080089 else
90 tst_resm(TPASS, "values from geteuid "
91 "and getpwuid match");
plars865695b2001-08-27 22:15:12 +000092 }
Garrett Cooper27408da2010-12-19 02:31:31 -080093 } else
plars865695b2001-08-27 22:15:12 +000094 tst_resm(TPASS, "call succeeded");
plars865695b2001-08-27 22:15:12 +000095 }
96 cleanup();
Garrett Cooper27408da2010-12-19 02:31:31 -080097 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080098
plars865695b2001-08-27 22:15:12 +000099}
100
subrata_modak56207ce2009-03-23 13:35:39 +0000101void setup()
plars865695b2001-08-27 22:15:12 +0000102{
Garrett Cooper2c282152010-12-16 00:55:50 -0800103
plars865695b2001-08-27 22:15:12 +0000104 tst_sig(NOFORK, DEF_HANDLER, cleanup);
105
plars865695b2001-08-27 22:15:12 +0000106 TEST_PAUSE;
107}
108
subrata_modak56207ce2009-03-23 13:35:39 +0000109void cleanup()
plars865695b2001-08-27 22:15:12 +0000110{
plars865695b2001-08-27 22:15:12 +0000111 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700112}