I'm trying to access LDAP from a C program (the first time I've used the OpenLDAP API) and so far I've only met with moderate success.
I can bind without issue, but I need to retrieve the values held by a specific multi valued attribute, and that's where I'm having issues.
I was using ldap_get_values() and all the other deprecated functions, but have recently converted my code to only use what's available in 2.4.x
Sadly, that didn't fix the problem, it still happens.
This line:
attr_values = ldap_get_values_len(ldap_conn, entry, attr);
Segfaults with SIGABRT and prints this to stderr:
Assertion failed: (LBER_VALID( ber )), function ber_scanf, file decode.c, line 779.
This is OpenLDAP 2.4.8 on FreeBSD 7.0-RELEASE (as built out of PORTS).
Where do I start looking to try and get this resolved?
Thanks!!
-brian
On Sat, 8 Mar 2008, Brian Hechinger wrote: ...
I can bind without issue, but I need to retrieve the values held by a specific multi valued attribute, and that's where I'm having issues.
I was using ldap_get_values() and all the other deprecated functions, but have recently converted my code to only use what's available in 2.4.x
Sadly, that didn't fix the problem, it still happens.
This line:
attr_values = ldap_get_values_len(ldap_conn, entry, attr);
Segfaults with SIGABRT and prints this to stderr:
Assertion failed: (LBER_VALID( ber )), function ber_scanf, file decode.c, line 779.
You passed an invalid 'entry' value to ldap_get_values_len(). Where did that value come from? (i.e., what's the code that leads up to that call?) Presumably there was a search that ended with an ldap_result() call. What sort of checking of the result of ldap_result() did you perform to handle errors and timeouts?
Philip Guenther
On Sat, Mar 08, 2008 at 11:31:40PM -0700, Philip Guenther wrote:
You passed an invalid 'entry' value to ldap_get_values_len(). Where did that value come from? (i.e., what's the code that leads up to that call?) Presumably there was a search that ended with an ldap_result() call. What sort of checking of the result of ldap_result() did you perform to handle errors and timeouts?
entry comes from:
entry = ldap_first_entry(ldap_conn, res);
and res comes from:
rc = ldap_search_ext_s(ldap_conn, conf.ldap.basedn, LDAP_SCOPE_SUBTREE, filter, NULL, 0, NULL, NULL, NULL, -1, &res);
I check that (rc != LDAP_SUCCESS) and error out of this function if that is the case and I check that (entry == NULL) and error out of the function if that is the case.
At one point (I've since taken it out) I was doing an ldap_count_entries() and getting the proper answer (1 in this case), but aside from that, I don't know how else to check that entry is valid.
The server is local on the machine, and I'm binding/searching for known things so I should be getting the proper data, presumably.
-brian
On Sun, Mar 09, 2008 at 09:55:00AM -0500, Brian Hechinger wrote:
entry comes from:
entry = ldap_first_entry(ldap_conn, res);
Ah ha! I was free()ing res right after that call (I had copied other code as an example). After moving the call to free() down to after I was done working with the entry has caused this to no longer explode.
Sorry for the noise!!
-brian
I'm trying to access LDAP from a C program (the first time I've used the OpenLDAP API) and so far I've only met with moderate success.
I can bind without issue, but I need to retrieve the values held by a specific multi valued attribute, and that's where I'm having issues.
I was using ldap_get_values() and all the other deprecated functions, but have recently converted my code to only use what's available in 2.4.x
Sadly, that didn't fix the problem, it still happens.
This line:
attr_values = ldap_get_values_len(ldap_conn, entry, attr);
Segfaults with SIGABRT and prints this to stderr:
Assertion failed: (LBER_VALID( ber )), function ber_scanf, file decode.c, line 779.
This is OpenLDAP 2.4.8 on FreeBSD 7.0-RELEASE (as built out of PORTS).
It appears that you're passing broken arguments to ldap_get_values*(); however, you don't provide details on what happens before. My guess is that entry was not obtained from the appropriate calls to the API. It should be the result of calling ldap_first_entry() or ldap_next_entry() applied to the LDAPMessage pointer resulting from ldap_result() or ldap_search*_s(). Please look at clients/tools/ldapsearch.c and related files for a thorough example.
p.
Ing. Pierangelo Masarati OpenLDAP Core Team
SysNet s.r.l. via Dossi, 8 - 27100 Pavia - ITALIA http://www.sys-net.it --------------------------------------- Office: +39 02 23998309 Mobile: +39 333 4963172 Email: pierangelo.masarati@sys-net.it ---------------------------------------
On Sun, Mar 09, 2008 at 09:27:37AM +0100, Pierangelo Masarati wrote:
that entry was not obtained from the appropriate calls to the API. It should be the result of calling ldap_first_entry() or ldap_next_entry() applied to the LDAPMessage pointer resulting from ldap_result() or ldap_search*_s().
See my previous reply for what exactly I've done to get to this point.
Please look at clients/tools/ldapsearch.c and related files for a thorough example.
Ugh, that code is horribly complicated and all I want to do is something simple. ;) I've been through it, which is how I've gotten to where I am now, but I'm wondering if there are better, simpler examples out there to work from?
Thanks!
-brian
--On Sunday, March 09, 2008 9:56 AM -0500 Brian Hechinger wonko@4amlunch.net wrote:
Ugh, that code is horribly complicated and all I want to do is something simple. ;) I've been through it, which is how I've gotten to where I am now, but I'm wondering if there are better, simpler examples out there to work from?
You could look at the perl module Net::LDAPapi perhaps.
--Quanah
--
Quanah Gibson-Mount Principal Software Engineer Zimbra, Inc -------------------- Zimbra :: the leader in open source messaging and collaboration
Quanah Gibson-Mount wrote:
--On Sunday, March 09, 2008 9:56 AM -0500 Brian Hechinger wonko@4amlunch.net wrote:
Ugh, that code is horribly complicated and all I want to do is something simple. ;) I've been through it, which is how I've gotten to where I am now, but I'm wondering if there are better, simpler examples out there to work from?
I find that ldapsearch.c is pretty simple already...
But for a very minimal set of features, look at plugins/ldapdb.c in the Cyrus SASL source.
You could look at the perl module Net::LDAPapi perhaps.
openldap-software@openldap.org