I have a process with 4750 permissions. There are two users on my Linux system. The root user and the appz user. The process inherits the permissions of the process manager, which runs as the appz user.
I have two main procedures:
void do_root (void) { int status; status = seteuid (euid); if (status < 0) { exit (status); } } void undo_root (void) { int status; status = seteuid (ruid); if (status < 0) { exit (status); } status = setuid(ruid); if (status < 0) { exit (status); } }
My thread is as follows:
int main() { undo_root(); do some stuff; do_root(); bind( port 80); //needs root perm undo_root(); while(1) { accept commads() if ( commands needs root user access) { do_root(); execute(); undo_root(); } }
As you can see, I want to execute some commands with root privileges. I am trying to temporarily remove permissions, and if tasks need root access, I end the command between calling do_root and undo_root.
However, it seems my program is not working.
What is the canonical way to do this?
source share