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);
}
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);
}
2 comments:
You probably really want to clean up the environment before execing the command.
Thank you for the code.
After compile, be sure to chmod 4711 pgm name.
Othewise, it may not work.
Post a Comment