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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| 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/ > |
| |||
| 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 |
| ||||
| 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. > |