root login program

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?
Last edited on
instead of using "su root", you can simply ssh into the machine you are trying to login, provided you have the permissions / keys.
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
command line to input my password, that's what I need to know how to do

http://www.cplusplus.com/forum/articles/13355/
;)
uhhh that link you sent didnt help at all, I stried compiling it and it didnt even work... help??
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.
no sudo is not sufficient, because in the linux I'm using sudo cannot do certain things.
sudo cannot do certain things
Like?
Last edited on
You do not want to hard-code your root password into your source code - a simple strings command would dump it right back out.

Look into:

http://en.wikipedia.org/wiki/Setuid

And also google on "setuid root" - you need to be aware of the security of risks of doing so.
Last edited on
Topic archived. No new replies allowed.