diff options
Diffstat (limited to 'debian/local/Parse_mc.pm.in')
-rw-r--r-- | debian/local/Parse_mc.pm.in | 197 |
1 files changed, 174 insertions, 23 deletions
diff --git a/debian/local/Parse_mc.pm.in b/debian/local/Parse_mc.pm.in index a80b754..e21d61d 100644 --- a/debian/local/Parse_mc.pm.in +++ b/debian/local/Parse_mc.pm.in @@ -16,7 +16,6 @@ # * changes made herein *must* be reflected in # parse_mc,update_mk,update_db,debian.m4 # * userdb can also have multiple databases and then a forward! -# * Cert support # * undefine support # * include support (also for OSTYPE, DOMAIN, SITE, etc) # * F and K lines @@ -29,7 +28,7 @@ require Exporter; @ISA = qw(Exporter); #@EXPORT = qw(read_mc write_dbs read_dbs); @EXPORT_OK = qw(read_mc write_dbs read_dbs - names_dbs restart_dbs entry_dbs); + names_dbs restart_dbs entry_dbs format_dbs); $VERSION = '2.0002'; # # Initialization of the perl environment @@ -50,6 +49,7 @@ use FileHandle; # I/O $Parse_mc::program_name = 'Parse_mc.pm'; $Parse_mc::program_version = '@sm_version@'; $Parse_mc::program_date = '@sm_date@ @sm_time@ cowboy'; +$Parse_mc::debug = 0; my $interp_pgm = "$^X"; my $interp_vrm = $]; @@ -59,6 +59,7 @@ my $user = getlogin || (getpwuid($<))[$[] || "Unknown!!"; my $hostname = hostname(); my $directory = getcwd(); +$Parse_mc::Conffile = "@sysconfdir@/mail/databases"; $Parse_mc::input_files = "@sysconfdir@/mail/sendmail.mc"; $Parse_mc::database_file = "@sysconfdir@/mail/databases"; @@ -114,10 +115,12 @@ my %smdb_classes = ( my $smdb_loc = "@sysconfdir@/mail/"; my $smdb_type = 'hash'; my %smdb_hash = ( +# ----------- Database defaults 'MAIL_SETTINGS_DIR' => ['-','-',["${smdb_loc}"],'-'] ,'DATABASE_MAP_TYPE' => ["${smdb_type}",'-',['-'],'-'] +# ----------- General stuff ,'sendmail.cf' => ['m4','-',["${smdb_loc}sendmail.mc"],'-'] @@ -145,7 +148,6 @@ my %smdb_hash = ( ['-','-',["@localstatedir@/lib/sendmail/sendmail.st"],'-'] # ,'VIRTUSER_DOMAIN_FILE' => # ['-','-',["${smdb_loc}virtual-domains"],'%[^\\#]'] - ,'confCONTROL_SOCKET_NAME' => ['-','-',["@localstatedir@/run/sendmail/smcontrol"],'-'] ,'confCR_FILE' => @@ -172,6 +174,35 @@ my %smdb_hash = ( ['-','-',["${smdb_loc}service.switch"],'-'] # ,'confUSERDB_SPEC' => # ['btree','-o',["${smdb_loc}userdb"],'-'] +# ----------- STARTTLS + ,'confTO_STARTTLS' => + ['-','-',["2m"],'-'] + ,'confCACERT' => + ['-','-',["${smdb_loc}tls/sendmail-server.crt"],'-'] + ,'confCACERT_PATH' => + ['-','-',["@sysconfdir@/ssl/certs"],'-'] + ,'confCRL' => + ['-','-',[""],'-'] + ,'confCLIENT_CERT' => + ['-','-',["${smdb_loc}tls/sendmail-client.crt"],'-'] + ,'confCLIENT_KEY' => + ['-','-',["${smdb_loc}tls/sendmail-common.key"],'-'] + ,'confSERVER_CERT' => + ['-','-',["${smdb_loc}tls/sendmail-server.crt"],'-'] + ,'confSERVER_KEY' => + ['-','-',["${smdb_loc}tls/sendmail-common.key"],'-'] + ,'confTLS_SRV_OPTIONS' => + ['-','-',["V"],'-'] +# ----------- SMTP AUTH (SASL) + ,'confTO_AUTH' => + ['-','-',["2m"],'-'] + ,'confAUTH_MECHANISMS' => + ['-','-',["DIGEST-MD5 CRAM-MD5 NTLM LOGIN PLAIN"],"-"] + ,'TRUST_AUTH_MECH' => + ['-','-',["DIGEST-MD5 CRAM-MD5 NTLM LOGIN PLAIN"],"-"] + ,'confAUTH_REALM' => + ['-','-',[""],'-'] + , ); # # @@ -179,6 +210,9 @@ my %smdb_hash = ( $smdb_hash{'databases'} = ['parse_mc','-',["${smdb_loc}sendmail.mc"],'-']; $smdb_hash{'Makefile'} = ['update_mk','-',["${smdb_loc}databases"],'-']; $smdb_hash{'crontab'} = ['update_conf','-',["${smdb_loc}sendmail.conf"],'-']; +$smdb_hash{'auth'} = ['update_auth','-',["${smdb_loc}sasl/sasl.m4"],'-']; +$smdb_hash{'tls'} = ['update_tls','-',["${smdb_loc}tls/starttls.m4"],'-']; +$smdb_hash{'include'} = ['-','-',[""],'-']; # # Conditional entries if ( -s "${smdb_loc}submit.mc" ) { @@ -201,6 +235,7 @@ my %smdb_restart = ( ,'confCR_FILE' => 1 ,'use_ct_file' => 1 ,'use_cw_file' => 1 + ,'crontab' => 1 ); $smdb_restart{'sendmail.cf'} = 1; @@ -221,6 +256,9 @@ my $smdb_flags = ''; my $smdb_options = ''; my $smdb_default = ''; +my $QUEUE_GROUPS = 0; +my $INCLUDES = 0; + #------------------------------------------------------------------------------ # Finally, some code (almost) #------------------------------------------------------------------------------ @@ -232,27 +270,22 @@ my $smdb_default = ''; #------------------------------------------------------------------------------ sub read_mc { my ($input_files) = @_; - @ARGV = split(' ', $input_files); - if ($#ARGV == -1) { - my @files = ( - '/usr/share/sendmail/cf/ostype/linux.m4' - ,'/usr/share/sendmail/cf/ostype/debian.m4' - ,'/usr/share/sendmail/cf/domain/debian-mta.m4' - ,"@sysconfdir@/mail/sendmail.mc" - ); - foreach my $file ( @files ) { - push @ARGV, $file if ( -s $file ); - }; - }; - $input_files = join(' ', @ARGV); + my $ifh = new FileHandle; + + $input_files = $input_files || $Parse_mc::input_files; $Parse_mc::input_files = $input_files; - die "No input files" if ($#ARGV == -1); $debug = $main::debug || ''; + unless ( open($ifh, "<$input_files") ) { + warn("Could not open $input_files($!)\n"); + return; + }; +#print "Reading files:",$input_files,"\n"; + #------------------------------------------------------------------ # Main loop, iterate over all input lines #------------------------------------------------------------------ - line: while (<ARGV>) { + line: while (<$ifh>) { next line if /^#/; # skip comments next line if /^$/; # skip empty lines chomp; # drop tailing \n @@ -260,6 +293,7 @@ sub read_mc { $_ .= <>; redo unless eof(); }; +#print "=>",$_,"\n"; #-------------------------------------------------------------- # Look for default database location @@ -405,9 +439,72 @@ sub read_mc { @smdb_file = ($2); $smdb_options = '-'; # Pull out other options? - &put_entry($ARGV, '', 1); + if ( $QUEUE_GROUPS == 0 ) { + &put_entry($ARGV, '', 0); + $QUEUE_GROUPS = 1; + } + else { + &put_entry($ARGV, '', 1); + }; } + #-------------------------------------------------------------- + # Look for all AUTH specifications + # define(confAUTH_MECHANISMS ...)dnl + # define(confAUTH_REALM ...)dnl + # TRUST_AUTH_MECH( ...)dnl + #-------------------------------------------------------------- + elsif (/^\s*`?define\(\s*`?confAUTH_(MECHANISMS|REALM)/ .. + /[^\)]*\)/) { + &parse_string($_, 'define'); + next line if ($smdb_state != $smdb_state_done); + + next line if ($smdb_string =~ /.*defn\(/); + + &get_flags_name_opts; + + push(@smdb_file, split(' ',$smdb_options)) + if ($smdb_options ne '-'); + $smdb_options = '-'; + + &put_entry($ARGV, 'define'); + } + elsif (/^\s*`?TRUST_AUTH_MECH\(/ .. + /[^\)]*\)/) { + &parse_string($_, '('); + next line if ($smdb_state != $smdb_state_done); + + next line if ($smdb_string eq ' EXTERNAL'); + + &get_flags_name_opts; + + push(@smdb_file, split(' ',$smdb_options)); + $smdb_options = '-'; + + &put_entry($ARGV, ''); + } + + #-------------------------------------------------------------- + # Look for all TLS specifications + # define(confCACERT, ...)dnl + # define(confCACERT_PATH, ...)dnl + # define(confCRL, ...)dnl + # define(confCLIENT_CERT, ...)dnl + # define(confCLIENT_KEY, ...)dnl + # define(confSERVER_CERT, ...)dnl + # define(confSERVER_KEY, ...)dnl + # define(confTLS_SRV_OPTIONS, ...)dnl + #-------------------------------------------------------------- + elsif (/^\s*`?define\(\s*`?conf(TO_STARTTLS|CACERT|CRL|((SERVER|CLIENT)_(KEY|CERT))|TLS_SRV_OPTIONS)/ .. + /[^\)]*\)/) { + &parse_string($_, 'define'); + next line if ($smdb_state != $smdb_state_done); + + &get_flags_name_opts; + + &put_entry($ARGV, 'define'); + } + # #-------------------------------------------------------------- # Locate all non-commented FEATURE macros @@ -432,12 +529,46 @@ sub read_mc { @smdb_file = ("${smdb_loc}$smdb_features{$smdb_name}") if ($smdb_file[$[] eq '-' - and $smdb_class ne 'ldap'); + and $smdb_class ne 'ldap'); $smdb_class = $smdb_type if ($smdb_class eq '-'); }; &put_entry($ARGV, 'FEATURE'); + } + + elsif (/^\s*`?(OSTYPE|DOMAIN|include)\(/ .. /[^\)]*/) { + &parse_string($_, '('); + next line if ($smdb_state != $smdb_state_done); + + next line if ($smdb_name eq 'include' + and $smdb_string =~ /^\s*`?_CF_DIR/); + + $smdb_string =~ /\s*`?([^'\)\s]+)/; + $smdb_string = $1; + if ($smdb_name eq 'OSTYPE') { + $smdb_string = + "@datadir@/sendmail/cf/ostype/$smdb_string.m4"; + } + elsif ($smdb_name eq 'DOMAIN') { + $smdb_string = + "@datadir@/sendmail/cf/domain/$smdb_string.m4"; + }; + + $smdb_name = 'include'; + $smdb_class = '-'; # $1 + $smdb_flags = '-'; + @smdb_file = ($smdb_string); + $smdb_options = '-'; # Pull out other options? + + if ($INCLUDES == 0) { + &put_entry($ARGV, 'include', 0); + $INCLUDES = 1; + } + else { + &put_entry($ARGV, 'include', 1); + }; + &read_mc("$smdb_string"); }; }; }; @@ -526,7 +657,7 @@ EOT }; close($ofh); - if ($database_file eq "@sysconfdir@/mail/databases") { + if ($database_file eq $Parse_mc::Conffile) { chown '0', '0', "$database_file"; chmod 0644, "$database_file"; }; @@ -718,6 +849,24 @@ sub get_entry { }; # +# +sub format_dbs { + my ($name) = @_; + my $string = ''; + + &get_entry($name); + $string .= " $smdb_class" + if ($smdb_class ne '-' and $smdb_class ne ' '); + $string .= " $smdb_flags" + if ($smdb_flags ne '-' and $smdb_flags ne ' '); + $string .= join(',', @smdb_file); + $string .= " $smdb_options" + if ($smdb_options ne '-' and $smdb_options ne ' '); + + return $string; + }; + +# #------------------------------------------------------------------------------ # This function does most of the work in parsing a series of lines to # construct a database entry - it manages the state machine and assorted @@ -773,7 +922,7 @@ sub parse_string { $smdb_state = $pending_state || $smdb_state_start; $smdb_string = ''; $count = (@entry = split(' ', $str)); - ($smdb_name = $entry[$[]) =~ tr/'//d; + ($smdb_name = $entry[$[]) =~ tr/`'//d; shift(@entry); $str = join(' ', @entry); } @@ -786,7 +935,9 @@ sub parse_string { $str =~ tr/`'//d; # FEATURE( is the only one allowed to have only one argument - if ($type ne 'FEATURE' and $count == 1) { + if ( ($type ne 'FEATURE' + and $type ne '(') + and $count == 1) { $str = ''; }; |