Home | History | Annotate | Download | only in getgid
      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 getgid().
     22  *
     23  * For functionality test the return value from getgid() 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(getgid03);
     37 int TST_TOTAL = 1;
     38 
     39 int main(int ac, char **av)
     40 {
     41 	int lc;
     42 	uid_t uid;
     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(GETGID(cleanup));
     53 
     54 		if (TEST_RETURN < 0) {
     55 			tst_brkm(TBROK, cleanup, "This should never happen");
     56 		}
     57 
     58 		uid = getuid();
     59 		pwent = getpwuid(uid);
     60 
     61 		if (pwent == NULL)
     62 			tst_brkm(TBROK, cleanup, "getuid() returned "
     63 				 "unexpected value %d", uid);
     64 
     65 		GID16_CHECK(pwent->pw_gid, getgid, cleanup);
     66 
     67 		if (pwent->pw_gid != TEST_RETURN) {
     68 			tst_resm(TFAIL, "getgid() return value "
     69 				 "%ld unexpected - expected %d",
     70 				 TEST_RETURN, pwent->pw_gid);
     71 		} else {
     72 			tst_resm(TPASS, "values from getuid "
     73 				 "and getpwuid match");
     74 		}
     75 	}
     76 
     77 	cleanup();
     78 	tst_exit();
     79 }
     80 
     81 static void setup(void)
     82 {
     83 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
     84 	TEST_PAUSE;
     85 }
     86 
     87 static void cleanup(void)
     88 {
     89 }
     90