2001-09-01 20:11:45 +02:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 The FreeBSD Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-10 23:29:12 +02:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-09-01 20:11:45 +02:00
|
|
|
#include <sys/param.h>
|
2002-04-14 01:11:23 +02:00
|
|
|
#include <sys/lock.h>
|
2002-09-05 10:13:20 +02:00
|
|
|
#include <sys/malloc.h>
|
2002-04-14 01:11:23 +02:00
|
|
|
#include <sys/mutex.h>
|
2001-09-01 20:11:45 +02:00
|
|
|
#include <sys/proc.h>
|
2002-09-02 00:30:27 +02:00
|
|
|
#include <sys/syscallsubr.h>
|
2001-09-01 20:11:45 +02:00
|
|
|
#include <sys/sysproto.h>
|
2002-09-05 10:13:20 +02:00
|
|
|
#include <sys/systm.h>
|
2001-09-01 20:11:45 +02:00
|
|
|
|
|
|
|
#include <machine/../linux/linux.h>
|
|
|
|
#include <machine/../linux/linux_proto.h>
|
2002-09-05 10:13:20 +02:00
|
|
|
|
2001-09-01 20:11:45 +02:00
|
|
|
#include <compat/linux/linux_util.h>
|
|
|
|
|
|
|
|
DUMMY(setfsuid16);
|
|
|
|
DUMMY(setfsgid16);
|
|
|
|
DUMMY(getresuid16);
|
|
|
|
DUMMY(getresgid16);
|
|
|
|
|
2002-09-02 00:30:27 +02:00
|
|
|
#define CAST_NOCHG(x) ((x == 0xFFFF) ? -1 : x)
|
2001-10-14 05:56:53 +02:00
|
|
|
|
2001-09-01 20:11:45 +02:00
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_chown16(struct thread *td, struct linux_chown16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
2002-09-02 00:30:27 +02:00
|
|
|
char *path;
|
|
|
|
int error;
|
2001-09-01 20:11:45 +02:00
|
|
|
|
2002-09-02 00:30:27 +02:00
|
|
|
LCONVPATHEXIST(td, args->path, &path);
|
2001-09-01 20:11:45 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ldebug(chown16))
|
2002-09-02 00:30:27 +02:00
|
|
|
printf(ARGS(chown16, "%s, %d, %d"), path, args->uid, args->gid);
|
2001-09-01 20:11:45 +02:00
|
|
|
#endif
|
2002-09-02 00:30:27 +02:00
|
|
|
error = kern_chown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
|
|
|
|
CAST_NOCHG(args->gid));
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_lchown16(struct thread *td, struct linux_lchown16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
2002-09-02 00:30:27 +02:00
|
|
|
char *path;
|
|
|
|
int error;
|
2001-09-01 20:11:45 +02:00
|
|
|
|
2002-09-02 00:30:27 +02:00
|
|
|
LCONVPATHEXIST(td, args->path, &path);
|
2001-09-01 20:11:45 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ldebug(lchown16))
|
2002-09-02 00:30:27 +02:00
|
|
|
printf(ARGS(lchown16, "%s, %d, %d"), path, args->uid,
|
2001-09-01 20:11:45 +02:00
|
|
|
args->gid);
|
|
|
|
#endif
|
2002-09-02 00:30:27 +02:00
|
|
|
error = kern_lchown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
|
|
|
|
CAST_NOCHG(args->gid));
|
|
|
|
LFREEPATH(path);
|
|
|
|
return (error);
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct ucred *newcred, *oldcred;
|
|
|
|
l_gid16_t linux_gidset[NGROUPS];
|
|
|
|
gid_t *bsd_gidset;
|
|
|
|
int ngrp, error;
|
2002-04-14 01:11:23 +02:00
|
|
|
struct proc *p;
|
2001-09-01 20:11:45 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ldebug(setgroups16))
|
|
|
|
printf(ARGS(setgroups16, "%d, *"), args->gidsetsize);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ngrp = args->gidsetsize;
|
2002-04-14 01:11:23 +02:00
|
|
|
if (ngrp >= NGROUPS)
|
|
|
|
return (EINVAL);
|
2003-03-03 10:14:26 +01:00
|
|
|
error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t));
|
2002-04-14 01:11:23 +02:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
newcred = crget();
|
|
|
|
p = td->td_proc;
|
|
|
|
PROC_LOCK(p);
|
|
|
|
oldcred = p->p_ucred;
|
2001-09-01 20:11:45 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* cr_groups[0] holds egid. Setting the whole set from
|
|
|
|
* the supplied set will cause egid to be changed too.
|
|
|
|
* Keep cr_groups[0] unchanged to prevent that.
|
|
|
|
*/
|
|
|
|
|
2002-04-14 01:11:23 +02:00
|
|
|
if ((error = suser_cred(oldcred, PRISON_ROOT)) != 0) {
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
crfree(newcred);
|
2001-09-01 20:11:45 +02:00
|
|
|
return (error);
|
2002-04-14 01:11:23 +02:00
|
|
|
}
|
2001-09-01 20:11:45 +02:00
|
|
|
|
2002-04-14 01:11:23 +02:00
|
|
|
crcopy(newcred, oldcred);
|
2001-09-01 20:11:45 +02:00
|
|
|
if (ngrp > 0) {
|
|
|
|
newcred->cr_ngroups = ngrp + 1;
|
|
|
|
|
|
|
|
bsd_gidset = newcred->cr_groups;
|
|
|
|
ngrp--;
|
|
|
|
while (ngrp >= 0) {
|
|
|
|
bsd_gidset[ngrp + 1] = linux_gidset[ngrp];
|
|
|
|
ngrp--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newcred->cr_ngroups = 1;
|
|
|
|
|
2001-09-12 10:38:13 +02:00
|
|
|
setsugid(td->td_proc);
|
2002-04-14 01:11:23 +02:00
|
|
|
p->p_ucred = newcred;
|
|
|
|
PROC_UNLOCK(p);
|
2001-09-01 20:11:45 +02:00
|
|
|
crfree(oldcred);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct ucred *cred;
|
|
|
|
l_gid16_t linux_gidset[NGROUPS];
|
|
|
|
gid_t *bsd_gidset;
|
|
|
|
int bsd_gidsetsz, ngrp, error;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ldebug(getgroups16))
|
|
|
|
printf(ARGS(getgroups16, "%d, *"), args->gidsetsize);
|
|
|
|
#endif
|
|
|
|
|
2002-02-27 19:32:23 +01:00
|
|
|
cred = td->td_ucred;
|
2001-09-01 20:11:45 +02:00
|
|
|
bsd_gidset = cred->cr_groups;
|
|
|
|
bsd_gidsetsz = cred->cr_ngroups - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cr_groups[0] holds egid. Returning the whole set
|
|
|
|
* here will cause a duplicate. Exclude cr_groups[0]
|
|
|
|
* to prevent that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((ngrp = args->gidsetsize) == 0) {
|
2001-09-12 10:38:13 +02:00
|
|
|
td->td_retval[0] = bsd_gidsetsz;
|
2001-09-01 20:11:45 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngrp < bsd_gidsetsz)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
ngrp = 0;
|
|
|
|
while (ngrp < bsd_gidsetsz) {
|
|
|
|
linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
|
|
|
|
ngrp++;
|
|
|
|
}
|
|
|
|
|
2003-03-03 10:14:26 +01:00
|
|
|
error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t));
|
2001-09-01 20:11:45 +02:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2001-09-12 10:38:13 +02:00
|
|
|
td->td_retval[0] = ngrp;
|
2001-09-01 20:11:45 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 10:38:13 +02:00
|
|
|
* The FreeBSD native getgid(2) and getuid(2) also modify td->td_retval[1]
|
2001-09-01 20:11:45 +02:00
|
|
|
* when COMPAT_43 or COMPAT_SUNOS is defined. This globbers registers that
|
|
|
|
* are assumed to be preserved. The following lightweight syscalls fixes
|
|
|
|
* this. See also linux_getpid(2), linux_getgid(2) and linux_getuid(2) in
|
|
|
|
* linux_misc.c
|
|
|
|
*
|
|
|
|
* linux_getgid16() - MP SAFE
|
|
|
|
* linux_getuid16() - MP SAFE
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_getgid16(struct thread *td, struct linux_getgid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
2001-09-12 10:38:13 +02:00
|
|
|
|
2002-02-27 19:32:23 +01:00
|
|
|
td->td_retval[0] = td->td_ucred->cr_rgid;
|
2001-09-01 20:11:45 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_getuid16(struct thread *td, struct linux_getuid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
2001-09-12 10:38:13 +02:00
|
|
|
|
2002-02-27 19:32:23 +01:00
|
|
|
td->td_retval[0] = td->td_ucred->cr_ruid;
|
2001-09-01 20:11:45 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_getegid16(struct thread *td, struct linux_getegid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct getegid_args bsd;
|
|
|
|
|
2001-09-12 10:38:13 +02:00
|
|
|
return (getegid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_geteuid16(struct thread *td, struct linux_geteuid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct geteuid_args bsd;
|
|
|
|
|
2001-09-12 10:38:13 +02:00
|
|
|
return (geteuid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setgid16(struct thread *td, struct linux_setgid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct setgid_args bsd;
|
|
|
|
|
|
|
|
bsd.gid = args->gid;
|
2001-09-12 10:38:13 +02:00
|
|
|
return (setgid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setuid16(struct thread *td, struct linux_setuid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct setuid_args bsd;
|
|
|
|
|
|
|
|
bsd.uid = args->uid;
|
2001-09-12 10:38:13 +02:00
|
|
|
return (setuid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setregid16(struct thread *td, struct linux_setregid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct setregid_args bsd;
|
|
|
|
|
2001-10-14 05:56:53 +02:00
|
|
|
bsd.rgid = CAST_NOCHG(args->rgid);
|
|
|
|
bsd.egid = CAST_NOCHG(args->egid);
|
2001-09-12 10:38:13 +02:00
|
|
|
return (setregid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setreuid16(struct thread *td, struct linux_setreuid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct setreuid_args bsd;
|
|
|
|
|
2001-10-14 05:56:53 +02:00
|
|
|
bsd.ruid = CAST_NOCHG(args->ruid);
|
|
|
|
bsd.euid = CAST_NOCHG(args->euid);
|
2001-09-12 10:38:13 +02:00
|
|
|
return (setreuid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setresgid16(struct thread *td, struct linux_setresgid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct setresgid_args bsd;
|
|
|
|
|
2001-10-14 05:56:53 +02:00
|
|
|
bsd.rgid = CAST_NOCHG(args->rgid);
|
|
|
|
bsd.egid = CAST_NOCHG(args->egid);
|
|
|
|
bsd.sgid = CAST_NOCHG(args->sgid);
|
2001-09-12 10:38:13 +02:00
|
|
|
return (setresgid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 10:38:13 +02:00
|
|
|
linux_setresuid16(struct thread *td, struct linux_setresuid16_args *args)
|
2001-09-01 20:11:45 +02:00
|
|
|
{
|
|
|
|
struct setresuid_args bsd;
|
|
|
|
|
2001-10-14 05:56:53 +02:00
|
|
|
bsd.ruid = CAST_NOCHG(args->ruid);
|
|
|
|
bsd.euid = CAST_NOCHG(args->euid);
|
|
|
|
bsd.suid = CAST_NOCHG(args->suid);
|
2001-09-12 10:38:13 +02:00
|
|
|
return (setresuid(td, &bsd));
|
2001-09-01 20:11:45 +02:00
|
|
|
}
|