Hopefully I can get some insight into what stupidity I am performing
I have a very simple application that will do LDAP lookups on an LDAP
database using the C language libraries provided in OpenLDAP 2.2.13.
This program is compiled and run on RedHat version 9, but I have
replaced the OpenLDAP, SSL, SASL, and Berkeley DB libraries. While
the C language libraries are used, the actual program itself is
written in C++.
I tried to model the structure of the program based on the ldapsearch
utility, and the available man pages (which are just a tad antiquated).
The application is intended to do a sequence of lookups. There is no
set number; it will run until the user gets tired of making requests
and ends the program. (Or, in my case, until the program crashes.)
The sequence of calls I make is:
- ldap_set_option() (to version 3)
- ldap_simple_bind_s() (null password; directory requires none)
(I intentionally use ldap_simple_bind_s and ldap_unbind_s despite
their being deprecated because (1) ldapsearch does and (2) I have
no idea what control lists are, and didn't think I needed to use
The actual search itself is very simple. I am simply providing
a single search key (email address) and returning a single value
Initially, I was doing that full process for each request (from
the initialize through the unbind) in order to isolate each
request from the other. But when I did that, the program would
get a segmentation fault on the second call to ldap_simple_bind_s.
I then modified the program to call ldap_initialize, ldap_set_option,
and ldap_simple_bind_s once in the beginning, ldap_unbind_s once
at the end, and ldap_search_ext_s as many times as needed in
between. This time a segmentation fault would occur in different
spots, at after a variable number of times. The location was
usually in ldab_simple_bind_s, ldap_search_ext_s, or ldap_unbind_s.
The number of queries successfully completed ranged from 3 to 7.
In both versions, I ran the program under gdb and did a "back
trace". Regardless of the library function the segmentation fault
occurred in, the function causing the fault was a call to malloc().
This program seems like it should be very simple to create and
run. I have followed the above mentioned examples as closely as
I understand, but am obviously missing something. (I can provide
more detail on my code, but didn't want to clutter up this already
Thanks in advance for any merciful help.