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

Problem with safe_mode

 
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 -> Installation and Setup
View previous topic :: View next topic  
Author Message
jppichon
Smarty n00b


Joined: 16 Mar 2004
Posts: 3
Location: France

PostPosted: Tue Mar 16, 2004 4:50 pm    Post subject: Problem with safe_mode Reply with quote

Hi,

I have some troubles with Smarty 2.6.2.
I followed the instructions given in the manual but when I attempt to run the demo I get the error message :

Warning: SAFE MODE Restriction in effect. The script whose uid is 318 is not allowed to access /usr/local/include/php/ext/Smarty/Smarty.class.php owned by uid 0 in /home/sites/site25/web/projets/smarty/index.php on line 14

Fatal error: Failed opening required 'Smarty.class.php' (include_path='/usr/local/include/php/ext/Smarty/') in /home/sites/site25/web/projets/smarty/index.php on line 14


I browsed through this forum and didn't find any solution.

I've checked that var $use_sub_dirs = false in Smarty.class.php

As recommanded in the manual the lib files are installed with some other php libs at /usr/local/include/php/ext/Smarty. I don't think it should be a good idea to chmod this folder to 777.

ANy help or suggestion will be appreciated.

Thanks

Jean Pierre
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


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

PostPosted: Tue Mar 16, 2004 5:16 pm    Post subject: Reply with quote

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1519
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Mar 16, 2004 5:19 pm    Post subject: Reply with quote

you have to set
safe_mode_include_dir = /usr/local/include/php/ext/Smarty/

in your php.ini to allow your script to include Smarty.class.php.
read more on safe-mode at http://php.net/features.safe-mode
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jppichon
Smarty n00b


Joined: 16 Mar 2004
Posts: 3
Location: France

PostPosted: Wed Mar 17, 2004 2:43 pm    Post subject: Problem with safe_mode... next Reply with quote

First of all, I thank you for your advices.

I set safe_mode_include_dir="/usr/local/include/php/ext/Smarty" in php.ini and now "Smarty.class.php" is correctly included, but the safe_mode is giving similar troubles with a subdirectory :

Warning: SAFE MODE Restriction in effect. The script whose uid is 318 is not allowed to access templates_c/405857ea54ee2 owned by uid 15 in /usr/local/include/php/ext/Smarty/core/core.write_file.php on line 37

Warning: Failed opening 'templates_c/%%117^%%1172603085^index.tpl.php' for inclusion (include_path='/usr/local/include/php/ext/Smarty/') in /usr/local/include/php/ext/Smarty/Smarty.class.php on line 1266

Warning: SAFE MODE Restriction in effect. The script whose uid is 318 is not allowed to access templates_c/405857ea59d18 owned by uid 15 in /usr/local/include/php/ext/Smarty/core/core.write_file.php on line 37

Warning: Failed opening 'templates_c/%%154^%%1541163521^debug.tpl.php' for inclusion (include_path='/usr/local/include/php/ext/Smarty/') in /usr/local/include/php/ext/Smarty/Smarty.class.php on line 1965


Any suggestion ?

Jean Pierre
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 Mar 17, 2004 3:13 pm    Post subject: Reply with quote

the templates_c directory has to be owned by the same user than the running script (uid 318 in your case). *and* templates_c has to be writable by the webserver.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jppichon
Smarty n00b


Joined: 16 Mar 2004
Posts: 3
Location: France

PostPosted: Wed Mar 17, 2004 4:48 pm    Post subject: Problem with safe_mode... next II Reply with quote

messju wrote:
the templates_c directory has to be owned by the same user than the running script (uid 318 in your case).


templates_c directory is owned by uid 318 but when Smarty write a file in it, it is owned by http (see directory listing below)

[root smarty]# ls -al templates_c/
total 11
drwxrwxrwx 2 webm_equ site25 1024 Mar 17 17:21 .
drwxr-xr-x 6 webm_equ site25 1024 Mar 16 09:22 ..
-rw-r--r-- 1 httpd site25 8029 Mar 17 17:21 %%117^%%1172603085^index.tpl.php
-rw-r--r-- 1 httpd site25 135 Mar 17 17:21 %%154^%%1541163521^debug.tpl.php



Quote:
*and* templates_c has to be writable by the webserver


yes it is writable :
drwxrwxrwx 2 webm_equ site25 1024 Mar 17 17:21 templates_c

How can I solve this ?

Jean Pierre
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


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

PostPosted: Thu Mar 18, 2004 1:03 am    Post subject: Reply with quote

Either A or B below should work -- you should only need one or the other:

A] have webserver create temporary dirs

1] Use the user account to remove the templates_c directory
2] write a script that creates the temp directories for you and execute the script through the webserver-- that way the webserver owns the directory and the files in it.

B] relax GID matching:

1] If you have control over the php.ini and you don't care if GID and UID match or not, set safe_mode_gid = On
More Info:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1519
http://www.zend.com/manual/features.safe-mode.php

HTH
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Thu Mar 18, 2004 1:14 am    Post subject: Reply with quote

Here is a code snippet from my constructor and two associated functions in my custom extended Smarty class that I use to initiate an environment. The functions are handy if you want the webserver to automagically create the temp directories for you. You will notice that when the function creates the directories, it also writes a .version file which indicates which version of Smarty was used when the directory was created and automatically removes old temp files when a new version of Smarty is installed.

Do not attempt to cut and paste (I use custom constants and custom class vars (like check_upgrade) which I am not defining here. Modify to your taste and environment:

[php:1:e79dabf214]
[...snip from constructor]
/**
* auto setup
*/
$this->use_sub_dirs = !ini_get('safe_mode');

/**
* general setup
*/
$this->_init_tempdir('compile_dir', MY_TEMP_SMARTY_COMPILED_DIR);
$this->plugins_dir = array(MY_ROOT_DIR . 'plugins', SMARTY_DIR . 'plugins');

$this->config_dir = MY_ROOT_DIR . 'configs';
$this->config_overwrite = false;

/**
* caching support (optional)
*/

if ($this->caching || $this->cache_handler_func) {
if ($this->cache_handler_func) {
require_once MY_APP_DIR . $this->cache_handler_func . '.inc';
} else if ($this->caching) {
$this->_init_tempdir('cache_dir', MY_TEMP_SMARTY_CACHED_DIR);
}
}
[/...snip from constructor]


function _init_tempdir($tempdir, $path)
{
if (!is_dir($path)) {
require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
smarty_core_write_file(array('filename' => $path . DIRECTORY_SEPARATOR . $tempdir . '.version', 'contents' => $this->_version, 'create_dirs' => true), $this);
$test = trim(file_get_contents($path . DIRECTORY_SEPARATOR . $tempdir . '.version'));
if (!$test) {
if (ini_get('safe_mode')) {
die("You are running in safe mode and files can not be read from `$path` with the current permission settings.");
}
die("Files can not be read from `$path` with the current permission settings.");
}
} else if ($this->check_upgrade) {
$test = trim(file_get_contents($path . DIRECTORY_SEPARATOR . $tempdir . '.version'));
if (!version_compare($this->_version, $test, "eq")) {
$this->_del_tempdir($path);
$this->_init_tempdir($tempdir, $path);
}
}
$this->$tempdir = $path;
}

function _del_tempdir($dir)
{
$current_dir = opendir($dir);
while ($entryname = readdir($current_dir)) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $entryname) and ($entryname != "." and $entryname != "..")) {
$this->_del_tempdir($dir . DIRECTORY_SEPARATOR . $entryname);
} elseif ($entryname != "." and $entryname != "..") {
unlink($dir . DIRECTORY_SEPARATOR . $entryname);
}
}
closedir($current_dir);
rmdir($dir);
}
[/php:1:e79dabf214]
Back to top
View user's profile Send private message
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 -> Installation and Setup All times are GMT
Page 1 of 1

 
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