Rebuild RaQ 550 virtusertable

From CobaltFAQs

Jump to: navigation, search

This solution comes originally from the Sun Support Forums, and has been slightly edited and altered for display here.


How do I rebuild the virtusertable if it becomes corrupt?


SSH into the server as admin, then become root:

 su –

Backup the /etc/mail/virtusertable file:

 cd /etc/mail
 cp virtusertable virtusertable.safe

The following Perl script will write a new virtusertable file from the contents of the CCE database. Put the following into rebuild_vut.pl and then do

 chmod 0755 rebuild_vut.pl

to make it executable.

#!/usr/bin/perl

# virtusertable rebuilder v .03
# by Jonathan Eaton
# jon@namesarecheap.com
# WORKS ONLY WITH THE COBALT RAQ 550

use strict;
use lib "/usr/sausalito/perl";
use CCE;
use Data::Dumper;

my $cce = new CCE;
my %vsites = ();

$cce->connectuds();
print "GETTING EMAIL ALIASES\n";
my @oids = $cce->find('EmailAlias');

foreach my $oid (@oids) {
  my ($ok, $cceObj) = $cce->get($oid);
  $vsites{$cceObj->{site}}{users}{$cceObj->{action}}{$cceObj->{alias}} = 1;
}

print "CROSS-REFERENCING EMAIL ALIASES FROM USER CLASS\n";

my @oids = $cce->find('User');
foreach my $oid (@oids) {
  my ($ok, $cceObj) = $cce->get($oid);
  my $user = $cceObj->{name};
  my $site = $cceObj->{site};
  my ($ok, $cceObj) = $cce->get($oid, 'Email');
  my @aliases = split( '&', $cceObj->{aliases});
  shift @aliases;
  foreach my $alias (@aliases){
    $vsites{$site}{users}{$user}{$alias} = 1;
  }	
}

print "GETTING PROTECTED EMAIL ALIASES\n";	
my @oids = $cce->find('ProtectedEmailAlias');		
foreach my $oid (@oids) {
  my ($ok, $cceObj) = $cce->get($oid);
  $vsites{$cceObj->{site}}{users}{$cceObj->{action}}{$cceObj->{alias}} = 1;
}	

print "GETTING VSITE INFO, CATCHALL, AND DOMAIN EMAIL ALIASES\n";
my @oids = $cce->find('Vsite');		
foreach my $oid (@oids) {
  my ($ok, $cceObj) = $cce->get($oid);
  $vsites{$cceObj->{name}}{fqdn} = $cceObj->{fqdn};
  my @domain_aliases = split( '&', $cceObj->{mailAliases});
  shift @domain_aliases;
  @{$vsites{$cceObj->{name}}{domain_aliases}} = @domain_aliases;
  if ($cceObj->{mailCatchAll}){
    $vsites{$cceObj->{name}}{catchall} = $cceObj->{mailCatchAll};
  }
}	

print "REBUILDING NEW VIRTUSERTABLE IN ./\n";		
my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
my $vut = <<EOF;
# VIRTUSERTABLE Rebuilt: $Month-$Day-$Year
EOF

foreach my $site (sort keys %vsites){
  my $fqdn = $vsites{$site}{fqdn};
  next if !$fqdn;
  $vut .= "#START: $fqdn - $site\n";

  foreach my $domain_alias (sort @{$vsites{$site}{domain_aliases}}){
    $vut .= "\@$domain_alias\t\%1\@$fqdn\n";
  }

  $vut .= "\@$fqdn\t" . $vsites{$site}{catchall} ."\n" if $vsites{$site}{catchall};

  foreach my $user (sort keys %{$vsites{$site}{users}}){
    next if $user eq "\%1\@$fqdn"; 

    foreach my $alias (sort keys %{$vsites{$site}{users}{$user}}){
      next if ($vsites{$site}{catchall} eq $user) and !$alias;
      next if $alias eq "\@$fqdn";
      $vut .= "$alias\@$fqdn\t$user\n";
    }
  }
  $vut .= "\n";	
}		

$vut .= "\n#ENTRIES BELOW ADDED AFTER REBUILD\n\n";
open (FILE, ">>" . "./virtusertable"); 
flock(FILE, 2); 
print FILE "$vut"; 
close FILE;


Once you have created the Perl script and made it executable, do the following steps:

 mv /etc/mail/virtusertable /etc/mail/virtusertable.bak
 mv /etc/mail/virtusertable.db /etc/mail/virtusertable.db.bak
 ./rebuild_vut.pl
 chown bin.bin /etc/mail/virtusertable
 makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable

At this point, the virtusertable file has been recreated, and the hashed file has been rebuilt with the new data so that sendmail can use it. If sendmail is working properly, you can remove the backup virtusertable file:

 rm /etc/mail/virtusertable.safe
Personal tools