comparison 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
comparison
equal deleted inserted replaced
369:5715eed39575 370:c7a26e26ad08
62 #include "generated/newtoys.h" 62 #include "generated/newtoys.h"
63 0; // Ends the opts || opts || opts... 63 0; // Ends the opts || opts || opts...
64 64
65 void toy_init(struct toy_list *which, char *argv[]) 65 void toy_init(struct toy_list *which, char *argv[])
66 { 66 {
67 // Drop permissions for non-suid commands.
68
69 if (CFG_TOYBOX_SUID) {
70 uid_t uid = getuid(), euid = geteuid();
71
72 if (!(which->flags & TOYFLAG_STAYROOT)) {
73 if (uid != euid) xsetuid(euid=uid);
74 } else if (CFG_TOYBOX_DEBUG && uid)
75 error_exit("Not installed suid root");
76
77 if ((which->flags & TOYFLAG_NEEDROOT) && euid)
78 error_exit("Not root");
79
80 }
81
67 // Free old toys contents here? 82 // Free old toys contents here?
68 83
69 toys.which = which; 84 toys.which = which;
70 toys.argv = argv; 85 toys.argv = argv;
71 if (NEED_OPTIONS && which->options) get_optflags(); 86 if (NEED_OPTIONS && which->options) get_optflags();