Kernel, libc: Add setuid() and setgid() system calls
This commit is contained in:
parent
2269ec267c
commit
1c4f1ab867
@ -28,6 +28,8 @@
|
||||
#define SYS_getdents 22
|
||||
#define SYS_stat 23
|
||||
#define SYS_dup2 24
|
||||
#define SYS_setuid 25
|
||||
#define SYS_setgid 26
|
||||
|
||||
struct stat;
|
||||
struct pstat;
|
||||
@ -63,3 +65,5 @@ void sys_pstat(Context* context, long pid, struct pstat* buf);
|
||||
void sys_getdents(Context* context, int fd, struct luna_dirent* buf, size_t count);
|
||||
void sys_stat(Context* context, const char* path, struct stat* buf);
|
||||
void sys_dup2(Context* context, int fd, int fd2);
|
||||
void sys_setuid(Context* context, int new_uid, int new_euid);
|
||||
void sys_setgid(Context* context, int new_gid, int new_egid);
|
@ -38,6 +38,8 @@ void Syscall::entry(Context* context)
|
||||
sys_getdents(context, (int)context->rdi, (struct luna_dirent*)context->rsi, (size_t)context->rdx);
|
||||
break;
|
||||
case SYS_dup2: sys_dup2(context, (int)context->rdi, (int)context->rsi); break;
|
||||
case SYS_setuid: sys_setuid(context, (int)context->rdi, (int)context->rsi); break;
|
||||
case SYS_setgid: sys_setgid(context, (int)context->rdi, (int)context->rsi); break;
|
||||
default: context->rax = -ENOSYS; break;
|
||||
}
|
||||
VMM::exit_syscall_context();
|
||||
|
@ -46,3 +46,51 @@ void sys_getprocid(Context* context, int field)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void sys_setuid(Context* context, int new_uid, int new_euid)
|
||||
{
|
||||
Task* current_task = Scheduler::current_task();
|
||||
|
||||
if (!current_task->is_superuser())
|
||||
{
|
||||
if (new_uid != current_task->uid && new_uid != current_task->euid)
|
||||
{
|
||||
context->rax = -EPERM;
|
||||
return;
|
||||
}
|
||||
if (new_euid != current_task->euid && new_euid != current_task->uid)
|
||||
{
|
||||
context->rax = -EPERM;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
current_task->uid = new_uid;
|
||||
current_task->euid = new_euid;
|
||||
|
||||
context->rax = 0;
|
||||
}
|
||||
|
||||
void sys_setgid(Context* context, int new_gid, int new_egid)
|
||||
{
|
||||
Task* current_task = Scheduler::current_task();
|
||||
|
||||
if (!current_task->is_superuser())
|
||||
{
|
||||
if (new_gid != current_task->gid && new_gid != current_task->egid)
|
||||
{
|
||||
context->rax = -EPERM;
|
||||
return;
|
||||
}
|
||||
if (new_egid != current_task->egid && new_egid != current_task->gid)
|
||||
{
|
||||
context->rax = -EPERM;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
current_task->gid = new_gid;
|
||||
current_task->egid = new_egid;
|
||||
|
||||
context->rax = 0;
|
||||
}
|
@ -26,5 +26,7 @@
|
||||
#define SYS_getdents 22
|
||||
#define SYS_stat 23
|
||||
#define SYS_dup2 24
|
||||
#define SYS_setuid 25
|
||||
#define SYS_setgid 26
|
||||
|
||||
#endif
|
@ -26,6 +26,8 @@ extern "C" long syscall(long number, ...)
|
||||
case SYS_fstat:
|
||||
case SYS_stat:
|
||||
case SYS_dup2:
|
||||
case SYS_setuid:
|
||||
case SYS_setgid:
|
||||
case SYS_pstat: {
|
||||
arg arg0 = va_arg(ap, arg);
|
||||
arg arg1 = va_arg(ap, arg);
|
||||
|
Loading…
Reference in New Issue
Block a user