Re: [SMARTY-DEV] Smarty & open_basedir

From: Date: Wed, 16 Oct 2002 18:19:55 +0000
Subject: Re: [SMARTY-DEV] Smarty & open_basedir
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-297@lists.php.net to get a copy of this message
This function is used for more than just $compile_dir, so this will break stuff. If you're running into open_basedir problems, then your templates and files should all reside under open_basedir, yes? Monte Alessandro Astarita wrote:
There is a problem with Smarty when the directive open_basedir is used. A message like this is showed by PHP: Warning: open_basedir restriction in effect. File is in wrong directory The problem is in the method _create_dir_structure() in Smarty class that use file_exists() and mkdir() trying to access directories restricted by PHP. I have this patch that solve this problem without setting $use_sub_dirs=true.
--- Smarty.class.php.orig       Mon Oct 14 17:55:16 2002
+++ Smarty.class.php    Mon Oct 14 17:48:13 2002
@@ -1599,13 +1601,15 @@
         if (!@file_exists($dir)) {
             $dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1, PREG_SPLIT_NO_EMPTY);
             $new_dir = ($dir{0} == DIR_SEP) ? DIR_SEP : '';
-            foreach ($dir_parts as $dir_part) {
-                $new_dir .= $dir_part;
+            for ($i = 0; $i < sizeof($dir_parts); $i++, $new_dir .= DIR_SEP) {
+                $new_dir .= $dir_parts[$i];
+                if (substr($new_dir, 0, strlen($this->compile_dir)) != $this->compile_dir) {
+                    continue;
+                }
                 if (!file_exists($new_dir) && !mkdir($new_dir, 0771)) {
                     $this->trigger_error("problem creating directory \"$dir\"");
                     return false;
                 }
-                $new_dir .= DIR_SEP;
             }
         }
     }
-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.

« previous php.smarty.dev (#297) next »