#include "sandbox.h" #include "utils.h" #include #include #include #include int main(int argc, char** argv) { // Ensure the sandbox user exists struct passwd* pw = getpwnam(SANDBOX_USER); if (pw == NULL) { fprintf(stderr, "User '%s' does not exist. Please check that the program is installed correctly.\n", SANDBOX_USER); return EXIT_FAILURE; } // Check that the program is either run as root or as the sandbox user if (geteuid() != 0 && geteuid() != pw->pw_uid) { fprintf(stderr, "This program must be run as root or as the user '%s'.\n", SANDBOX_USER); return EXIT_FAILURE; } // If the program is run as root, switch to the sandbox user if (geteuid() == 0) { if (setregid(pw->pw_gid, pw->pw_gid) != 0) { fprintf(stderr, "Failed to switch to the group '%s'.\n", pw->pw_name); return EXIT_FAILURE; } if (setreuid(pw->pw_uid, pw->pw_uid) != 0) { fprintf(stderr, "Failed to switch to the user '%s'.\n", pw->pw_name); return EXIT_FAILURE; } } // TODO: Parse commands from the command line }