View | Details | Raw Unified | Return to bug 136651
Collapse All | Expand All

(-)sapi/apache2handler/sapi_apache2.c (-26 / +52 lines)
Lines 18-24 Link Here
18
   +----------------------------------------------------------------------+
18
   +----------------------------------------------------------------------+
19
 */
19
 */
20
20
21
/* $Id: sapi_apache2.c,v 1.1.2.40 2005/04/08 20:35:02 sniper Exp $ */
21
/* $Id: sapi_apache2.c,v 1.1.2.40.2.9 2005/12/14 03:38:55 iliaa Exp $ */
22
22
23
#include <fcntl.h>
23
#include <fcntl.h>
24
24
Lines 443-448 Link Here
443
	php_request_shutdown(NULL);
443
	php_request_shutdown(NULL);
444
}
444
}
445
445
446
static void php_apache_ini_dtor(request_rec *r, request_rec *p TSRMLS_DC)
447
{
448
	if (strcmp(r->protocol, "INCLUDED")) {
449
		zend_try { zend_ini_deactivate(TSRMLS_C); } zend_end_try();
450
	}
451
	if (p) {
452
		((php_struct *)SG(server_context))->r = p;
453
	} else {
454
		apr_pool_cleanup_run(r->pool, (void *)&SG(server_context), php_server_context_cleanup);
455
	}
456
}
457
446
static int php_handler(request_rec *r)
458
static int php_handler(request_rec *r)
447
{
459
{
448
	php_struct *ctx;
460
	php_struct *ctx;
Lines 453-467 Link Here
453
	request_rec *parent_req = NULL;
465
	request_rec *parent_req = NULL;
454
	TSRMLS_FETCH();
466
	TSRMLS_FETCH();
455
467
468
#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);
469
456
	conf = ap_get_module_config(r->per_dir_config, &php4_module);
470
	conf = ap_get_module_config(r->per_dir_config, &php4_module);
471
472
	/* apply_config() needs r in some cases, so allocate server_context early */
473
	ctx = SG(server_context);
474
	if (ctx == NULL || (ctx && ctx->request_processed && !strcmp(r->protocol, "INCLUDED"))) {
475
		ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));
476
		/* register a cleanup so we clear out the SG(server_context)
477
		 * after each request. Note: We pass in the pointer to the
478
		 * server_context in case this is handled by a different thread.
479
		 */
480
		apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null);
481
		ctx->r = r;
482
		ctx = NULL; /* May look weird to null it here, but it is to catch the right case in the first_try later on */
483
	} else {
484
		parent_req = ctx->r;
485
		ctx->r = r;
486
	}
457
	apply_config(conf);
487
	apply_config(conf);
458
488
459
	if (strcmp(r->handler, PHP_MAGIC_TYPE) && strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(r->handler, PHP_SCRIPT)) {
489
	if (strcmp(r->handler, PHP_MAGIC_TYPE) && strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(r->handler, PHP_SCRIPT)) {
460
		/* Check for xbithack in this case. */
490
		/* Check for xbithack in this case. */
461
		if (!AP2(xbithack) || strcmp(r->handler, "text/html") || !(r->finfo.protection & APR_UEXECUTE)) {
491
		if (!AP2(xbithack) || strcmp(r->handler, "text/html") || !(r->finfo.protection & APR_UEXECUTE)) {
462
			zend_try {
492
			PHPAP_INI_OFF;
463
				zend_ini_deactivate(TSRMLS_C);
464
			} zend_end_try();
465
			return DECLINED;
493
			return DECLINED;
466
		}
494
		}
467
	}
495
	}
Lines 470-501 Link Here
470
	 * the configuration; default behaviour is to accept. */ 
498
	 * the configuration; default behaviour is to accept. */ 
471
	if (r->used_path_info == AP_REQ_REJECT_PATH_INFO
499
	if (r->used_path_info == AP_REQ_REJECT_PATH_INFO
472
		&& r->path_info && r->path_info[0]) {
500
		&& r->path_info && r->path_info[0]) {
473
		zend_try {
501
		PHPAP_INI_OFF;
474
			zend_ini_deactivate(TSRMLS_C);
475
		} zend_end_try();
476
		return HTTP_NOT_FOUND;
502
		return HTTP_NOT_FOUND;
477
	}
503
	}
478
504
479
	/* handle situations where user turns the engine off */
505
	/* handle situations where user turns the engine off */
480
	if (!AP2(engine)) {
506
	if (!AP2(engine)) {
481
		zend_try {
507
		PHPAP_INI_OFF;
482
			zend_ini_deactivate(TSRMLS_C);
483
		} zend_end_try();
484
		return DECLINED;
508
		return DECLINED;
485
	}
509
	}
486
510
487
	if (r->finfo.filetype == 0) {
511
	if (r->finfo.filetype == 0) {
488
		php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r);
512
		php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r);
489
		zend_try {
513
		PHPAP_INI_OFF;
490
				zend_ini_deactivate(TSRMLS_C);
491
		} zend_end_try();
492
		return HTTP_NOT_FOUND;
514
		return HTTP_NOT_FOUND;
493
	}
515
	}
494
	if (r->finfo.filetype == APR_DIR) {
516
	if (r->finfo.filetype == APR_DIR) {
495
		php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r);
517
		php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r);
496
		zend_try {
518
		PHPAP_INI_OFF;
497
			zend_ini_deactivate(TSRMLS_C);
498
		} zend_end_try();
499
		return HTTP_FORBIDDEN;
519
		return HTTP_FORBIDDEN;
500
	}
520
	}
501
521
Lines 511-534 Link Here
511
531
512
zend_first_try {
532
zend_first_try {
513
533
514
	ctx = SG(server_context);
515
	if (ctx == NULL) {
534
	if (ctx == NULL) {
516
		ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));
535
normal:
517
		/* register a cleanup so we clear out the SG(server_context)
518
		 * after each request. Note: We pass in the pointer to the
519
		 * server_context in case this is handled by a different thread.
520
		 */
521
		apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null);
522
523
		ctx->r = r;
524
		brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
536
		brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
537
		ctx = SG(server_context);
525
		ctx->brigade = brigade;
538
		ctx->brigade = brigade;
526
539
527
		if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
540
		if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
528
			zend_bailout();
541
			zend_bailout();
529
		}
542
		}
530
	} else {
543
	} else {
531
		parent_req = ctx->r;
544
		if (!parent_req) {
545
			parent_req = ctx->r;
546
		}
547
		if (parent_req && parent_req->handler && strcmp(parent_req->handler, PHP_MAGIC_TYPE) && strcmp(parent_req->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(parent_req->handler, PHP_SCRIPT)) {
548
			if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
549
				zend_bailout();
550
			}
551
		}
552
		
553
		/* check if comming due to ErrorDocument */
554
		if (parent_req && parent_req->status != HTTP_OK) {
555
			parent_req = NULL;
556
			goto normal;
557
		}
532
		ctx->r = r;
558
		ctx->r = r;
533
		brigade = ctx->brigade;
559
		brigade = ctx->brigade;
534
	}
560
	}

Return to bug 136651