71 |
*/ |
*/ |
72 |
|
|
73 |
|
|
74 |
/* NCSA added */ |
/* NCSA added */ |
75 |
/* common_cgi_env[index++] = env_gen_extra("SERVER_ROOT", server_root); */ |
#ifdef USE_NCSA_CGI_ENV |
76 |
|
common_cgi_env[index++] = env_gen_extra("SERVER_ROOT", server_root); |
77 |
|
#endif |
78 |
|
|
79 |
/* APACHE added */ |
/* APACHE added */ |
80 |
common_cgi_env[index++] = |
common_cgi_env[index++] = |
233 |
my_add_cgi_env(req, "SERVER_NAME", req->hostname); |
my_add_cgi_env(req, "SERVER_NAME", req->hostname); |
234 |
|
|
235 |
/* NCSA and APACHE added -- not in CGI spec */ |
/* NCSA and APACHE added -- not in CGI spec */ |
236 |
/* my_add_cgi_env( req, "DOCUMENT_ROOT", req->document_root); */ |
#ifdef USE_NCSA_CGI_ENV |
237 |
|
my_add_cgi_env( req, "DOCUMENT_ROOT", req->document_root); |
238 |
|
#endif |
239 |
|
|
240 |
my_add_cgi_env(req, "SERVER_ADDR", req->local_ip_addr); |
my_add_cgi_env(req, "SERVER_ADDR", req->local_ip_addr); |
241 |
my_add_cgi_env(req, "SERVER_PROTOCOL", req->http_version); |
my_add_cgi_env(req, "SERVER_PROTOCOL", req->http_version); |
467 |
case 0: |
case 0: |
468 |
/* child */ |
/* child */ |
469 |
if (req->is_cgi == CGI || req->is_cgi == NPH) { |
if (req->is_cgi == CGI || req->is_cgi == NPH) { |
470 |
char *foo = strdup(req->pathname); |
int l; |
471 |
|
char *newpath; |
472 |
char *c; |
char *c; |
473 |
|
|
474 |
if (!foo) { |
c = strrchr(req->pathname, '/'); |
475 |
WARN("unable to strdup pathname for req->pathname"); |
if (!c) { |
476 |
|
/* there will always be a '.' */ |
477 |
|
log_error_time(); |
478 |
|
WARN("unable to find '/' in req->pathname"); |
479 |
|
close(pipes[1]); |
480 |
_exit(1); |
_exit(1); |
481 |
} |
} |
482 |
c = strrchr(foo, '/'); |
|
483 |
if (c) { |
*c = '\0'; |
484 |
++c; |
|
485 |
*c = '\0'; |
if (chdir(req->pathname) != 0) { |
|
} else { |
|
|
/* we have a serious problem */ |
|
486 |
log_error_time(); |
log_error_time(); |
487 |
perror("chdir"); |
perror("chdir"); |
488 |
close(pipes[1]); |
close(pipes[1]); |
489 |
_exit(1); |
_exit(1); |
490 |
} |
} |
491 |
if (chdir(foo) != 0) { |
|
492 |
|
req->pathname = ++c; |
493 |
|
l = strlen(req->pathname) + 3; |
494 |
|
/* prefix './' */ |
495 |
|
newpath = malloc(sizeof(char) * l); |
496 |
|
if (!newpath) { |
497 |
|
/* there will always be a '.' */ |
498 |
log_error_time(); |
log_error_time(); |
499 |
perror("chdir"); |
perror("unable to malloc for newpath"); |
500 |
close(pipes[1]); |
close(pipes[1]); |
501 |
_exit(1); |
_exit(1); |
502 |
} |
} |
503 |
|
newpath[0] = '.'; |
504 |
|
newpath[1] = '/'; |
505 |
|
memcpy(&newpath[2], req->pathname, l - 2); /* includes the trailing '\0' */ |
506 |
|
req->pathname = newpath; |
507 |
} |
} |
508 |
close(pipes[0]); |
|
509 |
/* tie cgi's STDOUT to it's write end of pipe */ |
/* close the 'read' end of the pipes[] */ |
510 |
if (dup2(pipes[1], STDOUT_FILENO) == -1) { |
close(pipes[0]); |
511 |
log_error_time(); |
|
512 |
perror("dup2 - pipes"); |
/* tie cgi's STDOUT to our write end of pipe */ |
513 |
close(pipes[1]); |
if (dup2(pipes[1], STDOUT_FILENO) == -1) { |
514 |
_exit(1); |
log_error_time(); |
515 |
} |
perror("dup2 - pipes"); |
516 |
close(pipes[1]); |
_exit(1); |
517 |
if (set_block_fd(STDOUT_FILENO) == -1) { |
} |
518 |
log_error_time(); |
close(pipes[1]); |
519 |
perror("cgi-fcntl"); |
|
|
_exit(1); |
|
|
} |
|
|
|
|
520 |
/* tie post_data_fd to POST stdin */ |
/* tie post_data_fd to POST stdin */ |
521 |
if (req->method == M_POST) { /* tie stdin to file */ |
if (req->method == M_POST) { /* tie stdin to file */ |
522 |
lseek(req->post_data_fd, SEEK_SET, 0); |
lseek(req->post_data_fd, SEEK_SET, 0); |
523 |
dup2(req->post_data_fd, STDIN_FILENO); |
dup2(req->post_data_fd, STDIN_FILENO); |
524 |
close(req->post_data_fd); |
close(req->post_data_fd); |
525 |
} |
} |
526 |
/* Close access log, so CGI program can't scribble |
|
527 |
* where it shouldn't |
umask(cgi_umask); /* change umask *again* u=rwx,g=rxw,o= */ |
|
*/ |
|
|
close_access_log(); |
|
528 |
|
|
529 |
/* |
/* |
530 |
* tie STDERR to cgi_log_fd |
* tie STDERR to cgi_log_fd |
532 |
* if we don't tied STDERR (current log_error) to cgi_log_fd, |
* if we don't tied STDERR (current log_error) to cgi_log_fd, |
533 |
* then we ought to close it. |
* then we ought to close it. |
534 |
*/ |
*/ |
535 |
if (!cgi_log_fd) |
if (cgi_log_fd) { |
536 |
dup2(devnullfd, STDERR_FILENO); |
dup2(cgi_log_fd, STDERR_FILENO); |
537 |
else |
close( cgi_log_fd); |
538 |
dup2(cgi_log_fd, STDERR_FILENO); |
} |
539 |
|
|
540 |
if (req->is_cgi == NPH || req->is_cgi == CGI) { |
if (req->is_cgi == NPH || req->is_cgi == CGI) { |
541 |
char *aargv[CGI_ARGC_MAX + 1]; |
char *aargv[CGI_ARGC_MAX + 1]; |