blob: 0a85cff97d9e4330f8571e9c0fc518218d9a0725 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
Cyril Hrubis7dc42c92013-09-12 14:55:55 +02002 * Copyright (c) International Business Machines Corp., 2001
3 * Ported by Wayne Boyer
plars865695b2001-08-27 22:15:12 +00004 *
Cyril Hrubis7dc42c92013-09-12 14:55:55 +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 Hrubis7dc42c92013-09-12 14:55:55 +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 Hrubis7dc42c92013-09-12 14:55:55 +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 Hrubis7dc42c92013-09-12 14:55:55 +020021 * Testcase to check the basic functionality of getgid().
plars865695b2001-08-27 22:15:12 +000022 *
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020023 * For functionality test the return value from getgid() 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 Hrubis7dc42c92013-09-12 14:55:55 +020033static void cleanup(void);
34static void setup(void);
plars865695b2001-08-27 22:15:12 +000035
subrata_modak153f98c2008-09-19 10:09:58 +000036TCID_DEFINE(getgid03);
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 Kholmanskikh1c442442013-09-11 13:25:43 +040043 uid_t uid;
plars865695b2001-08-27 22:15:12 +000044 struct passwd *pwent;
45
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020046 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 Hrubis7dc42c92013-09-12 14:55:55 +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 Kholmanskikh1c442442013-09-11 13:25:43 +040054 TEST(GETGID(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 uid = getuid();
61 pwent = getpwuid(uid);
plars865695b2001-08-27 22:15:12 +000062
Cyril Hrubise38b9612014-06-02 17:20:57 +020063 if (pwent == NULL)
64 tst_brkm(TBROK, cleanup, "getuid() returned "
65 "unexpected value %d", uid);
Stanislav Kholmanskikh1c442442013-09-11 13:25:43 +040066
Cyril Hrubise38b9612014-06-02 17:20:57 +020067 GID16_CHECK(pwent->pw_gid, getgid, cleanup);
Stanislav Kholmanskikh1c442442013-09-11 13:25:43 +040068
Cyril Hrubise38b9612014-06-02 17:20:57 +020069 if (pwent->pw_gid != TEST_RETURN) {
70 tst_resm(TFAIL, "getgid() 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, "values from getuid "
75 "and getpwuid match");
plars865695b2001-08-27 22:15:12 +000076 }
77 }
plars865695b2001-08-27 22:15:12 +000078
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020079 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080080 tst_exit();
plars865695b2001-08-27 22:15:12 +000081}
82
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020083static void setup(void)
plars865695b2001-08-27 22:15:12 +000084{
plars865695b2001-08-27 22:15:12 +000085 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000086 TEST_PAUSE;
87}
88
Cyril Hrubis7dc42c92013-09-12 14:55:55 +020089static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000090{
Chris Dearmanec6edca2012-10-17 19:54:01 -070091}