blob: 046744d469710683884fc8e590576fd762d4b679 [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#include <pwd.h>
21#include <errno.h>
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040022
Garrett Coopere8530df2010-12-21 11:37:57 -080023#include "test.h"
subrata_modak493f24f2009-10-15 14:30:34 +000024#include "compat_16.h"
plars865695b2001-08-27 22:15:12 +000025
Stanislav Kholmanskikh1c442442013-09-11 13:25:43 +040026TCID_DEFINE(geteuid02);
plars865695b2001-08-27 22:15:12 +000027int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000028
Cyril Hrubis61e3e022013-09-12 15:37:26 +020029static void setup(void);
30static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000031
robbiew96d23372003-03-26 20:40:04 +000032int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000033{
Garrett Cooper60fa8012010-11-22 13:50:58 -080034 struct passwd *pwent;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020035 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020036 const char *msg;
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040037 uid_t uid;
plars865695b2001-08-27 22:15:12 +000038
Garrett Cooper53740502010-12-16 00:04:01 -080039 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080040 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000041
42 setup();
43
plars865695b2001-08-27 22:15:12 +000044 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080045 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000046
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040047 TEST(GETEUID(cleanup));
plars865695b2001-08-27 22:15:12 +000048
Garrett Cooper27408da2010-12-19 02:31:31 -080049 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080050 tst_brkm(TBROK | TTERRNO, cleanup, "geteuid* failed");
plars865695b2001-08-27 22:15:12 +000051
Cyril Hrubise38b9612014-06-02 17:20:57 +020052 uid = geteuid();
53 pwent = getpwuid(uid);
plars865695b2001-08-27 22:15:12 +000054
Cyril Hrubise38b9612014-06-02 17:20:57 +020055 if (pwent == NULL)
56 tst_resm(TFAIL | TERRNO, "getpwuid failed");
Stanislav Kholmanskikh4940d002013-09-11 13:25:44 +040057
Cyril Hrubise38b9612014-06-02 17:20:57 +020058 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");
plars865695b2001-08-27 22:15:12 +000067 }
Cyril Hrubis61e3e022013-09-12 15:37:26 +020068
plars865695b2001-08-27 22:15:12 +000069 cleanup();
Garrett Cooper27408da2010-12-19 02:31:31 -080070 tst_exit();
plars865695b2001-08-27 22:15:12 +000071}
72
Cyril Hrubis61e3e022013-09-12 15:37:26 +020073static void setup(void)
plars865695b2001-08-27 22:15:12 +000074{
plars865695b2001-08-27 22:15:12 +000075 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000076 TEST_PAUSE;
77}
78
Cyril Hrubis61e3e022013-09-12 15:37:26 +020079static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000080{
Chris Dearmanec6edca2012-10-17 19:54:01 -070081}