• 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  * ALGORITHM
22  *	As root sets the current group id to ltpuser1, verify the results
23  */
24 #include <pwd.h>
25 #include <errno.h>
26 
27 #include "test.h"
28 #include <compat_16.h>
29 
30 TCID_DEFINE(setgid03);
31 int TST_TOTAL = 1;
32 
33 static char ltpuser1[] = "nobody";
34 static char root[] = "root";
35 static struct passwd *ltpuser1pwent, *rootpwent;
36 static gid_t mygid;
37 
38 static void setup(void);
39 static void cleanup(void);
40 
main(int ac,char ** av)41 int main(int ac, char **av)
42 {
43 	int lc;
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(SETGID(cleanup, ltpuser1pwent->pw_gid));
53 
54 		if (TEST_RETURN == -1) {
55 			tst_resm(TFAIL, "call failed unexpectedly");
56 			continue;
57 		}
58 
59 		if (getgid() != ltpuser1pwent->pw_gid) {
60 			tst_resm(TFAIL, "setgid failed to set gid to "
61 				 "ltpuser1's gid");
62 		} else {
63 			tst_resm(TPASS, "functionality of getgid() is correct");
64 		}
65 	}
66 
67 	cleanup();
68 	tst_exit();
69 }
70 
setup(void)71 static void setup(void)
72 {
73 	tst_require_root();
74 
75 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
76 
77 	TEST_PAUSE;
78 
79 	if ((rootpwent = getpwnam(root)) == NULL) {
80 		tst_brkm(TBROK, cleanup, "getpwnam failed for "
81 			 "user id %s", root);
82 	}
83 
84 	mygid = getgid();
85 
86 	if (mygid != rootpwent->pw_gid) {
87 		tst_brkm(TBROK, cleanup, "real group id is not root");
88 	}
89 
90 	if ((ltpuser1pwent = getpwnam(ltpuser1)) == NULL) {
91 		tst_brkm(TBROK, cleanup, "getpwnam failed for user "
92 			 "id %s", ltpuser1);
93 	}
94 
95 	GID16_CHECK(ltpuser1pwent->pw_gid, setgid, cleanup);
96 }
97 
cleanup(void)98 static void cleanup(void)
99 {
100 }
101