Question

I write a simple program

When you run this program, if you are not root user, input root password, then change uid to root

if (getuid())
{
    char *pass = getpass("");
    //how to change uid to root ?
}

How to change uid to root when you got root password?

Was it helpful?

Solution

There is no way to change from a non-root user to root. That's the whole point. Programs like login, sshd, or su work by initially starting as root, either because of their ancestry or by having the suid bit on the executable file, and carefully restricting what you can do until you authenticate with a password or other method, then changing to an appropriate uid (either root or the user you're logging in as) and exec'ing another program (usually, the shell).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top