X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuhttpd.git;a=blobdiff_plain;f=cgi.c;h=0ffb1308c6141b5339a9fa41ac8f64c55f15266b;hp=7b47e7da9666dfa6292477ba6aaef0ab5697e068;hb=HEAD;hpb=1f4c517bb889413e55ccee466d9dfe79156092e8 diff --git a/cgi.c b/cgi.c index 7b47e7d..0ffb130 100644 --- a/cgi.c +++ b/cgi.c @@ -17,6 +17,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _GNU_SOURCE #include #include "uhttpd.h" @@ -51,12 +52,12 @@ static void cgi_main(struct client *cl, struct path_info *pi, char *url) setenv(var->name, var->value, 1); } - chdir(pi->root); - - if (ip) - execl(ip->path, ip->path, pi->phys, NULL); - else - execl(pi->phys, pi->phys, NULL); + if (!chdir(pi->root)) { + if (ip) + execl(ip->path, ip->path, pi->phys, NULL); + else + execl(pi->phys, pi->phys, NULL); + } printf("Status: 500 Internal Server Error\r\n\r\n" "Unable to launch the requested CGI program:\n" @@ -103,10 +104,15 @@ static bool check_cgi_path(struct path_info *pi, const char *url) } pi->ip = NULL; - return uh_path_match(conf.cgi_prefix, url); + + if (conf.cgi_docroot_path) + return uh_path_match(conf.cgi_docroot_path, pi->phys); + + return false; } struct dispatch_handler cgi_dispatch = { + .script = true, .check_path = check_cgi_path, .handle_request = cgi_handle_request, };