1

I'm writing a perl program to read, write, add, update and delete entries in LDAP server. What I got so far is write, add, update, delete using LDIF and read that returns entries as DSML.

Now to my question - is it possible to have write, add, update, delete return DSML? Code examples would be greatly appreciated.

My search looks like this and it works like a charm,

my $dsml = Net::LDAP::DSML->new(output => $oio, pretty_print => 1 )
  or die ("DSML object creation problem using an output file.\n");
$dsml->start_dsml();
$ldap->search(
    base => "applicationName=HSS_ESM,nodeName=jambala",
    scope => "sub",
    filter => $intext,
    attrs => ['*'],
    callback => sub {
        my ($mesg,$entry) =@_;
        $dsml->write_entry($entry)
        if (ref $entry eq 'Net::LDAP::Entry');
    }
);
$dsml->end_dsml();

My write, add, update, delete looks like this and I would like it to return DSML on either success or error,

# Create LDIF
my $ldif = Net::LDAP::LDIF->new($fh, "r", onerror => 'undef' );

# Loop over the entries in LDIF
while ( not $ldif->eof ( ) ) {
    my $entry = $ldif->read_entry( );
    if ( $ldif->error ( ) ) {
        # handle error
    } else {
        # do stuff
        my $res = $entry->update($ldap);
        if ($res->code != 0) {
            # handle error
        }
    }
}
$ldif->done ( );

Thank you.

Gunnlaugur
  • 341
  • 1
  • 8
  • 19
  • The `$entry` variable in your LDIF example should contain an `Net::LDAP::Entry` object which `Net::LDAP::DSML` can use. The DSML module can also be set to write to an array instead of a file handle, so can't you simply write the LDIF `$entry` to a DSML array and return the array? – interduo Dec 27 '16 at 17:54
  • I need to get the result from `my $res = $entry->update($ldap);` into `Net::LDAP::DSML` and `my $res = $entry->update($ldap);` return type is `Net::LDAP::Message` so I'm not sure how to add it to DSML or if it's even possible. Do you know if it's possible and then how if it is? Thank you. – Gunnlaugur Dec 28 '16 at 10:25
  • Sorry, the more I look at it, it doesn't seem like it's possible to do as-is in Net::LDAP. You may be stuck with writing your own methods to map the text from Net::LDAP::Message to DSML before returning it. Hopefully someone with more experience than me can find an easier way to do it. – interduo Dec 29 '16 at 23:35

0 Answers0