[SPARC64]: Fix 2 bugs in huge page support.
[linux-2.6/verdex.git] / kernel / uid16.c
blobaa25605027c8eb19c682cd6efec17b0d79073451
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/capability.h>
14 #include <linux/init.h>
15 #include <linux/highuid.h>
16 #include <linux/security.h>
17 #include <linux/syscalls.h>
19 #include <asm/uaccess.h>
21 asmlinkage long sys_chown16(const char __user * filename, old_uid_t user, old_gid_t group)
23 return sys_chown(filename, low2highuid(user), low2highgid(group));
26 asmlinkage long sys_lchown16(const char __user * filename, old_uid_t user, old_gid_t group)
28 return sys_lchown(filename, low2highuid(user), low2highgid(group));
31 asmlinkage long sys_fchown16(unsigned int fd, old_uid_t user, old_gid_t group)
33 return sys_fchown(fd, low2highuid(user), low2highgid(group));
36 asmlinkage long sys_setregid16(old_gid_t rgid, old_gid_t egid)
38 return sys_setregid(low2highgid(rgid), low2highgid(egid));
41 asmlinkage long sys_setgid16(old_gid_t gid)
43 return sys_setgid(low2highgid(gid));
46 asmlinkage long sys_setreuid16(old_uid_t ruid, old_uid_t euid)
48 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
51 asmlinkage long sys_setuid16(old_uid_t uid)
53 return sys_setuid(low2highuid(uid));
56 asmlinkage long sys_setresuid16(old_uid_t ruid, old_uid_t euid, old_uid_t suid)
58 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
59 low2highuid(suid));
62 asmlinkage long sys_getresuid16(old_uid_t __user *ruid, old_uid_t __user *euid, old_uid_t __user *suid)
64 int retval;
66 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
67 !(retval = put_user(high2lowuid(current->euid), euid)))
68 retval = put_user(high2lowuid(current->suid), suid);
70 return retval;
73 asmlinkage long sys_setresgid16(old_gid_t rgid, old_gid_t egid, old_gid_t sgid)
75 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
76 low2highgid(sgid));
79 asmlinkage long sys_getresgid16(old_gid_t __user *rgid, old_gid_t __user *egid, old_gid_t __user *sgid)
81 int retval;
83 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
84 !(retval = put_user(high2lowgid(current->egid), egid)))
85 retval = put_user(high2lowgid(current->sgid), sgid);
87 return retval;
90 asmlinkage long sys_setfsuid16(old_uid_t uid)
92 return sys_setfsuid(low2highuid(uid));
95 asmlinkage long sys_setfsgid16(old_gid_t gid)
97 return sys_setfsgid(low2highgid(gid));
100 static int groups16_to_user(old_gid_t __user *grouplist,
101 struct group_info *group_info)
103 int i;
104 old_gid_t group;
106 for (i = 0; i < group_info->ngroups; i++) {
107 group = high2lowgid(GROUP_AT(group_info, i));
108 if (put_user(group, grouplist+i))
109 return -EFAULT;
112 return 0;
115 static int groups16_from_user(struct group_info *group_info,
116 old_gid_t __user *grouplist)
118 int i;
119 old_gid_t group;
121 for (i = 0; i < group_info->ngroups; i++) {
122 if (get_user(group, grouplist+i))
123 return -EFAULT;
124 GROUP_AT(group_info, i) = low2highgid(group);
127 return 0;
130 asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t __user *grouplist)
132 int i = 0;
134 if (gidsetsize < 0)
135 return -EINVAL;
137 get_group_info(current->group_info);
138 i = current->group_info->ngroups;
139 if (gidsetsize) {
140 if (i > gidsetsize) {
141 i = -EINVAL;
142 goto out;
144 if (groups16_to_user(grouplist, current->group_info)) {
145 i = -EFAULT;
146 goto out;
149 out:
150 put_group_info(current->group_info);
151 return i;
154 asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t __user *grouplist)
156 struct group_info *group_info;
157 int retval;
159 if (!capable(CAP_SETGID))
160 return -EPERM;
161 if ((unsigned)gidsetsize > NGROUPS_MAX)
162 return -EINVAL;
164 group_info = groups_alloc(gidsetsize);
165 if (!group_info)
166 return -ENOMEM;
167 retval = groups16_from_user(group_info, grouplist);
168 if (retval) {
169 put_group_info(group_info);
170 return retval;
173 retval = set_current_groups(group_info);
174 put_group_info(group_info);
176 return retval;
179 asmlinkage long sys_getuid16(void)
181 return high2lowuid(current->uid);
184 asmlinkage long sys_geteuid16(void)
186 return high2lowuid(current->euid);
189 asmlinkage long sys_getgid16(void)
191 return high2lowgid(current->gid);
194 asmlinkage long sys_getegid16(void)
196 return high2lowgid(current->egid);