|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | PHP Version 4 | |
| 4 | + +----------------------------------------------------------------------+ |
| 5 | + | Copyright (c) 1997-2003 The PHP Group | |
| 6 | + +----------------------------------------------------------------------+ |
| 7 | + | This source file is subject to version 2.02 of the PHP license, | |
| 8 | + | that is bundled with this package in the file LICENSE, and is | |
| 9 | + | available at through the world-wide-web at | |
| 10 | + | http://www.php.net/license/2_02.txt. | |
| 11 | + | If you did not receive a copy of the PHP license and are unable to | |
| 12 | + | obtain it through the world-wide-web, please send a note to | |
| 13 | + | license@php.net so we can mail you a copy immediately. | |
| 14 | + +----------------------------------------------------------------------+ |
| 15 | + | Author: Sascha Schumann <sascha@schumann.cx> | |
| 16 | + +----------------------------------------------------------------------+ |
| 17 | + */ |
| 18 | + |
| 19 | +/* $Id$ */ |
| 20 | + |
| 21 | +#include "php.h" |
| 22 | +#include "php_ini.h" |
| 23 | +#include "php_apache.h" |
| 24 | + |
| 25 | +#include "apr_strings.h" |
| 26 | +#include "ap_config.h" |
| 27 | +#include "util_filter.h" |
| 28 | +#include "httpd.h" |
| 29 | +#include "http_config.h" |
| 30 | +#include "http_request.h" |
| 31 | +#include "http_core.h" |
| 32 | +#include "http_protocol.h" |
| 33 | +#include "http_log.h" |
| 34 | +#include "http_main.h" |
| 35 | +#include "util_script.h" |
| 36 | +#include "http_core.h" |
| 37 | + |
| 38 | +#ifdef PHP_AP_DEBUG |
| 39 | +#define phpapdebug(a) fprintf a |
| 40 | +#else |
| 41 | +#define phpapdebug(a) |
| 42 | +#endif |
| 43 | + |
| 44 | +typedef struct { |
| 45 | + HashTable config; |
| 46 | +} php_conf_rec; |
| 47 | + |
| 48 | +typedef struct { |
| 49 | + char *value; |
| 50 | + size_t value_len; |
| 51 | + char status; |
| 52 | +} php_dir_entry; |
| 53 | + |
| 54 | +static const char *real_value_hnd(cmd_parms *cmd, void *dummy, |
| 55 | + const char *name, const char *value, int status) |
| 56 | +{ |
| 57 | + php_conf_rec *d = dummy; |
| 58 | + php_dir_entry e; |
| 59 | + |
| 60 | + phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, |
| 61 | + zend_hash_num_elements(&d->config))); |
| 62 | + |
| 63 | + if (!strncasecmp(value, "none", sizeof("none"))) { |
| 64 | + value = ""; |
| 65 | + } |
| 66 | + |
| 67 | + e.value = apr_pstrdup(cmd->pool, value); |
| 68 | + e.value_len = strlen(value); |
| 69 | + e.status = status; |
| 70 | + |
| 71 | + zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, |
| 72 | + sizeof(e), NULL); |
| 73 | + return NULL; |
| 74 | +} |
| 75 | + |
| 76 | +static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, |
| 77 | + const char *name, const char *value) |
| 78 | +{ |
| 79 | + return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR); |
| 80 | +} |
| 81 | + |
| 82 | +static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, |
| 83 | + const char *name, const char *value) |
| 84 | +{ |
| 85 | + return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); |
| 86 | +} |
| 87 | + |
| 88 | +static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, |
| 89 | + const char *arg2, int status) |
| 90 | +{ |
| 91 | + char bool_val[2]; |
| 92 | + |
| 93 | + if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) { |
| 94 | + bool_val[0] = '1'; |
| 95 | + } else { |
| 96 | + bool_val[0] = '0'; |
| 97 | + } |
| 98 | + bool_val[1] = 0; |
| 99 | + |
| 100 | + return real_value_hnd(cmd, dummy, arg1, bool_val, status); |
| 101 | +} |
| 102 | + |
| 103 | +static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, |
| 104 | + const char *name, const char *value) |
| 105 | +{ |
| 106 | + return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR); |
| 107 | +} |
| 108 | + |
| 109 | +static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, |
| 110 | + const char *name, const char *value) |
| 111 | +{ |
| 112 | + return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); |
| 113 | +} |
| 114 | + |
| 115 | +static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, |
| 116 | + const char *arg) |
| 117 | +{ |
| 118 | + if (apache2_php_ini_path_override) { |
| 119 | + return "Only first PHPINIDir directive honored per configuration tree " |
| 120 | + "- subsequent ones ignored"; |
| 121 | + } |
| 122 | + apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg); |
| 123 | + return NULL; |
| 124 | +} |
| 125 | + |
| 126 | + |
| 127 | +void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) |
| 128 | +{ |
| 129 | + php_conf_rec *d = base_conf, *e = new_conf; |
| 130 | + php_dir_entry *pe; |
| 131 | + php_dir_entry *data; |
| 132 | + char *str; |
| 133 | + uint str_len; |
| 134 | + ulong num_index; |
| 135 | + |
| 136 | + phpapdebug((stderr, "Merge dir (%p) (%p)\n", base_conf, new_conf)); |
| 137 | + for (zend_hash_internal_pointer_reset(&d->config); |
| 138 | + zend_hash_get_current_key_ex(&d->config, &str, &str_len, |
| 139 | + &num_index, 0, NULL) == HASH_KEY_IS_STRING; |
| 140 | + zend_hash_move_forward(&d->config)) { |
| 141 | + pe = NULL; |
| 142 | + zend_hash_get_current_data(&d->config, (void **) &data); |
| 143 | + if (zend_hash_find(&e->config, str, str_len, (void **) &pe) == SUCCESS) { |
| 144 | + if (pe->status >= data->status) continue; |
| 145 | + } |
| 146 | + zend_hash_update(&e->config, str, str_len, data, sizeof(*data), NULL); |
| 147 | + phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, |
| 148 | + data->status, pe?pe->status:-1)); |
| 149 | + } |
| 150 | + return new_conf; |
| 151 | +} |
| 152 | + |
| 153 | +char *get_php_config(void *conf, char *name, size_t name_len) |
| 154 | +{ |
| 155 | + php_conf_rec *d = conf; |
| 156 | + php_dir_entry *pe; |
| 157 | + |
| 158 | + if (zend_hash_find(&d->config, name, name_len, (void **) &pe) == SUCCESS) { |
| 159 | + return pe->value; |
| 160 | + } |
| 161 | + |
| 162 | + return ""; |
| 163 | +} |
| 164 | + |
| 165 | +void apply_config(void *dummy) |
| 166 | +{ |
| 167 | + php_conf_rec *d = dummy; |
| 168 | + char *str; |
| 169 | + uint str_len; |
| 170 | + php_dir_entry *data; |
| 171 | + |
| 172 | + for (zend_hash_internal_pointer_reset(&d->config); |
| 173 | + zend_hash_get_current_key_ex(&d->config, &str, &str_len, NULL, 0, |
| 174 | + NULL) == HASH_KEY_IS_STRING; |
| 175 | + zend_hash_move_forward(&d->config)) { |
| 176 | + zend_hash_get_current_data(&d->config, (void **) &data); |
| 177 | + phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); |
| 178 | + if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, |
| 179 | + data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) { |
| 180 | + phpapdebug((stderr, "..FAILED\n")); |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +const command_rec php_dir_cmds[] = |
| 186 | +{ |
| 187 | + AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, |
| 188 | + "PHP Value Modifier"), |
| 189 | + AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, |
| 190 | + "PHP Flag Modifier"), |
| 191 | + AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, |
| 192 | + ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"), |
| 193 | + AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, |
| 194 | + ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"), |
| 195 | + AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, |
| 196 | + "Directory containing the php.ini file"), |
| 197 | + {NULL} |
| 198 | +}; |
| 199 | + |
| 200 | +static apr_status_t destroy_php_config(void *data) |
| 201 | +{ |
| 202 | + php_conf_rec *d = data; |
| 203 | + |
| 204 | + phpapdebug((stderr, "Destroying config %p\n", data)); |
| 205 | + zend_hash_destroy(&d->config); |
| 206 | + |
| 207 | + return APR_SUCCESS; |
| 208 | +} |
| 209 | + |
| 210 | +void *create_php_config(apr_pool_t *p, char *dummy) |
| 211 | +{ |
| 212 | + php_conf_rec *newx = |
| 213 | + (php_conf_rec *) apr_pcalloc(p, sizeof(*newx)); |
| 214 | + |
| 215 | + phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy)); |
| 216 | + zend_hash_init(&newx->config, 0, NULL, NULL, 1); |
| 217 | + apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null); |
| 218 | + return (void *) newx; |
| 219 | +} |
| 220 | + |
| 221 | +/* |
| 222 | + * Local variables: |
| 223 | + * tab-width: 4 |
| 224 | + * c-basic-offset: 4 |
| 225 | + * End: |
| 226 | + * vim600: sw=4 ts=4 fdm=marker |
| 227 | + * vim<600: sw=4 ts=4 |
| 228 | + */ |
0 commit comments