LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Temp root privilege in program? (https://www.linuxquestions.org/questions/programming-9/temp-root-privilege-in-program-208250/)

ZX_SA 07-22-2004 07:41 AM

Temp root privilege in program?
 
Hi all

Is it possible for a program (which is executed by a normal user) to obtain root privileges? How do you do it?

Basically I'm writing an app that needs to lock its allocated RAM. It's going to be filled way too fast to allow the kernel to swap the pages to harddrive. So I'm thinking of using the mlock() function to do that. But that requires that the program have root access.

I've had a look at setuid() but it seems like that only allows you to switch from root to a normal user. I need it to go the other way.

I could run the program with sudo, but I would prefer to just get temporary root access for the mlock() function.

Any advice welcome!

Hko 07-22-2004 08:14 AM

For obvious reasons that is not possible. At least not without having your program ask for the root password.

But you can do it the other way around by setting the executable file of your program SUID root or, better, starting it with sudo.

Then you can make your program change the effective user ID to a normal user, and regain root privileges again when it needs them. The system fucntion that can do this is seteuid(). See its man page for more information.


All times are GMT -5. The time now is 04:43 AM.