I have an program which I run as root. I would like the program to execute another application as a normal user. I tried setgid()
and it works, but I can't then go back to root or another user. The program for the time being is very simple;
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[] )
{
if ( argc != 2) {
printf("usage: %s command\n",argv[0]);
exit(1);
}
setgid(100);
setuid(1000);
putenv("HOME=/home/caroline");
putenv("DISPLAY=:0");
system(argv[1]);
seteuid(1001);
putenv("HOME=/home/john");
putenv("DISPLAY=:1");
system(argv[1]);
return 0;
}
How can I do this? It's like the action of command su $user-c $command