Subject: | Decode error returned from _decode.pm |
Date: | Thu, 25 Jan 2007 10:22:41 +0100 |
To: | bug-Convert-ASN1 [...] rt.cpan.org |
From: | Jean-Christophe Valiere <jvaliere [...] safehost.ch> |
Hello,
I run a script that parse email address located in a Windows Active
Directory.
The machine on which the script is running is a Debian Sarge and the
module version is: libconvert-asn-0.18-1
Sometimes the script return the following error: decode error 118
142 at /usr/share/perl5/Convert/ASN1/_decode.pm line 235, <DATA> line 283.
I'm not sure whether its a bug or an error in my code.
PS: I've attached the script to be sure you habe enough information
Thanks for your help.
--
Jyce
#!/usr/bin/env perl
use strict;
use warnings;
use Net::LDAP;
my @mail_relay = qw( mx1 mx2 );
my $postfix_path = "/etc/postfix/relay_recipient_maps";
my $tmp_path = "/tmp";
my $isdiff=0;
my @ActiveDirectory = (
{ domain=>'domain.tld',
server=>'dc.domain.tld',
binddn=>'CN=Administrator,CN=Users,DC=domain,DC=tld',
password => '********',
basedn=>'DC=domain,DC=tld'},
);
foreach my $ad (@ActiveDirectory){
system("/usr/bin/scp ".$mail_relay[0].":".$postfix_path."/".$ad->{'domain'}." ".$tmp_path."/".$ad->{'domain'}.".ori");
open TMP_VALID_USERS, ">".$tmp_path."/".$ad->{'domain'};
my $ldap = Net::LDAP->new( $ad->{'server'} ) or die "Can't connect to: $ad->{'server'}: $@";
my $mesg = $ldap->bind($ad->{'binddn'}, password => $ad->{'password'});
if($mesg->code) {print $mesg->error."\n"; next;}
$mesg = $ldap->search( # perform a search
base => $ad->{'basedn'},
scope => 'sub',
filter => '(proxyAddresses=*)'
);
if($mesg->code) {print "Err. for $ad->{'server'}: ".$mesg->error."\n"; next;}
my $cptAddress=0;
my @tabentries=$mesg->sorted('proxyAddresses');
foreach my $single_entry (@tabentries) {
# print $single_entry->dn.";";
my @tabvalue = $single_entry->get_value('proxyAddresses');
foreach my $value (@tabvalue){
next if($value =~ m/^smtp\:.*@.*\.local/i);
if($value =~ /^smtp\:/i){
print TMP_VALID_USERS "$' OK\n";
$cptAddress++;
}
}
}
$mesg = $ldap->unbind; # take down session
close TMP_VALID_USERS;
## /usr/bin/diff export_config/valid_users /tmp/valid_users ##
my $diff_cmd = "/usr/bin/diff ".$tmp_path."/".$ad->{'domain'}." ".$tmp_path."/".$ad->{'domain'}.".ori";
my $diff_results =`$diff_cmd`;
if ($diff_results or $?) {
$isdiff++;
print $0." have updated ".$tmp_path."/".$ad->{'domain'}." :\n".$diff_results."\n";
foreach my $i (@mail_relay) {
my $cmd= "ssh ".$i." 'sudo /bin/mv ".$postfix_path."/".$ad->{'domain'}." ".$postfix_path."/".$ad->{'domain'}.".old'";
print $cmd."\n";
system ($cmd);
$cmd = "scp ".$tmp_path."/".$ad->{'domain'}." ".$i.":".$tmp_path."/";
print $cmd."\n";
system ($cmd);
$cmd= "ssh ".$i." 'sudo /bin/mv ".$tmp_path."/".$ad->{'domain'}." ".$postfix_path."'";
print $cmd."\n";
system ($cmd);
$cmd= "ssh ".$i." 'sudo /bin/chown -R root.root ".$postfix_path."'";
print $cmd."\n";
system ($cmd);
$cmd ="ssh ".$i." 'sudo /usr/sbin/postmap ".$postfix_path."/".$ad->{'domain'}."'";
print $cmd."\n";
system ($cmd);
}
}
unlink $tmp_path."/".$ad->{'domain'};
unlink $tmp_path."/".$ad->{'domain'}.".ori";
}
if ($isdiff>0){
foreach my $i (@mail_relay) {
my $cmd= "ssh ".$i." 'sudo /usr/sbin/postfix reload'";
system ($cmd);
print $cmd."\n";
}
}else{
print "nothing have changed!\n";
}