LinuxQuestions.org
Visit Jeremy's Blog.
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 08-28-2005, 02:49 AM   #1
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Rep: Reputation: 15
how to get root privilage


I'm creating an appilcation in C which requires root privilage.....How can I invoke root privilage amidst the execution..I mean I can ask the user to enter the root passwd, but how I can substitute the user with root using C once I got the passwd.???????????
 
Old 08-28-2005, 04:41 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
do you want to elevate the privileges while executing or at the begining itself?
if its at the begining of the execution you can check the documentation for
sudo, chmod +s ,
or if you are in a graphical environment check out kdesu or gnomesu
 
Old 08-28-2005, 07:11 AM   #3
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Original Poster
Rep: Reputation: 15
But I need it while executing
 
Old 08-28-2005, 10:19 AM   #4
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#define UID_ROOT 0

int main(int argc, char *argv[]) {
    if (geteuid() != UID_ROOT) {
        execlp("su", "su", "-c", argv[0], NULL);
    }
    puts("root");
    return 0;
}
If you need to pass more arguments, RTFM.
 
Old 08-28-2005, 10:30 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
And to add on, you should really check user input very carefully before you do something with it as root. Otherwise you wilkl compromise your system's security.
 
  


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
giving root privilage to ordinary user... skie_knite007 Programming 5 09-13-2005 09:03 AM
How can I get root privilage using C skie_knite007 Programming 7 03-30-2005 06:25 AM
Write privilage with USB drive grenier Mandriva 8 03-12-2005 07:43 AM
Creating user in linux with the same or less privilage as root Tereno Linux - General 3 12-02-2004 06:36 AM
Creating user in linux with the same or less privilage as root sillyman Linux - General 2 12-01-2004 03:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration