1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
|
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
+----------------------------------------------------------------------+
*/
/* $Id: mod_php3.c,v 1.75 1998/06/02 14:28:42 rasmus Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#include "php.h"
#else
#include "httpd.h"
#include "http_config.h"
#if MODULE_MAGIC_NUMBER > 19980324
#include "compat.h"
#endif
#include "http_core.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_log.h"
#endif
#include "util_script.h"
#include "php_version.h"
#include "mod_php3.h"
module MODULE_VAR_EXPORT php3_module;
#ifndef THREAD_SAFE
int saved_umask;
#else
#define GLOBAL(a) php3_globals->a
#define STATIC GLOBAL
#define TLS_VARS \
php3_globals_struct *php3_globals; \
php3_globals = TlsGetValue(TlsIndex);
#endif
#ifndef TLS_VARS
#define TLS_VARS
#endif
#ifndef GLOBAL
#define GLOBAL(x) x
#endif
extern php3_ini_structure php3_ini; /* active config */
extern php3_ini_structure php3_ini_master; /* master copy of config */
extern int apache_php3_module_main(request_rec * r, int fd, int display_source_mode, int preprocessed);
extern int php3_module_startup();
extern void php3_module_shutdown();
extern void php3_module_shutdown_for_exec();
extern int tls_create(void);
extern int tls_destroy(void);
extern int tls_startup(void);
extern int tls_shutdown(void);
#if WIN32|WINNT
/*
we will want to change this to the apache api
process and thread entry and exit functions
*/
BOOL WINAPI DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch( ul_reason_for_call ) {
case DLL_PROCESS_ATTACH:
/*
I should be loading ini vars here
and doing whatever true global inits
need to be done
*/
if (!tls_startup())
return 0;
if (!tls_create())
return 0;
break;
case DLL_THREAD_ATTACH:
if (!tls_create())
return 0;
/* if (php3_module_startup()==FAILURE) {
return FAILURE;
}
*/ break;
case DLL_THREAD_DETACH:
if (!tls_destroy())
return 0;
/* if (initialized) {
php3_module_shutdown();
return SUCCESS;
} else {
return FAILURE;
}
*/ break;
case DLL_PROCESS_DETACH:
/*
close down anything down in process_attach
*/
if (!tls_destroy())
return 0;
if (!tls_shutdown())
return 0;
break;
}
return 1;
}
#endif
void php3_save_umask()
{
TLS_VARS;
GLOBAL(saved_umask) = umask(077);
umask(GLOBAL(saved_umask));
}
void php3_restore_umask()
{
TLS_VARS;
umask(GLOBAL(saved_umask));
}
int send_php3(request_rec *r, int display_source_mode, int preprocessed)
{
int fd, retval;
php3_ini_structure *conf;
/* We don't aacept OPTIONS requests, but take everything else */
if (r->method_number == M_OPTIONS) {
r->allowed |= (1 << METHODS) - 1;
return DECLINED;
}
/* Make sure file exists */
if (r->finfo.st_mode == 0)
return NOT_FOUND;
/* grab configuration settings */
conf = (php3_ini_structure *) get_module_config(r->per_dir_config, &php3_module);
memcpy(&php3_ini,conf,sizeof(php3_ini_structure)); /* copy to active configuration */
/*
* If PHP parser engine has been turned off with the phpEngine off directive,
* then decline to handle this request
*/
if (!conf->engine) {
r->content_type = "text/html";
r->allowed |= (1 << METHODS) - 1;
return DECLINED;
}
/* Open the file */
/* popenf isnt working on windows, so lets just open it*/
#if WIN32|WINNT
fd = open(r->filename, O_RDONLY,0);
#else
if ((fd = popenf(r->pool, r->filename, O_RDONLY, 0)) == -1) {
log_reason("file permissions deny server access", r->filename, r);
return FORBIDDEN;
}
#endif
/* Apache 1.2 has a more complex mechanism for reading POST data */
#if MODULE_MAGIC_NUMBER > 19961007
if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR)))
return retval;
#endif
if (conf->last_modified) {
#if MODULE_MAGIC_NUMBER < 19970912
if ((retval = set_last_modified(r, r->finfo.st_mtime))) {
return retval;
}
#else
update_mtime (r, r->finfo.st_mtime);
set_last_modified(r);
set_etag(r);
#endif
}
/* Assume output will be HTML. Individual scripts may change this
further down the line */
r->content_type = "text/html";
/* Init timeout */
hard_timeout("send", r);
php3_save_umask();
chdir_file(r->filename);
add_common_vars(r);
add_cgi_vars(r);
apache_php3_module_main(r, fd, display_source_mode, preprocessed);
/* Done, restore umask, turn off timeout, close file and return */
php3_restore_umask();
kill_timeout(r);
#if WIN32|WINNT
close(fd);
#else
pclosef(r->pool, fd);
#endif
return OK;
}
int send_parsed_preprocessed_php3(request_rec * r)
{
return send_php3(r, 0, 1);
}
int send_parsed_php3(request_rec * r)
{
return send_php3(r, 0, 0);
}
int send_parsed_php3_source(request_rec * r)
{
return send_php3(r, 1, 0);
}
/*
* Create the per-directory config structure with defaults from php3_ini_master
*/
static void *php3_create_dir(pool * p, char *dummy)
{
php3_ini_structure *new;
php3_module_startup(); /* php3_ini_master is set up here */
new = (php3_ini_structure *) palloc(p, sizeof(php3_ini_structure));
memcpy(new,&php3_ini_master,sizeof(php3_ini_structure));
return new;
}
/*
* Merge in per-directory .conf directives
*/
static void *php3_merge_dir(pool *p, void *basev, void *addv)
{
php3_ini_structure *new = (php3_ini_structure *) palloc(p, sizeof(php3_ini_structure));
php3_ini_structure *base = (php3_ini_structure *) basev;
php3_ini_structure *add = (php3_ini_structure *) addv;
php3_ini_structure orig = php3_ini_master;
/* Start with the base config */
memcpy(new,base,sizeof(php3_ini_structure));
/* Now, add any fields that have changed in *add compared to the master config */
if (add->smtp != orig.smtp) new->smtp = add->smtp;
if (add->sendmail_path != orig.sendmail_path) new->sendmail_path = add->sendmail_path;
if (add->sendmail_from != orig.sendmail_from) new->sendmail_from = add->sendmail_from;
if (add->errors != orig.errors) new->errors = add->errors;
if (add->magic_quotes_gpc != orig.magic_quotes_gpc) new->magic_quotes_gpc = add->magic_quotes_gpc;
if (add->magic_quotes_runtime != orig.magic_quotes_runtime) new->magic_quotes_runtime = add->magic_quotes_runtime;
if (add->magic_quotes_sybase != orig.magic_quotes_sybase) new->magic_quotes_sybase = add->magic_quotes_sybase;
if (add->track_errors != orig.track_errors) new->track_errors = add->track_errors;
if (add->display_errors != orig.display_errors) new->display_errors = add->display_errors;
if (add->log_errors != orig.log_errors) new->log_errors = add->log_errors;
if (add->doc_root != orig.doc_root) new->doc_root = add->doc_root;
if (add->user_dir != orig.user_dir) new->user_dir = add->user_dir;
if (add->safe_mode != orig.safe_mode) new->safe_mode = add->safe_mode;
if (add->track_vars != orig.track_vars) new->track_vars = add->track_vars;
if (add->safe_mode_exec_dir != orig.safe_mode_exec_dir) new->safe_mode_exec_dir = add->safe_mode_exec_dir;
if (add->cgi_ext != orig.cgi_ext) new->cgi_ext = add->cgi_ext;
if (add->isapi_ext != orig.isapi_ext) new->isapi_ext = add->isapi_ext;
if (add->nsapi_ext != orig.nsapi_ext) new->nsapi_ext = add->nsapi_ext;
if (add->include_path != orig.include_path) new->include_path = add->include_path;
if (add->auto_prepend_file != orig.auto_prepend_file) new->auto_prepend_file = add->auto_prepend_file;
if (add->auto_append_file != orig.auto_append_file) new->auto_append_file = add->auto_append_file;
if (add->upload_tmp_dir != orig.upload_tmp_dir) new->upload_tmp_dir = add->upload_tmp_dir;
if (add->extension_dir != orig.extension_dir) new->extension_dir = add->extension_dir;
if (add->short_open_tag != orig.short_open_tag) new->short_open_tag = add->short_open_tag;
if (add->debugger_host != orig.debugger_host) new->debugger_host = add->debugger_host;
if (add->debugger_port != orig.debugger_port) new->debugger_port = add->debugger_port;
if (add->error_log != orig.error_log) new->error_log = add->error_log;
/* skip the highlight stuff */
if (add->sql_safe_mode != orig.sql_safe_mode) new->sql_safe_mode = add->sql_safe_mode;
if (add->xbithack != orig.xbithack) new->xbithack = add->xbithack;
if (add->engine != orig.engine) new->engine = add->engine;
if (add->last_modified != orig.last_modified) new->last_modified = add->last_modified;
if (add->max_execution_time != orig.max_execution_time) new->max_execution_time = add->max_execution_time;
if (add->memory_limit != orig.memory_limit) new->memory_limit = add->memory_limit;
if (add->browscap != orig.browscap) new->browscap = add->browscap;
if (add->arg_separator != orig.arg_separator) new->arg_separator = add->arg_separator;
if (add->gpc_order != orig.gpc_order) new->gpc_order = add->gpc_order;
return new;
}
#if MODULE_MAGIC_NUMBER > 19961007
const char *php3flaghandler(cmd_parms * cmd, php3_ini_structure * conf, int val)
{
#else
char *php3flaghandler(cmd_parms * cmd, php3_ini_structure * conf, int val)
{
#endif
int c = (int) cmd->info;
switch (c) {
case 0:
conf->track_errors = val;
break;
case 1:
conf->magic_quotes_gpc = val;
break;
case 2:
conf->magic_quotes_runtime = val;
break;
case 3:
conf->short_open_tag = val;
break;
case 4:
conf->safe_mode = val;
break;
case 5:
conf->track_vars = val;
break;
case 6:
conf->sql_safe_mode = val;
break;
case 7:
conf->engine = val;
break;
case 8:
conf->xbithack = val;
break;
case 9:
conf->last_modified = val;
break;
case 10:
conf->log_errors = val;
break;
case 11:
conf->display_errors = val;
break;
case 12:
conf->magic_quotes_sybase = val;
break;
}
return NULL;
}
#if MODULE_MAGIC_NUMBER > 19961007
const char *php3take1handler(cmd_parms * cmd, php3_ini_structure * conf, char *arg)
{
#else
char *php3take1handler(cmd_parms * cmd, php3_ini_structure * conf, char *arg)
{
#endif
int c = (int) cmd->info;
switch (c) {
case 0:
conf->errors = atoi(arg);
break;
case 1:
conf->doc_root = pstrdup(cmd->pool, arg);
break;
case 2:
conf->user_dir = pstrdup(cmd->pool, arg);
break;
case 3:
conf->safe_mode_exec_dir = pstrdup(cmd->pool, arg);
break;
case 4:
conf->include_path = pstrdup(cmd->pool, arg);
break;
case 5:
if (strncasecmp(arg, "none", 4)) {
conf->auto_prepend_file = pstrdup(cmd->pool, arg);
} else {
conf->auto_prepend_file = "";
}
break;
case 6:
if (strncasecmp(arg, "none", 4)) {
conf->auto_append_file = pstrdup(cmd->pool, arg);
} else {
conf->auto_append_file = "";
}
break;
case 7:
conf->upload_tmp_dir = pstrdup(cmd->pool, arg);
break;
case 8:
conf->extension_dir = pstrdup(cmd->pool, arg);
break;
case 9:
conf->error_log = pstrdup(cmd->pool, arg);
break;
case 10:
conf->arg_separator = pstrdup(cmd->pool, arg);
break;
case 11:
conf->max_execution_time = atoi(arg);
break;
case 12:
conf->memory_limit = atoi(arg);
break;
case 13:
conf->sendmail_path = pstrdup(cmd->pool, arg);
break;
case 14:
conf->browscap = pstrdup(cmd->pool, arg);
break;
case 15:
conf->gpc_order = pstrdup(cmd->pool, arg);
break;
}
return NULL;
}
int php3_xbithack_handler(request_rec * r)
{
php3_ini_structure *conf;
conf = (php3_ini_structure *) get_module_config(r->per_dir_config, &php3_module);
if (!(r->finfo.st_mode & S_IXUSR)) {
r->allowed |= (1 << METHODS) - 1;
return DECLINED;
}
if (conf->xbithack == 0) {
r->allowed |= (1 << METHODS) - 1;
return DECLINED;
}
return send_parsed_php3(r);
}
void php3_init_handler(server_rec *s, pool *p)
{
register_cleanup(p, NULL, php3_module_shutdown, php3_module_shutdown_for_exec);
#if MODULE_MAGIC_NUMBER >= 19980527
ap_add_version_component("PHP/" PHP_VERSION);
#endif
}
handler_rec php3_handlers[] =
{
{"application/x-httpd-php3", send_parsed_php3},
{"application/x-httpd-php3-preprocessed", send_parsed_preprocessed_php3},
{"application/x-httpd-php3-source", send_parsed_php3_source},
{"text/html", php3_xbithack_handler},
{NULL}
};
command_rec php3_commands[] =
{
{"php3_error_reporting", php3take1handler, (void *)0, OR_OPTIONS, TAKE1, "error reporting level"},
{"php3_doc_root", php3take1handler, (void *)1, ACCESS_CONF|RSRC_CONF, TAKE1, "directory"}, /* not used yet */
{"php3_user_dir", php3take1handler, (void *)2, ACCESS_CONF|RSRC_CONF, TAKE1, "user directory"}, /* not used yet */
{"php3_safe_mode_exec_dir", php3take1handler, (void *)3, ACCESS_CONF|RSRC_CONF, TAKE1, "safe mode executable dir"},
{"php3_include_path", php3take1handler, (void *)4, OR_OPTIONS, TAKE1, "colon-separated path"},
{"php3_auto_prepend_file", php3take1handler, (void *)5, OR_OPTIONS, TAKE1, "file name"},
{"php3_auto_append_file", php3take1handler, (void *)6, OR_OPTIONS, TAKE1, "file name"},
{"php3_upload_tmp_dir", php3take1handler, (void *)7, ACCESS_CONF|RSRC_CONF, TAKE1, "directory"},
{"php3_extension_dir", php3take1handler, (void *)8, ACCESS_CONF|RSRC_CONF, TAKE1, "directory"},
{"php3_error_log", php3take1handler, (void *)9, OR_OPTIONS, TAKE1, "error log file"},
{"php3_arg_separator", php3take1handler, (void *)10, OR_OPTIONS, TAKE1, "GET method arg separator"},
{"php3_max_execution_time", php3take1handler, (void *)11, OR_OPTIONS, TAKE1, "Max script run time in seconds"},
{"php3_memory_limit", php3take1handler, (void *)12, OR_OPTIONS, TAKE1, "Max memory in bytes a script may use"},
{"php3_sendmail_path", php3take1handler, (void *)13, OR_OPTIONS, TAKE1, "Full path to sendmail binary"},
{"php3_browscap", php3take1handler, (void *)14, OR_OPTIONS, TAKE1, "Full path to browscap file"},
{"php3_gpc_order", php3take1handler, (void *)15, OR_OPTIONS, TAKE1, "Set GET-COOKIE-POST order [default is GPC]"},
{"php3_track_errors", php3flaghandler, (void *)0, OR_OPTIONS, FLAG, "on|off"},
{"php3_magic_quotes_gpc", php3flaghandler, (void *)1, OR_OPTIONS, FLAG, "on|off"},
{"php3_magic_quotes_runtime", php3flaghandler, (void *)2, OR_OPTIONS, FLAG, "on|off"},
{"php3_short_open_tag", php3flaghandler, (void *)3, OR_OPTIONS, FLAG, "on|off"},
{"php3_safe_mode", php3flaghandler, (void *)4, ACCESS_CONF|RSRC_CONF, FLAG, "on|off"},
{"php3_track_vars", php3flaghandler, (void *)5, OR_OPTIONS, FLAG, "on|off"},
{"php3_sql_safe_mode", php3flaghandler, (void *)6, ACCESS_CONF|RSRC_CONF, FLAG, "on|off"},
{"php3_engine", php3flaghandler, (void *)7, RSRC_CONF|ACCESS_CONF, FLAG, "on|off"},
{"php3_xbithack", php3flaghandler, (void *)8, OR_OPTIONS, FLAG, "on|off"},
{"php3_last_modified", php3flaghandler, (void *)9, OR_OPTIONS, FLAG, "on|off"},
{"php3_log_errors", php3flaghandler, (void *)10, OR_OPTIONS, FLAG, "on|off"},
{"php3_display_errors", php3flaghandler, (void *)11, OR_OPTIONS, FLAG, "on|off"},
{"php3_magic_quotes_sybase", php3flaghandler, (void *)12, OR_OPTIONS, FLAG, "on|off"},
{NULL}
};
module MODULE_VAR_EXPORT php3_module =
{
STANDARD_MODULE_STUFF,
php3_init_handler, /* initializer */
php3_create_dir, /* per-directory config creator */
php3_merge_dir, /* dir merger */
NULL, /* per-server config creator */
NULL, /* merge server config */
php3_commands, /* command table */
php3_handlers, /* handlers */
NULL, /* filename translation */
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
NULL, /* type_checker */
NULL, /* fixups */
NULL /* logger */
#if MODULE_MAGIC_NUMBER >= 19970103
,NULL /* header parser */
#endif
#if MODULE_MAGIC_NUMBER >= 19970719
,NULL /* child_init */
#endif
#if MODULE_MAGIC_NUMBER >= 19970728
,NULL /* child_exit */
#endif
#if MODULE_MAGIC_NUMBER >= 19970902
,NULL /* post read-request */
#endif
};
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/
|