X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcallcgi.c;h=9e7c21b4c7e76851991e31624312c3a84da65713;hb=d245c327ec854a63b6c6a6c90bd26c88d1a7ddaf;hp=da5fc9b6093cadb598a02c840c36851a0a3c6937;hpb=2e535ab038ae310e167ca301fe4d4ffd542ced19;p=ashd.git diff --git a/src/callcgi.c b/src/callcgi.c index da5fc9b..9e7c21b 100644 --- a/src/callcgi.c +++ b/src/callcgi.c @@ -52,6 +52,17 @@ static void passdata(FILE *in, FILE *out) free(buf); } +static char *absolutify(char *file) +{ + char cwd[1024]; + + if(*file != '/') { + getcwd(cwd, sizeof(cwd)); + return(sprintf2("%s/%s", cwd, file)); + } + return(sstrdup(file)); +} + static void forkchild(int inpath, char *prog, char *file, char *method, char *url, char *rest, int *infd, int *outfd) { int i; @@ -103,7 +114,7 @@ static void forkchild(int inpath, char *prog, char *file, char *method, char *ur * This is (understandably) missing from the CGI * specification, but PHP seems to require it. */ - putenv(sprintf2("SCRIPT_FILENAME=%s", file)); + putenv(sprintf2("SCRIPT_FILENAME=%s", absolutify(file))); if(inpath) execlp(prog, prog, file, NULL); else @@ -240,19 +251,20 @@ static void sendstatus(char **headers, FILE *out) **hp = 0; } else if(!strcasecmp(hp[0], "location")) { location = hp[1]; + hp += 2; } else { hp += 2; } } if(status) { if(strchr(status, ' ')) - fprintf(out, "HTTP/1.1 %s\r\n", status); + fprintf(out, "HTTP/1.1 %s\n", status); else - fprintf(out, "HTTP/1.1 %i %s\r\n", atoi(status), defstatus(atoi(status))); + fprintf(out, "HTTP/1.1 %i %s\n", atoi(status), defstatus(atoi(status))); } else if(location) { - fprintf(out, "HTTP/1.1 303 See Other\r\n"); + fprintf(out, "HTTP/1.1 303 See Other\n"); } else { - fprintf(out, "HTTP/1.1 200 OK\r\n"); + fprintf(out, "HTTP/1.1 200 OK\n"); } } @@ -260,7 +272,7 @@ static void sendheaders(char **headers, FILE *out) { while(*headers) { if(**headers) - fprintf(out, "%s: %s\r\n", headers[0], headers[1]); + fprintf(out, "%s: %s\n", headers[0], headers[1]); headers += 2; } } @@ -317,7 +329,7 @@ int main(int argc, char **argv, char **envp) } sendstatus(headers, stdout); sendheaders(headers, stdout); - printf("\r\n"); + printf("\n"); passdata(out, stdout); return(0); }