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