• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  *  Ported by Wayne Boyer
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
18  */
19 
20 /*
21  * Testcase to check the basic functionality of getegid().
22  *
23  * For functionality test the return value from getegid() is compared to passwd
24  * entry.
25  */
26 
27 #include <pwd.h>
28 #include <errno.h>
29 
30 #include "test.h"
31 #include "compat_16.h"
32 
33 static void cleanup(void);
34 static void setup(void);
35 
36 TCID_DEFINE(getegid02);
37 int TST_TOTAL = 1;
38 
main(int ac,char ** av)39 int main(int ac, char **av)
40 {
41 	int lc;
42 	uid_t euid;
43 	struct passwd *pwent;
44 
45 	tst_parse_opts(ac, av, NULL, NULL);
46 
47 	setup();
48 
49 	for (lc = 0; TEST_LOOPING(lc); lc++) {
50 		tst_count = 0;
51 
52 		TEST(GETEGID(cleanup));
53 
54 		if (TEST_RETURN < 0) {
55 			tst_brkm(TBROK, cleanup, "This should never happen");
56 		}
57 
58 		euid = geteuid();
59 		pwent = getpwuid(euid);
60 
61 		if (pwent == NULL)
62 			tst_brkm(TBROK, cleanup, "geteuid() returned "
63 				 "unexpected value %d", euid);
64 
65 		GID16_CHECK(pwent->pw_gid, getegid, cleanup);
66 
67 		if (pwent->pw_gid != TEST_RETURN) {
68 			tst_resm(TFAIL, "getegid() return value"
69 				 " %ld unexpected - expected %d",
70 				 TEST_RETURN, pwent->pw_gid);
71 		} else {
72 			tst_resm(TPASS,
73 				 "effective group id %ld "
74 				 "is correct", TEST_RETURN);
75 		}
76 	}
77 
78 	cleanup();
79 	tst_exit();
80 }
81 
setup(void)82 static void setup(void)
83 {
84 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
85 	TEST_PAUSE;
86 }
87 
cleanup(void)88 static void cleanup(void)
89 {
90 }
91