动态open_basedir与mod_vhost_alias

时间:2012-03-12 22:18:55

标签: php apache open-basedir mod-vhost-alias

我使用mod_vhost_alias并希望为每个用户动态设置open_basedir。像

这样的东西

php_admin_value open_basedir / var / www / vhosts /%1

但它不起作用。因为我有很多虚拟主机(4000-5000),mod_macro不适合我。

我正在尝试应用此修补程序 http://wiki.preshweb.co.uk/doku.php?id=apache:securemassvhosting

但没有成功。有什么建议吗?

2 个答案:

答案 0 :(得分:3)

您可以在php.ini中使用auto_prepend选项来提供将首先执行的脚本。 在那里你可以根据$ _SERVER数组的内容通过ini_set()函数设置open_basedir。

答案 1 :(得分:0)

可能有人会感兴趣。我已成功更改了补丁(http://www.phpbuilder.com/lists/php-developer-list/2000101/0994.php

*** main/fopen_wrappers.c       2010-04-22 01:22:31.000000000 +0300
--- main/fopen_wrappers.c       2012-03-14 17:22:49.130299133 +0200
***************
*** 145,156 ****
--- 145,168 ----
        char resolved_name[MAXPATHLEN];
        char resolved_basedir[MAXPATHLEN];
        char local_open_basedir[MAXPATHLEN];
+       char *local_open_basedir_sub; /* Substring pointer for strstr */
        char path_tmp[MAXPATHLEN];
        char *path_file;
        int resolved_basedir_len;
        int resolved_name_len;
        int path_len;
        int nesting_level = 0;
+
+       /* Special case for VIRTUAL_DOCUMENT_ROOT in the open_basedir value, which gets changed to the document root */
+       if ((strncmp(basedir, "VIRTUAL_DOCUMENT_ROOT", strlen("VIRTUAL_DOCUMENT_ROOT")) == 0) && SG(request_info).path_translated && *SG(request_info).path_translated )
+       {
+           strlcpy(local_open_basedir, SG(request_info).path_translated, sizeof(local_open_basedir));
+
+           local_open_basedir_sub=strstr(local_open_basedir,SG(request_info).request_uri);
+           /* Now insert null to break apart the string */
+           if (local_open_basedir_sub) *local_open_basedir_sub = '\0';
+
+       } else

        /* Special case basedir==".": Use script-directory */
        if (strcmp(basedir, ".") || !VCWD_GETCWD(local_open_basedir, MAXPATHLEN)) {

用php-5.3.10进行了测试,效果很好。