LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-22-2004, 08:41 AM   #1
ZX_SA
LQ Newbie
 
Registered: May 2004
Location: Stellenbosch, South Africa
Distribution: Kubuntu breezy, MDK10.2
Posts: 26

Rep: Reputation: 15
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!
 
Old 07-22-2004, 09:14 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute root-privilege programs in KDE autostart? rylan76 Linux - Software 3 07-31-2005 05:40 AM
how to get root privilege in a script jpan Linux - General 5 01-07-2005 03:46 PM
Insufficient Privilege instead of Root Password Request buckberger Linux - Security 3 12-25-2004 09:00 PM
Why root has no privilege to access some directories ymei Linux - General 4 10-08-2003 09:14 AM
How to get root privilege in program using c? whepin Programming 1 04-06-2002 06:27 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration