Skip to content

Instantly share code, notes, and snippets.

@shelling
Created July 14, 2012 15:28
Show Gist options
  • Select an option

  • Save shelling/3111831 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/3111831 to your computer and use it in GitHub Desktop.
import schema ldif with Net::LDAPI and Authen::SASL
#!/usr/bin/env perl
# USAGE:
# perl ldapi.pl schema.ldif
# will have the same result as running
# ldapadd -Y EXTERNAL -H ldapi:/// -f schema.ldif
use Modern::Perl;
use Net::LDAP;
use Authen::SASL;
use Net::LDAP::LDIF;
my $ldapi = Net::LDAP->new("ldapi://");
$ldapi->bind(
undef,
sasl => Authen::SASL->new(mechanism => 'EXTERNAL')
->client_new("ldap", "localhost"),
);
my $ldif = Net::LDAP::LDIF->new($ARGV[0], "r", onerror => "die");
my $entry = $ldif->read_entry;
say $entry->ldif;
my $msg = $ldapi->add($entry);
warn $msg->error if $msg->code;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment