Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active August 4, 2021 20:01
Show Gist options
  • Save rsperl/c7f6a7cae665bcadf68ac32884a37d26 to your computer and use it in GitHub Desktop.
Save rsperl/c7f6a7cae665bcadf68ac32884a37d26 to your computer and use it in GitHub Desktop.
get ldap connection base #perl #ldap
#!/usr/bin/env perl
# Getting the base from an ActiveDirectory connection
use Net::LDAP;
my $ldap = ...; # connect to ldap
my $dse = $ldap->root_dse();
my @contexts = $dse->get_value('namingContexts');
my $base;
foreach my $c (@contexts) {
$base = $c if $c =~ /^dc=/i;
}
$log->logdie("can't find base from connection - namingContexts: " . p(@contexts))
unless $base;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment