Execute command which requried root privileges. 
Author Message
 Execute command which requried root privileges.

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:
}



Wed, 30 Nov 2005 17:40:58 GMT  
 Execute command which requried root privileges.
try to use "sudo"

________________________________________________________________

La verdad es dulce y a la vez spera ya que cuando la conozcas sers libre
para ver lo cruda que puede llegar a ser la realidad...

http://www.ViKT0RY.com
________________________________________________________________



Quote:
> 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;
> }



Wed, 30 Nov 2005 20:34:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. c# execute exe file or execute commands

2. Execute code with administrator privileges

3. Executing a command (java command) via C program in Windows 9.X, 2K, NT.

4. How to execute a DOS Command (command line)

5. Help: C prog. to switch to root, execute unix comm., exit root

6. Some good books requried on C

7. How to view commands executed by C# IDE?

8. executing a command or executable from C

9. C code wanted to execute piped commands

10. executing system commands within a C program

11. Execute Windows commands from C#?

12. execute a Unix command in C

 

 
Powered by phpBB® Forum Software