Home | History | Annotate | Download | only in getresuid
      1 /*
      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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * Test Name: getresuid01
     22  *
     23  * Test Description:
     24  *  Verify that getresuid() will be successful to get the real, effective
     25  *  and saved user id of the calling process.
     26  *
     27  * Expected Result:
     28  *  getresuid() should return with 0 value and the real/effective/saved
     29  *  user ids should be equal to that of calling process.
     30  *
     31  * Algorithm:
     32  *  Setup:
     33  *   Setup signal handling.
     34  *   Pause for SIGUSR1 if option specified.
     35  *
     36  *  Test:
     37  *   Loop if the proper options are given.
     38  *   Execute system call
     39  *   Check return code, if system call failed (return=-1)
     40  *   	Log the errno and Issue a FAIL message.
     41  *   Otherwise,
     42  *   	Verify the Functionality of system call
     43  *      if successful,
     44  *      	Issue Functionality-Pass message.
     45  *      Otherwise,
     46  *		Issue Functionality-Fail message.
     47  *  Cleanup:
     48  *   Print errno log and/or timing stats if options given
     49  *
     50  * Usage:  <for command-line>
     51  *  getresuid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
     52  *     where,  -c n : Run n copies concurrently.
     53  *             -f   : Turn off functionality Testing.
     54  *	       -i n : Execute test n times.
     55  *	       -I x : Execute test for x seconds.
     56  *	       -P x : Pause for x seconds between iterations.
     57  *	       -t   : Turn on syscall timing.
     58  *
     59  * HISTORY
     60  *	07/2001 Ported by Wayne Boyer
     61  *
     62  * RESTRICTIONS:
     63  *  None.
     64  *
     65  */
     66 #include <stdio.h>
     67 #include <unistd.h>
     68 #include <sys/types.h>
     69 #include <errno.h>
     70 #include <fcntl.h>
     71 #include <string.h>
     72 #include <signal.h>
     73 
     74 #include "test.h"
     75 
     76 extern int getresuid(uid_t *, uid_t *, uid_t *);
     77 
     78 char *TCID = "getresuid01";
     79 int TST_TOTAL = 1;
     80 uid_t pr_uid, pe_uid, ps_uid;	/* calling process real/effective/saved uid */
     81 
     82 void setup();			/* Main setup function of test */
     83 void cleanup();			/* cleanup function for the test */
     84 
     85 int main(int ac, char **av)
     86 {
     87 	int lc;
     88 	uid_t real_uid,		/* real/eff./saved user id from getresuid() */
     89 	 eff_uid, sav_uid;
     90 
     91 	tst_parse_opts(ac, av, NULL, NULL);
     92 
     93 	setup();
     94 
     95 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     96 
     97 		tst_count = 0;
     98 
     99 		/*
    100 		 * Call getresuid() to get the real/effective/saved
    101 		 * user id's of the calling process.
    102 		 */
    103 		TEST(getresuid(&real_uid, &eff_uid, &sav_uid));
    104 
    105 		if (TEST_RETURN == -1) {
    106 			tst_resm(TFAIL, "getresuid() Failed, errno=%d : %s",
    107 				 TEST_ERRNO, strerror(TEST_ERRNO));
    108 			continue;
    109 		}
    110 
    111 		if ((real_uid != pr_uid) || (eff_uid != pe_uid) ||
    112 		    (sav_uid != ps_uid)) {
    113 			tst_resm(TFAIL, "real:%d, effective:%d, "
    114 				 "saved-user:%d ids differ",
    115 				 real_uid, eff_uid, sav_uid);
    116 		} else {
    117 			tst_resm(TPASS, "Functionality of getresuid() "
    118 				 "successful");
    119 		}
    120 	}
    121 
    122 	cleanup();
    123 	tst_exit();
    124 }
    125 
    126 /*
    127  * setup() - performs all ONE TIME setup for this test.
    128  *	     Get the real/effective/saved user id of the calling process.
    129  */
    130 void setup(void)
    131 {
    132 
    133 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    134 
    135 	TEST_PAUSE;
    136 
    137 	/* Real user-id of the calling process */
    138 	pr_uid = getuid();
    139 
    140 	/* Effective user-id of the calling process */
    141 	pe_uid = geteuid();
    142 
    143 	/* Saved user-id of the calling process */
    144 	ps_uid = geteuid();
    145 
    146 }
    147 
    148 /*
    149  * cleanup() - performs all ONE TIME cleanup for this test at
    150  *             completion or premature exit.
    151  */
    152 void cleanup(void)
    153 {
    154 
    155 }
    156