# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4
use strict;
use Net::LDAP;
my $server = 'dc1';
my $user = 'administrator@xyz.com';
my $passwd = 'password';
my $system_cont = "cn=system,dc=xyz,dc=com";
my @trustTypes = ('Unknown','Downlevel','Uplevel','Kerberos','DCE');
my @trustDirections = ('Disabled','Trusting','Trusted',
'Trusting and Trusted');
my $ldap = Net::LDAP->new($server) or die "$@";
my $result = $ldap->bind($user, password => $passwd);
$result->code && die $result->error;
my $filter = "(&(objectclass=trustedDomain)(objectcategory=TrustedDomain))";
$result = $ldap->search(base => $system_cont,
scope => "subtree",
attrs => [ 'trustPartner', 'trustType','trustDirection'],
filter => $filter);
$result->code && die $result->error;
print "Trusts for $server:\n";
my $count = 0;
foreach my $entry ($result->entries) {
$count++;
my $partner = $entry->get_value('trustPartner');
my $type = $trustTypes[$entry->get_value('trustType')];
my $direction = $trustDirections[$entry->get_value('trustDirection')];
print "$count. $partner - $type $direction\n";
}
$ldap->unbind;
|