Search code examples
c++clinuxredhatopenldap

LDAP connection ldap_sasl_bind_s gives assertion


So I'm developing an LDAP application on Red Hat 5.5.

I've not done LDAP before so I'm reading documents as I go along. I'm using OpenLDAP version 2.3

My source code looks like the following:

LDAP * ld;
int version=LDAP_VERSION3;
int retVal;
berval creds;
berval *serverCreds;

retVal= ldap_initialize(&ld,"ldap://myhost"); //myhost is an actual hostname.
if(retVal !=0)
{
    aWarning() << "Could not connect to host:" << hostname;
}

ldap_set_option(ld,LDAP_OPT_PROTOCOL_VERSION,&version);

creds.bv_val = "magic";  //These don't matter since I'm not using a cred mechanism.
creds.bv_len = strlen("magic");

cout << ldap_sasl_bind_s(ld,"uid=username, ou=groupname",NULL,&creds,NULL,NULL,servercred);

}

I've been following one of the only examples I could find of a c/c++ LDAP implementation here:

http://www-archive.mozilla.org/directory/csdk-docs/sasl.htm

But when I run this, I get the following error:

 ../../../libraries/libldap/sasl.c:108: ldap_sasl_bind: Assertion '((ber)->ber_opts.lbo_valid==0x2)' failed.

Based on some of my own research, I've it seems to suggest some sort of memory fault from a later version:

http://sourceforge.net/mailarchive/forum.php?thread_name=9F7FA2E0294A934CA0CD9E97BD580F840A801834%40CCS-EXCHANGE1.brynmill.swan.ac.uk&forum_name=vufind-tech

I'm curious if anyone familiar with LDAP sees any glaring mistakes or has seen this issue before.

Thanks


Solution

  • I got this issue on Red Hat 6 when linking with both OpenLDAP libldap.so and Oracle's client library libclntsh.so, which embedded inside it has an Oracle implementation of the C LDAP API.

    The issue is that OpenLDAP libldap.so requires library liblber.so, and if you don't explicitly link to it, these symbols are resolved by libclntsh.so, and hence are incompatible.

    The fix is to add -llber to your linker line.

    Note: on Red Hat 7, the error is different, you get -3 (LDAP_ENCODING_ERROR) 'Encoding error'.