Le mardi 08 février 2011 à 20:52 +0100, david touzeau a écrit :
> Le jeudi 03 février 2011 à 11:41 +0100, david touzeau a écrit :
> > Le jeudi 03 février 2011 à 01:31 +0100, Mark Martinec a écrit :
> > > David,
> > > 
> > > > On ubuntu 10.10 we encounter now this error since some perl lib updates
> > > 
> > > Which version or amavisd? Do you happen to know which perl modules
> > > were updated?
> > > 
> > > > amavis claim Feb 1 14:37:25 rez14 amavis[29857]: (29857-04) (!)custom
> > > > checks error: Insecure dependency in connect while running with -T
> > > > switch at /usr/lib/perl/5.10/IO/Socket.pm line 114
> > > 
> > > What is that custom hook doing (a method checks() in custom hooks).
> > > 
> > > > How can we fix it ?
> > > > 
> > > > in this file we have this
> > > > 
> > > > # cat -n /usr/lib/perl/5.10/IO/Socket.pm|grep 114
> > > > 114 if (!connect($sock, $addr)) {
> > > 
> > > Probably the $addr is tainted. Where does it come from?
> > > If you know it is safe to use (do some test before, just in case),
> > > you may untaint it by calling Amavis::Util::untaint, e.g.:
> > > 
> > >   if (!connect($sock, Amavis::Util::untaint($addr))) {
> > > 
> > > 
> > > Mark
> > > 
> > > ------------------------------------------------------------------------------
> > > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> > > Finally, a world-class log management solution at an even better 
> > > price-free!
> > > Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
> > > February 28th, so secure your free ArcSight Logger TODAY! 
> > > http://p.sf.net/sfu/arcsight-sfd2d
> > > _______________________________________________
> > > AMaViS-user mailing list
> > > AMaViS-user@lists.sourceforge.net 
> > > https://lists.sourceforge.net/lists/listinfo/amavis-user 
> > >  Please visit http://www.ijs.si/software/amavisd/ regularly
> > >  For administrativa requests please send email to rainer at openantivirus 
> > > dot org
> > > 
> > 
> > 
> > Many thanks to answer to my mail Mark
> > This is the details on the code.
> > 
> > I have created a custom hook that parse the last received server IP and
> > pass it trough GEOIP 
> > It seems that error is occurred when the scriptt check GeOIP address...
> > 
> > Could help me on this 
> > this custom hook will request GeoIP perl library has follow
> > 
> > sub checks {
> >   my($self,$conn,$msginfo) = @_;
> >   my($client_ip) = $msginfo->client_addr;
> >   my($tempdir) = $msginfo->mail_tempdir;
> >   my $recipient_domain;
> >   my($received)=$msginfo->get_header_field_body('received'); 
> > 
> > my $last_recived=tests_from_received($received);
> > 
> > ($country_name,$region_name,$city)=ScanGeoIP($last_recived);
> > 
> > }
> > 
> > 
> > sub tests_from_received($) {
> >   my($received) = @_;
> >   my($fields_ref) = parse_received($received);
> >   my($ip); local($1);
> >   for (grep {defined} (@$fields_ref{qw(from-tcp from from-com)})) {
> >     if (/ \[ (\d{1,3} (?: \. \d{1,3}){3}) (?: \. \d{4,5} )? \] /x) {
> >       $ip = $1;  last;
> >     } elsif (/\[ [^\]]* : [^\]]* \]/x &&  # triage, must contain a colon
> >              /\[ ( (?: IPv6: )?  [0-9a-f]{0,4}
> >                    (?: : [0-9a-f]{0,4} | \. [0-9]{1,3} ){2,9} ) \]/xi) {
> >       $ip = $1;  last;
> >     } elsif (/ (?: ^ | \D ) ( \d{1,3} (?: \. \d{1,3}){3}) (?!
> > [0-9.] ) /x) {
> >       $ip = $1;  last;
> >     }
> >   }
> >   !defined($ip) ? undef : $ip;  # undef need not be tainted
> >   return $ip;
> > }
> > 
> > 
> > sub ScanGeoIP($){
> >   my ($last_recived)=@_;
> >   my $country_name="undefined";  
> >   my $region_name="undefined";
> >   my $city="undefined";
> >   
> >   if(-e "/usr/local/share/GeoIP/GeoLiteCity.dat"){
> >     my $gi = Geo::IP->open("/usr/local/share/GeoIP/GeoLiteCity.dat",
> > GEOIP_STANDARD);
> >     my $record = $gi->record_by_addr($last_recived);
> >     $country_name=$record->country_name if $record;
> >     $region_name=$record->region_name if $record;
> >     $city=$record->city if $record;
> >   }else{
> >     do_log(0, "%s artica-plugin: GeoIP, unable to
> > stat /usr/local/share/GeoIP/GeoLiteCity.dat",$message_id);
> >   }
> >  
> >  return ($country_name,$region_name,$city);
> > 
> > }
> > 
> >  For administrativa requests please send email to rainer at openantivirus 
> > dot org
> 
> 
> Any help ???
> 
> -- 
> 
> 
> 
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb
> _______________________________________________
> AMaViS-user mailing list
> AMaViS-user@lists.sourceforge.net 
> https://lists.sourceforge.net/lists/listinfo/amavis-user 
>  Please visit http://www.ijs.si/software/amavisd/ regularly
>  For administrativa requests please send email to rainer at openantivirus dot 
> org


Your are definitely a cool person !!!
Many thanks for the tips 
Do you have tips to debug the situation 
I paste then entire code if you found the mistakes.


package Amavis::Custom;
use strict;
use Net::LDAP;
use Config::IniFiles;
use Geo::IP;
use File::Copy;
use File::stat;
use POSIX qw(ceil floor);
use Unix::Syslog qw(:macros);  # Syslog macros
use Unix::Syslog qw(:subs);    # Syslog functions



use vars qw($country_name $region_name $city $ldap_server
$ldap_server_port $ldap_admin $suffix $ldap_password $message_id
$search_dn @attachments @rules);

BEGIN {
  import Amavis::Conf qw(:platform :confvars c cr ca $myhostname);
  import Amavis::Util qw(do_log untaint safe_encode safe_decode);
  import Amavis::rfc2821_2822_Tools;
  import Amavis::Notify qw(build_mime_entity); 


}


sub new {
  my($class,$conn,$msginfo) = @_;
  bless {}, $class;


}

sub before_send {
  my($self,$conn,$msginfo) = @_;
  &MysqlInjection($msginfo);
  $self;
}

sub checks {
   #$r->recip_addr_modified($new_addr);  # replaces delivery address!  
  my($self,$conn,$msginfo) = @_;
  my($client_ip) = $msginfo->client_addr;
  my $Mustbanned=0;
  my $MustSpam=0;
  my $htmlsize=0;
  my $bann_reason='';
  my $sender_domain='';
  my($log_id)=$msginfo->log_id;
  my($tempdir) = $msginfo->mail_tempdir;
  my $recipient_domain;
  my($received)=$msginfo->get_header_field_body('received'); 
  my($kasrate)=
trim($msginfo->get_header_field_body('X-SpamTest-Rate'));
  my($mail_file_name) = $msginfo->mail_text_fn; 
  if(!$kasrate){$kasrate=0;}
  my($sender_address)=$msginfo->sender; 
  $message_id=Mydecode($msginfo->get_header_field_body('message-id'));
  $message_id=~ s/<//g;
  $message_id=~ s/>//g;
  my $ldap=init_ldap_settings();
  my $userid;
  my $syslog_info;
  


$msginfo->header_edits->add_header('X-Artica-scanner','artica version
'.&GET_VERSION_ARTICA());

  if (!exists $self->{geoip}) { 
    my $geo_file = "/usr/local/share/GeoIP/GeoLiteCity.dat";
    $self->{geoip} = undef;
    if (!-e $geo_file) {
      do_log(0, "artica-plugin: GeoIP, unable to stat %s", $geo_file);
    } else {
      $self->{geoip} = Geo::IP->open($geo_file, GEOIP_STANDARD);
      do_log(0, "artica-plugin: GeoIP, failed to open %s",
                 $geo_file)  if !$self->{geoip};
    }
  }


my $last_recived
=Amavis::UnmangleSender::parse_ip_address_from_received($msginfo);

  if ($self->{geoip}) {
    my $last_received_ip
=Amavis::UnmangleSender::parse_ip_address_from_received($msginfo);
    if (defined $last_received_ip && $last_received_ip ne '') {
        my($country_name,$region_name,$city) =
$self->ScanGeoIP($last_recived);
      do_log(2, "artica-plugin: GeoIP, IP: %s, country: %s, region: %s,
city: %s",$last_received_ip,
                map(defined $_ && $_ ne '' ? $_ : "-",$country_name,
$region_name, $city)
            );
    }
  }

$sender_address=~ m/(.+?)@(.+)/;
$sender_domain=$2;
 
  do_log(0, "%s artica-plugin: client's IP [%s], last [%s] sender: <%s>,
X-SpamTest-Rate: %s",$message_id,$client_ip,$last_recived,
$sender_address,$kasrate);
  do_log(0, "%s artica-plugin: Country [%s], Region [%s] City [%s]",
$message_id,$country_name,$region_name,$city);



if($kasrate>90){$MustSpam=1;}

if($MustSpam==1){
 for my $r (@{$msginfo->per_recip_data}) {
     if(!$r->recip_whitelisted_sender){
        $r->add_contents_category(CC_SPAM,0) if !$r->bypass_spam_checks;
      }
   }
   $msginfo->add_contents_category(CC_SPAM,0);
   $ldap->unbind();
   return 0;
 }

#$ldap->unbind();
$self;
};
#
-----------------------------------------------------------------------------------------------------------------
sub artica_syslog($){
    my($text)=@_;
    openlog('amavisd-new',LOG_CONS|LOG_PID, LOG_MAIL);
    syslog(LOG_INFO, $text);
    closelog;
}
#
-----------------------------------------------------------------------------------------------------------------
sub htmlSize($$){
  my($msginfo,$ldap)=@_;
  my $uid;
  my $ou;
  my @res;
  my $count_attach;
  my($sender_address)=$msginfo->sender;
  my $returned_value;
  
  @attachments=ParseAttachParts($msginfo);
  $count_attach=scalar(@attachments);
  do_log(1, "%s artica-plugin: htmlSize %s attachments...",$message_id,
$count_attach);
  if($count_attach==0){return 0;}

 for my $r (@{$msginfo->per_recip_data}) {
        my($recip) = $r->recip_addr;
        $uid=GetUidFromMail($recip,$ldap);
        if(length($uid)>0){
                $search_dn=~ m/cn=$uid,ou=(.+?),/;
                my $ou=$1;
                @res=GetLdapEntries("cn=html_blocker,ou=klf,
$suffix","BigMailHTMLEnabled",$ldap);
                @rules=GetLdapEntries("cn=html_blocker,ou=klf,
$suffix","BigMailHtmlRules",$ldap);
                if(scalar(@res)>0){
                        if($res[0] eq "yes"){
                                if(scalar(@rules)>0){
                                        do_log(1, "%s artica-plugin: htmlSize 
(parse rules)...",
$message_id);
                                        
$returned_value=ParseHtmlRules($sender_address,$recip);
                                        if($returned_value==1){return 1;}
                                }
                        }
                }
         }
    }
return 0;
}
#
-----------------------------------------------------------------------------------------------------------------
sub ParseAttachParts($$){
  my($msginfo)=@_;
  my($tempdir) = $msginfo->mail_tempdir;  # working directory for this
process
  my $part_path;
  my $size;
  my $ext;
  my($parts_root)=$msginfo->parts_root;
  my($top) = $parts_root->children;
  my($tempdir)=$msginfo->mail_tempdir;
  
  
    for my $e (!defined $top ? () : @$top) {
      my($name) = $e->name_declared;
      my($tshort)=$e->type_short;
      my($base_name)=$e->base_name;
      my($type_long)=$e->type_long;
      my($top2) = $e->children;
      for my $b (!defined $top2 ? () : @$top2) {
          my($name) = $b->name_declared;
          my($tshort)=$b->type_short;
          my($base_name)=$b->base_name;
          my($type_long)=$b->type_long;
         if(length($name)>0){
                $name=~ m/\.(.+?)$/;
                $ext=$1;
                $part_path="$tempdir/parts/$base_name";
                my $statF=stat($part_path);
                if($statF){
                        $size=$statF->size;
                        if(-e $part_path){
                                push(@attachments, "$ext;$size");
                        }
                   
                }
            }
         }
     }

return @attachments;
}

#
-----------------------------------------------------------------------------------------------------------------
sub UserDatas($$$){
my ($tofind,$email,$ldap)=@_;
my  $mesg = $ldap->search(
    base   => "dc=organizations,$suffix",
    scope  => 'sub',
    filter => "(&(objectClass=userAccount)(mail=$email))"
  );

if (! defined $mesg) {
        do_log(0, "%s artica-plugin: UserDatas:: LDAP connection problem -
temporary error -",$message_id);
        return "";
        }
  if ( $mesg->code ) {
    do_log(0, "%s artica-plugin: UserDatas:: Search failed with error %
s",$message_id,$mesg->error);
  }

  foreach my $entry ($mesg->all_entries) {
    $search_dn=$entry->dn;
    foreach my $attr ($entry->attributes) {
        foreach my $value ($entry->get_value($attr)) {
                if($attr eq $tofind){
                         #print "$attr: $value\n";
                         return $value;
                }
        }
    }   
  } 
}
#
-----------------------------------------------------------------------------------------------------------------

sub ScanGeoIP($$) {
  my($self,$last_received_ip) = @_;
  my($country_name,$region_name,$city);
  my $record = $self->{geoip}->record_by_addr($last_received_ip);
  if (!$record) {
    do_log(2, "artica-plugin: GeoIP, no record for %s",
$last_received_ip);
  } else {
    $country_name = $record->country_name;
    $region_name = $record->region_name;
    $city = $record->city;
  }
  return ($country_name,$region_name,$city);
}
#
-----------------------------------------------------------------------------------------------------------------
sub MysqlInjection($){
    my($msginfo) = @_;
    my $EnableMysqlFeatures=GET_INFOS('EnableMysqlFeatures');
    my $recipient_domain; 
    my $sender_domain;
    my $sql_query; 
    my $syslog_info;
    my $final_file;
    my ($sec, $min, $heure, $jour, $mois,$annee, undef, undef, undef) =
localtime();
    $mois += 1 and $annee += 1900;
    $jour = sprintf("%02d",$jour);
    $mois = sprintf("%02d",$mois);
   my $time_amavis = "$annee-$mois-$jour $heure:$min:$sec";
   
 my($kasrate)= trim($msginfo->get_header_field_body('X-SpamTest-Rate'));
   if(!$kasrate){$kasrate=0;}
   &Backup($msginfo);

    my($client_ip) = $msginfo->client_addr;
    my($sender_address)=$msginfo->sender;
    my($subject)=Mydecode($msginfo->get_header_field_body('subject'));
    my($from) =Mydecode($msginfo->get_header_field_body('from'));
    my($blacklisted) =0;
    my($whitelisted) =0;
    my $recip="";


   #retreive sender domain:
    $sender_address=~ m/(.+?)@(.+)/;
    $sender_domain=$2;

    my($received)=$msginfo->get_header_field_body('received');
    my $last_recived=tests_from_received($received);

  my($infected) = $msginfo->is_in_contents_category(CC_VIRUS);
  my($banned)   = $msginfo->is_in_contents_category(CC_BANNED);
  my($at_tag2)  = $msginfo->is_in_contents_category(CC_SPAMMY); # >=
tag2_level
  my($at_kill)  = $msginfo->is_in_contents_category(CC_SPAM);   # >=
kill_level

     for my $r (@{$msginfo->per_recip_data}) {
        $recip=$recip.",".$r->recip_addr;
        $blacklisted = $r->recip_blacklisted_sender;
        $whitelisted = $r->recip_whitelisted_sender;

        }

 
open (MYFILE, ">/var/log/artica-postfix/RTM/$message_id.id-message");
print MYFILE "[TIME]\n";
print MYFILE "mailfrom=$sender_address\n";
print MYFILE "server_from=$client_ip\n";
print MYFILE "time_amavis=$time_amavis\n";
print MYFILE "message-id=$message_id\n";   
print MYFILE "Country=$country_name\n";   
print MYFILE "Region=$region_name\n";
print MYFILE "City=$city\n";
print MYFILE "kas=$kasrate\n";
print MYFILE "banned=$banned\n";
print MYFILE "infected=$infected\n";
print MYFILE "spammy=$at_tag2\n";
print MYFILE "spam=$at_kill\n";
print MYFILE "blacklisted=$blacklisted\n";
print MYFILE "whitelisted=$whitelisted\n";
print MYFILE "mailto=$recip\n";
close(MYFILE);  
do_log(0, "%s artica-plugin: saved /var/log/artica-postfix/RTM/%
s.id-message",$message_id,$message_id);

$syslog_info="$message_id to=<$recip> passed trough amavis and event is
saved";
artica_syslog($syslog_info);

#SEND TO BACKUP...
if($infected==0){
  if($at_kill==0){&Backup($msginfo);}
}


}
#
-----------------------------------------------------------------------------------------------------------------
sub Backup(){
my($msginfo) = @_;
my $EnableAmavisBackup=GET_INFOS("EnableAmavisBackup");
my($mail_file_name) = $msginfo->mail_text_fn; 
   if($EnableAmavisBackup==1){
   mkdir "/tmp/savemail";
   copy($mail_file_name, "/tmp/savemail/$message_id.msg") or die "File
cannot be copied.";
   do_log(0, "%s artica-plugin: Success put into archive
queue /tmp/savemail/%s.msg",$message_id,$message_id);
   }else{
    do_log(0, "%s artica-plugin: Archive is disabled...",$message_id,
$message_id);
   }

}
#
-----------------------------------------------------------------------------------------------------------------
sub MysqlQuote($){
my $value=shift;
$value=~ s/\'/\'\'/g;
return $value;
}
#
-----------------------------------------------------------------------------------------------------------------
sub Mydecode {
  my($str) = shift;
  return unless defined $str or $str ne '';
  chomp $str;
  $str =~ s/\n([ \t])/$1/sg; $str =~ s/^[ \t]+//s; $str =~
s/[ \t]+\z//s;
  my($str2);
  eval { $str2 = safe_decode('MIME-Header',$str) };
  $@ eq '' ? return $str2 : return $str;
}
#
-----------------------------------------------------------------------------------------------------------------
sub IsLocalDomain($$){
my ($tofind,$ldap)=@_;  
$tofind=lc ($tofind);

my  $mesg = $ldap->search(
    base   => "dc=organizations,$suffix",
    scope  => 'sub',
    filter => "(&(objectclass=domainRelatedObject)(associatedDomain=
$tofind))",
     attrs  =>['associatedDomain']
  );
 $mesg->code && die $mesg->error;
 
  foreach my $entry ($mesg->all_entries) {
        foreach my $attr ($entry->attributes) {
                foreach my $value ($entry->get_value($attr)) {
                        if (lc ($value)  eq $tofind){
                                do_log(1, "artica-plugin: IsLocalDomain:
(&(objectclass=domainRelatedObject)(associatedDomain=%s))=%s",$value,
$tofind);
                                return 1;
                        }
                }
}       }
return IsTargetedDomain($tofind,$ldap);
}
#
-----------------------------------------------------------------------------------------------------------------
sub IsTargetedDomain($$){
my ($tofind,$ldap)=@_;  
$tofind=lc ($tofind);

my  $mesg = $ldap->search(
    base   => "dc=organizations,$suffix",
    scope  => 'sub',
    filter => "(&(objectclass=transportTable)(cn=$tofind))",
     attrs  =>['cn']
  );
 $mesg->code && die $mesg->error;
 
  foreach my $entry ($mesg->all_entries) {
        foreach my $attr ($entry->attributes) {
                foreach my $value ($entry->get_value($attr)) {
                        if (lc ($value)  eq $tofind){
                                do_log(1, "artica-plugin: IsTargetedDomain:
(&(objectclass=transportTable)(cn=%s))=%s",$value,$tofind);     
                                return 1;
                        }
                }
}       }
return 0;}
#
-----------------------------------------------------------------------------------------------------------------
sub init_ldap_settings(){
        my $fileset;
        my $admin;
        $fileset="/etc/artica-postfix/artica-postfix-ldap.conf";
        if(!$ldap_server){$ldap_server =GET_INFOS_LDAP('server');}
        if(!$ldap_server_port){ $ldap_server_port=GET_INFOS_LDAP('port');}
        if(!$suffix){$suffix=GET_INFOS_LDAP('suffix');}
        if(!$admin){$admin=GET_INFOS_LDAP('admin');}
        if(!$ldap_password){$ldap_password=GET_INFOS_LDAP('password');}         
        if(!$ldap_admin){$ldap_admin="cn=$admin,$suffix";}
        my $ldap = Net::LDAP->new($ldap_server , $ldap_server_port => 389,
version => 3)  or die "unable to connect to $ldap_server";
        my $results=$ldap->bind ( $ldap_admin, password => $ldap_password);
        $results->code && die $results->error;          
        return $ldap;
        }
#
-----------------------------------------------------------------------------------------------------------------
sub init_mysql_settings(){
        my $fileset;
        my $suffix;
        my $admin;
        $fileset="/etc/artica-postfix/artica-mysql.conf";
        my $sql_serv=GET_INFOS_MYSQL("mysql_server");
        my $admin=GET_INFOS_MYSQL("database_admin");
        my $password=GET_INFOS_MYSQL("database_password");      
        my $dsn = "DBI:mysql:database=artica_events;host=$sql_serv";
        my $dbh = DBI->connect($dsn, $admin, $password) || warn "Could not
connect to database: $DBI::errstr";
        return $dbh;
        }

#
-----------------------------------------------------------------------------------------------------------------
sub readini{
        my $section=$_[0];
        my $key=$_[1];
        my $Path=$_[2];
        my $def=$_[3];
        my $value="";
        my $len=0;
        if(!$Path){return $def;}
        if(!-e $Path){return $def;}
        if(!$section){return $def;}
        if(!$key){return $def;}
        if(!$Path){return $def;}
        
        my $cfg=Config::IniFiles->new( -file => $Path );
          if($cfg->SectionExists($section)){
                $value=$cfg->val($section,$key,$def);
                if(!$value){return $def;}
        }
return $value;
}

#
-----------------------------------------------------------------------------------------------------------------
sub tests_from_received($) {
  my($received) = @_;
  my($fields_ref) = parse_received($received);
  my($ip); local($1);
  for (grep {defined} (@$fields_ref{qw(from-tcp from from-com)})) {
    if (/ \[ (\d{1,3} (?: \. \d{1,3}){3}) (?: \. \d{4,5} )? \] /x) {
      $ip = $1;  last;
    } elsif (/\[ [^\]]* : [^\]]* \]/x &&  # triage, must contain a colon
             /\[ ( (?: IPv6: )?  [0-9a-f]{0,4}
                   (?: : [0-9a-f]{0,4} | \. [0-9]{1,3} ){2,9} ) \]/xi) {
      $ip = $1;  last;
    } elsif (/ (?: ^ | \D ) ( \d{1,3} (?: \. \d{1,3}){3}) (?!
[0-9.] ) /x) {
      $ip = $1;  last;
    }
  }
  !defined($ip) ? undef : $ip;  # undef need not be tainted
  return $ip;
}
#
-----------------------------------------------------------------------------------------------------------------
sub GET_INFOS($){
my($key) = @_;
my $data_file="/etc/artica-postfix/settings/Daemons/$key";
if(!-e $data_file){
        do_log(0, "artica-plugin: key [%s] has no file",$key);
        return "";
        }
if(!open(DAT, $data_file)){
        do_log(0, "Could not open file! $data_file",$key);
        return "";
        }
my @raw_data=<DAT>;
close(DAT);
foreach my $line_value (@raw_data){
        chomp($line_value);
        if(length($line_value)>0){
                return $line_value;
        }
} 
        #do_log(0, "artica-plugin: key [%s] has no datas",$key);
}
#
-----------------------------------------------------------------------------------------------------------------
sub GET_INFOS_ARRAY($){
my($key) = @_;
my @Array;
my $data_file="/etc/artica-postfix/settings/Daemons/$key";
if(!-e $data_file){return @Array;}

if(!open(DAT, $data_file)){
        do_log(0, "artica-plugin: Could not open file! $data_file",$key);
        return  @Array;
        }
my @raw_data=<DAT>;
close(DAT);
return @raw_data;
}
#
-----------------------------------------------------------------------------------------------------------------
sub GET_INFOS_MYSQL($){
my($key) = @_;
my $data_file="/etc/artica-postfix/settings/Mysql/$key";
my $oldinifile="/etc/artica-postfix/artica-mysql.conf";
my $result2="";
if(!-e $data_file){
        if(!-e $oldinifile){return "";}
        $result2=readini("MYSQL",$key,$oldinifile,"");
        if($key eq
"mysql_server"){if(length($result2)==0){$result2="127.0.0.1";}}
        return $result2;
        }
if(!open(DAT, $data_file)){
        do_log(0, "artica-plugin: Could not open file! $data_file",$key);
        return  "";
        }

my @raw_data=<DAT>;
close(DAT);
foreach my $line_value (@raw_data){
chomp($line_value);
if(length($line_value)>0){
        return $line_value;}
}
if($key eq "mysql_server"){return "127.0.0.1";}
}
#
-----------------------------------------------------------------------------------------------------------------

sub GET_INFOS_LDAP($){
my($key) = @_;
my $data_file="/etc/artica-postfix/ldap_settings/$key";
if(!open(DAT, $data_file)){
        do_log(0, "artica-plugin: Could not open file! $data_file",$key);
        return  "";
        }

my @raw_data=<DAT>;
close(DAT);
foreach my $line_value (@raw_data){
chomp($line_value);
if(length($line_value)>0){return trim($line_value);}}

}
#
-----------------------------------------------------------------------------------------------------------------


sub GET_VERSION_ARTICA(){
my $data_file="/usr/share/artica-postfix/VERSION";
if(!open(DAT, $data_file)){
        do_log(0, "artica-plugin: Could not open file! $data_file");
        return  "";
        }
my @raw_data=<DAT>;
close(DAT);
foreach my $line_value (@raw_data){
chomp($line_value);
if(length($line_value)>0){
        return $line_value;}
}
}
#
-----------------------------------------------------------------------------------------------------------------
sub trim($)
{
        my $string = shift;
        $string =~ s/^\s+//;
        $string =~ s/\s+$//;
        return $string;
}
#
-----------------------------------------------------------------------------------------------------------------

sub ReadFile($){
my $path = shift;
my $string;
open FILE, $path or die "Couldn't open file: $!"; 
while (<FILE>){
 $string .= $_;
}
close FILE;
return $string;

}
#
-----------------------------------------------------------------------------------------------------------------
sub GetUidFromMail($$){
        my ($email,$ldap)=@_;
        my $uid;
        my $tmpuid=0;
        $uid=UserDatas("uid",$email,$ldap);
        if(length($uid)>0){return $uid;}
        my  $mesg = $ldap->search(
                base   => "dc=organizations,$suffix",
                scope  => 'sub',
                filter => "(&(objectClass=userAccount)(mailAlias=$email))"
                );      
 $mesg->code && die $mesg->error;
  foreach my $entry ($mesg->all_entries) {
    $search_dn=$entry->dn;
    foreach my $attr ($entry->attributes) {
        foreach my $value ($entry->get_value($attr)) {
            if($attr eq "mailAlias"){if($value eq $email){$tmpuid=1;}}
        }
    }   
  }

if($tmpuid==1){
        foreach my $entry ($mesg->all_entries) {
                foreach my $attr ($entry->attributes) {
                        foreach my $value ($entry->get_value($attr)) {
                           if($attr eq "uid"){return $value;}
                        }
                }
        }
 }


}
#
-----------------------------------------------------------------------------------------------------------------
sub GetLdapEntries(){
my ($dn,$field,$ldap)=@_;
my @res;
my  $mesg = $ldap->search(
    base   => $dn,
    scope  => 'sub',
    filter => "(objectClass=*)"
  );
if(defined($mesg)){
        if(defined($mesg->code)){
                if(defined($mesg->error)){
                        $mesg->code && die $mesg->error;
                }
        }
}

  foreach my $entry ($mesg->all_entries) {
    foreach my $attr ($entry->attributes) {
        foreach my $value ($entry->get_value($attr)) {
            if($attr eq $field){
                push(@res, $value);
            }
        }
    }   
  }

return @res;
}
#
-----------------------------------------------------------------------------------------------------------------


1;  # insure a defined return





-- 



------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
AMaViS-user mailing list
AMaViS-user@lists.sourceforge.net 
https://lists.sourceforge.net/lists/listinfo/amavis-user 
 Please visit http://www.ijs.si/software/amavisd/ regularly
 For administrativa requests please send email to rainer at openantivirus dot 
org

Reply via email to