-
Notifications
You must be signed in to change notification settings - Fork 7.7k
/
main.c
2656 lines (2326 loc) · 78.3 KB
/
main.c
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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@php.net> |
| Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Zeev Suraski <zeev@php.net> |
+----------------------------------------------------------------------+
*/
/* {{{ includes */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
#include "php.h"
#include <stdio.h>
#include <fcntl.h>
#ifdef PHP_WIN32
#include "win32/time.h"
#include "win32/signal.h"
#include "win32/php_win32_globals.h"
#include "win32/winutil.h"
#include <process.h>
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <signal.h>
#include <locale.h>
#include "zend.h"
#include "zend_types.h"
#include "zend_extensions.h"
#include "php_ini.h"
#include "php_globals.h"
#include "php_main.h"
#include "php_syslog.h"
#include "fopen_wrappers.h"
#include "ext/standard/php_standard.h"
#include "ext/standard/php_string.h"
#include "ext/date/php_date.h"
#include "php_variables.h"
#include "ext/standard/credits.h"
#ifdef PHP_WIN32
#include <io.h>
#include "win32/php_registry.h"
#include "ext/standard/flock_compat.h"
#endif
#include "php_syslog.h"
#include "Zend/zend_exceptions.h"
#if PHP_SIGCHILD
#include <sys/types.h>
#include <sys/wait.h>
#endif
#include "zend_compile.h"
#include "zend_execute.h"
#include "zend_highlight.h"
#include "zend_extensions.h"
#include "zend_ini.h"
#include "zend_dtrace.h"
#include "zend_observer.h"
#include "zend_system_id.h"
#include "php_content_types.h"
#include "php_ticks.h"
#include "php_streams.h"
#include "php_open_temporary_file.h"
#include "SAPI.h"
#include "rfc1867.h"
#include "ext/standard/html_tables.h"
/* }}} */
PHPAPI int (*php_register_internal_extensions_func)(void) = php_register_internal_extensions;
#ifndef ZTS
php_core_globals core_globals;
#else
PHPAPI int core_globals_id;
PHPAPI size_t core_globals_offset;
#endif
#define SAFE_FILENAME(f) ((f)?(f):"-")
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetFacility)
{
const char *facility = ZSTR_VAL(new_value);
#ifdef LOG_AUTH
if (!strcmp(facility, "LOG_AUTH") || !strcmp(facility, "auth") || !strcmp(facility, "security")) {
PG(syslog_facility) = LOG_AUTH;
return SUCCESS;
}
#endif
#ifdef LOG_AUTHPRIV
if (!strcmp(facility, "LOG_AUTHPRIV") || !strcmp(facility, "authpriv")) {
PG(syslog_facility) = LOG_AUTHPRIV;
return SUCCESS;
}
#endif
#ifdef LOG_CRON
if (!strcmp(facility, "LOG_CRON") || !strcmp(facility, "cron")) {
PG(syslog_facility) = LOG_CRON;
return SUCCESS;
}
#endif
#ifdef LOG_DAEMON
if (!strcmp(facility, "LOG_DAEMON") || !strcmp(facility, "daemon")) {
PG(syslog_facility) = LOG_DAEMON;
return SUCCESS;
}
#endif
#ifdef LOG_FTP
if (!strcmp(facility, "LOG_FTP") || !strcmp(facility, "ftp")) {
PG(syslog_facility) = LOG_FTP;
return SUCCESS;
}
#endif
#ifdef LOG_KERN
if (!strcmp(facility, "LOG_KERN") || !strcmp(facility, "kern")) {
PG(syslog_facility) = LOG_KERN;
return SUCCESS;
}
#endif
#ifdef LOG_LPR
if (!strcmp(facility, "LOG_LPR") || !strcmp(facility, "lpr")) {
PG(syslog_facility) = LOG_LPR;
return SUCCESS;
}
#endif
#ifdef LOG_MAIL
if (!strcmp(facility, "LOG_MAIL") || !strcmp(facility, "mail")) {
PG(syslog_facility) = LOG_MAIL;
return SUCCESS;
}
#endif
#ifdef LOG_INTERNAL_MARK
if (!strcmp(facility, "LOG_INTERNAL_MARK") || !strcmp(facility, "mark")) {
PG(syslog_facility) = LOG_INTERNAL_MARK;
return SUCCESS;
}
#endif
#ifdef LOG_NEWS
if (!strcmp(facility, "LOG_NEWS") || !strcmp(facility, "news")) {
PG(syslog_facility) = LOG_NEWS;
return SUCCESS;
}
#endif
#ifdef LOG_SYSLOG
if (!strcmp(facility, "LOG_SYSLOG") || !strcmp(facility, "syslog")) {
PG(syslog_facility) = LOG_SYSLOG;
return SUCCESS;
}
#endif
#ifdef LOG_USER
if (!strcmp(facility, "LOG_USER") || !strcmp(facility, "user")) {
PG(syslog_facility) = LOG_USER;
return SUCCESS;
}
#endif
#ifdef LOG_UUCP
if (!strcmp(facility, "LOG_UUCP") || !strcmp(facility, "uucp")) {
PG(syslog_facility) = LOG_UUCP;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL0
if (!strcmp(facility, "LOG_LOCAL0") || !strcmp(facility, "local0")) {
PG(syslog_facility) = LOG_LOCAL0;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL1
if (!strcmp(facility, "LOG_LOCAL1") || !strcmp(facility, "local1")) {
PG(syslog_facility) = LOG_LOCAL1;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL2
if (!strcmp(facility, "LOG_LOCAL2") || !strcmp(facility, "local2")) {
PG(syslog_facility) = LOG_LOCAL2;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL3
if (!strcmp(facility, "LOG_LOCAL3") || !strcmp(facility, "local3")) {
PG(syslog_facility) = LOG_LOCAL3;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL4
if (!strcmp(facility, "LOG_LOCAL4") || !strcmp(facility, "local4")) {
PG(syslog_facility) = LOG_LOCAL4;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL5
if (!strcmp(facility, "LOG_LOCAL5") || !strcmp(facility, "local5")) {
PG(syslog_facility) = LOG_LOCAL5;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL6
if (!strcmp(facility, "LOG_LOCAL6") || !strcmp(facility, "local6")) {
PG(syslog_facility) = LOG_LOCAL6;
return SUCCESS;
}
#endif
#ifdef LOG_LOCAL7
if (!strcmp(facility, "LOG_LOCAL7") || !strcmp(facility, "local7")) {
PG(syslog_facility) = LOG_LOCAL7;
return SUCCESS;
}
#endif
return FAILURE;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetPrecision)
{
zend_long i;
ZEND_ATOL(i, ZSTR_VAL(new_value));
if (i >= -1) {
EG(precision) = i;
return SUCCESS;
} else {
return FAILURE;
}
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetSerializePrecision)
{
zend_long i;
ZEND_ATOL(i, ZSTR_VAL(new_value));
if (i >= -1) {
PG(serialize_precision) = i;
return SUCCESS;
} else {
return FAILURE;
}
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnChangeMemoryLimit)
{
if (new_value) {
PG(memory_limit) = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
} else {
PG(memory_limit) = Z_L(1)<<30; /* effectively, no limit */
}
zend_set_memory_limit(PG(memory_limit));
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetLogFilter)
{
const char *filter = ZSTR_VAL(new_value);
if (!strcmp(filter, "all")) {
PG(syslog_filter) = PHP_SYSLOG_FILTER_ALL;
return SUCCESS;
}
if (!strcmp(filter, "no-ctrl")) {
PG(syslog_filter) = PHP_SYSLOG_FILTER_NO_CTRL;
return SUCCESS;
}
if (!strcmp(filter, "ascii")) {
PG(syslog_filter) = PHP_SYSLOG_FILTER_ASCII;
return SUCCESS;
}
if (!strcmp(filter, "raw")) {
PG(syslog_filter) = PHP_SYSLOG_FILTER_RAW;
return SUCCESS;
}
return FAILURE;
}
/* }}} */
/* {{{ php_disable_classes */
static void php_disable_classes(void)
{
char *s = NULL, *e;
if (!*(INI_STR("disable_classes"))) {
return;
}
e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
while (*e) {
switch (*e) {
case ' ':
case ',':
if (s) {
*e = '\0';
zend_disable_class(s, e-s);
s = NULL;
}
break;
default:
if (!s) {
s = e;
}
break;
}
e++;
}
if (s) {
zend_disable_class(s, e-s);
}
}
/* }}} */
/* {{{ php_binary_init */
static void php_binary_init(void)
{
char *binary_location = NULL;
#ifdef PHP_WIN32
binary_location = (char *)malloc(MAXPATHLEN);
if (binary_location && GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
free(binary_location);
PG(php_binary) = NULL;
}
#else
if (sapi_module.executable_location) {
binary_location = (char *)malloc(MAXPATHLEN);
if (binary_location && !strchr(sapi_module.executable_location, '/')) {
char *envpath, *path;
int found = 0;
if ((envpath = getenv("PATH")) != NULL) {
char *search_dir, search_path[MAXPATHLEN];
char *last = NULL;
zend_stat_t s;
path = estrdup(envpath);
search_dir = php_strtok_r(path, ":", &last);
while (search_dir) {
snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK) && VCWD_STAT(binary_location, &s) == 0 && S_ISREG(s.st_mode)) {
found = 1;
break;
}
search_dir = php_strtok_r(NULL, ":", &last);
}
efree(path);
}
if (!found) {
free(binary_location);
binary_location = NULL;
}
} else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
free(binary_location);
binary_location = NULL;
}
}
#endif
PG(php_binary) = binary_location;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateTimeout)
{
if (stage==PHP_INI_STAGE_STARTUP) {
/* Don't set a timeout on startup, only per-request */
ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
return SUCCESS;
}
zend_unset_timeout();
ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
zend_set_timeout(EG(timeout_seconds), 0);
return SUCCESS;
}
/* }}} */
/* {{{ php_get_display_errors_mode() helper function */
static zend_uchar php_get_display_errors_mode(char *value, size_t value_length)
{
zend_uchar mode;
if (!value) {
return PHP_DISPLAY_ERRORS_STDOUT;
}
if (value_length == 2 && !strcasecmp("on", value)) {
mode = PHP_DISPLAY_ERRORS_STDOUT;
} else if (value_length == 3 && !strcasecmp("yes", value)) {
mode = PHP_DISPLAY_ERRORS_STDOUT;
} else if (value_length == 4 && !strcasecmp("true", value)) {
mode = PHP_DISPLAY_ERRORS_STDOUT;
} else if (value_length == 6 && !strcasecmp(value, "stderr")) {
mode = PHP_DISPLAY_ERRORS_STDERR;
} else if (value_length == 6 && !strcasecmp(value, "stdout")) {
mode = PHP_DISPLAY_ERRORS_STDOUT;
} else {
ZEND_ATOL(mode, value);
if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
mode = PHP_DISPLAY_ERRORS_STDOUT;
}
}
return mode;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateDisplayErrors)
{
PG(display_errors) = php_get_display_errors_mode(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_DISP */
static PHP_INI_DISP(display_errors_mode)
{
zend_uchar mode;
bool cgi_or_cli;
size_t tmp_value_length;
char *tmp_value;
if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
tmp_value = (ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : NULL );
tmp_value_length = (ini_entry->orig_value? ZSTR_LEN(ini_entry->orig_value) : 0);
} else if (ini_entry->value) {
tmp_value = ZSTR_VAL(ini_entry->value);
tmp_value_length = ZSTR_LEN(ini_entry->value);
} else {
tmp_value = NULL;
tmp_value_length = 0;
}
mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
/* Display 'On' for other SAPIs instead of STDOUT or STDERR */
cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg"));
switch (mode) {
case PHP_DISPLAY_ERRORS_STDERR:
if (cgi_or_cli ) {
PUTS("STDERR");
} else {
PUTS("On");
}
break;
case PHP_DISPLAY_ERRORS_STDOUT:
if (cgi_or_cli ) {
PUTS("STDOUT");
} else {
PUTS("On");
}
break;
default:
PUTS("Off");
break;
}
}
/* }}} */
PHPAPI const char *php_get_internal_encoding(void) {
if (PG(internal_encoding) && PG(internal_encoding)[0]) {
return PG(internal_encoding);
} else if (SG(default_charset) && SG(default_charset)[0]) {
return SG(default_charset);
}
return "UTF-8";
}
PHPAPI const char *php_get_input_encoding(void) {
if (PG(input_encoding) && PG(input_encoding)[0]) {
return PG(input_encoding);
} else if (SG(default_charset) && SG(default_charset)[0]) {
return SG(default_charset);
}
return "UTF-8";
}
PHPAPI const char *php_get_output_encoding(void) {
if (PG(output_encoding) && PG(output_encoding)[0]) {
return PG(output_encoding);
} else if (SG(default_charset) && SG(default_charset)[0]) {
return SG(default_charset);
}
return "UTF-8";
}
PHPAPI void (*php_internal_encoding_changed)(void) = NULL;
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateDefaultCharset)
{
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
if (php_internal_encoding_changed) {
php_internal_encoding_changed();
}
if (new_value) {
#ifdef PHP_WIN32
php_win32_cp_do_update(ZSTR_VAL(new_value));
#endif
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateInternalEncoding)
{
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
if (php_internal_encoding_changed) {
php_internal_encoding_changed();
}
if (new_value) {
#ifdef PHP_WIN32
php_win32_cp_do_update(ZSTR_VAL(new_value));
#endif
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateInputEncoding)
{
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
if (php_internal_encoding_changed) {
php_internal_encoding_changed();
}
if (new_value) {
#ifdef PHP_WIN32
php_win32_cp_do_update(NULL);
#endif
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateOutputEncoding)
{
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
if (php_internal_encoding_changed) {
php_internal_encoding_changed();
}
if (new_value) {
#ifdef PHP_WIN32
php_win32_cp_do_update(NULL);
#endif
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateErrorLog)
{
/* Only do the safemode/open_basedir check at runtime */
if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(ZSTR_VAL(new_value), "syslog")) {
if (PG(open_basedir) && php_check_open_basedir(ZSTR_VAL(new_value))) {
return FAILURE;
}
}
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnUpdateMailLog)
{
/* Only do the safemode/open_basedir check at runtime */
if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
if (PG(open_basedir) && php_check_open_basedir(ZSTR_VAL(new_value))) {
return FAILURE;
}
}
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnChangeMailForceExtra)
{
/* Don't allow changing it in htaccess */
if (stage == PHP_INI_STAGE_HTACCESS) {
return FAILURE;
}
return SUCCESS;
}
/* }}} */
/* defined in browscap.c */
PHP_INI_MH(OnChangeBrowscap);
/* Need to be read from the environment (?):
* PHP_AUTO_PREPEND_FILE
* PHP_AUTO_APPEND_FILE
* PHP_DOCUMENT_ROOT
* PHP_USER_DIR
* PHP_INCLUDE_PATH
*/
/* Windows use the internal mail */
#if defined(PHP_WIN32)
# define DEFAULT_SENDMAIL_PATH NULL
#else
# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i"
#endif
/* {{{ PHP_INI */
PHP_INI_BEGIN()
PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
STD_PHP_INI_BOOLEAN("display_startup_errors", "1", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("report_zend_debug", "0", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, short_tags, zend_compiler_globals, compiler_globals)
STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("serialize_precision", "-1", PHP_INI_ALL, OnSetSerializePrecision, serialize_precision, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateDefaultCharset, default_charset, sapi_globals_struct, sapi_globals)
STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct, sapi_globals)
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir, open_basedir, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("max_input_nesting_level", "64", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_nesting_level, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("max_input_vars", "1000", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_vars, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("request_order", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, request_order, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals)
PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
STD_PHP_INI_BOOLEAN("mail.add_x_header", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, mail_x_header, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateMailLog, mail_log, php_core_globals, core_globals)
PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, OnChangeBrowscap)
PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("enable_post_data_reading", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, enable_post_data_reading, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("realpath_cache_size", "4096K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("hard_timeout", "2", PHP_INI_SYSTEM, OnUpdateLong, hard_timeout, zend_executor_globals, executor_globals)
#ifdef PHP_WIN32
STD_PHP_INI_BOOLEAN("windows.show_crt_warning", "0", PHP_INI_ALL, OnUpdateBool, windows_show_crt_warning, php_core_globals, core_globals)
#endif
STD_PHP_INI_ENTRY("syslog.facility", "LOG_USER", PHP_INI_SYSTEM, OnSetFacility, syslog_facility, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("syslog.ident", "php", PHP_INI_SYSTEM, OnUpdateString, syslog_ident, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("syslog.filter", "no-ctrl", PHP_INI_ALL, OnSetLogFilter, syslog_filter, php_core_globals, core_globals)
PHP_INI_END()
/* }}} */
/* True globals (no need for thread safety */
/* But don't make them a single int bitfield */
static int module_initialized = 0;
static int module_startup = 1;
static int module_shutdown = 0;
/* {{{ php_during_module_startup */
PHPAPI int php_during_module_startup(void)
{
return module_startup;
}
/* }}} */
/* {{{ php_during_module_shutdown */
PHPAPI int php_during_module_shutdown(void)
{
return module_shutdown;
}
/* }}} */
/* {{{ php_get_module_initialized */
PHPAPI int php_get_module_initialized(void)
{
return module_initialized;
}
/* }}} */
/* {{{ php_log_err_with_severity */
PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int syslog_type_int)
{
int fd = -1;
time_t error_time;
if (PG(in_error_log)) {
/* prevent recursive invocation */
return;
}
PG(in_error_log) = 1;
/* Try to use the specified logging location. */
if (PG(error_log) != NULL) {
#ifdef HAVE_SYSLOG_H
if (!strcmp(PG(error_log), "syslog")) {
php_syslog(syslog_type_int, "%s", log_message);
PG(in_error_log) = 0;
return;
}
#endif
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
if (fd != -1) {
char *tmp;
size_t len;
zend_string *error_time_str;
time(&error_time);
#ifdef ZTS
if (!php_during_module_startup()) {
error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1);
} else {
error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0);
}
#else
error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1);
#endif
len = spprintf(&tmp, 0, "[%s] %s%s", ZSTR_VAL(error_time_str), log_message, PHP_EOL);
#ifdef PHP_WIN32
php_flock(fd, 2);
/* XXX should eventually write in a loop if len > UINT_MAX */
php_ignore_value(write(fd, tmp, (unsigned)len));
#else
php_ignore_value(write(fd, tmp, len));
#endif
efree(tmp);
zend_string_free(error_time_str);
close(fd);
PG(in_error_log) = 0;
return;
}
}
/* Otherwise fall back to the default logging location, if we have one */
if (sapi_module.log_message) {
sapi_module.log_message(log_message, syslog_type_int);
}
PG(in_error_log) = 0;
}
/* }}} */
/* {{{ php_write
wrapper for modules to use PHPWRITE */
PHPAPI size_t php_write(void *buf, size_t size)
{
return PHPWRITE(buf, size);
}
/* }}} */
/* {{{ php_printf */
PHPAPI size_t php_printf(const char *format, ...)
{
va_list args;
size_t ret;
char *buffer;
size_t size;
va_start(args, format);
size = vspprintf(&buffer, 0, format, args);
ret = PHPWRITE(buffer, size);
efree(buffer);
va_end(args);
return ret;
}
/* }}} */
/* {{{ php_printf_unchecked */
PHPAPI size_t php_printf_unchecked(const char *format, ...)
{
va_list args;
size_t ret;
char *buffer;
size_t size;
va_start(args, format);
size = vspprintf(&buffer, 0, format, args);
ret = PHPWRITE(buffer, size);
efree(buffer);
va_end(args);
return ret;
}
/* }}} */
static zend_string *escape_html(const char *buffer, size_t buffer_len) {
zend_string *result = php_escape_html_entities_ex(
(const unsigned char *) buffer, buffer_len, 0, ENT_COMPAT,
/* charset_hint */ NULL, /* double_encode */ 1, /* quiet */ 1);
if (!result || ZSTR_LEN(result) == 0) {
/* Retry with substituting invalid chars on fail. */
result = php_escape_html_entities_ex(
(const unsigned char *) buffer, buffer_len, 0, ENT_COMPAT | ENT_HTML_SUBSTITUTE_ERRORS,
/* charset_hint */ NULL, /* double_encode */ 1, /* quiet */ 1);
}
return result;
}
/* {{{ php_verror */
/* php_verror is called from php_error_docref<n> functions.
* Its purpose is to unify error messages and automatically generate clickable
* html error messages if corresponding ini setting (html_errors) is activated.
* See: CODING_STANDARDS.md for details.
*/
PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int type, const char *format, va_list args)
{
zend_string *replace_buffer = NULL, *replace_origin = NULL;
char *buffer = NULL, *docref_buf = NULL, *target = NULL;
char *docref_target = "", *docref_root = "";
char *p;
int buffer_len = 0;
const char *space = "";
const char *class_name = "";
const char *function;
int origin_len;
char *origin;
zend_string *message;
int is_function = 0;
/* get error text into buffer and escape for html if necessary */
buffer_len = (int)vspprintf(&buffer, 0, format, args);
if (PG(html_errors)) {
replace_buffer = escape_html(buffer, buffer_len);
efree(buffer);
if (replace_buffer) {
buffer = ZSTR_VAL(replace_buffer);
buffer_len = (int)ZSTR_LEN(replace_buffer);
} else {
buffer = "";
buffer_len = 0;
}
}
/* which function caused the problem if any at all */
if (php_during_module_startup()) {
function = "PHP Startup";
} else if (php_during_module_shutdown()) {
function = "PHP Shutdown";
} else if (EG(current_execute_data) &&
EG(current_execute_data)->func &&
ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
EG(current_execute_data)->opline &&
EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
) {
switch (EG(current_execute_data)->opline->extended_value) {
case ZEND_EVAL:
function = "eval";
is_function = 1;
break;
case ZEND_INCLUDE:
function = "include";
is_function = 1;
break;
case ZEND_INCLUDE_ONCE:
function = "include_once";
is_function = 1;
break;
case ZEND_REQUIRE:
function = "require";
is_function = 1;
break;
case ZEND_REQUIRE_ONCE:
function = "require_once";
is_function = 1;
break;
default:
function = "Unknown";
}
} else {
function = get_active_function_name();
if (!function || !strlen(function)) {
function = "Unknown";
} else {
is_function = 1;
class_name = get_active_class_name(&space);
}
}
/* if we still have memory then format the origin */
if (is_function) {
origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
} else {
origin_len = (int)spprintf(&origin, 0, "%s", function);
}
if (PG(html_errors)) {
replace_origin = escape_html(origin, origin_len);
efree(origin);
origin = ZSTR_VAL(replace_origin);
}
/* origin and buffer available, so lets come up with the error message */
if (docref && docref[0] == '#') {
docref_target = strchr(docref, '#');
docref = NULL;
}
/* no docref given but function is known (the default) */
if (!docref && is_function) {
int doclen;
while (*function == '_') {
function++;
}
if (space[0] == '\0') {
doclen = (int)spprintf(&docref_buf, 0, "function.%s", function);
} else {
doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function);
}
while((p = strchr(docref_buf, '_')) != NULL) {
*p = '-';
}