linux32_uid16.c revision 1.1 1 1.1 njoly /* $NetBSD: linux32_uid16.c,v 1.1 2008/01/15 22:38:35 njoly Exp $ */
2 1.1 njoly
3 1.1 njoly /*-
4 1.1 njoly * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 1.1 njoly * Copyright (c) 2008 Nicolas Joly, all rights reserved.
6 1.1 njoly *
7 1.1 njoly * Redistribution and use in source and binary forms, with or without
8 1.1 njoly * modification, are permitted provided that the following conditions
9 1.1 njoly * are met:
10 1.1 njoly * 1. Redistributions of source code must retain the above copyright
11 1.1 njoly * notice, this list of conditions and the following disclaimer.
12 1.1 njoly * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 njoly * notice, this list of conditions and the following disclaimer in the
14 1.1 njoly * documentation and/or other materials provided with the distribution.
15 1.1 njoly * 3. All advertising materials mentioning features or use of this software
16 1.1 njoly * must display the following acknowledgement:
17 1.1 njoly * This product includes software developed by Emmanuel Dreyfus
18 1.1 njoly * 4. The name of the author may not be used to endorse or promote
19 1.1 njoly * products derived from this software without specific prior written
20 1.1 njoly * permission.
21 1.1 njoly *
22 1.1 njoly * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
23 1.1 njoly * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 1.1 njoly * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1 njoly * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
26 1.1 njoly * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 njoly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 njoly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 njoly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 njoly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 njoly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 njoly * POSSIBILITY OF SUCH DAMAGE.
33 1.1 njoly */
34 1.1 njoly
35 1.1 njoly #include <sys/cdefs.h>
36 1.1 njoly __KERNEL_RCSID(0, "$NetBSD: linux32_uid16.c,v 1.1 2008/01/15 22:38:35 njoly Exp $");
37 1.1 njoly
38 1.1 njoly #include <sys/param.h>
39 1.1 njoly #include <sys/proc.h>
40 1.1 njoly #include <sys/kauth.h>
41 1.1 njoly
42 1.1 njoly #include <compat/netbsd32/netbsd32.h>
43 1.1 njoly
44 1.1 njoly #include <compat/linux/common/linux_types.h>
45 1.1 njoly #include <compat/linux/common/linux_signal.h>
46 1.1 njoly #include <compat/linux/linux_syscallargs.h>
47 1.1 njoly
48 1.1 njoly #include <compat/linux32/common/linux32_types.h>
49 1.1 njoly #include <compat/linux32/common/linux32_signal.h>
50 1.1 njoly #include <compat/linux32/common/linux32_machdep.h>
51 1.1 njoly #include <compat/linux32/linux32_syscallargs.h>
52 1.1 njoly
53 1.1 njoly #define LINUX32TOBSD_UID(u) \
54 1.1 njoly (((u) == (linux32_uid16_t)-1) ? -1 : (u))
55 1.1 njoly #define LINUX32TOBSD_GID(g) \
56 1.1 njoly (((g) == (linux32_gid16_t)-1) ? -1 : (g))
57 1.1 njoly
58 1.1 njoly #define BSDTOLINUX32_UID(u) \
59 1.1 njoly (((u) & ~0xffff) ? (linux32_uid16_t)65534 : (linux32_uid16_t)(u))
60 1.1 njoly #define BSDTOLINUX32_GID(g) \
61 1.1 njoly (((g) & ~0xffff) ? (linux32_gid16_t)65534 : (linux32_gid16_t)(g))
62 1.1 njoly
63 1.1 njoly int
64 1.1 njoly linux32_sys_chown16(struct lwp *l, const struct linux32_sys_chown16_args *uap, register_t *retval)
65 1.1 njoly {
66 1.1 njoly /* {
67 1.1 njoly syscallarg(const netbsd32_charp) path;
68 1.1 njoly syscallarg(linux32_uid16_t) uid;
69 1.1 njoly syscallarg(linux32_gid16_t) gid;
70 1.1 njoly } */
71 1.1 njoly struct sys___posix_chown_args ua;
72 1.1 njoly
73 1.1 njoly NETBSD32TOP_UAP(path, const char);
74 1.1 njoly SCARG(&ua, uid) = LINUX32TOBSD_UID(SCARG(uap, uid));
75 1.1 njoly SCARG(&ua, gid) = LINUX32TOBSD_GID(SCARG(uap, gid));
76 1.1 njoly
77 1.1 njoly return sys___posix_chown(l, &ua, retval);
78 1.1 njoly }
79 1.1 njoly
80 1.1 njoly int
81 1.1 njoly linux32_sys_lchown16(struct lwp *l, const struct linux32_sys_lchown16_args *uap, register_t *retval)
82 1.1 njoly {
83 1.1 njoly /* {
84 1.1 njoly syscallarg(const netbsd32_charp) path;
85 1.1 njoly syscallarg(linux32_uid16_t) uid;
86 1.1 njoly syscallarg(linux32_gid16_t) gid;
87 1.1 njoly } */
88 1.1 njoly struct sys___posix_lchown_args ua;
89 1.1 njoly
90 1.1 njoly NETBSD32TOP_UAP(path, const char);
91 1.1 njoly SCARG(&ua, uid) = LINUX32TOBSD_UID(SCARG(uap, uid));
92 1.1 njoly SCARG(&ua, gid) = LINUX32TOBSD_GID(SCARG(uap, gid));
93 1.1 njoly
94 1.1 njoly return sys___posix_lchown(l, &ua, retval);
95 1.1 njoly }
96 1.1 njoly
97 1.1 njoly int
98 1.1 njoly linux32_sys_fchown16(struct lwp *l, const struct linux32_sys_fchown16_args *uap, register_t *retval)
99 1.1 njoly {
100 1.1 njoly /* {
101 1.1 njoly syscallarg(int) fd;
102 1.1 njoly syscallarg(linux32_uid16_t) uid;
103 1.1 njoly syscallarg(linux32_gid16_t) gid;
104 1.1 njoly } */
105 1.1 njoly struct sys___posix_fchown_args ua;
106 1.1 njoly
107 1.1 njoly SCARG(&ua, fd) = SCARG(uap, fd);
108 1.1 njoly SCARG(&ua, uid) = LINUX32TOBSD_UID(SCARG(uap, uid));
109 1.1 njoly SCARG(&ua, gid) = LINUX32TOBSD_GID(SCARG(uap, gid));
110 1.1 njoly
111 1.1 njoly return sys___posix_fchown(l, &ua, retval);
112 1.1 njoly }
113 1.1 njoly
114 1.1 njoly int
115 1.1 njoly linux32_sys_getgroups16(struct lwp *l, const struct linux32_sys_getgroups16_args *uap, register_t *retval)
116 1.1 njoly {
117 1.1 njoly /* {
118 1.1 njoly syscallarg(int) gidsetsize;
119 1.1 njoly syscallarg(linux32_gid16p_t) gidset;
120 1.1 njoly } */
121 1.1 njoly struct linux_sys_getgroups16_args ua;
122 1.1 njoly
123 1.1 njoly NETBSD32TO64_UAP(gidsetsize);
124 1.1 njoly NETBSD32TOP_UAP(gidset, linux_gid16_t);
125 1.1 njoly
126 1.1 njoly return linux_sys_getgroups16(l, &ua, retval);
127 1.1 njoly }
128 1.1 njoly
129 1.1 njoly int
130 1.1 njoly linux32_sys_setgroups16(struct lwp *l, const struct linux32_sys_setgroups16_args *uap, register_t *retval)
131 1.1 njoly {
132 1.1 njoly /* {
133 1.1 njoly syscallarg(int) gidsetsize;
134 1.1 njoly syscallarg(linux32_gid16p_t) gidset;
135 1.1 njoly } */
136 1.1 njoly struct linux_sys_setgroups16_args ua;
137 1.1 njoly
138 1.1 njoly NETBSD32TO64_UAP(gidsetsize);
139 1.1 njoly NETBSD32TOP_UAP(gidset, linux_gid16_t);
140 1.1 njoly
141 1.1 njoly return linux_sys_setgroups16(l, &ua, retval);
142 1.1 njoly }
143 1.1 njoly
144 1.1 njoly int
145 1.1 njoly linux32_sys_setreuid16(struct lwp *l, const struct linux32_sys_setreuid16_args *uap, register_t *retval)
146 1.1 njoly {
147 1.1 njoly /* {
148 1.1 njoly syscallarg(linux32_uid16_t) ruid;
149 1.1 njoly syscallarg(linux32_uid16_t) euid;
150 1.1 njoly } */
151 1.1 njoly struct sys_setreuid_args bsa;
152 1.1 njoly
153 1.1 njoly SCARG(&bsa, ruid) = LINUX32TOBSD_UID(SCARG(uap, ruid));
154 1.1 njoly SCARG(&bsa, euid) = LINUX32TOBSD_UID(SCARG(uap, euid));
155 1.1 njoly
156 1.1 njoly return sys_setreuid(l, &bsa, retval);
157 1.1 njoly }
158 1.1 njoly
159 1.1 njoly int
160 1.1 njoly linux32_sys_setregid16(struct lwp *l, const struct linux32_sys_setregid16_args *uap, register_t *retval)
161 1.1 njoly {
162 1.1 njoly /* {
163 1.1 njoly syscallarg(linux32_gid16_t) rgid;
164 1.1 njoly syscallarg(linux32_gid16_t) egid;
165 1.1 njoly } */
166 1.1 njoly struct sys_setregid_args bsa;
167 1.1 njoly
168 1.1 njoly SCARG(&bsa, rgid) = LINUX32TOBSD_GID(SCARG(uap, rgid));
169 1.1 njoly SCARG(&bsa, egid) = LINUX32TOBSD_GID(SCARG(uap, egid));
170 1.1 njoly
171 1.1 njoly return sys_setregid(l, &bsa, retval);
172 1.1 njoly }
173 1.1 njoly
174 1.1 njoly int
175 1.1 njoly linux32_sys_setresuid16(struct lwp *l, const struct linux32_sys_setresuid16_args *uap, register_t *retval)
176 1.1 njoly {
177 1.1 njoly /* {
178 1.1 njoly syscallarg(linux32_uid16_t) ruid;
179 1.1 njoly syscallarg(linux32_uid16_t) euid;
180 1.1 njoly syscallarg(linux32_uid16_t) suid;
181 1.1 njoly } */
182 1.1 njoly struct linux32_sys_setresuid_args lsa;
183 1.1 njoly
184 1.1 njoly SCARG(&lsa, ruid) = LINUX32TOBSD_UID(SCARG(uap, ruid));
185 1.1 njoly SCARG(&lsa, euid) = LINUX32TOBSD_UID(SCARG(uap, euid));
186 1.1 njoly SCARG(&lsa, suid) = LINUX32TOBSD_UID(SCARG(uap, suid));
187 1.1 njoly
188 1.1 njoly return linux32_sys_setresuid(l, &lsa, retval);
189 1.1 njoly }
190 1.1 njoly
191 1.1 njoly int
192 1.1 njoly linux32_sys_setresgid16(struct lwp *l, const struct linux32_sys_setresgid16_args *uap, register_t *retval)
193 1.1 njoly {
194 1.1 njoly /* {
195 1.1 njoly syscallarg(linux32_gid16_t) rgid;
196 1.1 njoly syscallarg(linux32_gid16_t) egid;
197 1.1 njoly syscallarg(linux32_gid16_t) sgid;
198 1.1 njoly } */
199 1.1 njoly struct linux32_sys_setresgid_args lsa;
200 1.1 njoly
201 1.1 njoly SCARG(&lsa, rgid) = LINUX32TOBSD_GID(SCARG(uap, rgid));
202 1.1 njoly SCARG(&lsa, egid) = LINUX32TOBSD_GID(SCARG(uap, egid));
203 1.1 njoly SCARG(&lsa, sgid) = LINUX32TOBSD_GID(SCARG(uap, sgid));
204 1.1 njoly
205 1.1 njoly return linux32_sys_setresgid(l, &lsa, retval);
206 1.1 njoly }
207 1.1 njoly
208 1.1 njoly int
209 1.1 njoly linux32_sys_getresuid16(struct lwp *l, const struct linux32_sys_getresuid16_args *uap, register_t *retval)
210 1.1 njoly {
211 1.1 njoly /* {
212 1.1 njoly syscallarg(linux32_uid16p_t) ruid;
213 1.1 njoly syscallarg(linux32_uid16p_t) euid;
214 1.1 njoly syscallarg(linux32_uid16p_t) suid;
215 1.1 njoly } */
216 1.1 njoly kauth_cred_t pc = l->l_cred;
217 1.1 njoly int error;
218 1.1 njoly uid_t buid;
219 1.1 njoly linux32_uid16_t luid;
220 1.1 njoly
221 1.1 njoly buid = kauth_cred_getuid(pc);
222 1.1 njoly luid = BSDTOLINUX32_UID(buid);
223 1.1 njoly if ((error = copyout(&luid, SCARG_P32(uap, ruid), sizeof(luid))) != 0)
224 1.1 njoly return error;
225 1.1 njoly
226 1.1 njoly buid = kauth_cred_geteuid(pc);
227 1.1 njoly luid = BSDTOLINUX32_UID(buid);
228 1.1 njoly if ((error = copyout(&luid, SCARG_P32(uap, euid), sizeof(luid))) != 0)
229 1.1 njoly return error;
230 1.1 njoly
231 1.1 njoly buid = kauth_cred_getsvuid(pc);
232 1.1 njoly luid = BSDTOLINUX32_UID(buid);
233 1.1 njoly return (copyout(&luid, SCARG_P32(uap, suid), sizeof(luid)));
234 1.1 njoly }
235 1.1 njoly
236 1.1 njoly int
237 1.1 njoly linux32_sys_getresgid16(struct lwp *l, const struct linux32_sys_getresgid16_args *uap, register_t *retval)
238 1.1 njoly {
239 1.1 njoly /* {
240 1.1 njoly syscallarg(linux32_gid16p_t) rgid;
241 1.1 njoly syscallarg(linux32_gid16p_t) egid;
242 1.1 njoly syscallarg(linux32_gid16p_t) sgid;
243 1.1 njoly } */
244 1.1 njoly kauth_cred_t pc = l->l_cred;
245 1.1 njoly int error;
246 1.1 njoly gid_t bgid;
247 1.1 njoly linux32_gid16_t lgid;
248 1.1 njoly
249 1.1 njoly bgid = kauth_cred_getgid(pc);
250 1.1 njoly lgid = BSDTOLINUX32_GID(bgid);
251 1.1 njoly if ((error = copyout(&lgid, SCARG_P32(uap, rgid), sizeof(lgid))) != 0)
252 1.1 njoly return error;
253 1.1 njoly
254 1.1 njoly bgid = kauth_cred_getegid(pc);
255 1.1 njoly lgid = BSDTOLINUX32_GID(bgid);
256 1.1 njoly if ((error = copyout(&lgid, SCARG_P32(uap, egid), sizeof(lgid))) != 0)
257 1.1 njoly return error;
258 1.1 njoly
259 1.1 njoly bgid = kauth_cred_getsvgid(pc);
260 1.1 njoly lgid = BSDTOLINUX32_GID(bgid);
261 1.1 njoly return (copyout(&lgid, SCARG_P32(uap, sgid), sizeof(lgid)));
262 1.1 njoly }
263