plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 2 | * |
Mike Frysinger | a25f89e | 2013-04-27 02:35:01 -0400 | [diff] [blame] | 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 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Test Name: getresgid01 |
| 22 | * |
| 23 | * Test Description: |
| 24 | * Verify that getresgid() will be successful to get the real, effective |
| 25 | * and saved user id of the calling process. |
| 26 | * |
| 27 | * Expected Result: |
| 28 | * getresgid() 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) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 40 | * Log the errno and Issue a FAIL message. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 41 | * Otherwise, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | * Verify the Functionality of system call |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | * if successful, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 44 | * Issue Functionality-Pass message. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 | * getresgid01 [-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 | */ |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 66 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | #include <stdio.h> |
| 68 | #include <unistd.h> |
| 69 | #include <sys/types.h> |
| 70 | #include <errno.h> |
| 71 | #include <fcntl.h> |
| 72 | #include <string.h> |
| 73 | #include <signal.h> |
| 74 | |
| 75 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | extern int getresgid(gid_t *, gid_t *, gid_t *); |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 78 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 79 | char *TCID = "getresgid01"; |
| 80 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | gid_t pr_gid, pe_gid, ps_gid; /* calling process real/effective/saved gid */ |
| 82 | |
| 83 | void setup(); /* Main setup function of test */ |
| 84 | void cleanup(); /* cleanup function for the test */ |
| 85 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 88 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 89 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | gid_t real_gid, /* real/eff./saved user id from getresgid() */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | eff_gid, sav_gid; |
| 92 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 93 | msg = parse_opts(ac, av, NULL, NULL); |
| 94 | if (msg != NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 96 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | } |
| 98 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | setup(); |
| 100 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 102 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 103 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 105 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | * Call getresgid() to get the real/effective/saved |
| 107 | * user id's of the calling process. |
| 108 | */ |
| 109 | TEST(getresgid(&real_gid, &eff_gid, &sav_gid)); |
| 110 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | if (TEST_RETURN == -1) { |
| 112 | tst_resm(TFAIL, "getresgid() Failed, errno=%d : %s", |
| 113 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 114 | continue; |
| 115 | } |
| 116 | /* |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 117 | * Verify the real/effective/saved gid values returned |
| 118 | * by getresgid with the expected values. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | */ |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 120 | if ((real_gid != pr_gid) || (eff_gid != pe_gid) || |
| 121 | (sav_gid != ps_gid)) { |
| 122 | tst_resm(TFAIL, "real:%d, effective:%d, " |
| 123 | "saved-user:%d ids differ", |
| 124 | real_gid, eff_gid, sav_gid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 126 | tst_resm(TPASS, "Functionality of getresgid() " |
| 127 | "successful"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 128 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 129 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 130 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 132 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 133 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * setup() - performs all ONE TIME setup for this test. |
| 137 | * Get the real/effective/saved user id of the calling process. |
| 138 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 139 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 141 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 142 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 143 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 144 | TEST_PAUSE; |
| 145 | |
| 146 | /* Real user-id of the calling process */ |
| 147 | pr_gid = getgid(); |
| 148 | |
| 149 | /* Effective user-id of the calling process */ |
| 150 | pe_gid = getegid(); |
| 151 | |
| 152 | /* Saved user-id of the calling process */ |
| 153 | ps_gid = getegid(); |
| 154 | |
| 155 | } |
| 156 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 157 | /* |
| 158 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 159 | * completion or premature exit. |
| 160 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 161 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 163 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 164 | } |