xref: /aosp_15_r20/external/ltp/include/tst_uid.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2021 Linux Test Project
3*49cdfc7eSAndroid Build Coastguard Worker  */
4*49cdfc7eSAndroid Build Coastguard Worker 
5*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_UID_H_
6*49cdfc7eSAndroid Build Coastguard Worker #define TST_UID_H_
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker /*
11*49cdfc7eSAndroid Build Coastguard Worker  * Find unassigned gid. The skip argument can be used to ignore e.g. the main
12*49cdfc7eSAndroid Build Coastguard Worker  * group of a specific user in case it's not listed in the group file. If you
13*49cdfc7eSAndroid Build Coastguard Worker  * do not need to skip any specific gid, simply set it to 0.
14*49cdfc7eSAndroid Build Coastguard Worker  */
15*49cdfc7eSAndroid Build Coastguard Worker gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip);
16*49cdfc7eSAndroid Build Coastguard Worker #define tst_get_free_gid(skip) tst_get_free_gid_(__FILE__, __LINE__, (skip))
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker /*
19*49cdfc7eSAndroid Build Coastguard Worker  * Get a specific number of unique existing non-root user or group IDs.
20*49cdfc7eSAndroid Build Coastguard Worker  * The "start" parameter is the number of buffer entries that are already
21*49cdfc7eSAndroid Build Coastguard Worker  * filled and will not be modified. The function will fill the remaining
22*49cdfc7eSAndroid Build Coastguard Worker  * (size-start) entries with unique UID/GID values.
23*49cdfc7eSAndroid Build Coastguard Worker  */
24*49cdfc7eSAndroid Build Coastguard Worker void tst_get_uids(uid_t *buf, unsigned int start, unsigned int size);
25*49cdfc7eSAndroid Build Coastguard Worker void tst_get_gids(gid_t *buf, unsigned int start, unsigned int size);
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker /*
28*49cdfc7eSAndroid Build Coastguard Worker  * Helper functions for checking current proces UIDs/GIDs.
29*49cdfc7eSAndroid Build Coastguard Worker  */
30*49cdfc7eSAndroid Build Coastguard Worker int tst_check_resuid_(const char *file, const int lineno, const char *callstr,
31*49cdfc7eSAndroid Build Coastguard Worker 	uid_t exp_ruid, uid_t exp_euid, uid_t exp_suid);
32*49cdfc7eSAndroid Build Coastguard Worker #define tst_check_resuid(cstr, ruid, euid, suid) \
33*49cdfc7eSAndroid Build Coastguard Worker 	tst_check_resuid_(__FILE__, __LINE__, (cstr), (ruid), (euid), (suid))
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker int tst_check_resgid_(const char *file, const int lineno, const char *callstr,
36*49cdfc7eSAndroid Build Coastguard Worker 	gid_t exp_rgid, gid_t exp_egid, gid_t exp_sgid);
37*49cdfc7eSAndroid Build Coastguard Worker #define tst_check_resgid(cstr, rgid, egid, sgid) \
38*49cdfc7eSAndroid Build Coastguard Worker 	tst_check_resgid_(__FILE__, __LINE__, (cstr), (rgid), (egid), (sgid))
39*49cdfc7eSAndroid Build Coastguard Worker 
40*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_UID_H_ */
41