root privileges


 
Thread Tools Search this Thread
Top Forums Programming root privileges
# 1  
Old 11-14-2005
root privileges

Hi

I have make a program that needs root privleges but any user can try to run it, so what I want it is, when any user tries( other than root ) to run the program, an input prompt would open to enter root password ( if user knows ) and program will run ( otherwise exit ), and after completing the task the user returns in its originol state.

So how should I manage it in C or C++.

Plz Help.

thanks & regards.
# 2  
Old 11-14-2005
this can be done in two ways

a)one using the uid of root and the current user
Code:
struct passwd *passent;
passent=getpwnam("root");
if( getuid() == passent->pw_uid )
{
  //root can run this program
}
else
{
  //not root cannot run this pgm
  exit(0);
}

b) second one is to use the login name
Code:
struct passwd *passent;
passent=getpwnam("root");
if( strcmp(getlogin(),passent->pw_name) == 0)
{
  //root can run this program
}
else
{
  //not root cannot run this pgm
  exit(0);
}

# 3  
Old 11-15-2005
but I also want to prompt the user to enter 'root password' and if this is not valid root password the program will exit.

In ur solution we are only checking that if the current user is root continue with the program otherwise exit.

thanks.
# 4  
Old 11-15-2005
matrixmadhan's solution can be extended to also do what you want to. Check the man pages of getpwnam and related syscalls to see how you can go about this.
# 5  
Old 11-15-2005
Ya thats fine, but where I am in the trouble is...

let the current user is not root.
so I prompt an input dialog box( in Qt password mode ).
if user enters a wrong password it must exit.
else the program would proceed.

but what the problem is :

1. How will I validate root's password.
2. If password found valid how will I change user only for current program and after exiting this program user should automatically come in its previous state.

( Something like when you click 'Add/Remove Applications' in 'Systems Settings' in RedHat 9 as a normal user it prompts for root password and after finishing the task you came in your previous state )

thanks

sumsin
# 6  
Old 11-15-2005
See the man page of getpwent/getpwnam. The structure that these system calls return also has the encrypted password. Your program can use this to validate the password that the user enters and then go ahead with a 'setuid' call. Once this is one, you are running with root privs.
# 7  
Old 11-15-2005
but how an encrypted password compare with a non-encrypted password.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Infrastructure Monitoring

Monitoring tools that do NOT require root privileges

Hi guys, I am currently managing an application running on around 150 servers. I only have application usage rights on those servers and do not have any root privileges. I have an external node that can connect to those servers and I have root privileges on that one box. I want to setup... (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

2. UNIX for Dummies Questions & Answers

Can you gain root privileges if the suid program does not belong to root?

I had a question in my test which asked where suppose user B has a program with 's' bit set. Can user A run this program and gain root privileges in any way? I suppose not as the suid program run with privileges of owner and this program will run with B's privileges and not root. (1 Reply)
Discussion started by: syncmaster
1 Replies

3. HP-UX

User with root privileges in hp ux

hi, i am new in hp ux and i must create a user with root privileges and so i disable ssh connection from root login. thanks.. (6 Replies)
Discussion started by: eliste
6 Replies

4. Solaris

Gaining root privileges

Hello I am a new (and only) administrator of a Solaris 10 environment. The previous admin gave me a use (say user123) that is supposed to have administrative privileges. Now the problem is, the user does not have this privilege! Here is what i tried so far: $ id uid=109(user123) gid=1(other)... (3 Replies)
Discussion started by: abohmeed
3 Replies

5. Shell Programming and Scripting

Privileges like root

My English is no very good. I must make a bash scripting sh create like a backdoor, and when execute the script a user without privileges convert in super user or root, whithout introducing the password. In Spanish: Crear un script que sirva como puerta trasera al sistema, de manera que al... (1 Reply)
Discussion started by: kitievbr
1 Replies

6. Shell Programming and Scripting

Python: Bind to port 80 as root, then drop privileges?

I have written a small web server in Python, and now I would like to run it on port 80, but in order to be able to bind to a port below 1024 I need to have root privileges. I don't want to run the server as root, though. How can I bind to port 80 as root and then drop root privileges? Thankful... (0 Replies)
Discussion started by: Ilja
0 Replies

7. Linux

grant root privileges to ordinary user

Hi, Is it possible to grant root privileges to an ordinary user? Other than 'sudo', is there some way under Users/Groups configuration? I want ordinary user to be able to mount, umount and use command mt. /Brendan (4 Replies)
Discussion started by: brendan76
4 Replies

8. UNIX for Dummies Questions & Answers

root privileges

Hello, As admin with root rights, to execute any command from another user without password-ask, I do : su - <user> -c "<cmd>" But how can I do to give the same rights to another physical user without using root user ? :confused: I've try to create another user "toor" with the same primary... (4 Replies)
Discussion started by: madmat
4 Replies

9. Solaris

sshd (openssh) on SunOS without root privileges

Hi, I've just managed to install openssh in my home directory on a server I have access to by using --prefix=$HOME/local after ./configure. Another thing I was having trouble with without root access was privilege separation, so I disabled that in my sshd_config. However, when I run... (10 Replies)
Discussion started by: sayeo
10 Replies

10. UNIX for Dummies Questions & Answers

Root privileges &Sudoer

Hi guys... how can a root assign a user all or most of the root privileges? is sudoer comand enough 4 this? thx alot.. (2 Replies)
Discussion started by: blue_7
2 Replies
Login or Register to Ask a Question