20070612 ldap over tls with netldap - plembo/onemoretech GitHub Wiki

title: LDAP over TLS with Net::LDAP link: https://onemoretech.wordpress.com/2007/06/12/ldap-over-tls-with-netldap/ author: lembobro description: post_id: 689 created: 2007/06/12 17:44:00 created_gmt: 2007/06/12 17:44:00 comment_status: open post_name: ldap-over-tls-with-netldap status: publish post_type: post

LDAP over TLS with Net::LDAP

This is an article from my old personal site.

Following is a simple script using LDAP over TLS (start_tls). Like LDAP over SSL (LDAPS), communications are done over a secure channel. In the case of TLS, however, those communications happen over port 389 instead of a dedicated secure port (LDAPS defaults to port 636). The “require” line is used to import host, userdn and password values from a separate configuration file.

`

#!/usr/bin/perl

use Net::LDAP;

our($dirHost,$dirUsr,$dirPass);

require "../etc/config.inc";

my $basedn = "dc=example,dc=com";
my @attrs = qw(cn sn givenname uid mail);
my $query = "(cn=*)";

my $ldap = Net::LDAP-> new( $dirHost );
my $mesg = $ldap-> start_tls(verify=> 'require',
       cafile => '/etc/ssl/cacert.pem'      );
       # die $mesg->error() if $mesg-> code();
     
     $mesg = $ldap-> bind($dirUsr, password => $dirPass);
     
     my $mesg = $ldap-> search (
         base => $basedn,
         scope =>’sub’,
         filter => $query,
         attrs => @attrs
        );

while (my $entry = $mesg-> shift_entry()) {

    $entry-> dump;

}

$ldap-> unbind

__END__;

`

Copyright 2004-2019 Phil Lembo