blob: e353d45caa1813fc8317ffe0751d4a48b218cdbe [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
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>
45#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;
51extern int Tst_count;
52
53void setup(void);
54void cleanup(void);
55
robbiew96d23372003-03-26 20:40:04 +000056int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000057{
subrata_modak56207ce2009-03-23 13:35:39 +000058 int lc; /* loop counter */
59 char *msg; /* message returned by parse_opts */
plars865695b2001-08-27 22:15:12 +000060
61 struct passwd *getpwuid(), *pwent;
62
63 /* parse standard options */
subrata_modak56207ce2009-03-23 13:35:39 +000064 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
plars865695b2001-08-27 22:15:12 +000065 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
66 }
67
68 setup();
69
70 /* check looping state if -i option is given */
71 for (lc = 0; TEST_LOOPING(lc); lc++) {
72 /* reset Tst_count in case we are looping */
73 Tst_count = 0;
74
subrata_modak493f24f2009-10-15 14:30:34 +000075 TEST(GETEUID());
plars865695b2001-08-27 22:15:12 +000076
77 if (TEST_RETURN < 0) {
78 tst_brkm(TBROK, cleanup, "This should never happen");
79 }
80
81 if (STD_FUNCTIONAL_TEST) {
82
83 pwent = getpwuid(TEST_RETURN);
84 if (pwent == NULL) {
85 tst_resm(TFAIL, "geteuid() returned unexpected "
86 "value %d", TEST_RETURN);
subrata_modak493f24f2009-10-15 14:30:34 +000087 } else if (!UID_SIZE_CHECK(pwent->pw_uid)) {
88 tst_brkm(TBROK,
89 cleanup,
90 "uid(%d) is too large for testing geteuid16",
91 TEST_RETURN);
plars865695b2001-08-27 22:15:12 +000092 } else {
93 if (pwent->pw_uid != TEST_RETURN) {
94 tst_resm(TFAIL, "getpwuid() value, %d, "
95 "does not match geteuid() "
96 "value, %d", pwent->pw_uid,
97 TEST_RETURN);
98 } else {
99 tst_resm(TPASS, "values from geteuid()"
100 " and getpwuid() match");
101 }
102 }
103 } else {
104 tst_resm(TPASS, "call succeeded");
105 }
106 }
107 cleanup();
108
subrata_modak56207ce2009-03-23 13:35:39 +0000109 /*NOTREACHED*/ return 0;
plars865695b2001-08-27 22:15:12 +0000110}
111
112/*
113 * setup() - performs all ONE TIME setup for this test.
114 */
subrata_modak56207ce2009-03-23 13:35:39 +0000115void setup()
plars865695b2001-08-27 22:15:12 +0000116{
117 /* capture signals */
118 tst_sig(NOFORK, DEF_HANDLER, cleanup);
119
120 /* Pause if that option was specified */
121 TEST_PAUSE;
122}
123
plars865695b2001-08-27 22:15:12 +0000124/*
125 * cleanup() - performs all ONE TIME cleanup for this test at
126 * completion or premature exit.
127 */
subrata_modak56207ce2009-03-23 13:35:39 +0000128void cleanup()
plars865695b2001-08-27 22:15:12 +0000129{
130 /*
131 * print timing stats if that option was specified.
132 * print errno log if that option was specified.
133 */
134 TEST_CLEANUP;
135
136 /* exit with return code appropriate for results */
137 tst_exit();
138}