CfgTie

 view release on metacpan or  search on metacpan

bin/mail-validate  view on Meta::CPAN

use CfgTie::TieGroup;

# Set up the hooks to the users and groups:
my (%Users, %Groups,%GIds,%UIds);
tie %Users, 'CfgTie::TieUser';
tie %Groups,'CfgTie::TieGroup';
tie %GIds,'CfgTie::TieGroup_id';
tie %UIds,'CfgTie::TieUser_id';

# Check out the folder itself
my @S=stat $Spool;

if ($Verbose & 0x1) {print $Msgs->{phase1};}
if (($S[2] & 0xfff) != 0x3fd)
  {
     #The permissions for the mail spool are unusual
     if ($Verbose & 0x4) {print ".",$Msgs->{mailodd};}

     if ($Verbose & 0x8)
       {
          #Describe the situation to the user
          if ($S[2] & 2)      {print "..",$Msgs->{allwrite};}
          if (!($S[2]&0x200)) {print "..",$Msgs->{stickymissing};}
       }

     #Make a recommendation
     if ($Verbose & 0x10) {print ".",$Msgs->{spoolrec};}

     #Explain the recommendation
     if ($Verbose & 0x20) {print ".",$Msgs->{spoolwhy};}
  }
 elsif ($Verbose & 0x2) {print ".",$Msgs->{okay1};}


if ($Verbose & 0x1) {print "\n",$Msgs->{phase2};}

my $D;
opendir D, $Spool;
my ($S,$P,@Files)=readdir D;
closedir D;

foreach my $I (@Files)
{
   if (exists $Users{$I}) {next;}

   #These is a mail folder for a none existent user: is someone hiding files
   #here?
   if ($Verbose & 0x4)
     {
        my $A = $Msgs->{nouser};
        $A =~ s/\\1/$I/g;
        print ".$A";
     }
}

if ($Verbose & 0x1) {print "\n",$Msgs->{phase3};}

my $GID = $Groups{'mail'}->{id};
foreach $I (@Files)
{
   @S = stat($Spool.'/'.$I);
   if ($GID != $S[5])
     {
        #The group owner is wrong.
        if ($Verbose & 0x8)
          {
             my $A = $Msgs->{badgroup};
             $A=~s/\\1/$I/g;
             print ".$A";
          }
        if ($Verbose & 0x10)
          {
             my $A = $Msgs->{groupshould};
             my $B = $GIds{$S[5]}->{'name'};
             $A=~s/\\1/$B/g;
             print "..$A";
          }
     }
   if ($Users{$I}->{id} != $S[4])
     {
        #The owner is wrong.
        if ($Verbose & 0x8)
          {
             my $A = $Msgs->{badowner};
             $A=~s/\\1/$1/g;
             print ".$A";
          }
        if ($Verbose & 0x10)
          {
             my $A = $Msgs->{usershould};
             my $B = $UIds{$S[4]}->{'name'};
             $A=~s/\\1/$B/g;
             $A=~s/\\2/$I/g;
             print "..$A";
          }
     }
   if (($S[2]&0xfff) !=0x1b0)
     {
        if ($Verbose & 0x8)
          {
             my $A = $Msgs->{badperms};
             $A=~s/\\1/$I/g;
             print ".$A";
          }
        if (!($S[2]&0x100)) {print "..",$Msgs->{cantread};}
        if (!($S[2]&0x080)) {print "..",$Msgs->{cantdelete};}
        if (($S[2]&0x030)!=0x30)
          {print "..The mail daemon isn't allowed to deliver mail to the user\n";}
        if (($S[2]&0x06))
          {print "..The general public can see or modify the users mail\n";}
        if (($S[2]&0x49))
          {print "..The file is marked executable.  No one should be allowed to execute it: otherwise anyone could email scripts or other badness.\n";}

        print ".The permissions should be 660\n"; 
     }
}



( run in 1.150 second using v1.01-cache-2.11-cpan-389fe586d7c )