Opened 7 years ago

Closed 7 years ago

#1418381 closed Bugs (fixed)

Safe_Mode: tmp dir

Reported by: neverloop Owned by: thomasb
Priority: 5 Milestone: 0.1-rc1
Component: PHP backend Version: 0.1-beta
Severity: normal Keywords:
Cc:

Description (last modified by thomasb)

When running with safe_mode=enabled, various problems
occur when you create a directory with PHP's
mkdir-function and subsequently try to open/create
files in this directory. This is a general problem and
not specific to RoundCubeMail?. The only solution is not
to create directories (owned by the apache user).

Please find a patch below which changes RC's caching
mechanism to not create per-session directories.

Warning: fopen(): SAFE MODE Restriction in effect. The
script whose uid is 3456 is not allowed to access
/path/to/tmp/roundcube/0c2da71545bb6fa67dbba1b00a0b
owned by uid 123 in
/path/to/webmail/program/steps/mail/func.inc on line 1241

diff -Nurd ./program/include/main.inc
./webmail/program/include/main.inc
--- ./program/include/main.inc  Fri Jan 20 01:01:53 2006
+++ ./webmail/program/include/main.inc  Sat Jan 28
13:34:15 2006
@@ -687,12 +687,10 @@
   global $CONFIG;
 
   $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$',
$CONFIG['temp_dir']) ? '/' : '');
-  $cache_dir = $temp_dir.$sess_id;
 
-  if (is_dir($cache_dir))
+  if (is_dir($temp_dir))
     {
-    clear_directory($cache_dir);
-    rmdir($cache_dir);
+    clear_directory($temp_dir, $sess_id);
     }  
   }
 
diff -Nurd ./program/include/rcube_shared.inc
./webmail/program/include/rcube_shared.inc
--- ./program/include/rcube_shared.inc  Fri Jan 13
18:14:35 2006
+++ ./webmail/program/include/rcube_shared.inc  Sat Jan
28 13:31:39 2006
@@ -1338,14 +1338,14 @@
   }
 
 
-// delete all files within a folder
-function clear_directory($dir_path)
+// delete all files beginning with prefix within a folder
+function clear_directory($dir_path, $prefix)
   {
   $dir = @opendir($dir_path);
   if(!$dir) return FALSE;
 
   while ($file = readdir($dir))
-    if (strlen($file)>2)
+    if (ereg("^".$prefix."-", $file))
       unlink("$dir_path/$file");
 
   closedir($dir);
diff -Nurd ./program/steps/mail/func.inc
./webmail/program/steps/mail/func.inc
--- ./program/steps/mail/func.inc       Wed Jan 25
23:56:52 2006
+++ ./webmail/program/steps/mail/func.inc       Sat Jan
28 13:24:30 2006
@@ -1191,11 +1191,10 @@
     $message_id =
md5($headers->uid.'@'.$_SESSION['imap_host']);
   
   $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$',
$CONFIG['temp_dir']) ? '/' : '');
-  $cache_dir = $temp_dir.$_SESSION['client_id'];
-  $cache_path = $cache_dir.'/'.$message_id;
+  $cache_path =
$temp_dir.$_SESSION['client_id'].'-'.$message_id;
 
   // message is cached in temp dir
-  if ($CONFIG['enable_caching'] && is_dir($cache_dir)
&& is_file($cache_path))
+  if ($CONFIG['enable_caching'] && is_dir($temp_dir)
&& is_file($cache_path))
     {
     if ($fp = fopen($cache_path, 'r'))
       {
@@ -1231,14 +1230,8 @@
     }
 
 
-  // create dir for caching
-  if (!is_dir($cache_dir))
-    $dir = mkdir($cache_dir);
-  else
-    $dir = true;
-
   // attempt to write a file with the message body    
-  if ($dir && ($fp = fopen($cache_path, 'w')))
+  if (is_dir($temp_dir) && ($fp = fopen($cache_path,
'w')))
     {
     fwrite($fp, $msg_source);
     fclose($fp);

Change History (4)

comment:1 Changed 7 years ago by thomasb

  • Description modified (diff)
  • Milestone 0.1-beta2 deleted
  • Owner changed from roundcube to thomasb
  • Severity changed from critical to normal
  • Status changed from assigned to new

comment:2 Changed 7 years ago by thomasb

  • Milestone set to 0.1-stable
  • Status changed from new to assigned

comment:3 Changed 7 years ago by thomasb

  • Milestone changed from 0.1-stable to 0.1-rc1
  • Version changed from None to 0.1-beta

comment:4 Changed 7 years ago by thomasb

  • Resolution changed from None to fixed
  • Status changed from assigned to closed

This issue went away with new message parsing where there is not message cache anymore. Other safe_mode issues have been fixed in [70d4b9a5]

Note: See TracTickets for help on using tickets.