aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2010-01-05 12:17:05 -0600
committerRob Landley <rob@landley.net>2010-01-05 12:17:05 -0600
commite0377fb294821a68112d4da09f836ac42e3d5956 (patch)
tree489d2a2b21393f7283870c2f21ed82b5818f1d82 /main.c
parent1e01cd1f48bff3fdd12f45bf1c3adfab821ee287 (diff)
downloadtoybox-e0377fb294821a68112d4da09f836ac42e3d5956.tar.gz
Add TOYBOX_SUID.
Diffstat (limited to 'main.c')
-rw-r--r--main.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/main.c b/main.c
index 4e6a31e7..e0dab1cc 100644
--- a/main.c
+++ b/main.c
@@ -64,6 +64,21 @@ static const int NEED_OPTIONS =
void toy_init(struct toy_list *which, char *argv[])
{
+ // Drop permissions for non-suid commands.
+
+ if (CFG_TOYBOX_SUID) {
+ uid_t uid = getuid(), euid = geteuid();
+
+ if (!(which->flags & TOYFLAG_STAYROOT)) {
+ if (uid != euid) xsetuid(euid=uid);
+ } else if (CFG_TOYBOX_DEBUG && uid)
+ error_exit("Not installed suid root");
+
+ if ((which->flags & TOYFLAG_NEEDROOT) && euid)
+ error_exit("Not root");
+
+ }
+
// Free old toys contents here?
toys.which = which;