Merge with Linux 2.3.40.
[linux-2.6/linux-mips.git] / kernel / uid16.c
blobf76e4fd706e576caa7651447f90b1336fb581a5e
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>
16 #include <asm/uaccess.h>
18 extern asmlinkage long sys_chown(const char *, uid_t,gid_t);
19 extern asmlinkage long sys_lchown(const char *, uid_t,gid_t);
20 extern asmlinkage long sys_fchown(unsigned int, uid_t,gid_t);
21 extern asmlinkage long sys_setregid(gid_t, gid_t);
22 extern asmlinkage long sys_setgid(gid_t);
23 extern asmlinkage long sys_setreuid(uid_t, uid_t);
24 extern asmlinkage long sys_setuid(uid_t);
25 extern asmlinkage long sys_setresuid(uid_t, uid_t, uid_t);
26 extern asmlinkage long sys_setresgid(gid_t, gid_t, gid_t);
27 extern asmlinkage long sys_setfsuid(uid_t);
28 extern asmlinkage long sys_setfsgid(gid_t);
30 asmlinkage long sys_chown16(const char * filename, old_uid_t user, old_gid_t group)
32 return sys_chown(filename, low2highuid(user), low2highgid(group));
35 asmlinkage long sys_lchown16(const char * filename, old_uid_t user, old_gid_t group)
37 return sys_lchown(filename, low2highuid(user), low2highgid(group));
40 asmlinkage long sys_fchown16(unsigned int fd, old_uid_t user, old_gid_t group)
42 return sys_fchown(fd, low2highuid(user), low2highgid(group));
45 asmlinkage long sys_setregid16(old_gid_t rgid, old_gid_t egid)
47 return sys_setregid(low2highgid(rgid), low2highgid(egid));
50 asmlinkage long sys_setgid16(old_gid_t gid)
52 return sys_setgid((gid_t)gid);
55 asmlinkage long sys_setreuid16(old_uid_t ruid, old_uid_t euid)
57 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
60 asmlinkage long sys_setuid16(old_uid_t uid)
62 return sys_setuid((uid_t)uid);
65 asmlinkage long sys_setresuid16(old_uid_t ruid, old_uid_t euid, old_uid_t suid)
67 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
68 low2highuid(suid));
71 asmlinkage long sys_getresuid16(old_uid_t *ruid, old_uid_t *euid, old_uid_t *suid)
73 int retval;
75 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
76 !(retval = put_user(high2lowuid(current->euid), euid)))
77 retval = put_user(high2lowuid(current->suid), suid);
79 return retval;
82 asmlinkage long sys_setresgid16(old_gid_t rgid, old_gid_t egid, old_gid_t sgid)
84 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
85 low2highgid(sgid));
88 asmlinkage long sys_getresgid16(old_gid_t *rgid, old_gid_t *egid, old_gid_t *sgid)
90 int retval;
92 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
93 !(retval = put_user(high2lowgid(current->egid), egid)))
94 retval = put_user(high2lowgid(current->sgid), sgid);
96 return retval;
99 asmlinkage long sys_setfsuid16(old_uid_t uid)
101 return sys_setfsuid((uid_t)uid);
104 asmlinkage long sys_setfsgid16(old_gid_t gid)
106 return sys_setfsgid((gid_t)gid);
109 asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t *grouplist)
111 old_gid_t groups[NGROUPS];
112 int i,j;
114 if (gidsetsize < 0)
115 return -EINVAL;
116 i = current->ngroups;
117 if (gidsetsize) {
118 if (i > gidsetsize)
119 return -EINVAL;
120 for(j=0;j<i;j++)
121 groups[j] = current->groups[j];
122 if (copy_to_user(grouplist, groups, sizeof(old_gid_t)*i))
123 return -EFAULT;
125 return i;
128 asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t *grouplist)
130 old_gid_t groups[NGROUPS];
131 int i;
133 if (!capable(CAP_SETGID))
134 return -EPERM;
135 if ((unsigned) gidsetsize > NGROUPS)
136 return -EINVAL;
137 if (copy_from_user(groups, grouplist, gidsetsize * sizeof(old_gid_t)))
138 return -EFAULT;
139 for (i = 0 ; i < gidsetsize ; i++)
140 current->groups[i] = (gid_t)groups[i];
141 current->ngroups = gidsetsize;
142 return 0;
145 asmlinkage long sys_getuid16(void)
147 return high2lowuid(current->uid);
150 asmlinkage long sys_geteuid16(void)
152 return high2lowuid(current->euid);
155 asmlinkage long sys_getgid16(void)
157 return high2lowgid(current->gid);
160 asmlinkage long sys_getegid16(void)
162 return high2lowgid(current->egid);