plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * Ported by Wayne Boyer |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 9 | * |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 14 | * |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 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 | #include <pwd.h> |
| 21 | #include <errno.h> |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 22 | |
Garrett Cooper | e8530df | 2010-12-21 11:37:57 -0800 | [diff] [blame] | 23 | #include "test.h" |
subrata_modak | 493f24f | 2009-10-15 14:30:34 +0000 | [diff] [blame] | 24 | #include "compat_16.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 25 | |
Stanislav Kholmanskikh | 1c44244 | 2013-09-11 13:25:43 +0400 | [diff] [blame] | 26 | TCID_DEFINE(geteuid02); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 27 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 28 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 29 | static void setup(void); |
| 30 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 31 | |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 32 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 33 | { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 34 | struct passwd *pwent; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 35 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 36 | const char *msg; |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 37 | uid_t uid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 39 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 40 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 41 | |
| 42 | setup(); |
| 43 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 45 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 47 | TEST(GETEUID(cleanup)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 49 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 50 | tst_brkm(TBROK | TTERRNO, cleanup, "geteuid* failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 52 | uid = geteuid(); |
| 53 | pwent = getpwuid(uid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 55 | if (pwent == NULL) |
| 56 | tst_resm(TFAIL | TERRNO, "getpwuid failed"); |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 57 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 58 | UID16_CHECK(pwent->pw_uid, geteuid, cleanup); |
| 59 | if (pwent->pw_uid != TEST_RETURN) |
| 60 | tst_resm(TFAIL, "getpwuid value, %d, " |
| 61 | "does not match geteuid " |
| 62 | "value, %ld", pwent->pw_uid, |
| 63 | TEST_RETURN); |
| 64 | else |
| 65 | tst_resm(TPASS, "values from geteuid " |
| 66 | "and getpwuid match"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | } |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 68 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | cleanup(); |
Garrett Cooper | 27408da | 2010-12-19 02:31:31 -0800 | [diff] [blame] | 70 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 73 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | TEST_PAUSE; |
| 77 | } |
| 78 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 79 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 81 | } |