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 |
| 22 | * getuid02.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Testcase to check the basic functionality of the geteuid() system call. |
| 26 | * |
| 27 | * USAGE: <for command-line> |
| 28 | * getuid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t] |
| 29 | * where, -c n : Run n copies concurrently. |
| 30 | * -f : Turn off functionality Testing. |
| 31 | * -i n : Execute test n times. |
| 32 | * -I x : Execute test for x seconds. |
| 33 | * -P x : Pause for x seconds between iterations. |
| 34 | * -t : Turn on syscall timing. |
| 35 | * |
| 36 | * HISTORY |
| 37 | * 07/2001 Ported by Wayne Boyer |
| 38 | * |
| 39 | * RESTRICTIONS |
| 40 | * None |
| 41 | */ |
| 42 | |
| 43 | #include <pwd.h> |
| 44 | #include <errno.h> |
| 45 | #include <test.h> |
| 46 | #include <usctest.h> |
subrata_modak | 493f24f | 2009-10-15 14:30:34 +0000 | [diff] [blame^] | 47 | #include "compat_16.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | |
subrata_modak | 493f24f | 2009-10-15 14:30:34 +0000 | [diff] [blame^] | 49 | TCID_DEFINE(getuid02); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | int TST_TOTAL = 1; |
| 51 | extern int Tst_count; |
| 52 | |
| 53 | void setup(void); |
| 54 | void cleanup(void); |
| 55 | |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 56 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 58 | int lc; /* loop counter */ |
| 59 | char *msg; /* message returned by parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
| 61 | struct passwd *getpwuid(), *pwent; |
| 62 | |
| 63 | /* parse standard options */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 64 | if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); |
| 66 | } |
| 67 | |
| 68 | setup(); |
| 69 | |
| 70 | /* check looping state if -i option is given */ |
| 71 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 72 | /* reset Tst_count in case we are looping */ |
| 73 | Tst_count = 0; |
| 74 | |
subrata_modak | 493f24f | 2009-10-15 14:30:34 +0000 | [diff] [blame^] | 75 | TEST(GETEUID()); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
| 77 | if (TEST_RETURN < 0) { |
| 78 | tst_brkm(TBROK, cleanup, "This should never happen"); |
| 79 | } |
| 80 | |
| 81 | if (STD_FUNCTIONAL_TEST) { |
| 82 | |
| 83 | pwent = getpwuid(TEST_RETURN); |
| 84 | if (pwent == NULL) { |
| 85 | tst_resm(TFAIL, "geteuid() returned unexpected " |
| 86 | "value %d", TEST_RETURN); |
subrata_modak | 493f24f | 2009-10-15 14:30:34 +0000 | [diff] [blame^] | 87 | } else if (!UID_SIZE_CHECK(pwent->pw_uid)) { |
| 88 | tst_brkm(TBROK, |
| 89 | cleanup, |
| 90 | "uid(%d) is too large for testing geteuid16", |
| 91 | TEST_RETURN); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | } else { |
| 93 | if (pwent->pw_uid != TEST_RETURN) { |
| 94 | tst_resm(TFAIL, "getpwuid() value, %d, " |
| 95 | "does not match geteuid() " |
| 96 | "value, %d", pwent->pw_uid, |
| 97 | TEST_RETURN); |
| 98 | } else { |
| 99 | tst_resm(TPASS, "values from geteuid()" |
| 100 | " and getpwuid() match"); |
| 101 | } |
| 102 | } |
| 103 | } else { |
| 104 | tst_resm(TPASS, "call succeeded"); |
| 105 | } |
| 106 | } |
| 107 | cleanup(); |
| 108 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | /*NOTREACHED*/ return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * setup() - performs all ONE TIME setup for this test. |
| 114 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | { |
| 117 | /* capture signals */ |
| 118 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 119 | |
| 120 | /* Pause if that option was specified */ |
| 121 | TEST_PAUSE; |
| 122 | } |
| 123 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | /* |
| 125 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 126 | * completion or premature exit. |
| 127 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 128 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | { |
| 130 | /* |
| 131 | * print timing stats if that option was specified. |
| 132 | * print errno log if that option was specified. |
| 133 | */ |
| 134 | TEST_CLEANUP; |
| 135 | |
| 136 | /* exit with return code appropriate for results */ |
| 137 | tst_exit(); |
| 138 | } |