Compare commits
2 Commits
09a615bd99
...
68d0d0b759
Author | SHA1 | Date | |
---|---|---|---|
68d0d0b759 | |||
8f0e358360 |
@ -1,4 +1,4 @@
|
|||||||
APPS := init sym sh crash uname uptime hello ps ls args cat stat
|
APPS := init sym sh crash uname uptime hello ps ls args cat stat su
|
||||||
|
|
||||||
APPS_DIR := $(LUNA_ROOT)/apps
|
APPS_DIR := $(LUNA_ROOT)/apps
|
||||||
APPS_SRC := $(APPS_DIR)/src
|
APPS_SRC := $(APPS_DIR)/src
|
||||||
|
32
apps/src/su.c
Normal file
32
apps/src/su.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
char* default_argv[] = {"/bin/sh", NULL};
|
||||||
|
|
||||||
|
void run_program(char** argv)
|
||||||
|
{
|
||||||
|
execv(argv[0], argv);
|
||||||
|
|
||||||
|
perror("execv");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: %s [uid] [command | sh]\n", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setuid(atoi(argv[1])) < 0)
|
||||||
|
{
|
||||||
|
perror("setuid");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 2) run_program(default_argv);
|
||||||
|
else
|
||||||
|
run_program(argv + 2);
|
||||||
|
}
|
@ -50,6 +50,18 @@ extern "C"
|
|||||||
/* Returns the current process' effective group ID. */
|
/* Returns the current process' effective group ID. */
|
||||||
gid_t getegid(void);
|
gid_t getegid(void);
|
||||||
|
|
||||||
|
/* Sets the current process' real and effective user IDs. */
|
||||||
|
int setuid(uid_t uid);
|
||||||
|
|
||||||
|
/* Sets the current process' effective user ID. */
|
||||||
|
int seteuid(uid_t uid);
|
||||||
|
|
||||||
|
/* Sets the current process' real and effective group IDs. */
|
||||||
|
int setgid(gid_t gid);
|
||||||
|
|
||||||
|
/* Sets the current process' effective group ID. */
|
||||||
|
int setegid(gid_t gid);
|
||||||
|
|
||||||
/* Terminates the program with the status code status. */
|
/* Terminates the program with the status code status. */
|
||||||
__lc_noreturn void _exit(int status);
|
__lc_noreturn void _exit(int status);
|
||||||
|
|
||||||
|
@ -58,6 +58,26 @@ extern "C"
|
|||||||
return (gid_t)getprocid(ID_EGID);
|
return (gid_t)getprocid(ID_EGID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int setuid(uid_t uid)
|
||||||
|
{
|
||||||
|
return (int)__lc_fast_syscall2(SYS_setuid, uid, uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int seteuid(uid_t uid)
|
||||||
|
{
|
||||||
|
return (int)__lc_fast_syscall2(SYS_setuid, getprocid(ID_UID), uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setgid(gid_t gid)
|
||||||
|
{
|
||||||
|
return (int)__lc_fast_syscall2(SYS_setgid, gid, gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setegid(gid_t gid)
|
||||||
|
{
|
||||||
|
return (int)__lc_fast_syscall2(SYS_setgid, getprocid(ID_GID), gid);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int sleep(unsigned int seconds)
|
unsigned int sleep(unsigned int seconds)
|
||||||
{
|
{
|
||||||
return msleep(seconds * 1000);
|
return msleep(seconds * 1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user