diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-06-28 10:53:23 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-06-28 10:53:23 +0000 |
| commit | 7d51c0b16c1d304c47bde72761d87965f8686268 (patch) | |
| tree | 75e591d3f698055c2733dd1158fa3328003d8c09 /src | |
| parent | 930b48dd0373e4c4e29ab590b9e90f4cd6dcedad (diff) | |
added quasi privilege escalation (as long as you don't clone into a directory that you don't have access to)
Diffstat (limited to 'src')
| -rw-r--r-- | src/fetch_git.c | 2 | ||||
| -rw-r--r-- | src/lua_state.c | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/fetch_git.c b/src/fetch_git.c index 296cdb7..2640f9c 100644 --- a/src/fetch_git.c +++ b/src/fetch_git.c @@ -25,6 +25,8 @@ #include <unistd.h> #include "fetch_git.h" + +#include "lua_state.h" #include "vars.h" int fetch_git(Pkg pkg) { diff --git a/src/lua_state.c b/src/lua_state.c index 3c53668..9ba71de 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -104,6 +104,20 @@ void free_lua_state(void) { lua_State *get_lua_state(void) { return L; } +const char* get_privilege_escalator(void) { + lua_getglobal(L, "privilege_escalator"); + if (!lua_isstring(L, -1)) { + printf( + "%s init.lua: 'privilege_escalator' is not a string.\n", + print_error + ); + return ""; + } + const char* privilege_escalator = lua_tostring(L, -1); + lua_pop(L, 1); + return privilege_escalator; +} + void cache_prefix_directory(void) { lua_getglobal(L, "prefix"); if (!lua_isstring(L, -1)) { @@ -465,6 +479,11 @@ bool repo_build(const char *repository, const char *target) { } bool repo_install(const char *repository, const char* target) { + if (!access(prefix_dir, W_OK)) { + lua_pushfstring(L, "%s", ""); + lua_setglobal(L, "privilege_escalator"); + lua_pop(L, 1); + } lua_getglobal(L, "repositories"); if (!config_loaded || !lua_istable(L, -1)) { if (is_verbose) printf( @@ -497,6 +516,11 @@ bool repo_install(const char *repository, const char* target) { } bool repo_uninstall(const char *repository, const char *target) { + if (!access(prefix_dir, W_OK)) { + lua_pushfstring(L, "%s", get_privilege_escalator()); + lua_setglobal(L, "privilege_escalator"); + lua_pop(L, 1); + } lua_getglobal(L, "repositories"); if (!config_loaded || !lua_istable(L, -1)) { if (is_verbose) printf( @@ -634,6 +658,11 @@ bool bldit_install(const char *target) { lua_pushfstring(B, "%s", prefix_dir); lua_setglobal(B, "prefix"); lua_pop(B, 1); + if (!access(prefix_dir, W_OK)) { + lua_pushfstring(B, "%s", get_privilege_escalator()); + lua_setglobal(B, "privilege_escalator"); + lua_pop(B, 1); + } lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { if (is_verbose) printf( @@ -675,6 +704,11 @@ bool bldit_uninstall(const char *target) { lua_pushfstring(B, "%s", prefix_dir); lua_setglobal(B, "prefix"); lua_pop(B, 1); + if (!access(prefix_dir, W_OK)) { + lua_pushfstring(B, "%s", get_privilege_escalator()); + lua_setglobal(B, "privilege_escalator"); + lua_pop(B, 1); + } lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { if (is_verbose) printf( @@ -799,6 +833,11 @@ bool config_build(const char *path, const char *target) { } bool config_install(const char *path, const char *target) { + if (!access(prefix_dir, W_OK)) { + lua_pushfstring(L, "%s", get_privilege_escalator()); + lua_setglobal(L, "privilege_escalator"); + lua_pop(L, 1); + } lua_getglobal(L, "build_systems"); if (!config_loaded || !lua_istable(L, -1)) { lua_pop(L, 1); @@ -835,13 +874,18 @@ bool config_install(const char *path, const char *target) { } bool config_uninstall(const char *path, const char *target) { + if (!access(prefix_dir, W_OK)) { + lua_pushfstring(L, "%s", get_privilege_escalator()); + lua_setglobal(L, "privilege_escalator"); + lua_pop(L, 1); + } lua_getglobal(L, "build_systems"); if (!config_loaded || !lua_istable(L, -1)) { lua_pop(L, 1); return false; } - bool target_loop_success = false; lua_pushnil(L); + bool target_loop_success = false; while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); if (!lua_istable(L, -1)) { |
