I want to run process as a different user in Linux with its personal rights. In server program I ask user to enter login and password to get an access to the system. Next I have to run client program as another user to separate workspaces and provide the authentication. Then client program is supposed to send and receive messages from server via Linux IPC sockets. I have found some ways to run a program as another user:
int pid = fork();
if(pid == 0) // child
{
int ret = system("sudo -u username ./client.out");
}
else if(pid > 0) // server
{
// communicate with client via socket
}
else {
exit(EXIT_FAILURE);
}
But it does not use password. My question is how to run a program as another user and pass a password? Also using system
command is not a good solution. sudo
is a command line program, but I have to call it from C. How to run another program properly in C?