#include "sandbox.h" #include "utils.h" #include #include #include Command COMMANDS[] = { { command_help, {{"help", NULL}, NULL}, NULL, {{"command", "TODO: Add description.", false}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_version, {{"version", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." }, { command_config, {{"config", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." }, { command_container_add, {{"container", "add", NULL}, NULL}, { { {"-r", "--root", NULL}, {{"size", "TODO: Add description.", true}, NULL}, "TODO: Add description." }, { {"-i", "--image", NULL}, {{"image", "TODO: Add description.", true}, NULL}, "TODO: Add description." }, NULL }, {{"container", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_container_remove, {{"container", "rm", NULL}, {"container", "remove", NULL}, {"container", "del", NULL}, {"container", "delete", NULL}, NULL}, NULL, {{"container", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_container_reset, {{"container", "reset", NULL}, NULL}, NULL, {{"container", "TODO: Add description.", true}, NULL}, "Resets the container.", "TODO: Add details." }, { command_container_trim, {{"container", "trim", NULL}, NULL}, NULL, {{"container", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_container_info, {{"container", "info", NULL}, NULL}, NULL, {{"container", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_container_list, {{"container", "ls", NULL}, {"container", "list", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." }, { command_container_wipe, {{"container", "wipe", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." }, { command_container_start, {{"container", "start", NULL}, NULL}, { { {"-p", "--no-pci", NULL}, NULL, "TODO: Add description." }, { {"-v", "--vnc", NULL}, { {"port", "TODO: Add description.", true}, {"password", "TODO: Add description.", true}, NULL }, "TODO: Add description." }, { {"-i", "--iso", NULL}, { {"iso", "TODO: Add description.", true}, NULL }, "TODO: Add description." }, NULL }, {{"container", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_container_stop, {{"container", "stop", NULL}, NULL}, { { {"-f", "--force", NULL}, NULL, "TODO: Add description." }, { {"-t", "--timeout", NULL}, { {"timeout", "TODO: Add description.", true}, NULL }, "TODO: Add description." }, NULL }, {{"container", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_container_ps, {{"container", "ps", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." }, { command_image_sync, {{"image", "sync", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." }, { command_image_add, {{"image", "add", NULL}, NULL}, NULL, { {"container", "The name of the container to add.", true}, NULL }, "TODO: Add details.", "TODO: Add details." }, { command_image_import, {{"image", "import", NULL}, NULL}, NULL, { {"file", "TODO: Add description.", true}, NULL }, "TODO: Add description.", "TODO: Add details." }, { command_image_remove, {{"image", "rm", NULL}, {"image", "remove", NULL}, NULL}, NULL, {{"image", "TODO: Add description.", true}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_image_default, {{"image", "default", NULL}, NULL}, NULL, {{"image", "TODO: Add description.", false}, NULL}, "TODO: Add description.", "TODO: Add details." }, { command_image_list, {{"image", "ls", NULL}, {"image", "list", NULL}, NULL}, NULL, NULL, "TODO: Add description.", "TODO: Add details." } }; int main(int argc, char** argv) { // Ensure the sandbox user exists struct passwd* pw = getpwnam(SANDBOX_USER); if (pw == NULL) { Log(LOG_LEVEL_ERROR, "User '%s' does not exist. Please check that the program is installed correctly.", 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) { Log(LOG_LEVEL_ERROR, "This program must be run as root or as the user '%s'.", 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) { Log(LOG_LEVEL_ERROR, "Failed to switch to the group '%s'.", pw->pw_name); return EXIT_FAILURE; } if (setreuid(pw->pw_uid, pw->pw_uid) != 0) { Log(LOG_LEVEL_ERROR, "Failed to switch to the user '%s'.", pw->pw_name); return EXIT_FAILURE; } } // TODO: Parse commands from the command line } int command_help(int argc, char** argv) { return EXIT_SUCCESS; } int command_version(int argc, char** argv) { return EXIT_SUCCESS; } int command_config(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_add(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_remove(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_reset(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_trim(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_info(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_list(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_wipe(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_start(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_stop(int argc, char** argv) { return EXIT_SUCCESS; } int command_container_ps(int argc, char** argv) { return EXIT_SUCCESS; } int command_image_sync(int argc, char** argv) { return EXIT_SUCCESS; } int command_image_add(int argc, char** argv) { return EXIT_SUCCESS; } int command_image_import(int argc, char** argv) { return EXIT_SUCCESS; } int command_image_remove(int argc, char** argv) { return EXIT_SUCCESS; } int command_image_default(int argc, char** argv) { return EXIT_SUCCESS; } int command_image_list(int argc, char** argv) { return EXIT_SUCCESS; }