php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
apache_config.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Sascha Schumann <sascha@schumann.cx> |
14 +----------------------------------------------------------------------+
15 */
16
17#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
18
19#include "php.h"
20#ifdef strcasecmp
21# undef strcasecmp
22#endif
23#ifdef strncasecmp
24# undef strncasecmp
25#endif
26#include "php_ini.h"
27#include "php_apache.h"
28
29#include "apr_strings.h"
30#include "ap_config.h"
31#include "util_filter.h"
32#include "httpd.h"
33#include "http_config.h"
34#include "http_request.h"
35#include "http_core.h"
36#include "http_protocol.h"
37#include "http_log.h"
38#include "http_main.h"
39#include "util_script.h"
40#include "http_core.h"
41
42#ifdef PHP_AP_DEBUG
43#define phpapdebug(a) fprintf a
44#else
45#define phpapdebug(a)
46#endif
47
48typedef struct {
51
52typedef struct {
53 char *value;
54 size_t value_len;
55 char status;
58
59static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status)
60{
61 php_conf_rec *d = dummy;
63
64 phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config)));
65
66 if (!strncasecmp(value, "none", sizeof("none"))) {
67 value = "";
68 }
69
70 e.value = apr_pstrdup(cmd->pool, value);
72 e.status = status;
73 e.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0);
74
75 zend_hash_str_update_mem(&d->config, (char *) name, strlen(name), &e, sizeof(e));
76 return NULL;
77}
78
79static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
80{
81 return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
82}
83
84static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
85{
86 return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
87}
88
89static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, 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
103static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
104{
105 return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
106}
107
108static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
109{
110 return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
111}
112
113static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg)
114{
116 return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored";
117 }
118 apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
119 return NULL;
120}
121
122static bool should_overwrite_per_dir_entry(HashTable *target_ht, zval *zv, zend_hash_key *hash_key, void *pData)
123{
124 php_dir_entry *new_per_dir_entry = Z_PTR_P(zv);
125 php_dir_entry *orig_per_dir_entry;
126
127 if ((orig_per_dir_entry = zend_hash_find_ptr(target_ht, hash_key->key)) == NULL) {
128 return 1; /* does not exist in dest, copy from source */
129 }
130
131 if (new_per_dir_entry->status >= orig_per_dir_entry->status) {
132 /* use new entry */
133 phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", ZSTR_VAL(hash_key->key), new_per_dir_entry->status, orig_per_dir_entry->status));
134 return 1;
135 } else {
136 return 0;
137 }
138}
139
141{
143 php_dir_entry *npe = malloc(sizeof(php_dir_entry));
144
145 memcpy(npe, pe, sizeof(php_dir_entry));
146 ZVAL_PTR(zv, npe);
147}
148
149void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
150{
151 php_conf_rec *d = base_conf, *e = new_conf, *n = NULL;
152#ifdef ZTS
153 zend_string *str;
154 zval *data;
155#endif
156
157 n = create_php_config(p, "merge_php_config");
158 /* copy old config */
159#ifdef ZTS
162 zval *new_entry;
163
164 /* Avoid sharing the non interned string among threads. */
165 key = zend_string_dup(str, 1);
166
167 new_entry = zend_hash_add(&n->config, key, data);
168
169 config_entry_ctor(new_entry);
171#else
173#endif
174 /* merge new config */
175 phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n));
176 zend_hash_merge_ex(&n->config, &e->config, config_entry_ctor, should_overwrite_per_dir_entry, NULL);
177 return n;
178}
179
180char *get_php_config(void *conf, char *name, size_t name_len)
181{
182 php_conf_rec *d = conf;
183 php_dir_entry *pe;
184
185 if ((pe = zend_hash_str_find_ptr(&d->config, name, name_len)) != NULL) {
186 return pe->value;
187 }
188
189 return "";
190}
191
192void apply_config(void *dummy)
193{
194 php_conf_rec *d = dummy;
195 zend_string *str;
197
199 phpapdebug((stderr, "APPLYING (%s)(%s)\n", ZSTR_VAL(str), data->value));
200 if (zend_alter_ini_entry_chars(str, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) {
201 phpapdebug((stderr, "..FAILED\n"));
202 }
204}
205
206const command_rec php_dir_cmds[] =
207{
208 AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"),
209 AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, "PHP Flag Modifier"),
210 AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
211 AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
212 AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php.ini file"),
213 {NULL}
214};
215
216static apr_status_t destroy_php_config(void *data)
217{
218 php_conf_rec *d = data;
219
220 phpapdebug((stderr, "Destroying config %p\n", data));
222
223 return APR_SUCCESS;
224}
225
226static void config_entry_dtor(zval *zv)
227{
228 free((php_dir_entry*)Z_PTR_P(zv));
229}
230
231void *create_php_config(apr_pool_t *p, char *dummy)
232{
233 php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
234
235 phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
236 zend_hash_init(&newx->config, 0, NULL, config_entry_dtor, 1);
237 apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null);
238 return (void *) newx;
239}
void config_entry_ctor(zval *zv)
char * get_php_config(void *conf, char *name, size_t name_len)
const command_rec php_dir_cmds[]
void * merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
void apply_config(void *dummy)
void * create_php_config(apr_pool_t *p, char *dummy)
#define phpapdebug(a)
DNS_STATUS status
Definition dns_win32.c:49
zval * zv
Definition ffi.c:3975
zend_long n
Definition ffi.c:4979
memcpy(ptr1, ptr2, size)
zval * arg
Definition ffi.c:3975
#define NULL
Definition gdcache.h:45
char * apache2_php_ini_path_override
#define PHP_INI_STAGE_ACTIVATE
Definition php_ini.h:73
#define PHP_INI_PERDIR
Definition php_ini.h:42
#define PHP_INI_SYSTEM
Definition php_ini.h:43
#define PHP_INI_STAGE_HTACCESS
Definition php_ini.h:76
unsigned char key[REFLECTION_KEY_LEN]
zend_constant * data
p
Definition session.c:1105
zend_string * key
Definition zend_hash.h:96
HashTable config
size_t value_len
char status
char * value
char htaccess
struct _zval_struct zval
strlen(string $string)
#define strncasecmp(s1, s2, n)
#define strcasecmp(s1, s2)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor)
Definition zend_hash.c:2240
ZEND_API void ZEND_FASTCALL zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam)
Definition zend_hash.c:2643
ZEND_API zval *ZEND_FASTCALL zend_hash_add(HashTable *ht, zend_string *key, zval *pData)
Definition zend_hash.c:992
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
Definition zend_hash.h:108
struct _zend_hash_key zend_hash_key
#define ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(ht, _key, _ptr)
Definition zend_hash.h:1433
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, _key, _val)
Definition zend_hash.h:1374
ZEND_API zend_result zend_alter_ini_entry_chars(zend_string *name, const char *value, size_t value_length, int modify_type, int stage)
Definition zend_ini.c:332
struct _zend_string zend_string
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
struct _zend_array HashTable
Definition zend_types.h:386
#define Z_PTR_P(zval_p)
@ FAILURE
Definition zend_types.h:61
#define ZVAL_PTR(z, p)
zval * arg1
zval * arg2
zend_string * name
value