blob: 3a95fd119485e7e4584122759a1c89c6a9d2b96e [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
Cyril Hrubis61e3e022013-09-12 15:37:26 +02002 * Copyright (c) International Business Machines Corp., 2001
3 * Ported by Wayne Boyer
plars865695b2001-08-27 22:15:12 +00004 *
Cyril Hrubis61e3e022013-09-12 15:37:26 +02005 * 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.
plars865695b2001-08-27 22:15:12 +00009 *
Cyril Hrubis61e3e022013-09-12 15:37:26 +020010 * 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.
plars865695b2001-08-27 22:15:12 +000014 *
Cyril Hrubis61e3e022013-09-12 15:37:26 +020015 * 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
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
Cyril Hrubis61e3e022013-09-12 15:37:26 +020021 * Testcase to check the basic functionality of getegid().
plars865695b2001-08-27 22:15:12 +000022 *
Cyril Hrubis61e3e022013-09-12 15:37:26 +020023 * For functionality test the return value from getegid() is compared to passwd
24 * entry.
plars865695b2001-08-27 22:15:12 +000025 */
26
27#include <pwd.h>
28#include <errno.h>
29
30#include "test.h"
subrata_modak153f98c2008-09-19 10:09:58 +000031#include "compat_16.h"
32
Cyril Hrubis61e3e022013-09-12 15:37:26 +020033static void cleanup(void);
34static void setup(void);
plars865695b2001-08-27 22:15:12 +000035
subrata_modak4f41ee32008-09-22 06:52:57 +000036TCID_DEFINE(getegid02);
plars865695b2001-08-27 22:15:12 +000037int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000038
plars74948ad2002-11-14 16:16:14 +000039int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000040{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020041 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020042 const char *msg;
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040043 uid_t euid;
plars865695b2001-08-27 22:15:12 +000044 struct passwd *pwent;
45
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080046 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080047 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000048
Cyril Hrubis61e3e022013-09-12 15:37:26 +020049 setup();
plars865695b2001-08-27 22:15:12 +000050
plars865695b2001-08-27 22:15:12 +000051 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080052 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000053
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040054 TEST(GETEGID(cleanup));
plars865695b2001-08-27 22:15:12 +000055
56 if (TEST_RETURN < 0) {
57 tst_brkm(TBROK, cleanup, "This should never happen");
58 }
59
Cyril Hrubise38b9612014-06-02 17:20:57 +020060 euid = geteuid();
61 pwent = getpwuid(euid);
plars865695b2001-08-27 22:15:12 +000062
Cyril Hrubise38b9612014-06-02 17:20:57 +020063 if (pwent == NULL)
64 tst_brkm(TBROK, cleanup, "geteuid() returned "
65 "unexpected value %d", euid);
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040066
Cyril Hrubise38b9612014-06-02 17:20:57 +020067 GID16_CHECK(pwent->pw_gid, getegid, cleanup);
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040068
Cyril Hrubise38b9612014-06-02 17:20:57 +020069 if (pwent->pw_gid != TEST_RETURN) {
70 tst_resm(TFAIL, "getegid() return value"
71 " %ld unexpected - expected %d",
72 TEST_RETURN, pwent->pw_gid);
plars865695b2001-08-27 22:15:12 +000073 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020074 tst_resm(TPASS,
75 "effective group id %ld "
76 "is correct", TEST_RETURN);
plars865695b2001-08-27 22:15:12 +000077 }
78 }
plars865695b2001-08-27 22:15:12 +000079
Cyril Hrubis61e3e022013-09-12 15:37:26 +020080 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080081 tst_exit();
plars865695b2001-08-27 22:15:12 +000082}
83
Cyril Hrubis61e3e022013-09-12 15:37:26 +020084static void setup(void)
plars865695b2001-08-27 22:15:12 +000085{
plars865695b2001-08-27 22:15:12 +000086 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000087 TEST_PAUSE;
88}
89
Cyril Hrubis61e3e022013-09-12 15:37:26 +020090static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000091{
Chris Dearmanec6edca2012-10-17 19:54:01 -070092}