Last active
August 4, 2021 20:01
-
-
Save rsperl/c7f6a7cae665bcadf68ac32884a37d26 to your computer and use it in GitHub Desktop.
get ldap connection base #perl #ldap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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