plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
subrata_modak | 4f41ee3 | 2008-09-22 06:52:57 +0000 | [diff] [blame] | 22 | * getegid02.c |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Testcase to check the basic functionality of getegid(). |
| 26 | * |
| 27 | * ALGORITHM |
| 28 | * call setup |
| 29 | * loop if that option was specified |
| 30 | * Execute getegid() call using TEST macro |
| 31 | * if not expected value |
| 32 | * break remaining tests and cleanup |
| 33 | * if STD_FUNCTIONAL_TEST |
| 34 | * Execute geteuid() call |
| 35 | * Execute getpwduid() call |
| 36 | * if the passwd entry is NULL |
| 37 | * break the remaining tests and cleanup |
| 38 | * else if pwent->pw_gid != TEST_RETURN |
| 39 | * print failure message |
| 40 | * else |
| 41 | * print pass message |
| 42 | * else |
| 43 | * print pass message |
| 44 | * call cleanup |
| 45 | * |
| 46 | * USAGE: <for command-line> |
subrata_modak | 4f41ee3 | 2008-09-22 06:52:57 +0000 | [diff] [blame] | 47 | * getegid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t] |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | * where, -c n : Run n copies concurrently. |
| 49 | * -f : Turn off functionality Testing. |
| 50 | * -i n : Execute test n times. |
| 51 | * -I x : Execute test for x seconds. |
| 52 | * -P x : Pause for x seconds between iterations. |
| 53 | * -t : Turn on syscall timing. |
| 54 | * |
| 55 | * HISTORY |
| 56 | * 07/2001 Ported by Wayne Boyer |
| 57 | * |
| 58 | * RESTRICTIONS |
| 59 | * none |
| 60 | */ |
| 61 | |
| 62 | #include <pwd.h> |
| 63 | #include <errno.h> |
| 64 | |
| 65 | #include "test.h" |
| 66 | #include "usctest.h" |
| 67 | |
subrata_modak | 153f98c | 2008-09-19 10:09:58 +0000 | [diff] [blame] | 68 | #include "compat_16.h" |
| 69 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | void cleanup(void); |
| 71 | void setup(void); |
| 72 | |
subrata_modak | 4f41ee3 | 2008-09-22 06:52:57 +0000 | [diff] [blame] | 73 | TCID_DEFINE(getegid02); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | int TST_TOTAL = 1; |
| 75 | extern int Tst_count; |
| 76 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 77 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | int lc; /* loop counter */ |
| 80 | char *msg; /* message returned from parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | int euid; |
| 82 | struct passwd *pwent; |
| 83 | |
| 84 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 85 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | /*NOTREACHED*/} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | |
| 91 | /* The following loop checks looping state if -i option given */ |
| 92 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 93 | |
| 94 | /* reset Tst_count in case we are looping */ |
| 95 | Tst_count = 0; |
| 96 | |
subrata_modak | 153f98c | 2008-09-19 10:09:58 +0000 | [diff] [blame] | 97 | TEST(GETEGID()); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | |
| 99 | if (TEST_RETURN < 0) { |
| 100 | tst_brkm(TBROK, cleanup, "This should never happen"); |
| 101 | } |
| 102 | |
| 103 | if (STD_FUNCTIONAL_TEST) { |
| 104 | euid = geteuid(); |
| 105 | |
| 106 | pwent = getpwuid(euid); |
| 107 | |
| 108 | if (pwent == NULL) { |
| 109 | tst_brkm(TBROK, cleanup, "geteuid() returned " |
| 110 | "unexpected value %d", euid); |
subrata_modak | 153f98c | 2008-09-19 10:09:58 +0000 | [diff] [blame] | 111 | } else if (!GID_SIZE_CHECK(pwent->pw_gid)) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 112 | tst_brkm(TBROK, |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 113 | cleanup, |
subrata_modak | 153f98c | 2008-09-19 10:09:58 +0000 | [diff] [blame] | 114 | "gid for euid %d is too large for testing getegid16", |
| 115 | euid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | } else { |
| 117 | if (pwent->pw_gid != TEST_RETURN) { |
| 118 | tst_resm(TFAIL, "getegid() return value" |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 119 | " %ld unexpected - expected %d", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | TEST_RETURN, pwent->pw_gid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 122 | tst_resm(TPASS, "effective group id %ld " |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | "is correct", TEST_RETURN); |
| 124 | } |
| 125 | } |
| 126 | } else { |
| 127 | tst_resm(TPASS, "call succeeded"); |
| 128 | } |
| 129 | } |
| 130 | cleanup(); |
| 131 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | /*NOTREACHED*/ return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | } |
| 134 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 135 | /* |
| 136 | * setup() - performs all ONE TIME setup for this test |
| 137 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | { |
| 140 | /* capture signals */ |
| 141 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 142 | |
| 143 | /* Pause if that option was specified */ |
| 144 | TEST_PAUSE; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | * or premature exit. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 152 | { |
| 153 | /* |
| 154 | * print timing status if that option was specified. |
| 155 | * print errno log if that option was specified |
| 156 | */ |
| 157 | TEST_CLEANUP; |
| 158 | |
| 159 | /* exit with return code appropriate for results */ |
| 160 | tst_exit(); |
| 161 | } |