• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) International Business Machines  Corp., 2001
3  * Ported by Wayne Boyer
4  * Adapted by Dustin Kirkland (k1rkland@us.ibm.com)
5  * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Verify that setfsuid() correctly updates the filesystem uid
12  * when caller is a non-root user and provided fsuid matches
13  * caller's real user ID.
14  */
15 
16 #include <pwd.h>
17 
18 #include "tst_test.h"
19 #include "compat_tst_16.h"
20 
21 static uid_t nobody_uid;
22 
setup(void)23 static void setup(void)
24 {
25 	struct passwd *nobody;
26 
27 	nobody = SAFE_GETPWNAM("nobody");
28 	nobody_uid = nobody->pw_uid;
29 }
30 
run(void)31 static void run(void)
32 {
33 	uid_t ruid, euid, suid;
34 
35 	SAFE_GETRESUID(&ruid, &euid, &suid);
36 	SAFE_SETEUID(nobody_uid);
37 	UID16_CHECK(ruid, setfsuid);
38 
39 	TST_EXP_VAL_SILENT(SETFSUID(ruid), nobody_uid);
40 	TST_EXP_VAL(SETFSUID(-1), ruid, "setfsuid(fsuid) by non-root user:");
41 }
42 
43 static struct tst_test test = {
44 	.needs_root = 1,
45 	.setup = setup,
46 	.test_all = run
47 };
48