• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Red Hat Inc., 2008
3  * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /* Author: Masatake YAMATO <yamato@redhat.com> */
21 
22 #ifndef __LTP_COMPAT_16_H__
23 #define __LTP_COMPAT_16_H__
24 
25 #include <errno.h>
26 #include <grp.h>
27 #if defined(__GLIBC__) || defined(__ANDROID__)
28 #include <sys/fsuid.h>
29 #endif
30 #include <sys/types.h>
31 #include <unistd.h>
32 
33 #include "compat_gid.h"
34 #include "compat_uid.h"
35 #include "lapi/syscalls.h"
36 
37 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
38 int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
39 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
40 int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
41 
42 
43 /* If the platform has __NR_sys_name32 defined it
44  * means that __NR_sys_name is a 16-bit version of
45  * sys_name() syscall
46  */
47 #ifdef TST_USE_COMPAT16_SYSCALL
48 # define LTP_CREATE_SYSCALL(sys_name, cleanup, ...) \
49 	if (__NR_##sys_name##32 != __LTP__NR_INVALID_SYSCALL) { \
50 		return ltp_syscall(__NR_##sys_name, ##__VA_ARGS__); \
51 	} else { \
52 		tst_brkm(TCONF, cleanup, \
53 			"16-bit version of %s() is not supported on your " \
54 			"platform", #sys_name); \
55 	}
56 #else
57 # define LTP_CREATE_SYSCALL(sys_name, cleanup, ...) \
58 	(void) cleanup;                             \
59 	return sys_name(__VA_ARGS__)
60 #endif
61 
62 #define UID16_CHECK(uid, sys_name, cleanup) \
63 if (!UID_SIZE_CHECK(uid)) { \
64 	tst_brkm(TBROK, cleanup, \
65 		"uid %d of %s is too large for testing 16-bit version " \
66 		"of %s()", uid, #uid, #sys_name); \
67 }
68 
69 #define GID16_CHECK(gid, sys_name, cleanup) \
70 if (!GID_SIZE_CHECK(gid)) { \
71 	tst_brkm(TBROK, cleanup, \
72 		"gid %d of %s is too large for testing 16-bit version " \
73 		"of %s()", gid, #gid, #sys_name); \
74 }
75 
76 
SETGROUPS(void (cleanup)(void),size_t gidsetsize,GID_T * list)77 int SETGROUPS(void (cleanup)(void), size_t gidsetsize, GID_T *list)
78 {
79 	LTP_CREATE_SYSCALL(setgroups, cleanup, gidsetsize, list);
80 }
81 
GETGROUPS(void (cleanup)(void),size_t gidsetsize,GID_T * list)82 int GETGROUPS(void (cleanup)(void), size_t gidsetsize, GID_T *list)
83 {
84 	LTP_CREATE_SYSCALL(getgroups, cleanup, gidsetsize, list);
85 }
86 
SETUID(void (cleanup)(void),UID_T uid)87 int SETUID(void (cleanup)(void), UID_T uid)
88 {
89 	LTP_CREATE_SYSCALL(setuid, cleanup, uid);
90 }
91 
GETUID(void (cleanup)(void))92 UID_T GETUID(void (cleanup)(void))
93 {
94 	LTP_CREATE_SYSCALL(getuid, cleanup);
95 }
96 
SETGID(void (cleanup)(void),GID_T gid)97 int SETGID(void (cleanup)(void), GID_T gid)
98 {
99 	LTP_CREATE_SYSCALL(setgid, cleanup, gid);
100 }
101 
GETGID(void (cleanup)(void))102 GID_T GETGID(void (cleanup)(void))
103 {
104 	LTP_CREATE_SYSCALL(getgid, cleanup);
105 }
106 
GETEUID(void (cleanup)(void))107 UID_T GETEUID(void (cleanup)(void))
108 {
109 	LTP_CREATE_SYSCALL(geteuid, cleanup);
110 }
111 
GETEGID(void (cleanup)(void))112 GID_T GETEGID(void (cleanup)(void))
113 {
114 	LTP_CREATE_SYSCALL(getegid, cleanup);
115 }
116 
SETFSUID(void (cleanup)(void),UID_T uid)117 int SETFSUID(void (cleanup)(void), UID_T uid)
118 {
119 	LTP_CREATE_SYSCALL(setfsuid, cleanup, uid);
120 }
121 
SETFSGID(void (cleanup)(void),GID_T gid)122 int SETFSGID(void (cleanup)(void), GID_T gid)
123 {
124 	LTP_CREATE_SYSCALL(setfsgid, cleanup, gid);
125 }
126 
SETREUID(void (cleanup)(void),UID_T ruid,UID_T euid)127 int SETREUID(void (cleanup)(void), UID_T ruid, UID_T euid)
128 {
129 	LTP_CREATE_SYSCALL(setreuid, cleanup, ruid, euid);
130 }
SETREGID(void (cleanup)(void),GID_T rgid,GID_T egid)131 int SETREGID(void (cleanup)(void), GID_T rgid, GID_T egid)
132 {
133 	LTP_CREATE_SYSCALL(setregid, cleanup, rgid, egid);
134 }
135 
SETRESUID(void (cleanup)(void),UID_T ruid,UID_T euid,UID_T suid)136 int SETRESUID(void (cleanup)(void), UID_T ruid, UID_T euid, UID_T suid)
137 {
138 	LTP_CREATE_SYSCALL(setresuid, cleanup, ruid, euid, suid);
139 }
140 
GETRESUID(void (cleanup)(void),UID_T * ruid,UID_T * euid,UID_T * suid)141 int GETRESUID(void (cleanup)(void), UID_T *ruid, UID_T *euid, UID_T *suid)
142 {
143 	LTP_CREATE_SYSCALL(getresuid, cleanup, ruid, euid, suid);
144 }
145 
SETRESGID(void (cleanup)(void),GID_T rgid,GID_T egid,GID_T sgid)146 int SETRESGID(void (cleanup)(void), GID_T rgid, GID_T egid, GID_T sgid)
147 {
148 	LTP_CREATE_SYSCALL(setresgid, cleanup, rgid, egid, sgid);
149 }
150 
GETRESGID(void (cleanup)(void),GID_T * rgid,GID_T * egid,GID_T * sgid)151 int GETRESGID(void (cleanup)(void), GID_T *rgid, GID_T *egid, GID_T *sgid)
152 {
153 	LTP_CREATE_SYSCALL(getresgid, cleanup, rgid, egid, sgid);
154 }
155 
FCHOWN(void (cleanup)(void),unsigned int fd,UID_T owner,GID_T group)156 int FCHOWN(void (cleanup)(void), unsigned int fd, UID_T owner, GID_T group)
157 {
158 	LTP_CREATE_SYSCALL(fchown, cleanup, fd, owner, group);
159 }
160 
LCHOWN(void (cleanup)(void),const char * path,UID_T owner,GID_T group)161 int LCHOWN(void (cleanup)(void), const char *path, UID_T owner, GID_T group)
162 {
163 	LTP_CREATE_SYSCALL(lchown, cleanup, path, owner, group);
164 }
165 
CHOWN(void (cleanup)(void),const char * path,UID_T owner,GID_T group)166 int CHOWN(void (cleanup)(void), const char *path, UID_T owner, GID_T group)
167 {
168 	LTP_CREATE_SYSCALL(chown, cleanup, path, owner, group);
169 }
170 #endif /* __LTP_COMPAT_16_H__ */
171