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.
--On Monday, May 26, 2008 10:19 PM +0100 Gavin Henry ghenry@suretecsystems.com wrote:
Hi All,
I've been debugging the RealTime Asterisk LDAP driver, namely the function: 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);
The line:
bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
I don't see that line in the code you quote.
--Quanah
--
Quanah Gibson-Mount Principal Software Engineer Zimbra, Inc -------------------- Zimbra :: the leader in open source messaging and collaboration
<quote who="Quanah Gibson-Mount">
--On Monday, May 26, 2008 10:19 PM +0100 Gavin Henry ghenry@suretecsystems.com wrote:
Hi All,
I've been debugging the RealTime Asterisk LDAP driver, namely the function: 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);
The line:
bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
That was me messing. The (ldapConn, "", should be like above:
(ldapConn, NULL
Suretec Systems is a limited company registered in Scotland. Registered number: SC258005. Registered office: 13 Whiteley Well Place, Inverurie, Aberdeenshire, AB51 4FP.
On Dienstag, 27. Mai 2008, Gavin Henry wrote:
<quote who="Quanah Gibson-Mount">
--On Monday, May 26, 2008 10:19 PM +0100 Gavin Henry
ghenry@suretecsystems.com wrote:
Hi All,
I've been debugging the RealTime Asterisk LDAP driver, namely the function: 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);
The line:
bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
You need to set the cred pointer to an empty struct berval instead of NULL for an anoynmous bind:
cred.bv_val = NULL; cred.bv_len = 0; ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
You need to set the cred pointer to an empty struct berval instead of NULL for an anoynmous bind:
cred.bv_val = NULL; cred.bv_len = 0; ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
Ah, ok. That works. I was confused by this in sasl.c:
113 | } else if ( cred == NULL || cred->bv_val == NULL ) { 114 | | /* SASL bind w/o credentials */ 115 | | rc = ber_printf( ber, "{it{ist{sN}N}" /*}*/, 116 | | | id, LDAP_REQ_BIND, 117 | | | ld->ld_version, dn, LDAP_AUTH_SASL, 118 | | | mechanism );
But I shouldn't be looking at the lib internals I guess, but the above isn't doing a LDAP_SASL_SIMPLE then.
Thanks.
openldap-technical@openldap.org