[CPUFREQ] Recalibrate cpu_khz [2/2]
[linux-2.6/mini2440.git] / kernel / uid16.c
blobf669941e8b26d8d483d22889c9e328d3a5b6264f
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/smp_lock.h>
10 #include <linux/notifier.h>
11 #include <linux/reboot.h>
12 #include <linux/prctl.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 asmlinkage long sys_chown16(const char __user * filename, old_uid_t user, old_gid_t group)
22 return sys_chown(filename, low2highuid(user), low2highgid(group));
25 asmlinkage long sys_lchown16(const char __user * filename, old_uid_t user, old_gid_t group)
27 return sys_lchown(filename, low2highuid(user), low2highgid(group));
30 asmlinkage long sys_fchown16(unsigned int fd, old_uid_t user, old_gid_t group)
32 return sys_fchown(fd, low2highuid(user), low2highgid(group));
35 asmlinkage long sys_setregid16(old_gid_t rgid, old_gid_t egid)
37 return sys_setregid(low2highgid(rgid), low2highgid(egid));
40 asmlinkage long sys_setgid16(old_gid_t gid)
42 return sys_setgid(low2highgid(gid));
45 asmlinkage long sys_setreuid16(old_uid_t ruid, old_uid_t euid)
47 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
50 asmlinkage long sys_setuid16(old_uid_t uid)
52 return sys_setuid(low2highuid(uid));
55 asmlinkage long sys_setresuid16(old_uid_t ruid, old_uid_t euid, old_uid_t suid)
57 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
58 low2highuid(suid));
61 asmlinkage long sys_getresuid16(old_uid_t __user *ruid, old_uid_t __user *euid, old_uid_t __user *suid)
63 int retval;
65 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
66 !(retval = put_user(high2lowuid(current->euid), euid)))
67 retval = put_user(high2lowuid(current->suid), suid);
69 return retval;
72 asmlinkage long sys_setresgid16(old_gid_t rgid, old_gid_t egid, old_gid_t sgid)
74 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
75 low2highgid(sgid));
78 asmlinkage long sys_getresgid16(old_gid_t __user *rgid, old_gid_t __user *egid, old_gid_t __user *sgid)
80 int retval;
82 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
83 !(retval = put_user(high2lowgid(current->egid), egid)))
84 retval = put_user(high2lowgid(current->sgid), sgid);
86 return retval;
89 asmlinkage long sys_setfsuid16(old_uid_t uid)
91 return sys_setfsuid(low2highuid(uid));
94 asmlinkage long sys_setfsgid16(old_gid_t gid)
96 return sys_setfsgid(low2highgid(gid));
99 static int groups16_to_user(old_gid_t __user *grouplist,
100 struct group_info *group_info)
102 int i;
103 old_gid_t group;
105 for (i = 0; i < group_info->ngroups; i++) {
106 group = high2lowgid(GROUP_AT(group_info, i));
107 if (put_user(group, grouplist+i))
108 return -EFAULT;
111 return 0;
114 static int groups16_from_user(struct group_info *group_info,
115 old_gid_t __user *grouplist)
117 int i;
118 old_gid_t group;
120 for (i = 0; i < group_info->ngroups; i++) {
121 if (get_user(group, grouplist+i))
122 return -EFAULT;
123 GROUP_AT(group_info, i) = low2highgid(group);
126 return 0;
129 asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t __user *grouplist)
131 int i = 0;
133 if (gidsetsize < 0)
134 return -EINVAL;
136 get_group_info(current->group_info);
137 i = current->group_info->ngroups;
138 if (gidsetsize) {
139 if (i > gidsetsize) {
140 i = -EINVAL;
141 goto out;
143 if (groups16_to_user(grouplist, current->group_info)) {
144 i = -EFAULT;
145 goto out;
148 out:
149 put_group_info(current->group_info);
150 return i;
153 asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t __user *grouplist)
155 struct group_info *group_info;
156 int retval;
158 if (!capable(CAP_SETGID))
159 return -EPERM;
160 if ((unsigned)gidsetsize > NGROUPS_MAX)
161 return -EINVAL;
163 group_info = groups_alloc(gidsetsize);
164 if (!group_info)
165 return -ENOMEM;
166 retval = groups16_from_user(group_info, grouplist);
167 if (retval) {
168 put_group_info(group_info);
169 return retval;
172 retval = set_current_groups(group_info);
173 put_group_info(group_info);
175 return retval;
178 asmlinkage long sys_getuid16(void)
180 return high2lowuid(current->uid);
183 asmlinkage long sys_geteuid16(void)
185 return high2lowuid(current->euid);
188 asmlinkage long sys_getgid16(void)
190 return high2lowgid(current->gid);
193 asmlinkage long sys_getegid16(void)
195 return high2lowgid(current->egid);