getexch.pl
Posted in by rain on November 7th, 2007
#!/usr/bin/perl -T -w
use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant ( “LDAP_CONTROL_PAGED” );
$VALID = “/etc/initsetup/exchange_recipients”;
$list = “/etc/initsetup/tmpnusr”;
$dc1=”ctrl1.fakedomain.local”;
$dc2=”ctrl2.fakedomain.local”;
#$hqbase=”cn=Users,dc=fakedomain,dc=local”;
$hqbase=”dc=fakedomain,dc=local”;
#$user=”cn=identity,cn=Users,dc=fakedomain,dc=local”;
$user=”identity\@fakedomain.local”;
$passwd=”secret”;
$noldapserver=0;
$ldap = Net::LDAP->new($dc1) or
$noldapserver=1;
if ($noldapserver == 1) {
$ldap = Net::LDAP->new($dc2) or
die “Error connecting to specified domain controllers $@ \n”;
}
$mesg = $ldap->bind ( dn => $user,
password =>$passwd);
if ( $mesg->code()) {
die (”error:”, $mesg->code(),”\n”,”error name: “,$mesg->error_name(),
“\n”, “error text: “,$mesg->error_text(),”\n”);
}
$page = Net::LDAP::Control::Paged->new( size => 990 );
@args = ( base => $hqbase,
# filter => “(&(sAMAccountName=*)(mail=*))”,
filter => “(& (mailnickname=*) (| (&(objectCategory=person)
(objectClass=)(!(homeMDB=*))(!(msExchHomeServerName=*)))
(&(objectCategory=person)(objectClass=)(|(homeMDB=*)
(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))
(objectCategory=group)(objectCategory=publicFolder)(objectClass=msExchDynamicDistributionList) ))”,
control => [ $page ],
attrs => “proxyAddresses”,
);
my $cookie;
while(1) {
my $mesg = $ldap->search( @args );
foreach my $entry ( $mesg->entries ) {
my $name = $entry->get_value( “cn” );
foreach my $mail ( $entry->get_value( “proxyAddresses” ) ) {
push(@tmpvalid, $name.” \n”);
if ( $mail =~ s/^(smtp|SMTP)://gs ) {
push(@valid, $mail.” OK\n”);
}
}
}
$mesg->code and last;
my($resp) = $mesg->control( LDAP_CONTROL_PAGED ) or last;
$cookie = $resp->cookie or last;
$page->cookie($cookie);
}
if ($cookie) {
$page->cookie($cookie);
$page->size(0);
$ldap->search( @args );
die(”LDAP query unsuccessful”);
}
open VALID, “>$list” or die “not possible to open $!”;
print VALID @tmpvalid;
open VALID, “>$VALID” or die “CANNOT OPEN $VALID $!”;
print VALID @valid;
#print VALID “\@example. OK\n”;
#print VALID “1\@example. 550 User unknown.\n”;
#print VALID “bad.example. 550 User does not exist.\n”;
close VALID;
In the void is virtue, and no evil. Wisdom has existence, principle has existence, The Way has existence, spirit is nothingness.
Image
Search This Blog
Blog Archive
-
▼
2008
(13)
-
▼
September
(9)
- qd-update
- redir init scriptPosted by rain on August 29th, 20...
- antivirus replacementPosted by rain on June 24th, ...
- update Posted by rain on May 3rd, 2008 ei da, m...
- process_exchangePosted in by rain on December 1st,...
- getexch.plPosted in by rain on November 7th, 2007#...
- process_unixPosted by rain on October 18th, 2007#!...
- initsetupPosted by rain on September 18th, 2007#!/...
- despre fine-tuning in linux (part one)Posted by r...
-
▼
September
(9)
No comments:
Post a Comment