]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fallback to hostnames if we don't have ldap_url_parse, ldap_is_ldap_url, ldap_urldesc...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 30 Jun 2015 14:37:36 +0000 (10:37 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 30 Jun 2015 14:39:08 +0000 (10:39 -0400)
Use ldap_url_desc2str to produce the URL we pass to ldap_initialize, this should fix ldapi://

src/modules/rlm_ldap/config.h.in
src/modules/rlm_ldap/configure
src/modules/rlm_ldap/configure.ac
src/modules/rlm_ldap/rlm_ldap.c

index 12fadca2382434146f58ebc7f97d48fa385234da..e392d4894f9a1f25d07dde2ef253ec52473ca1cb 100644 (file)
@@ -12,6 +12,9 @@
 /* Define to 1 if you have the `ldap_initialize' function. */
 #undef HAVE_LDAP_INITIALIZE
 
+/* Define to 1 if you have the `ldap_is_ldap_url' function. */
+#undef HAVE_LDAP_IS_LDAP_URL
+
 /* Define to 1 if you have the `ldap_sasl_interactive_bind' function. */
 #undef HAVE_LDAP_SASL_INTERACTIVE_BIND
 
 /* Define to 1 if you have the `ldap_unbind_ext_s' function. */
 #undef HAVE_LDAP_UNBIND_EXT_S
 
+/* Define to 1 if you have the `ldap_url_desc2str' function. */
+#undef HAVE_LDAP_URL_DESC2STR
+
+/* Define to 1 if you have the `ldap_url_parse' function. */
+#undef HAVE_LDAP_URL_PARSE
+
 /* Number of arguments the rebind procedure takes */
 #undef LDAP_SET_REBIND_PROC_ARGS
 
index 2675abe9646603e7d80d8dad15f5dbac6c340a65..c8f0e74b6b18c1560772f51c8c43184e77e1864f 100755 (executable)
@@ -3105,7 +3105,10 @@ smart_prefix=
                        ldap_set_rebind_proc \
                        ldap_create_sort_control \
                        ldap_create_sort_keylist \
-                       ldap_free_sort_keylist
+                       ldap_free_sort_keylist \
+                       ldap_url_parse \
+                       ldap_is_ldap_url \
+                       ldap_url_desc2str
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
index 20215caf8997e478bbe0689109191706504efc70..bce260ba7f6653a2c48d6b99d2741e2ce08f8f5e 100644 (file)
@@ -94,7 +94,10 @@ if test x$with_[]modname != xno; then
                        ldap_set_rebind_proc \
                        ldap_create_sort_control \
                        ldap_create_sort_keylist \
-                       ldap_free_sort_keylist
+                       ldap_free_sort_keylist \
+                       ldap_url_parse \
+                       ldap_is_ldap_url \
+                       ldap_url_desc2str
                )
                AC_CACHE_CHECK(whether ldap_set_rebind_proc takes 3 arguments, ac_cv_ldap_set_rebind_proc, [
                        AC_TRY_COMPILE([
index 7a49eb43eed62af5d8aff22f050c60055d72f75a..1dc7feaf81bf6e772d8a5d87ab21f099403948eb 100644 (file)
@@ -852,6 +852,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
 
                value = cf_pair_value(cp);
 
+#if defined(HAVE_LDAP_URL_PARSE) && defined(HAVE_LDAP_IS_LDAP_URL) && defined(LDAP_URL_DESC2STR)
                /*
                 *      Split original server value out into URI, server and port
                 *      so whatever initialization function we use later will have
@@ -859,65 +860,87 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                 */
                if (ldap_is_ldap_url(value)) {
                        LDAPURLDesc     *ldap_url;
-                       int             port = -1;
+                       int             default_port = LDAP_PORT;
 
                        if (ldap_url_parse(value, &ldap_url)){
                                cf_log_err_cs(conf, "Parsing LDAP URL \"%s\" failed", value);
+                       ldap_url_error:
+                               ldap_free_urldesc(ldap_url);
                                return -1;
                        }
 
-#ifndef HAVE_LDAP_INITIALIZE
-                       /*
-                        *      No LDAP initialize function.  Can't specify a scheme.
-                        */
-                       if (ldap_url->lud_scheme &&
-                           (strcmp(ldap_url->lud_scheme, "ldaps") == 0) ||
-                           (strcmp(ldap_url->lud_scheme, "ldapi") == 0) ||
-                           (strcmp(ldap_url->lud_scheme, "cldap") == 0)) {
-                               cf_log_err_cs(conf, "%s is not supported by linked libldap",
-                                             ldap_url->lud_scheme);
-                               return -1;
+                       if (ldap_url->lud_dn) {
+                               cf_log_err_cs(conf, "Base DN cannot be specified via server URL");
+                               goto ldap_url_error;
                        }
 
-#else
-                       /*
-                        *      Figure out the port from the URL
-                        */
-                       if (ldap_url->lud_scheme) {
-                               if (strcmp(ldap_url->lud_scheme, "ldaps") == 0) {
+                       if (ldap_url->lud_attrs && ldap_url->lud_attrs[0]) {
+                               cf_log_err_cs(conf, "Attribute list cannot be specified via server URL");
+                               goto ldap_url_error;
+                       }
+
+                       if (ldap_url->lud_scope >= 0) {
+                               cf_log_err_cs(conf, "Scope cannot be specified via server URL");
+                               goto ldap_url_error;
+                       }
+
+                       /* We allow extensions */
+
+#  ifdef HAVE_LDAP_INITIALIZE
+                       {
+                               char *url;
+
+                               /*
+                                *      Figure out the default port from the URL
+                                */
+                               if (ldap_url->lud_scheme && (strcmp(ldap_url->lud_scheme, "ldaps") == 0)) {
                                        if (inst->start_tls == true) {
                                                cf_log_err_cs(conf, "ldaps:// scheme is not compatible "
                                                              "with 'start_tls'");
-                                               return -1;
+                                               goto ldap_url_error;
                                        }
+                                       default_port = LDAPS_PORT;
+                               }
 
-                                       port = inst->port ? inst->port : LDAPS_PORT;
-
-                               } else if (strcmp(ldap_url->lud_scheme, "ldapi") == 0) {
-                                       port = 0;
-
-                               } else if (strcmp(ldap_url->lud_scheme, "cldap") == 0) {
-                                       port = inst->port ? inst->port : LDAP_PORT;
-                               } /* else don't set the port */
-                       }         /* else don't set the port */
-#endif
-                       if (port < 0) port = inst->port ? inst->port : LDAP_PORT;
+                               /*
+                                *      Configured port overrides URL port
+                                */
+                               if (inst->port) ldap_url->lud_port = inst->port;
 
+                               /*
+                                *      If there's no URL port, then set it to the default
+                                *      this is so debugging messages show explicitly
+                                *      the port we're connecting to.
+                                */
+                               if (!ldap_url->lud_port) ldap_url->lud_port = default_port;
 
-                       if (ldap_url->lud_port > 0) port = ldap_url->lud_port;
+                               url = ldap_url_desc2str(ldap_url);
+                               if (!url) {
+                                       cf_log_err_cs(conf, "Failed recombining URL components");
+                                       goto ldap_url_error;
+                               }
+                               inst->server = talloc_asprintf_append(inst->server, "%s ", url);
+                               LDAP_FREE(url);
+                       }
+#  else
+                       /*
+                        *      No LDAP initialize function.  Can't specify a scheme.
+                        */
+                       if (ldap_url->lud_scheme &&
+                           ((strcmp(ldap_url->lud_scheme, "ldaps") == 0) ||
+                           (strcmp(ldap_url->lud_scheme, "ldapi") == 0) ||
+                           (strcmp(ldap_url->lud_scheme, "cldap") == 0))) {
+                               cf_log_err_cs(conf, "%s is not supported by linked libldap",
+                                             ldap_url->lud_scheme);
+                               return -1;
+                       }
 
-#ifdef HAVE_LDAP_INITIALIZE
-                       inst->server = talloc_asprintf_append(inst->server, "%s://%s",
-                                                             ldap_url->lud_scheme ? ldap_url->lud_scheme : "ldap",
-                                                             ldap_url->lud_host ? ldap_url->lud_host : "");
-                       if (port) inst->server = talloc_asprintf_append(inst->server, ":%i", port);
-                       inst->server = talloc_strdup_append(inst->server, " ");
-#else
+                       default_port = inst->port ? inst->port : LDAP_PORT;
                        inst->server = talloc_asprintf_append(inst->server, "%s",
                                                              ldap_url->lud_host ? ldap_url->lud_host : "localhost");
-                       if (port) inst->server = talloc_asprintf_append(inst->server, ":%i", port);
+                       if (default_port) inst->server = talloc_asprintf_append(inst->server, ":%i", default_port);
                        inst->server = talloc_strdup_append(inst->server, " ");
-#endif
+#  endif
                        /*
                         *      @todo We could set a few other top level
                         *      directives using the URL, like base_dn
@@ -927,7 +950,14 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                /*
                 *      We need to construct an LDAP URI
                 */
-               } else {
+               } else
+#endif /* HAVE_LDAP_URL_PARSE && HAVE_LDAP_IS_LDAP_URL && LDAP_URL_DESC2STR */
+               /*
+                *      If it's not an URL, or we don't have the functions necessary
+                *      to break apart the URL and recombine it, then just treat
+                *      server as a hostname.
+                */
+               {
 #ifdef HAVE_LDAP_INITIALIZE
                        char    const *p;
                        char    *q;