@@ -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 }
0 commit comments