#!/usr/bin/perl -w -I/usr/local/raqdevil/perl/ -I/usr/local/raqdevil/handlers/base/email/ # $Id: mapmaker.pl,v 1.2 2005/08/15 04:14:54 dodell Exp $ # Copyright 2000, 2001 Sun Microsystems, Inc., All rights reserved. # Author: Harris Vaegan-Lloyd # Make maps of all the text files in /etc/mail/ use strict; use CCE; use Email; use Sauce::Util; my $cce = new CCE( Domain => 'base-email' ); $cce->connectfd(); my $obj = $cce->event_object(); if ($cce->event_is_destroy()) { $obj = $cce->event_old(); } # check for explicit property saying whether to rebuild # the maps if (exists($obj->{build_maps}) && !$obj->{build_maps}) { # explicit property saying to not build maps my ($ok) = $cce->set($cce->event_oid(), $cce->event_namespace(), { 'build_maps' => 1 }); $cce->bye('SUCCESS'); exit(0); } # Hacky virtusertable auto-sort # Sauce::Util::editfile('/etc/mail/virtusertable', *sortvirtuser); foreach my $file (($Email::ACCESS, $Email::VIRTUSER)) { if( ! makemap($file) ) { $cce->warn("couldnt_make_map", { file => $file } ); $cce->bye("FAIL"); exit 1; } } $cce->bye("SUCCESS"); exit 0; sub makemap { my $map = shift; # Yes, I know this could have been done in a shorter manner, but handling # shell return values in perl always makes me do a double take so I # took the clearest path, ratehr than the shortest. if( system("/usr/sbin/makemap hash $map < $map >>/dev/null 2>&1") == 0 ) { return 1; } else { return 0; } } sub sortvirtuser { my($in, $out) = @_; my ($routes, $ca, $users); while(<$in>) { if(/^\@/ && /\%/) { $routes .= $_; } elsif (/^@/) { $ca .= $_; } elsif (/\@/) { $users .= $_; } elsif (/(catch-all email|accept-email-at)/) { next; } else { print $out $_; } } print $out <