Hey
I'm fairly new to programming in c++, and I was wondering how I could make a program that logs me in as su root and automatically inputs my password? I've managed to get it to show me the password option by inputting:
#include <stdlib.h>
using namespace std;
int main()
{
system("su root");
}
but I cant figure out how to get it to input my password for me. Help?
but that would force me to have some kind of input into the command line to input my password, that's what I need to know how to do, and then even if I just manually enter my password, the program stops running commands until I type "exit" which logs me out of root
Are you really sure you want to do that? Is sudo not sufficient? Some systems (e.g. OS X and Ubuntu) disable the root account and require you to use sudo instead because it's much safer. Have you thought about where you might store the root password? I'll say now, it's a really bad idea, you may as well disable the root password because your system will be so compromised, you'll only have an illusion of security.
After a fairly relaxed intial view of security, Unix systems have been trying to improve security over the years. As a result, there's a variety of approaches, it depends on what you're running. For a start, your process will need the setuid bit set. To get an idea what's involved, check out Advanced Programming in the UNIX Environment, Chapter 8, Section Changing User IDs and Group IDs.