plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [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 | * |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [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 | * |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [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 | * |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [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 | /* |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 21 | * Testcase to check the basic functionality of setfsgid(2) system call. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | */ |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 23 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <unistd.h> |
robbiew | 8541eeb | 2003-03-27 19:59:32 +0000 | [diff] [blame] | 26 | #include <sys/fsuid.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 27 | #include <sys/types.h> |
| 28 | #include <errno.h> |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 29 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 30 | #include "test.h" |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 31 | #include "compat_16.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 32 | |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 33 | TCID_DEFINE(setfsgid01); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 36 | static void setup(void); |
| 37 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | |
robbiew | 8541eeb | 2003-03-27 19:59:32 +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; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | |
| 44 | gid_t gid; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 45 | |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [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 | |
| 49 | setup(); |
| 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 | |
| 54 | gid = getegid(); |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 55 | GID16_CHECK(gid, setfsgid, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 57 | TEST(SETFSGID(cleanup, gid)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
| 59 | if (TEST_RETURN == -1) { |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 60 | tst_resm(TFAIL | TTERRNO, |
| 61 | "setfsgid() failed unexpectedly"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | continue; |
| 63 | } |
| 64 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | if (TEST_RETURN != gid) { |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 66 | tst_resm(TFAIL, "setfsgid() returned %ld, expected %d", |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | TEST_RETURN, gid); |
| 68 | } else { |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 69 | tst_resm(TPASS, |
| 70 | "setfsgid() returned expected value : %ld", |
| 71 | TEST_RETURN); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 74 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 76 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 79 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 82 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | TEST_PAUSE; |
| 84 | } |
| 85 | |
Stanislav Kholmanskikh | 0e7a99b | 2013-09-13 13:59:10 +0400 | [diff] [blame] | 86 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 88 | } |