#!/usr/bin/perl # Copyright (c) 2005 by Herb Rubin herbr@pfinders.com $version = "1.00"; # Purpose: To Fix mailing lists for Bluequartz majordomo to work with Sendmail 8.12 # This script does 3 things: # 1) Append lines to virtusertable for all mailing lists but use real hostname # 2) Remove group write permissions on majordomo list files to make sendmail happy # 3) patch majordomo.cf files to avoid an error email to admin upon every post to list # # Note: You should patch /usr/sausalito/handlers/base/maillist/listmod_virtusertable # based on Patrick's Post at: http://bluequartz.org/ml/archive/coba-e/1500/1590.html # # Supported Platform: Blue Quartz, tested on FC1 # Script covered under GPL license # Begin User Defined Section #---------------------------- my $hostname = `hostname`; chomp $hostname; my $mail_file = "/etc/mail/virtusertable"; my $major_dir = "/usr/local/majordomo"; #---------------------------- # End User Defined Section $progname = $0; $progname = $1 if ($progname =~ /([\w\._]+)$/); # trim off path use Getopt::Std; &getopts("tmhvV",\%Options); # get cmd line args, ":" means parameter follows letter &usage if ($Options{'h'}); # then exit if ($Options{"V"}) { print "$progname version $version\n"; exit 0; # good exit } chdir "/etc/mail"; $lists = `grep approval $mail_file`; # find all majordomo approval lines $added = 0; foreach $line (split /\n/, $lists) { chomp $line; if ($line =~ /^(\S+)-approval\@(\S+)\s+(\S+)-approval$/) { $external_list = $1; $virt_hostname = $2; $internal_list = $3; $virt_left = $internal_list . "-list\@$hostname"; $virt_right = $internal_list . "-list"; $site = `ls -l /home/sites/$virt_hostname`; chomp $site; if ($site =~ /\/(site\d+)$/) { ############################################# # remove group write to make sendmail happy # ############################################# $sitenum = $1; if (($Options{'v'}) or ($Options{'m'})) { print "$virt_hostname ($sitenum) mailing list:\t$external_list\n"; } if ($Options{'t'}) { print "chmod g-w: $major_dir/sites/$sitenum/lists/*\n"; } else { print "chmod g-w: $major_dir/sites/$sitenum/lists/*\n" if ($Options{'v'}); `chmod g-w $major_dir/sites/$sitenum/lists/*`; } ########################################################### # fix majordomo.cf files including template. Its to avoid # # an error email to admin on every post to mailing list. # ########################################################### &fix_cf("$major_dir/sites/$sitenum/majordomo.cf"); } $grep = `grep $virt_left $mail_file`; chomp $grep; if ($grep eq "") { if ($Options{'t'}) { print "append virtusertable: $virt_left\t$virt_right\n"; } else { `echo $virt_left\t$virt_right >> $mail_file`; $added ++; } } } } if ($added) { if ($Options{'t'}) { print "running make in /etc/mail\n"; } else { print "running make in /etc/mail\n" if ($Options{'v'}); my $make = `make`; print $make if ($Options{'v'}); } } print "added $added lines to $mail_file\n" if ($Options{'v'}); # ########################## # subroutines start here # ########################## sub fix_cf { ########################################################### # change undef to "" on line 255 in majordomo.cf to avoid # # excessive error emails to admin. # ########################################################### my ($fname) = @_; my $new_cf = ""; my $patched = 0; if (open CF, "<$fname") { while ($line = ) { chomp $line; if ($line =~ /^\$admin_body = undef/) { $new_cf .= "#$line\n"; # comment it out $new_cf .= "\$admin_body = \"\";\n"; $patched = 1; } else { $new_cf .= "$line\n"; # keep original lines } } close CF; if ($patched) { if (open CF, ">$fname") { print CF $new_cf; close CF; print "patched $fname\n"; } else { print "Error: could not open $fname for writing\n"; } } } } sub usage { print <