Home | History | Annotate | Download | only in getuid
      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 the getuid() system call.
     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 TCID_DEFINE(getuid03);
     34 int TST_TOTAL = 1;
     35 
     36 static void setup(void);
     37 static void cleanup(void);
     38 
     39 int main(int ac, char **av)
     40 {
     41 	struct passwd *pwent;
     42 	int lc;
     43 	uid_t uid;
     44 
     45 	tst_parse_opts(ac, av, NULL, NULL);
     46 
     47 	setup();
     48 
     49 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     50 
     51 		tst_count = 0;
     52 
     53 		TEST(GETUID(cleanup));
     54 
     55 		if (TEST_RETURN == -1)
     56 			tst_brkm(TBROK | TTERRNO, cleanup, "getuid failed");
     57 
     58 		uid = getuid();
     59 		pwent = getpwuid(uid);
     60 
     61 		if (pwent == NULL)
     62 			tst_resm(TFAIL | TERRNO, "getpwuid failed");
     63 
     64 		UID16_CHECK(pwent->pw_uid, getuid, cleanup);
     65 
     66 		if (pwent->pw_uid != TEST_RETURN)
     67 			tst_resm(TFAIL, "getpwuid value, %d, "
     68 				 "does not match getuid "
     69 				 "value, %ld", pwent->pw_uid,
     70 				 TEST_RETURN);
     71 		else
     72 			tst_resm(TPASS, "values from getuid "
     73 				 "and getpwuid match");
     74 	}
     75 	cleanup();
     76 	tst_exit();
     77 }
     78 
     79 static void setup(void)
     80 {
     81 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
     82 
     83 	TEST_PAUSE;
     84 }
     85 
     86 static void cleanup(void)
     87 {
     88 }
     89