Unix Technical Forum

C program(& script) for running commands

This is a discussion on C program(& script) for running commands within the Linux Operating System forums, part of the Unix Operating Systems category; --> HI there, I have a small C program which acts as a wrapper to run an SUID shell script ...


Go Back   Unix Technical Forum > Unix Operating Systems > Linux Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-18-2008, 06:38 PM
richardrothwell@gmail.com
 
Posts: n/a
Default C program(& script) for running commands

HI there, I have a small C program which acts as a wrapper to run an
SUID shell script for running root commands. The current coding for
this is as follows:

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

int main(void)
{
system("/path/to/script");
return(0);

}


But although the C prog will run the script, I need to develop this
further so that i can run like this:

../wrapper.c date

This would work as the C program calls the shell script, the script
executes an inputted variable which would be the command, date (as an
example).

I already know about all the potential security holes/problems but this
is only as part of a project so security isnt a concern here.

Any suggestions greatly appreciated.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-18-2008, 06:38 PM
Giovanni
 
Posts: n/a
Default Re: C program(& script) for running commands

richardrothwell@gmail.com wrote:
> HI there, I have a small C program which acts as a wrapper to run an
> SUID shell script for running root commands. The current coding for
> this is as follows:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
> system("/path/to/script");
> return(0);
>
> }
>
>
> But although the C prog will run the script, I need to develop this
> further so that i can run like this:
>
> ./wrapper.c date
>
> This would work as the C program calls the shell script, the script
> executes an inputted variable which would be the command, date (as an
> example).
>
> I already know about all the potential security holes/problems but this
> is only as part of a project so security isnt a concern here.
>
> Any suggestions greatly appreciated.
>



The simplest is:

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

int main(int argc, char **argv)
{
char *var = argv[1];

system(var);
return(0);
}

but you maybe want to add if the passed argument exists, is executable
if itis in the PATH directories, etc...

ciao
Giovanni
--
A computer is like an air conditioner,
it stops working when you open Windows.
Registered Linux user #337974 < http://giovanni.homelinux.net/ >
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 06:38 PM
Bill Marcum
 
Posts: n/a
Default Re: C program(& script) for running commands

On 11 Sep 2006 06:11:31 -0700, richardrothwell@gmail.com
<richardrothwell@gmail.com> wrote:
> HI there, I have a small C program which acts as a wrapper to run an
> SUID shell script for running root commands. The current coding for
> this is as follows:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
> system("/path/to/script");
> return(0);
>
> }
>
>
> But although the C prog will run the script, I need to develop this
> further so that i can run like this:
>
> ./wrapper.c date
>

Wouldn't you be reinventing the wheel of sudo? If you really want to do
this, you could study the sudo source code.


--
<Joy> that's a Kludge(TM)
<knghtbrd> It Works(tm)
<Joy> AIX works(TM)
<knghtbrd> no it doesn't
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-18-2008, 06:38 PM
richardrothwell@gmail.com
 
Posts: n/a
Default Re: C program(& script) for running commands

In a way yes. The project must be completed from scratch so I cant use
sudo.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 06:38 PM
Jim Garrison
 
Posts: n/a
Default Re: C program(& script) for running commands

Sounds like an OS class homework assignment. If so, don't expect
people to just give you a solution.

richardrothwell@gmail.com wrote:
> In a way yes. The project must be completed from scratch so I cant use
> sudo.
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:52 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com