2

I am writing a simple LDAP client to connect to LDAP sever over SSL. I am using "openldap-2.4.35"

So far I've tried to do a simple bind without any encryption mechanisms. Here is the code I have tried:

#define LDAP_DEPRECATED 1
#include<stdio.h>
#include<ldap.h>

#define HOST "ldap://192.168.1.95:389"
#define BASEDN "cn=manager,dc=ashwin,dc=com"

int main(){
    LDAP *ld;
    int rc;

    LDAPMessage *message;

    if(ldap_initialize(&ld, HOST))    
    {
        perror( "ldap_initialize" );
        return( 1 );
    }
    printf("LDAP initialized\n");

    rc = ldap_simple_bind_s( ld, BASEDN, "secret" );
    if( rc != LDAP_SUCCESS )
    {
        fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc) );
        return( 1 );
    }
    printf( "Successful authentication\n" );

    return 0;
}

This connects to LDAP and binds the user. If the ldap_simple_bind_s is successful then the authentication is successful.

Is there any documentation for building LDAP client to connect to LDAP server on SSL and StartTLS?

Ashwin
  • 1,942
  • 4
  • 30
  • 59

2 Answers2

3

There is a detailed example on how to establish an ldap connection over SSL on MSDN (for a win32 application) :
Example Code for Establishing a Session over SSL

hope this will be useful,

Bastien
  • 994
  • 11
  • 25
  • 1
    For linux, you can check [LDAP Libraries for C](http://www.novell.com/developer/ndk/ldap_libraries_for_c.html). There are a few examples including a TLS connection : [Sample code file for TLS connection](http://www.novell.com/documentation/developer/samplecode/cldap_sample/starttls.c.html) – Bastien May 07 '13 at 09:37
0
HOST "ldap://192.168.1.95:389" should be: HOST "ldaps://192.168.1.95:636"

Also, in /etc/openssl/ldap.conf, make sure that your top root certificate is included in the pem file, e.g:

TLS_CACERT /my/top/root/certs.pem

If you have no TLS_CACERT line, add one and make sure that the pem file is readable:

cat /my/top/root/certs.pem
-----BEGIN CERTIFICATE-----
MII...
....I=
-----END CERTIFICATE-----
CrisB
  • 1
  • 2