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 | /* |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 21 | * Testcase to check the basic functionality of getegid(). |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 23 | * For functionality test the return value from getegid() is compared to passwd |
| 24 | * entry. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include <pwd.h> |
| 28 | #include <errno.h> |
| 29 | |
| 30 | #include "test.h" |
subrata_modak | 153f98c | 2008-09-19 10:09:58 +0000 | [diff] [blame] | 31 | #include "compat_16.h" |
| 32 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 33 | static void cleanup(void); |
| 34 | static void setup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | |
subrata_modak | 4f41ee3 | 2008-09-22 06:52:57 +0000 | [diff] [blame] | 36 | TCID_DEFINE(getegid02); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 37 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 39 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 41 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 42 | const char *msg; |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 43 | uid_t euid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | struct passwd *pwent; |
| 45 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 46 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 47 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 49 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 52 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 54 | TEST(GETEGID(cleanup)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | |
| 56 | if (TEST_RETURN < 0) { |
| 57 | tst_brkm(TBROK, cleanup, "This should never happen"); |
| 58 | } |
| 59 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 60 | euid = geteuid(); |
| 61 | pwent = getpwuid(euid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 63 | if (pwent == NULL) |
| 64 | tst_brkm(TBROK, cleanup, "geteuid() returned " |
| 65 | "unexpected value %d", euid); |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 66 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 67 | GID16_CHECK(pwent->pw_gid, getegid, cleanup); |
Stanislav Kholmanskikh | 4940d00 | 2013-09-11 13:25:44 +0400 | [diff] [blame] | 68 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 69 | if (pwent->pw_gid != TEST_RETURN) { |
| 70 | tst_resm(TFAIL, "getegid() return value" |
| 71 | " %ld unexpected - expected %d", |
| 72 | TEST_RETURN, pwent->pw_gid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 74 | tst_resm(TPASS, |
| 75 | "effective group id %ld " |
| 76 | "is correct", TEST_RETURN); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 80 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 81 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 84 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | TEST_PAUSE; |
| 88 | } |
| 89 | |
Cyril Hrubis | 61e3e02 | 2013-09-12 15:37:26 +0200 | [diff] [blame] | 90 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 92 | } |