Skip to content

Commit c0651ed

Browse files
committed
fix issues from MR 1053 review
1 parent 015a175 commit c0651ed

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

install/lib/installer_base.lib.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ public function get_postfix_service($service, $type) {
876876
$postfix_service = @($out[0]=='')?false:true;
877877
} else { //* fallback - Postfix < 2.9
878878
$content = rf($conf['postfix']['config_dir'].'/master.cf');
879-
$regex = "/^((?!#)".$service.".*".$type.".*)$/m";
880-
$postfix_service = @(preg_match($regex, $content))?true:false;
879+
$quoted_regex = "^((?!#)".preg_quote($service, '/').".*".preg_quote($type, '/').".*)$";
880+
$postfix_service = @(preg_match("/$quoted_regex/m", $content))?true:false;
881881
}
882882

883883
return $postfix_service;
@@ -915,18 +915,19 @@ public function remove_postfix_service( $service, $type ) {
915915
while ( !feof( $cf ) ) {
916916
$line = fgets( $cf );
917917

918+
$quoted_regex = '^'.preg_quote($service, '/').'\s+'.preg_quote($type, '/');
918919
if ( $reading_service ) {
919920
# regex matches a new service or "empty" (whitespace) line
920921
if ( preg_match( '/^([^\s#]+.*|\s*)$/', $line ) &&
921-
! preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
922+
! preg_match( "/$quoted_regex/", $line ) ) {
922923
$out .= $line;
923924
$reading_service = false;
924925
}
925926

926927
# $skipped_lines .= $line;
927928

928929
# regex matches definition matching service to be removed
929-
} else if ( preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
930+
} else if ( preg_match( "/$quoted_regex/", $line ) ) {
930931

931932
$reading_service = true;
932933
# $skipped_lines .= $line;
@@ -1157,13 +1158,13 @@ public function configure_postfix($options = '') {
11571158
if(is_file('/var/run/courier/authdaemon/')) caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
11581159

11591160
//* Check maildrop service in posfix master.cf
1160-
$regex = "/^maildrop unix.*pipe flags=DRhu user=vmail argv=\\/usr\\/bin\\/maildrop -d ".$cf['vmail_username']." \\$\{extension} \\$\{recipient} \\$\{user} \\$\{nexthop} \\$\{sender}/";
1161+
$quoted_regex = '^maildrop unix.*pipe flags=DRhu user=vmail '.preg_quote('argv=/usr/bin/maildrop -d '.$cf['vmail_username'].' ${extension} ${recipient} ${user} ${nexthop} ${sender}', '/');
11611162
$configfile = $config_dir.'/master.cf';
11621163
if($this->get_postfix_service('maildrop', 'unix')) {
11631164
exec ("postconf -M maildrop.unix 2> /dev/null", $out, $ret);
1164-
$change_maildrop_flags = @(preg_match($regex, $out[0]) && $out[0] !='')?false:true;
1165+
$change_maildrop_flags = @(preg_match("/$quoted_regex/", $out[0]) && $out[0] !='')?false:true;
11651166
} else {
1166-
$change_maildrop_flags = @(preg_match($regex, $configfile))?false:true;
1167+
$change_maildrop_flags = @(preg_match("/$quoted_regex/", $configfile))?false:true;
11671168
}
11681169
if ($change_maildrop_flags) {
11691170
//* Change maildrop service in posfix master.cf
@@ -1343,6 +1344,7 @@ public function configure_dovecot() {
13431344
}
13441345

13451346
$config_dir = $conf['postfix']['config_dir'];
1347+
$quoted_config_dir = preg_quote($config_dir, '/');
13461348
$postfix_version = `postconf -d mail_version 2>/dev/null`;
13471349
$postfix_version = preg_replace( '/mail_version\s*=\s*(.*)\s*/', '$1', $postfix_version );
13481350

@@ -1375,11 +1377,12 @@ public function configure_dovecot() {
13751377
// Make a backup copy of the main.cf file
13761378
copy($config_dir.'/main.cf', $config_dir.'/main.cf~3');
13771379

1378-
$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
1380+
$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
13791381
$new_options = array();
13801382
foreach ($options as $value) {
1381-
if (($value = trim($value)) == '') continue;
1382-
if (preg_match("|check_recipient_access\s+proxy:mysql:${config_dir}/mysql-verify_recipients.cf|", $value)) {
1383+
$value = trim($value);
1384+
if ($value == '') continue;
1385+
if (preg_match("|check_recipient_access\s+proxy:mysql:${quoted_config_dir}/mysql-verify_recipients.cf|", $value)) {
13831386
continue;
13841387
}
13851388
$new_options[] = $value;
@@ -1638,10 +1641,11 @@ public function configure_rspamd() {
16381641
exec("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated'");
16391642

16401643

1641-
$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
1644+
$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
16421645
$new_options = array();
16431646
foreach ($options as $value) {
1644-
if (($value = trim($value)) == '') continue;
1647+
$value = trim($value);
1648+
if ($value == '') continue;
16451649
if (preg_match('/check_policy_service\s+inet:127.0.0.1:10023/', $value)) {
16461650
continue;
16471651
}

server/plugins-available/postfix_server_plugin.inc.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function update($event_name, $data) {
8585

8686
if ($mail_config['relayhost'].$mail_config['relayhost_user'].$mail_config['relayhost_password'] != $old_ini_data['mail']['relayhost'].$old_ini_data['mail']['relayhost_user'].$old_ini_data['mail']['relayhost_password']) {
8787
$content = file_exists('/etc/postfix/sasl_passwd') ? file_get_contents('/etc/postfix/sasl_passwd') : '';
88-
$content = preg_replace('/^'.preg_quote($old_ini_data['email']['relayhost']).'\s+[^\n]*(:?\n|)/m','',$content);
88+
$content = preg_replace('/^'.preg_quote($old_ini_data['email']['relayhost'], '/').'\s+[^\n]*(:?\n|)/m','',$content);
8989

9090
if (!empty($mail_config['relayhost_user']) || !empty($mail_config['relayhost_password'])) {
9191
$content .= "\n".$mail_config['relayhost'].' '.$mail_config['relayhost_user'].':'.$mail_config['relayhost_password'];
@@ -114,10 +114,11 @@ function update($event_name, $data) {
114114
if($rbl_hosts != ''){
115115
$rbl_hosts = explode(",", $rbl_hosts);
116116
}
117-
$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
117+
$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
118118
$new_options = array();
119119
foreach ($options as $key => $value) {
120-
if (($value = trim($value)) == '') continue;
120+
$value = trim($value);
121+
if ($value == '') continue;
121122
if (!preg_match('/reject_rbl_client/', $value)) {
122123
$new_options[] = $value;
123124
} else {
@@ -142,7 +143,7 @@ function update($event_name, $data) {
142143
}
143144

144145
if($mail_config['reject_sender_login_mismatch'] != $old_ini_data['mail']['reject_sender_login_mismatch']) {
145-
$options = explode(", ", exec("postconf -h smtpd_sender_restrictions"));
146+
$options = preg_split("/,\s*/", exec("postconf -h smtpd_sender_restrictions"));
146147
$new_options = array();
147148
foreach ($options as $key => $value) {
148149
if (!preg_match('/reject_authenticated_sender_login_mismatch/', $value)) {
@@ -193,12 +194,13 @@ function update($event_name, $data) {
193194
}
194195
}
195196

196-
$postfix_config_dir = $conf['postfix']['config_dir'];
197+
$quoted_postfix_config_dir = preg_quote($conf['postfix']['config_dir'], '|');
197198
$new_options = array();
198-
$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
199+
$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
199200
foreach ($options as $key => $value) {
200-
if (($value = trim($value)) == '') continue;
201-
if (preg_match("|check_recipient_access\s+proxy:mysql:${postfix_config_dir}/mysql-verify_recipients.cf|", $value)) {
201+
$value = trim($value);
202+
if ($value == '') continue;
203+
if (preg_match("|check_recipient_access\s+proxy:mysql:${quoted_postfix_config_dir}/mysql-verify_recipients.cf|", $value)) {
202204
continue;
203205
}
204206
$new_options[] = $value;
@@ -231,9 +233,10 @@ function update($event_name, $data) {
231233
exec("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated'");
232234

233235
$new_options = array();
234-
$options = explode(",", exec("postconf -h smtpd_recipient_restrictions"));
236+
$options = preg_split("/,\s*/", exec("postconf -h smtpd_recipient_restrictions"));
235237
foreach ($options as $key => $value) {
236-
if (($value = trim($value)) == '') continue;
238+
$value = trim($value);
239+
if ($value == '') continue;
237240
if (preg_match('/check_policy_service\s+inet:127.0.0.1:10023/', $value)) {
238241
continue;
239242
}

0 commit comments

Comments
 (0)