Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problems with _create_dir_structure
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Nimlin
Smarty n00b


Joined: 02 May 2003
Posts: 3

PostPosted: Sat May 03, 2003 8:55 am    Post subject: Problems with _create_dir_structure Reply with quote

NOTE: This topic was split from an original help request. The original thread is located here -- ADMIN
---------------------------------------
I'm on Linux, but I've spent some time debugging the Smarty.class.php file and think I've located the problem. In the "_create_dir_structure" function, there's a line that checks for Open_basedir restrictions, and then compares the restricted directories to the directory I want to create:

Code:

 1] if ($_use_open_basedir) {
 2]   $_make_new_dir = false;
 3]   foreach ($_open_basedirs as $_open_basedir) {
 4]     if (substr($_new_dir.'/', 0, strlen($_open_basedir)) == $_open_basedir) {
 5]       $_make_new_dir = true;
 6]       break;
 7]     }
 8]   }
 9] } else {
10]   $_make_new_dir = true;
11] }


The problem is, if $_new_dir is a relative path, rather than absolute, the comparison on line 4 will most likely fail. On the problem mentioned above, the $_open_basedirs are "/data/httpd/vhosts/www.######.com/httpdocs" and "/tmp", but $_new_dir is "templates_c/%%940".

The simple fix seems to be making sure $compile_dir, at the top of the Smarty.class.php file has an absolute path so it attempts to create "/data/httpd/vhosts/www.######.com/httpdocs/templates_c/%%940" instead.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat May 03, 2003 11:12 am    Post subject: Reply with quote

Nimlin wrote:
The simple fix seems to be making sure $compile_dir, at the top of the Smarty.class.php file has an absolute path so it attempts to create "/data/httpd/vhosts/www.######.com/httpdocs/templates_c/%%940" instead.


Good sleuthing. I think a lot of people have problems with this and yes, always use absolute paths for the configurable dirs.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun May 04, 2003 2:08 pm    Post subject: Reply with quote

okay, _create_dir_structure() should start creating directories at getcwd() and not at '' when using relative paths. this makes the comparason to allowed open_basedirs work on both unix- and windows-filesystems.

but i see another issue:
"($dir{0} == DIR_SEP)" is not an appropiate test to check for absolute-paths on the windows-platform, right? (path = "c:\...". this is $dir{2} not $dir{0} ) . and the comparason has to be done case-insensitive in windows. this adds a few extra-cases that are unnecessary to most of us Sad
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 2:20 pm    Post subject: Reply with quote

@messju: So that's it! Very interesting. I'll have to think about that and try what you suggested. I'm still getting used to the code-base Smile

Quote:
this adds a few extra-cases that are unnecessary to most of us


heh heh. Lots of Windows boxen out there!! Never-the-less, maybe the file/directory handling can be abstracted so that separate localized libs can be auto loaded for the running platform. It would be nice if the engine internally used ONE style of paths Wink
Back to top
View user's profile Send private message
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Sun May 04, 2003 2:24 pm    Post subject: Reply with quote

forgive me if I dind't get the point of the discussion, but why not use slashes generally?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu May 08, 2003 1:28 pm    Post subject: Reply with quote

FYI: i fixed _create_dir_structure() in cvs for the case of a relative template_dir, use_sub_dirs=true (both smarty-defaults) and open_basedir set.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
packman
Smarty n00b


Joined: 09 May 2003
Posts: 3
Location: Blackpool, UK

PostPosted: Fri May 09, 2003 7:47 pm    Post subject: Reply with quote

I was having open_basedir restriction problems, so I tried your fix from CVS to see if it would help. Just before applying your mods I had tried fully specifying the directories and didn't switch back to the relative directory names. Your fix looks like it fixes the relative directory case, but it seems to break the fully specified directory case.

I found I had to change a test in create_dir_structure() from:

Code:
if (substr($_new_dir.'/', 0, strlen($_open_basedir)) == $_open_basedir) {

to:
Code:
if (substr($_new_dir, 0, strlen($_open_basedir)) == $_open_basedir) {


The problem is that when the trailing slash is added, the root directory of the open_basedir tree correctly passes the test of being within the open_basedir. When the code then goes on to check if the root directory exists the file_exists() fails because it's looking for the root open_basedir directory entry in the parent directory of the root. This directory isn't part of the open_basedir tree and is therefore out of bounds to file_exists.

I hope this makes sense! Hopefully someone can verify my fix and add it to CVS if it really does make things better!
_________________
--
Chris
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri May 09, 2003 8:33 pm    Post subject: Reply with quote

hmm, i see. be sure i tested quite a some cases, maybe not yours. Sad
i didn't write _create_dir_structure(). i think the trailing slash (which should read DIRECTORY_SEPARATOR, right?) is for testing, when people have a trailing slash, in an element of their open_basedir-directory list.

i cannot reproduce the behaviour you report, file_exists() succeeds happily on a component of open_basedir in my environment. what version of php do you use, and what platform? i tested php-4.0.6 and php-4.3.1 on linux.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri May 09, 2003 9:18 pm    Post subject: Reply with quote

I was wondering if this should be split into a new thread in the bugs forum.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri May 09, 2003 9:47 pm    Post subject: Reply with quote

boots: feel free, i'm sure i'll find it, if feedback arrives Smile
(edit: try to avoid pidgeon-english, it's hard for me)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
packman
Smarty n00b


Joined: 09 May 2003
Posts: 3
Location: Blackpool, UK

PostPosted: Sat May 10, 2003 8:43 pm    Post subject: Reply with quote

4.3.1 on Linux (RH7.2 + Ensim). All my open_basedir entries have a trailing slash, so perhaps that's why it's different for me? I'm guessing that the problem was because file_exists was trying to look at a directory outside the open_basedir tree, but I've yet to find a decent description of exactly how open_basedir works, so I can't be sure!
_________________
--
Chris
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun May 11, 2003 1:57 am    Post subject: Reply with quote

consider using $smarty->use_sub_dirs=false after you established your smarty object or specify a full path for $smarty->compile_dir
Back to top
View user's profile Send private message Send e-mail Visit poster's website
packman
Smarty n00b


Joined: 09 May 2003
Posts: 3
Location: Blackpool, UK

PostPosted: Sun May 11, 2003 7:55 pm    Post subject: Reply with quote

compile_dir (like all my paths) is fully specified.

I did try use_sub_dirs=false and still had problems, although I can't remember at exactly what else I had/hadn't done when I tried it. However the docs suggest that use_sub_dirs=false is to overcome safe_mode problems and I don't seem to have those...just open_basedir problems Sad
_________________
--
Chris
Back to top
View user's profile Send private message Visit poster's website
k-fish
Smarty n00b


Joined: 22 Oct 2003
Posts: 2
Location: Germany

PostPosted: Wed Oct 22, 2003 1:41 pm    Post subject: Reply with quote

packman wrote:
I found I had to change a test in create_dir_structure() from:
...
The problem is that when the trailing slash is added, the root directory of the open_basedir tree correctly passes the test of being within the open_basedir. When the code then goes on to check if the root directory exists the file_exists() fails because it's looking for the root open_basedir directory entry in the parent directory of the root. This directory isn't part of the open_basedir tree and is therefore out of bounds to file_exists.


I can verify this, and I am wondering why this hasn't been changed in CVS... :) The above observation is true and the fix is working correctly for me as well.

Karsten
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Oct 22, 2003 4:41 pm    Post subject: Reply with quote

this wasn't fixed yet because of my ignorance about the fact that open_basedir doesn't contain directories, but prefixes. i was confident open_basedir contains directories and the trailing slash is a buggy configuration. but i was false, sorry.

http://bugs.php.net/bug.php?id=8848 and
http://www.php.net/manual/en/features.safe-mode.php#ini.open-basedir
told me so.

after reading that, the fix looks fully reasonable to me now. i will commit something like that soon.

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP