ACPI: fix broken usage of acpi_ut_get_node_name()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / uid16.c
blob67bb92ce49d1c03f42cb455de1323434dcfcf4ff
1 /*
2 * Wrapper functions for 16bit uid back compatibility. All nicely tied
3 * together in the faint hope we can take the out in five years time.
4 */
6 #include <linux/mm.h>
7 #include <linux/utsname.h>
8 #include <linux/mman.h>
9 #include <linux/notifier.h>
10 #include <linux/reboot.h>
11 #include <linux/prctl.h>
12 #include <linux/capability.h>
13 #include <linux/init.h>
14 #include <linux/highuid.h>
15 #include <linux/security.h>
16 #include <linux/syscalls.h>
18 #include <asm/uaccess.h>
20 SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
22 long ret = sys_chown(filename, low2highuid(user), low2highgid(group));
23 /* avoid REGPARM breakage on x86: */
24 asmlinkage_protect(3, ret, filename, user, group);
25 return ret;
28 SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
30 long ret = sys_lchown(filename, low2highuid(user), low2highgid(group));
31 /* avoid REGPARM breakage on x86: */
32 asmlinkage_protect(3, ret, filename, user, group);
33 return ret;
36 SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
38 long ret = sys_fchown(fd, low2highuid(user), low2highgid(group));
39 /* avoid REGPARM breakage on x86: */
40 asmlinkage_protect(3, ret, fd, user, group);
41 return ret;
44 SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)
46 long ret = sys_setregid(low2highgid(rgid), low2highgid(egid));
47 /* avoid REGPARM breakage on x86: */
48 asmlinkage_protect(2, ret, rgid, egid);
49 return ret;
52 SYSCALL_DEFINE1(setgid16, old_gid_t, gid)
54 long ret = sys_setgid(low2highgid(gid));
55 /* avoid REGPARM breakage on x86: */
56 asmlinkage_protect(1, ret, gid);
57 return ret;
60 SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid)
62 long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid));
63 /* avoid REGPARM breakage on x86: */
64 asmlinkage_protect(2, ret, ruid, euid);
65 return ret;
68 SYSCALL_DEFINE1(setuid16, old_uid_t, uid)
70 long ret = sys_setuid(low2highuid(uid));
71 /* avoid REGPARM breakage on x86: */
72 asmlinkage_protect(1, ret, uid);
73 return ret;
76 SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid)
78 long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid),
79 low2highuid(suid));
80 /* avoid REGPARM breakage on x86: */
81 asmlinkage_protect(3, ret, ruid, euid, suid);
82 return ret;
85 SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruid, old_uid_t __user *, euid, old_uid_t __user *, suid)
87 int retval;
89 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
90 !(retval = put_user(high2lowuid(current->euid), euid)))
91 retval = put_user(high2lowuid(current->suid), suid);
93 return retval;
96 SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
98 long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid),
99 low2highgid(sgid));
100 /* avoid REGPARM breakage on x86: */
101 asmlinkage_protect(3, ret, rgid, egid, sgid);
102 return ret;
106 SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgid, old_gid_t __user *, egid, old_gid_t __user *, sgid)
108 int retval;
110 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
111 !(retval = put_user(high2lowgid(current->egid), egid)))
112 retval = put_user(high2lowgid(current->sgid), sgid);
114 return retval;
117 SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid)
119 long ret = sys_setfsuid(low2highuid(uid));
120 /* avoid REGPARM breakage on x86: */
121 asmlinkage_protect(1, ret, uid);
122 return ret;
125 SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid)
127 long ret = sys_setfsgid(low2highgid(gid));
128 /* avoid REGPARM breakage on x86: */
129 asmlinkage_protect(1, ret, gid);
130 return ret;
133 static int groups16_to_user(old_gid_t __user *grouplist,
134 struct group_info *group_info)
136 int i;
137 old_gid_t group;
139 for (i = 0; i < group_info->ngroups; i++) {
140 group = high2lowgid(GROUP_AT(group_info, i));
141 if (put_user(group, grouplist+i))
142 return -EFAULT;
145 return 0;
148 static int groups16_from_user(struct group_info *group_info,
149 old_gid_t __user *grouplist)
151 int i;
152 old_gid_t group;
154 for (i = 0; i < group_info->ngroups; i++) {
155 if (get_user(group, grouplist+i))
156 return -EFAULT;
157 GROUP_AT(group_info, i) = low2highgid(group);
160 return 0;
163 SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
165 int i = 0;
167 if (gidsetsize < 0)
168 return -EINVAL;
170 get_group_info(current->group_info);
171 i = current->group_info->ngroups;
172 if (gidsetsize) {
173 if (i > gidsetsize) {
174 i = -EINVAL;
175 goto out;
177 if (groups16_to_user(grouplist, current->group_info)) {
178 i = -EFAULT;
179 goto out;
182 out:
183 put_group_info(current->group_info);
184 return i;
187 SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
189 struct group_info *group_info;
190 int retval;
192 if (!capable(CAP_SETGID))
193 return -EPERM;
194 if ((unsigned)gidsetsize > NGROUPS_MAX)
195 return -EINVAL;
197 group_info = groups_alloc(gidsetsize);
198 if (!group_info)
199 return -ENOMEM;
200 retval = groups16_from_user(group_info, grouplist);
201 if (retval) {
202 put_group_info(group_info);
203 return retval;
206 retval = set_current_groups(group_info);
207 put_group_info(group_info);
209 return retval;
212 SYSCALL_DEFINE0(getuid16)
214 return high2lowuid(current->uid);
217 SYSCALL_DEFINE0(geteuid16)
219 return high2lowuid(current->euid);
222 SYSCALL_DEFINE0(getgid16)
224 return high2lowgid(current->gid);
227 SYSCALL_DEFINE0(getegid16)
229 return high2lowgid(current->egid);