From b38c883e1dd580bca91469fcd77415bbe2fcb942 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Wed, 25 Jan 2012 07:22:37 -0500 Subject: [PATCH] Improved maildir path creation code as part of FS#1984 --- server/plugins-available/mail_plugin.inc.php | 13 +++++++------ server/lib/classes/system.inc.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/server/lib/classes/system.inc.php b/server/lib/classes/system.inc.php index 5de2f81..7537ef4 100644 --- a/server/lib/classes/system.inc.php +++ b/server/lib/classes/system.inc.php @@ -1253,6 +1253,24 @@ $app->log('Created Maildir '.$maildir_path.' with subfolder: '.$subfolder,LOGLEVEL_DEBUG); } + + //* Function to create directory paths and chown them to a user and group + function mkdirpath($path, $mode = 0755, $user = '', $group = '') { + $path_parts = explode('/',$path); + $new_path = ''; + if(is_array($path_parts)) { + foreach($path_parts as $part) { + $new_path .= '/'.$part; + if(!@is_dir($new_path)) { + mkdir($new_path); + chmod($new_path,$mode); + if($user != '') chown($new_path,$user); + if($group != '') chgrp($new_path,$group); + } + } + } + + } } ?> diff --git a/server/plugins-available/mail_plugin.inc.php b/server/plugins-available/mail_plugin.inc.php index 6781fb6..3e3d208 100644 --- a/server/plugins-available/mail_plugin.inc.php +++ b/server/plugins-available/mail_plugin.inc.php @@ -91,18 +91,18 @@ $tmp_basepath_parts = explode('/',$tmp_basepath); unset($tmp_basepath_parts[count($tmp_basepath_parts)-1]); $base_path = implode('/',$tmp_basepath_parts); - - //* Create the mail domain directory, if it does not exist if(!empty($base_path) && !is_dir($base_path)) { - exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']); + //exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']); + $app->system->mkdirpath($base_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); $app->log('Created Directory: '.$base_path,LOGLEVEL_DEBUG); } // Dovecot uses a different mail layout with a separate 'Maildir' subdirectory. if($mail_config['pop3_imap_daemon'] == 'dovecot') { - exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); + //exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); + $app->system->mkdirpath($maildomain_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); $app->log('Created Directory: '.$maildomain_path,LOGLEVEL_DEBUG); $maildomain_path .= '/Maildir'; } @@ -221,13 +221,14 @@ //* Create the mail domain directory, if it does not exist if(!empty($base_path) && !is_dir($base_path)) { - exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']); + //exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']); + $app->system->mkdirpath($base_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); $app->log('Created Directory: '.$base_path,LOGLEVEL_DEBUG); } // Dovecot uses a different mail layout with a separate 'Maildir' subdirectory. if($mail_config['pop3_imap_daemon'] == 'dovecot') { - exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); + $app->system->mkdirpath($maildomain_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); $app->log('Created Directory: '.$base_path,LOGLEVEL_DEBUG); $maildomain_path .= '/Maildir'; } -- Gitblit v1.9.1