LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 11-24-2007, 12:12 AM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 441

Rep: Reputation: 30
How do I switch to root user


I'm designing a program that will periodically need to have root privalages periodically. How do I switch over to root from within a qt program. I tried system("su - root"), but I got a message that it must be run in a terminal.
 
Old 11-24-2007, 01:34 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
First of all, the program will need to either be run as root or will have to be owned by root with the setuid flag set on the actual binary. To change to root when using the setuid flag use the seteuid function.
ta0kira
 
Old 11-25-2007, 05:10 AM   #3
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 441

Original Poster
Rep: Reputation: 30
How does the KDE clock do it? When you click on adjust date and time it asks for the root users password and then suddenly it has root privileges.
 
Old 11-26-2007, 03:10 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
what is this program?
 
Old 11-26-2007, 03:26 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
One approach is to separate out the admin tasks into a separate program, which can then be called with sudo (if your system uses it).

In the case of the KDE clock it is this way: The clock applet runs as the normal user. When the clock applet is told to set the clock it spawns kdesudo (a graphical wrapper to sudo), which runs kcmshell to set the clock. Only the kcmshell process runs with escalated privileges - the clock applet keeps running with normal privileges.
 
  


Reply

Tags
root, sudo


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 do you switch to root user barrythai Ubuntu 19 04-13-2007 11:55 AM
How do I switch ROOT/ADMINISTRATOR to another user?? Balarabay1 Linux - Software 4 07-21-2006 03:54 AM
switch to user installed window manager without root jaddison Linux - Software 13 04-13-2006 07:23 PM
How switch root to another user? Xiangbuilder Linux - Newbie 1 09-15-2003 07:19 AM


All times are GMT -5. The time now is 01:09 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