From 79eb4385bd34e8ee06b35637f092ee45dc3e3706 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 14 Mar 2026 09:31:51 +0200 Subject: dfm: Add privilege escalation. Pressing 'Z' (default) will spawn a nested dfm by escalating privileges using the value of DFM_SU (default 'sudo'). Pressing 'Z' again inside of this escalated mode returns to the original dfm. --- dfm.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'dfm.c') diff --git a/dfm.c b/dfm.c index 23d0b68..02a1d9b 100644 --- a/dfm.c +++ b/dfm.c @@ -196,6 +196,7 @@ struct fm { s64 tz; u8 nl; u8 im; + const char *a0; }; // Entry Virtual {{{ @@ -2852,6 +2853,33 @@ act_quit_print_pwd(struct fm *p) act_quit(p); } +static inline void +act_toggle_root(struct fm *p) +{ + cut pe = get_env("DFM_SU", DFM_SU); + if (p->f & FM_ROOT) + term_set_dead(&p->t, 1); + else if (!pe.l) + fm_draw_err(p, S("DFM_SU not set"), 0); + else { + usize o = p->ppwd.l; + STR_PUSH(&p->ppwd, "env DFM_LEVEL="); + str_push_c(&p->ppwd, p->nl ? p->nl : '0'); + str_push_c(&p->ppwd, ' '); + str_push_s(&p->ppwd, p->a0); + str_terminate(&p->ppwd); + p->ppwd.l = o; + if (!strcmp(basename_l(pe.d, pe.l), "su")) { + const char *const a[] = { pe.d, "-c", p->ppwd.m + o, NULL }; + fm_exec(p, -1, NULL, a, 0, 1); + } else { + p->ppwd.m[o + 15] = 0; + const char *const a[] = { pe.d, "env", p->ppwd.m + 5, p->a0, NULL }; + fm_exec(p, -1, NULL, a, 0, 1); + } + } +} + static inline void act_cd_home(struct fm *p) { @@ -3700,6 +3728,7 @@ int main(int argc, char *argv[]) { static struct fm p; + p.a0 = argv[0]; str *s = &p.pwd; if (fm_init(&p) < 0) { -- cgit v1.2.3