Mercurial > hg > toybox
diff main.c @ 370:c7a26e26ad08
Add TOYBOX_SUID.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 05 Jan 2010 12:17:05 -0600 |
parents | 951110c37fee |
children | 5e68c7cab1a4 |
line wrap: on
line diff
--- a/main.c Tue Jan 05 10:48:32 2010 -0600 +++ b/main.c Tue Jan 05 12:17:05 2010 -0600 @@ -64,6 +64,21 @@ 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;