2013-01-12 20:37:14 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2014-06-27 10:15:30 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
2013-01-12 20:37:14 -05:00
|
|
|
|
|
|
|
This file is part of Sortix.
|
|
|
|
|
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
identity.cpp
|
|
|
|
System calls for managing user and group identities.
|
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/kernel.h>
|
2013-01-12 20:37:14 -05:00
|
|
|
#include <sortix/kernel/kthread.h>
|
2013-05-12 18:41:30 -04:00
|
|
|
#include <sortix/kernel/process.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/syscall.h>
|
2013-01-12 20:37:14 -05:00
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
uid_t sys_getuid()
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->uid;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_setuid(uid_t uid)
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->uid = uid, 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
gid_t sys_getgid()
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->gid;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_setgid(gid_t gid)
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->gid = gid, 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
uid_t sys_geteuid()
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->euid;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_seteuid(uid_t euid)
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->euid = euid, 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
gid_t sys_getegid()
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->egid;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_setegid(gid_t egid)
|
2013-01-12 20:37:14 -05:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
ScopedLock lock(&process->idlock);
|
|
|
|
return process->egid = egid, 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Sortix
|