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