1

I am new in openLDAP and perl. I want to export /import LDAP data with/without schema from LDAP database. Is this possible to do that using perl script? If yes ,please give me a sample code. I would like to create a new schema using openLDAP and perl without dns.How to do that?

1 Answer 1

2

This is too many questions in one item. Please ask one question at a time.

How to read Ldap from wtih Perl:

use strict;
use warnings;
use Data::Dumper;
### for ldap  
use Convert::ASN1;  
use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_name canonical_dn ldap_explode_dn ldap_error_text);
use Net::LDAP::LDIF;

my %parms (
  host => 'localhost',
  port => 389,
  binddn => 'your dn',
  passwd => 'password',
  base => "",
  filter => "(objectclass=*)",
  scope => "base",
  attrs => ['*'],

);
my $ldif = Net::LDAP::LDIF->new( "out.ldif", "w", onerror => 'die', wrap  => 0 );
my $ldap= Net::LDAP->new($parms{'host'}, port => $parms{'port'}); 
my $bind_result = $ldap->bind($parms{'binddn'},'password' => $parms{'passwd'},'version' => '3');
if($bind_result->is_error()) {
  die ('Unable to bind to ' . $parms{'host'} . ': '.$bind_result->error()); 
}
my @search_args = (
    'base'     => $parms{"base"},               
    'scope'    => $parms{'scope'},                             
    'filter'   => $parms{'filter'},
    'attrs'    => $parms{'attrs'},
    'deref'    => 'always',
);

my $msg = $ldap->search(@search_args);
if ($msg->is_error()) {
    die "ERROR: ".Dumper(\@search_args).", ".$msg->error."\n";  
}
while (my $entry = $msg->pop_entry()){
    my $cn = $entry->get_value("cn");
    print "cn: $cn\n";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.