banan-os/userspace/programs/sudo/main.cpp

32 lines
451 B
C++
Raw Normal View History

#include <stdio.h>
#include <unistd.h>
int usage(char* argv0, int ret)
{
FILE* fp = (ret == 0) ? stdout : stderr;
2023-12-07 14:05:17 +02:00
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);
2023-12-07 14:05:17 +02:00
perror("execvp");
return 1;
}