Give a hint when setuid logic fails.
authorRob Landley <rob@landley.net>
Sun, 31 Aug 2014 16:58:39 +0000 (11:58 -0500)
committerRob Landley <rob@landley.net>
Sun, 31 Aug 2014 16:58:39 +0000 (11:58 -0500)
Toybox expects to be setuid root; setuid some other user confuses the attempt to drop privileges, and we err on the side of avoiding shenanigans.

main.c

diff --git a/main.c b/main.c
index 6321ad1..5bd4460 100644 (file)
--- a/main.c
+++ b/main.c
@@ -96,8 +96,10 @@ void toy_init(struct toy_list *which, char *argv[])
     uid_t uid = getuid(), euid = geteuid();
 
     if (!(which->flags & TOYFLAG_STAYROOT)) {
-      if (uid != euid)
-        if (!setuid(euid=uid)) perror_exit("setuid"); // drop root
+      if (uid != euid) {
+        if (!setuid(uid)) perror_exit("setuid %d->%d", euid, uid); // drop root
+        else euid = uid;
+      }
     } else if (CFG_TOYBOX_DEBUG && uid && which != toy_list)
       error_msg("Not installed suid root");