setuid warpper problem 
Author Message
 setuid warpper problem

I want to have a bash scripts run setuid as root, The bash
script('do_something') suppose to write to a file('/var/filename')
that has an root owner and -rw--r--r permission
So I've created a C-wrapper that calls the script with permissions
4755 and has an root owner.
I have no problem to run the C-program as root, but when I am trying
to execute it as regular user I get a Permission denied message.

#include <stdio.h>
#include  <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(){

    if((pid = fork()) == -1)
        return -1;

   if(pid == 0){
         char *args[2];

         args[0] = "./do_something";          
         args[1] = "/var/filename";  
         args[2] = NULL;

          setuid(0);
          rc = execv(args[0], args);

          exit(rc);
   }

   rc = wait(NULL);

Quote:
}

does anyone know what is wrong ?
how can i let a regular user run that script with superuser
permissions ?

Thanks for any information

Itzik



Fri, 04 Feb 2005 20:36:34 GMT  
 setuid warpper problem


Wed, 18 Jun 1902 08:00:00 GMT  
 setuid warpper problem
Quote:

> I want to have a bash scripts run setuid as root, The bash
> script('do_something') suppose to write to a file('/var/filename')
> that has an root owner and -rw--r--r permission
> So I've created a C-wrapper that calls the script with permissions
> 4755 and has an root owner.
> I have no problem to run the C-program as root, but when I am trying
> to execute it as regular user I get a Permission denied message.

> #include <stdio.h>
> #include  <stdlib.h>
> #include <sys/types.h>
> #include <unistd.h>

> int main(){

>     if((pid = fork()) == -1)
>    return -1;

>    if(pid == 0){
>          char *args[2];

>          args[0] = "./do_something";            
>          args[1] = "/var/filename";      
>          args[2] = NULL;

>           setuid(0);

AFAIR
A program may only success in a setuid (0) call if owned by root and
only if permissions on file has the sticky bit set (chmod 4555) thus
root granted you permissions to run this program with root permissions.


Fri, 04 Feb 2005 20:54:16 GMT  
 setuid warpper problem


Wed, 18 Jun 1902 08:00:00 GMT  
 setuid warpper problem
after compile, do a

chown root wrapper
chgrp root wrapper
chmod ugo+s wrapper

hth,
Wolf



Fri, 04 Feb 2005 21:01:19 GMT  
 setuid warpper problem
Quote:

> I want to have a bash scripts run setuid as root, The bash
> script('do_something') suppose to write to a file('/var/filename')
> that has an root owner and -rw--r--r permission
> So I've created a C-wrapper that calls the script with permissions
> 4755 and has an root owner.

[...]

This isn't really a C question.  Try comp.unix.programmer.

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"



Sat, 05 Feb 2005 03:15:23 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problems to pass HWND from c# client to unmanaged vc++ class via MC++ warpper

2. crontab with setuid()

3. setuid()

4. Setuid

5. HELP: setuid root program can't verify passwords???

6. setuid & dynamic libraries?

7. problems problems problems

8. Problems, problems, problems!

9. Problems, problems problems

10. Problems, Problems, Problems

11. VC6 to VC7 migration problem (problem with ATL and MFC)

 

 
Powered by phpBB® Forum Software