xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/setreuid/setreuid01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  *	Author: William Roske
5  *	Co-pilot: Dave Fenner
6  * Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
7  */
8 
9 /*\
10  * [Description]
11  *
12  * Verify the basic functionality of setreuid(2) system call when executed
13  * as non-root user.
14  */
15 
16 #include "tst_test.h"
17 #include "compat_tst_16.h"
18 
19 static uid_t ruid, euid;
20 
run(void)21 static void run(void)
22 {
23 	ruid = getuid();
24 	UID16_CHECK(ruid, setreuid);
25 
26 	euid = geteuid();
27 	UID16_CHECK(euid, setreuid);
28 
29 	TST_EXP_PASS(SETREUID(-1, -1));
30 	TST_EXP_PASS(SETREUID(-1, euid));
31 	TST_EXP_PASS(SETREUID(ruid, -1));
32 	TST_EXP_PASS(SETREUID(-1, ruid));
33 	TST_EXP_PASS(SETREUID(euid, -1));
34 	TST_EXP_PASS(SETREUID(euid, euid));
35 	TST_EXP_PASS(SETREUID(ruid, ruid));
36 }
37 
38 static struct tst_test test = {
39 	.test_all = run
40 };
41