tags:

views:

82

answers:

1

I have a program which runs a bunch of tasks as root at launch. After that it needs to drop to a different user. How can that be done?

And just wondering, is it possible to reacquire root without relaunching the program?

+3  A: 

The short answer is to use the setuid() function.

It is not possible to reacquire root privileges after switching to a non-root user.

Greg Hewgill
"It is not possible to reacquire root privileges after switching to a non-root user." As a matter of fact, this is *the whole point* of dropping superuser privs. You want to limit the impact of any security holes in your program. If you could re-escalate, so could any exploit targeting your program...
sleske
@sleske: actually, if your effective UID is not root, and the implementation supports _POSIX_SAVED_IDS, you can regain the original effective UID.
ninjalj