Squash commits for public release

This commit is contained in:
2025-02-12 09:54:05 -05:00
commit 7118adc514
1108 changed files with 80873 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import("//build/userland/TEMPLATE.gni")
xOS_executable("sudo") {
install_path = "bin/"
sources = [ "main.c" ]
configs = [ "//build/userland:userland_flags" ]
deplibs = [ "libc" ]
}

View File

@@ -0,0 +1,50 @@
#include <fcntl.h>
#include <pwd.h>
#include <shadow.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char pswd[64];
int auth(char* uname)
{
spwd_t* spwd;
spwd = getspnam(uname);
if (spwd == NULL) {
return -1;
}
printf("Password: ");
fflush(stdout);
scanf("%s", pswd);
int res = strcmp(pswd, spwd->sp_pwdp);
endspent();
return res;
}
int main(int argc, char** argv)
{
char* envp[] = { "PATH=/bin:/usr/bin", NULL };
if (auth("root") != 0) {
printf("Incorrect password\n");
return -1;
}
// Sign as root
passwd_t* pwd = getpwnam("root");
if (pwd == NULL) {
printf("unable to retrieve user info");
return -1;
}
if (setuid(pwd->pw_uid) != 0) {
printf("setuid failure");
return -1;
}
execvpe(argv[1], &argv[1], envp);
return 0;
}