February 5th, 2008, 12:43 AM
executing CGI programs using C++
I am currently trying to write a simple web server program in C++. The only problem that I have come across, so far, is that I would like my web server to be able to execute CGI (Common Gateway Interface) programs, but I'm not sure how to accomplish this.
I know that I need to be able to execute the CGI program and some how redirect the output of this program back to the network connection. I am thinking along the lines of using the exec system calls (execlp, execvp etc.) in some way.
If anyone could offer me some ideas, I would greatly appreciate it.
Thanks in advance,
February 5th, 2008, 04:58 AM
First you have to decide what your CGI programs are... and what CGI languages you support.
CGI = Common Gateway Interface as you mentioned, however many people assume that CGI == PERL... this is not the case. CGI describes any application that performs server-side scripting.
Your Web Server could execute perl directly... and return the output... Or it could execute php, python or almost any other language.
Your CGI's could actually be other compiled C++ programs. Unfortunately I don't think there's an answer for "How do I execute CGI programs"... at least not until you define a spec.
Questions to Answer:
1. What languages will I support?
2. Will I fully support the language, or will I support a subset?
3. Will I implement the vendor supplied method of processing the language, or will I write my own processor.
4. Ultimate question... Do you want it to be a CGI, or do you just want to support the language?
Now let's look at #4 a bit. You could read into the SAPI/ISAPI implementation of PHP (as an example language) and implement the SAPI module, alternately you could implement the executable as a CGI (technically a CGI)... In the end both will product the same result. the choice is yours.
Let me know if I've left you more confused than you already were, or if I've cleared things up.
IT Blog: .:Computer Defense:.
(Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".
February 5th, 2008, 10:38 PM
thanks for your reply. at this point I am only concerning myself with CGI which has been written in other compiled languages (i.e. C).
February 6th, 2008, 08:55 AM
A CGI program is just that, a program, an executable if you will. The variables like ?page=12 etc. will be fed to it as arguments and the program gets executed. The program's output (stdout) will be fed back to the (web) client connected to it.
It doesn't matter which language was used to create that executable. The only thing that matters are the arguments passed to it and it's output.
Experience is something you don't get until just after you need it.
By el-half in forum Code Review
Last Post: June 23rd, 2004, 09:17 AM
By slick8790 in forum Miscellaneous Security Discussions
Last Post: December 13th, 2003, 09:34 AM
By -DaRK-RaiDeR- in forum Newbie Security Questions
Last Post: December 14th, 2002, 08:38 PM
By R0n1n in forum *nix Security Discussions
Last Post: November 20th, 2002, 02:20 PM
By Ennis in forum The Security Tutorials Forum
Last Post: November 15th, 2001, 07:42 PM