Execute command which requried root privileges.

Execute command which requried root privileges.

Post by Jigne » Sun, 15 Jun 2003 18:37:34



Hello,

I have two users on Linux box which are user1 & root. I want to
execute IPFW command from user1 login. IPFW command required root user
privileges.

I have written programme which is as under. When i am running the
programme as  user1 loggedin, it is promting me for password which i
donot want.

Problem:-
        I want other programme to feed password when following programme is
asking for password & i can execute IPFW command. How can i do this?
This new passwdfeed program should also run by user1 loggedin.

Please suggest any solution.

Thanking You.

//CODE

#include <stdio.h>
#include <stdlib.h>

void write_data (FILE * stream) {
   fprintf (stream, "%s\n", "ipfw show");
   fprintf (stream, "%s\n", "exit");
   if (ferror (stream)) {
      fprintf (stderr, "Output to stream failed.\n");
      exit (EXIT_FAILURE);
   }

Quote:}

int main(int argc, char *argv[])
{
   FILE *output;
   output = popen ("su", "w");
   write_data (output);
   if (pclose (output) != 0) {
      fprintf (stderr,"Could not run more or other error.\n");
   }
   return 0;
Quote:}

 
 
 

Execute command which requried root privileges.

Post by Chris Lowt » Sun, 15 Jun 2003 21:47:19



> Hello,

> I have two users on Linux box which are user1 & root. I want to
> execute IPFW command from user1 login. IPFW command required root user
> privileges.

> I have written programme which is as under. When i am running the
> programme as  user1 loggedin, it is promting me for password which i
> donot want.

> Problem:-
> I want other programme to feed password when following programme is
> asking for password & i can execute IPFW command. How can i do this?
> This new passwdfeed program should also run by user1 loggedin.

> Please suggest any solution.

> Thanking You.

> //CODE

> #include <stdio.h>
> #include <stdlib.h>

> void write_data (FILE * stream) {
>    fprintf (stream, "%s\n", "ipfw show");
>    fprintf (stream, "%s\n", "exit");
>    if (ferror (stream)) {
>       fprintf (stderr, "Output to stream failed.\n");
>       exit (EXIT_FAILURE);
>    }
> }

> int main(int argc, char *argv[])
> {
>    FILE *output;
>    output = popen ("su", "w");
>    write_data (output);
>    if (pclose (output) != 0) {
>       fprintf (stderr,"Could not run more or other error.\n");
>    }
>    return 0;
> }

You need to think about using the "setuid" bit on your program - but if you
do this, be VERY careful about potential exploits. Keep the code as simple
as possible, and remember that once it is running as "setuid root", it is
down to the program itself to police it's own security rules.

        see: man chmod
        and: man chown

Chris
--
Real address: chris at lowth dot sea oh em.
World's first wrist-watch PDA with Palm OS, available June 30
from Amazon.com. Order now to beat the rush!
   http://www.lowth.com/shop/wrist_pda

 
 
 

Execute command which requried root privileges.

Post by Jigne » Tue, 17 Jun 2003 20:14:03




> > Hello,

> > I have two users on Linux box which are user1 & root. I want to
> > execute IPFW command from user1 login. IPFW command required root user
> > privileges.

> > I have written programme which is as under. When i am running the
> > programme as  user1 loggedin, it is promting me for password which i
> > donot want.

> > Problem:-
> > I want other programme to feed password when following programme is
> > asking for password & i can execute IPFW command. How can i do this?
> > This new passwdfeed program should also run by user1 loggedin.

> > Please suggest any solution.

> > Thanking You.

> > //CODE

> > #include <stdio.h>
> > #include <stdlib.h>

> > void write_data (FILE * stream) {
> >    fprintf (stream, "%s\n", "ipfw show");
> >    fprintf (stream, "%s\n", "exit");
> >    if (ferror (stream)) {
> >       fprintf (stderr, "Output to stream failed.\n");
> >       exit (EXIT_FAILURE);
> >    }
> > }

> > int main(int argc, char *argv[])
> > {
> >    FILE *output;
> >    output = popen ("su", "w");
> >    write_data (output);
> >    if (pclose (output) != 0) {
> >       fprintf (stderr,"Could not run more or other error.\n");
> >    }
>  return 0;
> > }

> You need to think about using the "setuid" bit on your program - but if you
> do this, be VERY careful about potential exploits. Keep the code as simple
> as possible, and remember that once it is running as "setuid root", it is
> down to the program itself to police it's own security rules.

>         see: man chmod
>         and: man chown

> Chris

Hello,

    I have use setuid() with "usr1" login, which do not have
privileges for set user id as root.

Please suggest any other alternative.

Thanking You.

 
 
 

1. Users executing Privileged commands selectively

Hi,

If I have a user Telnetted into a server, and I would like them to be
running a script, certain options for which require Root-level commands
to be run, eg. adding a user group. I would like to "su" in the script
to execute these commands, but obviously I don't want the user
him/herself to end up with root privileges.
How do I accomplish this?
Is it enough to just chmod a+x and chmod a-rw the script? That just
seems way too flimsy.

Thanks,
The Nomad.

2. TV Card support

3. root privileges through non-root process?

4. managing large amounts of user accounts

5. root privileges for non-root users

6. External machines to view web server

7. Root privilege using non-root account

8. Help Installing over IP.

9. Log in as root but can't execute any commands or read files.

10. Log in as root but can't execute commands or read files.

11. How to execute superuser commands without being root

12. How to remotely execute commands as root

13. How to execute superuser commands without being root