1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2014 Fujitsu Ltd.
4 * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
5 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Verify that after updating euid with setresuid(), any file creation
12 * also gets the new euid as its owner user ID.
13 */
14
15 #include <pwd.h>
16 #include <sys/stat.h>
17 #include "tst_test.h"
18 #include "compat_tst_16.h"
19
20 #define TEMP_FILE "testfile"
21 static struct passwd *ltpuser;
22
setup(void)23 static void setup(void)
24 {
25 ltpuser = SAFE_GETPWNAM("nobody");
26 UID16_CHECK(ltpuser->pw_uid, "setresuid");
27 }
28
run(void)29 static void run(void)
30 {
31 struct stat buf;
32
33 TST_EXP_PASS(SETRESUID(-1, ltpuser->pw_uid, -1));
34
35 SAFE_TOUCH(TEMP_FILE, 0644, NULL);
36 SAFE_STAT(TEMP_FILE, &buf);
37
38 TST_EXP_EQ_LI(ltpuser->pw_uid, buf.st_uid);
39
40 SAFE_UNLINK(TEMP_FILE);
41 TST_EXP_PASS_SILENT(SETRESUID(-1, 0, -1));
42 }
43
44 static struct tst_test test = {
45 .setup = setup,
46 .test_all = run,
47 .needs_root = 1,
48 .needs_tmpdir = 1
49 };
50