Skip to content

Commit cd51c37

Browse files
committed
use seperate config for amavis-dkim-config even is the systems uses a monolith config to prevent overwriting the key-config during updates
1 parent a15af77 commit cd51c37

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

install/dist/lib/centos_base.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function configure_amavis() {
4848
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
4949
$content = str_replace('{hostname}', $conf['hostname'], $content);
5050
$content = str_replace('/var/spool/amavisd/clamd.sock', $this->clamav_socket, $content);
51+
$content = str_replace('{amavis_config_dir}', $conf['amavis']['config_dir']);
5152
wf($conf["amavis"]["config_dir"].'/amavisd.conf', $content);
5253
chmod($conf['amavis']['config_dir'].'/amavisd.conf', 0640);
5354

install/dist/lib/opensuse.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ public function configure_amavis() {
507507
$content = str_replace('{mysql_server_port}', $conf["mysql"]["port"], $content);
508508
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
509509
$content = str_replace('{hostname}', $conf['hostname'], $content);
510+
$content = str_replace('{amavis_config_dir}', $conf['amavis']['config_dir']);
510511
wf($conf["amavis"]["config_dir"].'/amavisd.conf', $content);
511512
chmod($conf['amavis']['config_dir'].'/amavisd.conf', 0640);
512513

install/tpl/fedora_amavisd_conf.master

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ $banned_filename_re = new_RE(
711711
# package/port of an audio editor. Make sure the correct 'sweep' is found
712712
# in the path when enabling.
713713
#
714+
w
714715
# ### http://www.sophos.com/ - backs up Sophie or SAVI-Perl
715716
# ['Sophos Anti Virus (sweep)', 'sweep',
716717
# '-nb -f -all -rec -ss -sc -archive -cab -mime -oe -tnef '.
@@ -785,6 +786,7 @@ $LOGFILE = "/var/log/amavis.log"; # (defaults to empty, no log)
785786

786787
$log_level = 0; # (defaults to 0)
787788

789+
include_config_files('{amavis_config_dir}/60-dkim');
788790

789791
$enable_dkim_verification = 1;
790792
$enable_dkim_signing = 1; # load DKIM signing code

install/tpl/opensuse_amavisd_conf.master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ $DO_SYSLOG = 1;
779779
$LOGFILE = "/var/log/amavis.log"; # (defaults to empty, no log)
780780

781781
# DKIM
782-
782+
include_config_files('{amavis_config_dir}/60-dkim');
783783
$enable_dkim_verification = 1;
784784
$enable_dkim_signing = 1; # load DKIM signing code
785785
$signed_header_fields{'received'} = 0; # turn off signing of Received

server/plugins-available/mail_plugin_dkim.inc.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ function get_amavis_config() {
8787
break;
8888
}
8989
}
90-
//* If we can use seperate config-files with amavis use 60-dkim
91-
if (substr_compare($amavis_configfile, '50-user', -7) === 0)
90+
if (substr_compare($amavis_configfile, '50-user', -7) === 0) {
9291
$amavis_configfile = str_replace('50-user', '60-dkim', $amavis_configfile);
93-
92+
} else { //* fake 60-dkim on system with a monolithic amavis-config
93+
$amavis_configfile = str_replace('amavisd.conf', '60-dkim', $amavis_configfile);
94+
}
9495
return $amavis_configfile;
9596
}
9697

@@ -109,7 +110,7 @@ function check_system($data) {
109110
/* check for amavis-config */
110111
$amavis_configfile = $this->get_amavis_config();
111112

112-
//* When we can use 60-dkim for the dkim-keys create the file if it does not exists.
113+
//* Create the file if it does not exists.
113114
if (substr_compare($amavis_configfile, '60-dkim', -7) === 0 && !file_exists($amavis_configfile))
114115
$app->system->touch($amavis_configfile);
115116

@@ -120,12 +121,7 @@ function check_system($data) {
120121

121122
/* dir for dkim-keys writeable? */
122123
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
123-
if ( isset($mail_config['dkim_path']) &&
124-
!empty($mail_config['dkim_path']) &&
125-
// isset($data['new']['dkim_private']) &&
126-
// !empty($data['new']['dkim_private']) &&
127-
$mail_config['dkim_path'] != '/'
128-
) {
124+
if (isset($mail_config['dkim_path']) && !empty($mail_config['dkim_path']) && $mail_config['dkim_path'] != '/') {
129125
if (!is_dir($mail_config['dkim_path'])) {
130126
$app->log('DKIM Path '.$mail_config['dkim_path'].' not found - (re)created.', LOGLEVEL_DEBUG);
131127
if($app->system->is_user('amavis')) {
@@ -239,16 +235,18 @@ function add_to_amavis($key_domain, $selector, $old_selector) {
239235

240236
$search_regex = "/(\n|\r)?dkim_key\(\'".$key_domain."\',\ \'(".$selector."|".$old_selector."){1}?\'.*/";
241237

242-
//* If we are using seperate config-files with amavis remove existing keys from 50-user to avoid duplicate keys
238+
//* If we are using seperate config-files (no faked 60-dkim) with amavis remove existing keys from 50-user to avoid duplicate keys
243239
if (substr_compare($amavis_configfile, '60-dkim', -7) === 0) {
244240
$temp_configfile = str_replace('60-dkim', '50-user', $amavis_configfile);
245-
$temp_config = $app->system->file_get_contents($temp_configfile, true);
246-
if (preg_match($search_regex, $temp_config)) {
247-
$temp_config = preg_replace($search_regex, '', $temp_config)."\n";
248-
$app->system->file_put_contents($temp_configfile, $temp_config, true);
241+
if(file_exists($temp_configfile)) {
242+
$temp_config = $app->system->file_get_contents($temp_configfile, true);
243+
if (preg_match($search_regex, $temp_config)) {
244+
$temp_config = preg_replace($search_regex, '', $temp_config)."\n";
245+
$app->system->file_put_contents($temp_configfile, $temp_config, true);
246+
}
247+
unset($temp_config);
249248
}
250249
unset($temp_configfile);
251-
unset($temp_config);
252250
}
253251

254252
$key_value="dkim_key('".$key_domain."', '".$selector."', '".$mail_config['dkim_path']."/".$key_domain.".private');\n";
@@ -285,17 +283,19 @@ function remove_from_amavis($key_domain) {
285283
$restart = true;
286284
}
287285

288-
//* If we are using seperate config-files with amavis remove existing keys from 50-user, too
286+
//* If we are using seperate config-files (no faked 60-dkim) with amavis remove existing keys from 50-user to avoid duplicate keys
289287
if (substr_compare($amavis_configfile, '60-dkim', -7) === 0) {
290288
$temp_configfile = str_replace('60-dkim', '50-user', $amavis_configfile);
291-
$temp_config = $app->system->file_get_contents($temp_configfile, true);
292-
if (preg_match($search_regex, $temp_config)) {
293-
$temp_config = preg_replace($search_regex, '', $temp_config);
294-
$app->system->file_put_contents($temp_configfile, $temp_config, true);
295-
$restart = true;
289+
if(file_exists($temp_configfile)) {
290+
$temp_config = $app->system->file_get_contents($temp_configfile, true);
291+
if (preg_match($search_regex, $temp_config)) {
292+
$temp_config = preg_replace($search_regex, '', $temp_config);
293+
$app->system->file_put_contents($temp_configfile, $temp_config, true);
294+
$restart = true;
295+
}
296+
unset($temp_configfile);
297+
unset($temp_config);
296298
}
297-
unset($temp_configfile);
298-
unset($temp_config);
299299
}
300300

301301
return $restart;

0 commit comments

Comments
 (0)