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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 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 | * 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> |
Garrett Cooper | e8530df | 2010-12-21 11:37:57 -0800 | [diff] [blame] | 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; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
| 52 | void setup(void); |
| 53 | void cleanup(void); |
| 54 | |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 55 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 57 | struct passwd *pwent; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 58 | int lc; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 59 | char *msg; /* message returned by parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 61 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 62 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | |
| 64 | setup(); |
| 65 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | Tst_count = 0; |
| 68 | |
subrata_modak | 493f24f | 2009-10-15 14:30:34 +0000 | [diff] [blame] | 69 | TEST(GETEUID()); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 71 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 72 | tst_brkm(TBROK | TTERRNO, cleanup, "geteuid* failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | |
| 74 | if (STD_FUNCTIONAL_TEST) { |
| 75 | |
| 76 | pwent = getpwuid(TEST_RETURN); |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 77 | if (pwent == NULL) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 78 | tst_resm(TFAIL | TERRNO, "getpwuid failed"); |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 79 | else if (!UID_SIZE_CHECK(pwent->pw_uid)) |
| 80 | tst_brkm(TBROK, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 81 | "uid = %ld is too large for testing " |
| 82 | "via geteuid16", TEST_RETURN); |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 83 | else { |
| 84 | if (pwent->pw_uid != TEST_RETURN) |
| 85 | tst_resm(TFAIL, "getpwuid value, %d, " |
| 86 | "does not match geteuid " |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 87 | "value, %ld", pwent->pw_uid, |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | TEST_RETURN); |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 89 | else |
| 90 | tst_resm(TPASS, "values from geteuid " |
| 91 | "and getpwuid match"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | } |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 93 | } else |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | tst_resm(TPASS, "call succeeded"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | } |
| 96 | cleanup(); |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 97 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 98 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | } |
| 100 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 103 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 105 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | TEST_PAUSE; |
| 107 | } |
| 108 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | TEST_CLEANUP; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 112 | } |