BuildSystem: Cleanup userspace directory layout
userspace programs are now in userspace/programs userspace tests are now in userspace/tests This makes listing userspace projects much cleaner. Libraries were already separated to their own directory, so other programs should also.
This commit is contained in:
16
userspace/programs/sudo/CMakeLists.txt
Normal file
16
userspace/programs/sudo/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(sudo ${SOURCES})
|
||||
banan_link_library(sudo libc)
|
||||
|
||||
install(
|
||||
TARGETS sudo
|
||||
PERMISSIONS
|
||||
OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
SETUID
|
||||
OPTIONAL
|
||||
)
|
||||
31
userspace/programs/sudo/main.cpp
Normal file
31
userspace/programs/sudo/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int usage(char* argv0, int ret)
|
||||
{
|
||||
FILE* fp = (ret == 0) ? stdout : stderr;
|
||||
fprintf(fp, "usage: %s COMMAND [ARGUMENTS...]\n", argv0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
return usage(argv[0], 1);
|
||||
|
||||
if (setuid(0) == -1)
|
||||
{
|
||||
perror("setuid");
|
||||
return 1;
|
||||
}
|
||||
if (setgid(0) == -1)
|
||||
{
|
||||
perror("setgid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
execvp(argv[1], argv + 1);
|
||||
|
||||
perror("execvp");
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user