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

ldap_url_search fails when URL does not specify host (ldap:///) (ITS#843)

Full_Name: Brian Candler
Version: 2.0.6
OS: FreeBSD-4.1
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (

If you explicitly open a connection to a particular host, but then give a URL
without a host to ldap_url_search, the search fails (error 81,

Demonstration: the program below fails with the first version of #define URL,
but works with the second version of #define URL.

#include <stdio.h>
#include <ldap.h>

#define HOST ""
#define URL  "ldap:///o=whatever,c=GB??sub?(objectclass=*)"
/* #define URL  "ldap://,c=GB??sub?(objectclass=*)" */

int main(void)
  LDAP *ld = ldap_open(HOST, 389);
  LDAPMessage *result;
  int r1, r2;
  int errorno;

  r1 = ldap_url_search(ld, URL, 0);
  if (r1 == -1) {
    char *error;
    ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error);
    fprintf(stderr, "Error in ldap_url_search: %s\n", error?error:"NULL");
    ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &errorno);
    fprintf(stderr, "Error in ldap_url_search: %d\n", errorno);
    return 1;
  r2 = ldap_result(ld, LDAP_RES_ANY, 1, NULL, &result);
  if (r2 == -1) {
    char *error;
    ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error);
    fprintf(stderr, "Error in ldap_result: %s\n", error);
    return 1;
  return 0;

Error in ldap_url_search: NULL
Error in ldap_url_search: 81

Possibly connected: ldap_url_parse now seems to return an
empty string, rather than a null pointer, in lud_host for URLs without
explicit hosts.