Reputation: 494
I'd like to fork and exec and program as a non root user while the parent retains root permissions.
pseudo code:
pid = fork();
if (pid == 0) {
if (RunAsUser(ConvertStringToUserId("John")) == false) {
stop();
}
if (RunAsUser(ConvertStringToUserId("admin")) == true) {
stop();
}
CreateProcess();
}
Upvotes: 4
Views: 2375
Reputation: 20520
Get your program to invoke the child process as
sudo -u user /path/to/externalprogram
instead of just
/path/to/externalprogram
Upvotes: 0
Reputation: 21003
If you want to drop privileges in C code, use the function setuid
.
Upvotes: 4