Skip to content

Commit 8855933

Browse files
committed
postfix plugins should not corrupt settings "other" settings
fixes also some misconfiguration under some circonstances
1 parent 76c0bd3 commit 8855933

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

server/plugins-available/postfix_server_plugin.inc.php

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

8686
copy('/etc/postfix/main.cf', '/etc/postfix/main.cf~');
8787

88-
if($mail_config['relayhost'] != '') {
89-
exec("postconf -e 'relayhost = ".$mail_config['relayhost']."'");
90-
if($mail_config['relayhost_user'] != '' && $mail_config['relayhost_password'] != '') {
88+
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']) {
89+
$content = file_exists('/etc/postfix/sasl_passwd') ? file_get_contents('/etc/postfix/sasl_passwd') : '';
90+
$content = preg_replace('/^'.preg_quote($old_ini_data['email']['relayhost']).'\s+[^\n]*(:?\n|)/m','',$content);
91+
92+
if (!empty($mail_config['relayhost']) || !empty($mail_config['relayhost_user']) || !empty($mail_config['relayhost_password'])) {
93+
$content .= "\n".$mail_config['relayhost'].' '.$mail_config['relayhost_user'].':'.$mail_config['relayhost_password'];
94+
}
95+
96+
if (preg_replace('/^(#[^\n]*|\s+)(:?\n+|)/m','',$content) != '') {
9197
exec("postconf -e 'smtp_sasl_auth_enable = yes'");
9298
} else {
9399
exec("postconf -e 'smtp_sasl_auth_enable = no'");
94100
}
95-
exec("postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'");
96-
exec("postconf -e 'smtp_sasl_security_options ='");
97-
98-
// Store the sasl passwd
99-
$content = $mail_config['relayhost'].' '.$mail_config['relayhost_user'].':'.$mail_config['relayhost_password'];
101+
102+
exec("postconf -e 'relayhost = ".$mail_config['relayhost']."'");
100103
file_put_contents('/etc/postfix/sasl_passwd', $content);
101104
chmod('/etc/postfix/sasl_passwd', 0600);
102105
chown('/etc/postfix/sasl_passwd', 'root');
103106
chgrp('/etc/postfix/sasl_passwd', 'root');
107+
exec("postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'");
108+
exec("postconf -e 'smtp_sasl_security_options ='");
104109
exec('postmap /etc/postfix/sasl_passwd');
105110
exec($conf['init_scripts'] . '/' . 'postfix restart');
106-
107-
} else {
108-
exec("postconf -e 'relayhost ='");
109111
}
110112

111113
if($mail_config['realtime_blackhole_list'] != $old_ini_data['mail']['realtime_blackhole_list']) {

0 commit comments

Comments
 (0)