Skip to content

Commit 2f61ad9

Browse files
committed
- add EG(windows_version_info), set at init time once per instance
contains a OSVERSIONINFOEX struct. It lets us determine easily on which windows version is used (for example) - add the ability to disable a function when the windows function does not support a feature (for example symlink) - symlink, hardlink & co support (1/2)
1 parent fc6c8f5 commit 2f61ad9

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

main/main.c

+47-4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,33 @@ php_core_globals core_globals;
9999
PHPAPI int core_globals_id;
100100
#endif
101101

102+
#ifdef PHP_WIN32
103+
#include "win32_internal_function_disabled.h"
104+
105+
static php_win32_disable_functions() {
106+
int i;
107+
TSRMLS_FETCH();
108+
109+
if (EG(windows_version_info).dwMajorVersion < 5) {
110+
for (i = 0; i < function_name_cnt_5; i++) {
111+
if (zend_hash_del(CG(function_table), function_name_5[i], strlen(function_name_5[i]) + 1)==FAILURE) {
112+
php_printf("Unable to disable function '%s'\n", function_name_5[i]);
113+
return FAILURE;
114+
}
115+
}
116+
}
117+
118+
if (EG(windows_version_info).dwMajorVersion < 6) {
119+
for (i = 0; i < function_name_cnt_6; i++) {
120+
if (zend_hash_del(CG(function_table), function_name_6[i], strlen(function_name_6[i]) + 1)==FAILURE) {
121+
php_printf("Unable to disable function '%s'\n", function_name_6[i]);
122+
return FAILURE;
123+
}
124+
}
125+
}
126+
}
127+
#endif
128+
102129
#define SAFE_FILENAME(f) ((f)?(f):"-")
103130

104131
/* {{{ PHP_INI_MH
@@ -1677,6 +1704,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
16771704
#ifdef ZTS
16781705
zend_executor_globals *executor_globals;
16791706
void ***tsrm_ls;
1707+
#ifdef PHP_WIN32
1708+
DWORD dwVersion = GetVersion();
1709+
#endif
16801710

16811711
php_core_globals *core_globals;
16821712
#endif
@@ -1685,16 +1715,12 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
16851715
WSADATA wsaData;
16861716
#endif
16871717
#ifdef PHP_WIN32
1688-
{
1689-
DWORD dwVersion = GetVersion();
1690-
16911718
/* Get build numbers for Windows NT or Win95 */
16921719
if (dwVersion < 0x80000000){
16931720
php_os="WINNT";
16941721
} else {
16951722
php_os="WIN32";
16961723
}
1697-
}
16981724
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
16991725
old_invalid_parameter_handler =
17001726
_set_invalid_parameter_handler(dummy_invalid_parameter_handler);
@@ -1752,6 +1778,18 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
17521778
#endif
17531779
gc_globals_ctor(TSRMLS_C);
17541780

1781+
#ifdef PHP_WIN32
1782+
{
1783+
OSVERSIONINFOEX *osvi = &EG(windows_version_info);
1784+
1785+
ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
1786+
osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1787+
if( !GetVersionEx((OSVERSIONINFO *) osvi)) {
1788+
php_printf("\nGetVersionEx unusable. %d\n", GetLastError());
1789+
return FAILURE;
1790+
}
1791+
}
1792+
#endif
17551793
EG(bailout) = NULL;
17561794
EG(error_reporting) = E_ALL & ~E_NOTICE;
17571795

@@ -1927,6 +1965,11 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
19271965
module->info_func = PHP_MINFO(php_core);
19281966
}
19291967

1968+
#ifdef PHP_WIN32
1969+
/* Disable incompatible functions for the running platform */
1970+
php_win32_disable_functions();
1971+
#endif
1972+
19301973
#ifdef ZTS
19311974
zend_post_startup(TSRMLS_C);
19321975
#endif
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 5 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2009 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 3.01 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.php.net/license/3_01.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+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: Pierre A. Joye <[email protected]> |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
/* 5 means the min version is 5 (XP/2000), 6 (2k8/vista), etc. */
22+
static const char *function_name_5[] = {"link", NULL};
23+
const int function_name_cnt_5 = 1;
24+
static const char *function_name_6[] = {"readlink", "symlink", NULL};
25+
const int function_name_cnt_6 = 2;

0 commit comments

Comments
 (0)