Thursday, March 01, 2007

setuid wrapper

I needed to run a script with root privileges,but had
forgotten that Solaris (and I guess mosts versions of Unix) will not allow setuid on scripts. The solutions is to write a binary wrapper will will call the script:


#include <unistd.h>
#include <stdio.h>

#define myfile "/path/to/script"

main(argc, argv)
char **argv;
{
setuid(0);
seteuid(0);
execv(myfile, argv);
}