apps: Add a new su utility
This commit is contained in:
parent
8f0e358360
commit
68d0d0b759
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user