[Date Prev][Date Next] [Chronological] [Thread] [Top]

ldap_sasl_bind_s



Hi All,

I've been debugging the RealTime Asterisk LDAP driver, namely the function:

static int ldap_reconnect(void)
{
        int bind_result = 0;
        struct berval cred;

        if (ldapConn) {
                ast_debug(2, "Everything seems fine.\n");
                return 1;
        }

        if (ast_strlen_zero(url)) {
                ast_log(LOG_ERROR, "Not enough parameters to connect to
ldap database\n");
                return 0;
        }

        if (LDAP_SUCCESS != ldap_initialize(&ldapConn, url)) {
                ast_log(LOG_ERROR, "Failed to init ldap connection to
'%s'. Check debug for more info.\n", url);
                return 0;
        }

        if (LDAP_OPT_SUCCESS != ldap_set_option(ldapConn,
LDAP_OPT_PROTOCOL_VERSION, &version)) {
                ast_log(LOG_WARNING, "Unable to set LDAP protocol version
to %d, falling back to default.\n", version);
        }

        if (!ast_strlen_zero(user)) {
                ast_debug(2, "bind to '%s' as user '%s'\n", url, user);
cred.bv_val = (char *) pass;
                cred.bv_len = strlen(pass);
                bind_result = ldap_sasl_bind_s(ldapConn, user,
LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
        } else {
                ast_debug(2, "bind %s anonymously\n", url);
                bind_result = ldap_sasl_bind_s(ldapConn, "",
LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
        }
        if (bind_result == LDAP_SUCCESS) {
                ast_debug(2, "Successfully connected to database.\n");
connect_time = time(NULL);
                return 1;
        } else {
                ast_log(LOG_WARNING, "bind failed: %s\n",
ldap_err2string(bind_result));
                ldap_unbind_ext_s(ldapConn, NULL, NULL);
                ldapConn = NULL;
                return 0;
        }
}


The line:

bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL,
NULL, NULL, NULL);

is giving:

May 26 14:52:03 asterisk slapd[30075]: conn=1 fd=12 ACCEPT from
IP=127.0.0.1:57926 (IP=0.0.0.0:389)
May 26 14:52:03 asterisk slapd[30075]: bind: ber_scanf failed
May 26 14:52:03 asterisk slapd[30075]: conn=1 op=0 DISCONNECT tag=120
err=2 text=decoding error
May 26 14:52:03 asterisk slapd[30075]: conn=1 fd=12 closed (operations error)


Any debug tips would be greatly appreciated.

Two different libldap have been tested (Centos 5.1 package and Symas
OpenLDAP Devel package):

openldap-devel-2.3.27-8.el5_1.3
cdsdevel-3.9-2


Thanks.

-- 
Kind Regards,

Gavin Henry.

T +44 (0) 1224 279484
M +44 (0) 7930 323266
F +44 (0) 1224 824887
E ghenry@suretecsystems.com

Open Source. Open Solutions(tm).

http://www.suretecsystems.com/

Suretec Systems is a limited company registered in Scotland. Registered
number: SC258005. Registered office: 13 Whiteley Well Place, Inverurie,
Aberdeenshire, AB51 4FP.