• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
3  * Author: yang xu <xuyang.jy@cn.fujitsu.com>
4  *
5  * This program is free software;  you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  * the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef COMPAT_TST_16_H__
20 #define COMPAT_TST_16_H__
21 
22 #include <errno.h>
23 #include <grp.h>
24 #if defined(__GLIBC__) || defined(__ANDROID__)
25 #include <sys/fsuid.h>
26 #endif
27 #include <sys/types.h>
28 #include <unistd.h>
29 
30 #include "compat_gid.h"
31 #include "compat_uid.h"
32 #include "lapi/syscalls.h"
33 
34 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
35 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
36 
37 
38 /* If the platform has __NR_sys_name32 defined it
39  * means that __NR_sys_name is a 16-bit version of
40  * sys_name() syscall
41  */
42 #ifdef TST_USE_COMPAT16_SYSCALL
43 # define TST_CREATE_SYSCALL(sys_name, ...) ({ \
44 	if (__NR_##sys_name##32 != __LTP__NR_INVALID_SYSCALL) { \
45 		return tst_syscall(__NR_##sys_name, ##__VA_ARGS__); \
46 	} else { \
47 		tst_brk(TCONF, \
48 			"16-bit version of %s() is not supported on your " \
49 			"platform", #sys_name); \
50 		return -1; \
51 	} \
52 })
53 #else
54 # define TST_CREATE_SYSCALL(sys_name, ...) ({\
55 	return sys_name(__VA_ARGS__); \
56 })
57 #endif
58 
59 #define UID16_CHECK(uid, sys_name) ({ \
60 	if (!UID_SIZE_CHECK(uid)) { \
61 		tst_brk(TBROK, \
62 			"uid %d of %s is too large for testing 16-bit " \
63 			"version of %s()", uid, #uid, #sys_name); \
64 	} \
65 })
66 #define GID16_CHECK(gid, sys_name) ({ \
67 	if (!GID_SIZE_CHECK(gid)) { \
68 		tst_brk(TBROK, \
69 			"gid %d of %s is too large for testing 16-bit " \
70 			"version of %s()", gid, #gid, #sys_name); \
71 	} \
72 })
73 
SETGROUPS(size_t gidsetsize,GID_T * list)74 int SETGROUPS(size_t gidsetsize, GID_T *list)
75 {
76 	TST_CREATE_SYSCALL(setgroups, gidsetsize, list);
77 }
78 
GETGROUPS(size_t gidsetsize,GID_T * list)79 int GETGROUPS(size_t gidsetsize, GID_T *list)
80 {
81 	TST_CREATE_SYSCALL(getgroups, gidsetsize, list);
82 }
83 
SETUID(UID_T uid)84 int SETUID(UID_T uid)
85 {
86 	TST_CREATE_SYSCALL(setuid, uid);
87 }
88 
GETUID(void)89 UID_T GETUID(void)
90 {
91 	TST_CREATE_SYSCALL(getuid);
92 }
93 
SETGID(GID_T gid)94 int SETGID(GID_T gid)
95 {
96 	TST_CREATE_SYSCALL(setgid, gid);
97 }
98 
GETGID(void)99 GID_T GETGID(void)
100 {
101 	TST_CREATE_SYSCALL(getgid);
102 }
103 
GETEUID(void)104 UID_T GETEUID(void)
105 {
106 	TST_CREATE_SYSCALL(geteuid);
107 }
108 
GETEGID(void)109 GID_T GETEGID(void)
110 {
111 	TST_CREATE_SYSCALL(getegid);
112 }
113 
SETFSUID(UID_T uid)114 int SETFSUID(UID_T uid)
115 {
116 	TST_CREATE_SYSCALL(setfsuid, uid);
117 }
118 
SETFSGID(GID_T gid)119 int SETFSGID(GID_T gid)
120 {
121 	TST_CREATE_SYSCALL(setfsgid, gid);
122 }
123 
SETREUID(UID_T ruid,UID_T euid)124 int SETREUID(UID_T ruid, UID_T euid)
125 {
126 	TST_CREATE_SYSCALL(setreuid, ruid, euid);
127 }
SETREGID(GID_T rgid,GID_T egid)128 int SETREGID(GID_T rgid, GID_T egid)
129 {
130 	TST_CREATE_SYSCALL(setregid, rgid, egid);
131 }
132 
SETRESUID(UID_T ruid,UID_T euid,UID_T suid)133 int SETRESUID(UID_T ruid, UID_T euid, UID_T suid)
134 {
135 	TST_CREATE_SYSCALL(setresuid, ruid, euid, suid);
136 }
137 
SETRESGID(GID_T rgid,GID_T egid,GID_T sgid)138 int SETRESGID(GID_T rgid, GID_T egid, GID_T sgid)
139 {
140 	TST_CREATE_SYSCALL(setresgid, rgid, egid, sgid);
141 }
142 
FCHOWN(unsigned int fd,UID_T owner,GID_T group)143 int FCHOWN(unsigned int fd, UID_T owner, GID_T group)
144 {
145 	TST_CREATE_SYSCALL(fchown, fd, owner, group);
146 }
147 
LCHOWN(const char * path,UID_T owner,GID_T group)148 int LCHOWN(const char *path, UID_T owner, GID_T group)
149 {
150 	TST_CREATE_SYSCALL(lchown, path, owner, group);
151 }
152 
CHOWN(const char * path,UID_T owner,GID_T group)153 int CHOWN(const char *path, UID_T owner, GID_T group)
154 {
155 	TST_CREATE_SYSCALL(chown, path, owner, group);
156 }
157 #endif /* COMPAT_TST_16_H__ */
158