diff options
author | Rob Landley <rob@landley.net> | 2022-04-01 14:19:28 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2022-04-01 14:19:28 -0500 |
commit | d040b01c2eab4e13efe20cf916e6bc80e7927a0d (patch) | |
tree | 9742c468add5444fa35eedef9b91170dca290039 | |
parent | 83d5d7a0bbf60f5d08a1e145058758e717f3a03a (diff) | |
download | toybox-d040b01c2eab4e13efe20cf916e6bc80e7927a0d.tar.gz |
Fix "toybox command --help" for NEEDROOT commands.
-rw-r--r-- | main.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -165,7 +165,6 @@ void toy_init(struct toy_list *which, char *argv[]) void *oldwhich = toys.which; // Drop permissions for non-suid commands. - if (CFG_TOYBOX_SUID) { if (!toys.which) toys.which = toy_list; @@ -181,6 +180,7 @@ void toy_init(struct toy_list *which, char *argv[]) error_msg("Not installed suid root"); if ((which->flags & TOYFLAG_NEEDROOT) && euid) { + toys.which = which; check_help(argv+1); help_exit("Not root"); } @@ -237,12 +237,13 @@ void toybox_main(void) // fast path: try to exec immediately. // (Leave toys.which null to disable suid return logic.) - // Try dereferencing one layer of symlink + // Try dereferencing symlinks until we hit a recognized name while (s) { - struct toy_list *tl = toy_find(basename(s)); + char *ss = basename(s); + struct toy_list *tl = toy_find(ss); - if (tl==toy_list && s!=toys.argv[1]) unknown(basename(s)); - toy_exec_which(toy_find(basename(s)), toys.argv+1); + if (tl==toy_list && s!=toys.argv[1]) unknown(ss); + toy_exec_which(tl, toys.argv+1); s = (0<readlink(s, libbuf, sizeof(libbuf))) ? libbuf : 0; } |