OK, forget my hints, now I remember why I didn't do that
right from the beginning: the call to ldap_initialize cannot
assess whether the server is up or not, since the connection
is actually established when the first operation is attempted.
There needs be a lot of reworking to allow this kind of feature
(which is not impossible in principle), but a lot of specific
coding is required, and it cannot definitely done at the API
level (unless extensively playing with the LDAP* structure)
More on this: the point is that ldap_initialize() expects
a comma/space separated url list; unfortunately, I chose
to use a (legal) URI of the form <PROTO>://[<host>]:[<PORT>]/<DN>
to simultaneously specify the protocol, the host, the port AND
the base dn for a specific target, and the commas in the dn are
erroneously parsed into illegal URIs.
One workaround is to change ldap_url_parselist() to use only spaces
as separators (dunno who relies on URI lists being comma-separated,
though).
Another workaround is to use semicolons ';' to separate RDNs
in the <DN> part of the URI; note that semicolons as RDN separators
are deprecated, but currently accepted by OpenLDAP's DN parsing code,
as required by rfc2253.
This way, you can specify a list of URIs. I haven't checked
if the URIs are tried in sequence in case one or more fail.
P.M.