plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * $Copyright: $ |
| 3 | * Copyright (c) 1984-2000 |
| 4 | * Sequent Computer Systems, Inc. All rights reserved. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 5 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 6 | * This software is furnished under a license and may be used |
| 7 | * only in accordance with the terms of that license and with the |
| 8 | * inclusion of the above copyright notice. This software may not |
| 9 | * be provided or otherwise made available to, or used by, any |
| 10 | * other person. No title to or ownership of the software is |
| 11 | * hereby transferred. |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * Test Name: getresgid01 |
| 16 | * |
| 17 | * Test Description: |
| 18 | * Verify that getresgid() will be successful to get the real, effective |
| 19 | * and saved user id of the calling process. |
| 20 | * |
| 21 | * Expected Result: |
| 22 | * getresgid() should return with 0 value and the real/effective/saved |
| 23 | * user ids should be equal to that of calling process. |
| 24 | * |
| 25 | * Algorithm: |
| 26 | * Setup: |
| 27 | * Setup signal handling. |
| 28 | * Pause for SIGUSR1 if option specified. |
| 29 | * |
| 30 | * Test: |
| 31 | * Loop if the proper options are given. |
| 32 | * Execute system call |
| 33 | * Check return code, if system call failed (return=-1) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 34 | * Log the errno and Issue a FAIL message. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | * Otherwise, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 36 | * Verify the Functionality of system call |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 37 | * if successful, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 38 | * Issue Functionality-Pass message. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 39 | * Otherwise, |
| 40 | * Issue Functionality-Fail message. |
| 41 | * Cleanup: |
| 42 | * Print errno log and/or timing stats if options given |
| 43 | * |
| 44 | * Usage: <for command-line> |
| 45 | * getresgid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] |
| 46 | * where, -c n : Run n copies concurrently. |
| 47 | * -f : Turn off functionality Testing. |
| 48 | * -i n : Execute test n times. |
| 49 | * -I x : Execute test for x seconds. |
| 50 | * -P x : Pause for x seconds between iterations. |
| 51 | * -t : Turn on syscall timing. |
| 52 | * |
| 53 | * HISTORY |
| 54 | * 07/2001 Ported by Wayne Boyer |
| 55 | * |
| 56 | * RESTRICTIONS: |
| 57 | * None. |
| 58 | * |
| 59 | */ |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 60 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | #include <stdio.h> |
| 62 | #include <unistd.h> |
| 63 | #include <sys/types.h> |
| 64 | #include <errno.h> |
| 65 | #include <fcntl.h> |
| 66 | #include <string.h> |
| 67 | #include <signal.h> |
| 68 | |
| 69 | #include "test.h" |
| 70 | #include "usctest.h" |
| 71 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 72 | extern int getresgid(gid_t *, gid_t *, gid_t *); |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 73 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | char *TCID = "getresgid01"; /* Test program identifier. */ |
| 75 | int TST_TOTAL = 1; /* Total number of test cases. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
| 77 | gid_t pr_gid, pe_gid, ps_gid; /* calling process real/effective/saved gid */ |
| 78 | |
| 79 | void setup(); /* Main setup function of test */ |
| 80 | void cleanup(); /* cleanup function for the test */ |
| 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | { |
| 84 | int lc; /* loop counter */ |
| 85 | char *msg; /* message returned from parse_opts */ |
| 86 | gid_t real_gid, /* real/eff./saved user id from getresgid() */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | eff_gid, sav_gid; |
| 88 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | /* Parse standard options given to run the test. */ |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 90 | <<<<<<< HEAD |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 91 | msg = parse_opts(ac, av, NULL, NULL); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 92 | ======= |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | msg = parse_opts(ac, av, (option_t *) NULL, NULL); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 94 | >>>>>>> master |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 95 | if (msg != NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 97 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | } |
| 99 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | setup(); |
| 101 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 103 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | Tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 106 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 107 | * Call getresgid() to get the real/effective/saved |
| 108 | * user id's of the calling process. |
| 109 | */ |
| 110 | TEST(getresgid(&real_gid, &eff_gid, &sav_gid)); |
| 111 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | if (TEST_RETURN == -1) { |
| 113 | tst_resm(TFAIL, "getresgid() Failed, errno=%d : %s", |
| 114 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 115 | continue; |
| 116 | } |
| 117 | /* |
| 118 | * Perform functional verification if test |
| 119 | * executed without (-f) option. |
| 120 | */ |
| 121 | if (STD_FUNCTIONAL_TEST) { |
| 122 | /* |
| 123 | * Verify the real/effective/saved gid values returned |
| 124 | * by getresgid with the expected values. |
| 125 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | if ((real_gid != pr_gid) || (eff_gid != pe_gid) || |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 127 | (sav_gid != ps_gid)) { |
| 128 | tst_resm(TFAIL, "real:%d, effective:%d, " |
| 129 | "saved-user:%d ids differ", |
| 130 | real_gid, eff_gid, sav_gid); |
| 131 | } else { |
| 132 | tst_resm(TPASS, "Functionality of getresgid() " |
| 133 | "successful"); |
| 134 | } |
| 135 | } else { |
| 136 | tst_resm(TPASS, "call succeeded"); |
| 137 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 138 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | cleanup(); |
| 141 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 142 | return 0; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 143 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * setup() - performs all ONE TIME setup for this test. |
| 147 | * Get the real/effective/saved user id of the calling process. |
| 148 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 151 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 152 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 153 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 154 | TEST_PAUSE; |
| 155 | |
| 156 | /* Real user-id of the calling process */ |
| 157 | pr_gid = getgid(); |
| 158 | |
| 159 | /* Effective user-id of the calling process */ |
| 160 | pe_gid = getegid(); |
| 161 | |
| 162 | /* Saved user-id of the calling process */ |
| 163 | ps_gid = getegid(); |
| 164 | |
| 165 | } |
| 166 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 167 | /* |
| 168 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 169 | * completion or premature exit. |
| 170 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 172 | { |
| 173 | /* |
| 174 | * print timing stats if that option was specified. |
| 175 | * print errno log if that option was specified. |
| 176 | */ |
| 177 | TEST_CLEANUP; |
| 178 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 179 | } |