Remove fr_connection_delete
[freeradius.git] / src / modules / rlm_ldap / rlm_ldap.c
index 6987f26..6593303 100644 (file)
@@ -42,8 +42,9 @@ FR_NAME_NUMBER const ldap_scope[] = {
        { "sub",        LDAP_SCOPE_SUB  },
        { "one",        LDAP_SCOPE_ONE  },
        { "base",       LDAP_SCOPE_BASE },
+#ifdef LDAP_SCOPE_CHILDREN
        { "children",   LDAP_SCOPE_CHILDREN },
-
+#endif
        {  NULL , -1 }
 };
 
@@ -59,6 +60,15 @@ FR_NAME_NUMBER const ldap_tls_require_cert[] = {
 };
 #endif
 
+FR_NAME_NUMBER const ldap_dereference[] = {
+       { "never",      LDAP_DEREF_NEVER        },
+       { "searching",  LDAP_DEREF_SEARCHING    },
+       { "finding",    LDAP_DEREF_FINDING      },
+       { "always",     LDAP_DEREF_ALWAYS       },
+
+       {  NULL , -1 }
+};
+
 /*
  *     TLS Configuration
  */
@@ -66,37 +76,37 @@ static CONF_PARSER tls_config[] = {
        /*
         *      Deprecated attributes
         */
-       {"cacertfile", PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, offsetof(ldap_instance_t, tls_ca_file), NULL, NULL},
-       {"ca_file", PW_TYPE_FILE_INPUT, offsetof(ldap_instance_t, tls_ca_file), NULL, NULL},
+       { "cacertfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_ca_file), NULL },
+       { "ca_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_ca_file), NULL },
 
-       {"cacertdir", PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, offsetof(ldap_instance_t, tls_ca_path), NULL, NULL},
-       {"ca_path", PW_TYPE_FILE_INPUT, offsetof(ldap_instance_t, tls_ca_path), NULL, NULL},
+       { "cacertdir", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_ca_path), NULL },
+       { "ca_path", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_ca_path), NULL },
 
-       {"certfile", PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, offsetof(ldap_instance_t, tls_certificate_file), NULL, NULL},
-       {"certificate_file", PW_TYPE_FILE_INPUT, offsetof(ldap_instance_t, tls_certificate_file), NULL, NULL},
+       { "certfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_certificate_file), NULL },
+       { "certificate_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_certificate_file), NULL },
 
-       {"keyfile", PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, offsetof(ldap_instance_t, tls_private_key_file), NULL, NULL}, // OK if it changes on HUP
-       {"private_key_file", PW_TYPE_FILE_INPUT, offsetof(ldap_instance_t, tls_private_key_file), NULL, NULL}, // OK if it changes on HUP
+       { "keyfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_private_key_file), NULL }, // OK if it changes on HUP
+       { "private_key_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_private_key_file), NULL }, // OK if it changes on HUP
 
-       {"randfile", PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, offsetof(ldap_instance_t, tls_random_file), NULL, NULL},
-       {"random_file", PW_TYPE_FILE_INPUT, offsetof(ldap_instance_t, tls_random_file), NULL, NULL},
+       { "randfile", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, ldap_instance_t, tls_random_file), NULL },
+       { "random_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, ldap_instance_t, tls_random_file), NULL },
 
        /*
         *      LDAP Specific TLS attributes
         */
-       {"start_tls", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t, start_tls), NULL, "no"},
-       {"require_cert", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, tls_require_cert_str), NULL, NULL},
+       { "start_tls", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, start_tls), "no" },
+       { "require_cert", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, tls_require_cert_str), NULL },
 
        { NULL, -1, 0, NULL, NULL }
 };
 
 
 static CONF_PARSER profile_config[] = {
-       {"filter", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, profile_filter), NULL, "(&)"}, //!< Correct filter for
+       { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, profile_filter), "(&)" },   //!< Correct filter for
                                                                                                //!< when the DN is
                                                                                                //!< known.
-       {"attribute", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, profile_attr), NULL, NULL},
-       {"default", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, default_profile), NULL, NULL},
+       { "attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, profile_attr), NULL },
+       { "default", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, default_profile), NULL },
 
        { NULL, -1, 0, NULL, NULL }
 };
@@ -105,12 +115,12 @@ static CONF_PARSER profile_config[] = {
  *     User configuration
  */
 static CONF_PARSER user_config[] = {
-       {"filter", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, userobj_filter), NULL, "(uid=%u)"},
-       {"scope", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, userobj_scope_str), NULL, "sub"},
-       {"base_dn", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t,userobj_base_dn), NULL, ""},
+       { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_filter), "(uid=%u)" },
+       { "scope", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_scope_str), "sub" },
+       { "base_dn", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_base_dn), "" },
 
-       {"access_attribute", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, userobj_access_attr), NULL, NULL},
-       {"access_positive", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t, access_positive), NULL, "yes"},
+       { "access_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_access_attr), NULL },
+       { "access_positive", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, access_positive), "yes" },
 
        { NULL, -1, 0, NULL, NULL }
 };
@@ -119,15 +129,16 @@ static CONF_PARSER user_config[] = {
  *     Group configuration
  */
 static CONF_PARSER group_config[] = {
-       {"filter", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, groupobj_filter), NULL, NULL},
-       {"scope", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, groupobj_scope_str), NULL, "sub"},
-       {"base_dn", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, groupobj_base_dn), NULL, ""},
+       { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_filter), NULL },
+       { "scope", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_scope_str), "sub" },
+       { "base_dn", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_base_dn), "" },
 
-       {"name_attribute", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, groupobj_name_attr), NULL, "cn"},
-       {"membership_attribute", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, userobj_membership_attr), NULL, NULL},
-       {"membership_filter", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, groupobj_membership_filter), NULL, NULL},
-       {"cacheable_name", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t, cacheable_group_name), NULL, "no"},
-       {"cacheable_dn", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t, cacheable_group_dn), NULL, "no"},
+       { "name_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_name_attr), "cn" },
+       { "membership_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, userobj_membership_attr), NULL },
+       { "membership_filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, groupobj_membership_filter), NULL },
+       { "cacheable_name", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, cacheable_group_name), "no" },
+       { "cacheable_dn", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, cacheable_group_dn), "no" },
+       { "cache_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, cache_attribute), NULL },
 
        { NULL, -1, 0, NULL, NULL }
 };
@@ -136,22 +147,21 @@ static CONF_PARSER group_config[] = {
  *     Client configuration
  */
 static CONF_PARSER client_attribute[] = {
-       {"identifier", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_identifier), NULL, "host"},
-       {"shortname", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_shortname), NULL, "cn"},
-       {"nas_type", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_type), NULL, NULL},
-       {"secret", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_secret), NULL, NULL},
-       {"virtual_server", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_server), NULL, NULL},
-       {"require_message_authenticator", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_require_ma),
-        NULL, NULL},
+       { "identifier", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_identifier), "host" },
+       { "shortname", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_shortname), "cn" },
+       { "nas_type", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_type), NULL },
+       { "secret", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_secret), NULL },
+       { "virtual_server", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_server), NULL },
+       { "require_message_authenticator", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_require_ma), NULL },
 
        { NULL, -1, 0, NULL, NULL }
 };
 
 static CONF_PARSER client_config[] = {
-       {"filter", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_filter), NULL, NULL},
-       {"scope", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_scope_str), NULL, "sub"},
-       {"base_dn", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, clientobj_base_dn), NULL, ""},
-       {"attribute", PW_TYPE_SUBSECTION, 0, NULL, (void const *) client_attribute},
+       { "filter", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_filter), NULL },
+       { "scope", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_scope_str), "sub" },
+       { "base_dn", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, clientobj_base_dn), "" },
+       { "attribute", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) client_attribute },
 
        { NULL, -1, 0, NULL, NULL }
 };
@@ -160,7 +170,7 @@ static CONF_PARSER client_config[] = {
  *     Reference for accounting updates
  */
 static const CONF_PARSER acct_section_config[] = {
-       {"reference", PW_TYPE_STRING_PTR, offsetof(ldap_acct_section_t, reference), NULL, "."},
+       { "reference", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_acct_section_t, reference), "." },
 
        {NULL, -1, 0, NULL, NULL}
 };
@@ -174,29 +184,33 @@ static CONF_PARSER option_config[] = {
        /*
         *      Debugging flags to the server
         */
-       {"ldap_debug", PW_TYPE_INTEGER, offsetof(ldap_instance_t,ldap_debug), NULL, "0x0000"},
+       { "ldap_debug", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, ldap_debug), "0x0000" },
 
-       {"chase_referrals", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t,chase_referrals), NULL, NULL},
+       { "dereference", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, dereference_str), NULL },
 
-       {"rebind", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t,rebind), NULL, NULL},
+       { "chase_referrals", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, chase_referrals), NULL },
 
+       { "rebind", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, rebind), NULL },
+
+#ifdef LDAP_OPT_NETWORK_TIMEOUT
        /* timeout on network activity */
-       {"net_timeout", PW_TYPE_INTEGER, offsetof(ldap_instance_t,net_timeout), NULL, "10"},
+       { "net_timeout", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, net_timeout), "10" },
+#endif
 
        /* timeout for search results */
-       {"res_timeout", PW_TYPE_INTEGER, offsetof(ldap_instance_t,res_timeout), NULL, "20"},
+       { "res_timeout", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, res_timeout), "20" },
 
        /* allow server unlimited time for search (server-side limit) */
-       {"srv_timelimit", PW_TYPE_INTEGER, offsetof(ldap_instance_t,srv_timelimit), NULL, "20"},
+       { "srv_timelimit", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, srv_timelimit), "20" },
 
 #ifdef LDAP_OPT_X_KEEPALIVE_IDLE
-       {"idle", PW_TYPE_INTEGER, offsetof(ldap_instance_t,keepalive_idle), NULL, "60"},
+       { "idle", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, keepalive_idle), "60" },
 #endif
 #ifdef LDAP_OPT_X_KEEPALIVE_PROBES
-       {"probes", PW_TYPE_INTEGER, offsetof(ldap_instance_t,keepalive_probes), NULL, "3"},
+       { "probes", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, keepalive_probes), "3" },
 #endif
 #ifdef LDAP_OPT_X_KEEPALIVE_INTERVAL
-       {"interval", PW_TYPE_INTEGER,  offsetof(ldap_instance_t,keepalive_interval), NULL, "30"},
+       { "interval", FR_CONF_OFFSET(PW_TYPE_INTEGER, ldap_instance_t, keepalive_interval), "30" },
 #endif
 
        { NULL, -1, 0, NULL, NULL }
@@ -204,38 +218,38 @@ static CONF_PARSER option_config[] = {
 
 
 static const CONF_PARSER module_config[] = {
-       {"server", PW_TYPE_STRING_PTR | PW_TYPE_REQUIRED, offsetof(ldap_instance_t,server), NULL, "localhost"},
-       {"port", PW_TYPE_INTEGER, offsetof(ldap_instance_t,port), NULL, "389"},
+       { "server", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_REQUIRED, ldap_instance_t, server), "localhost" },
+       { "port", FR_CONF_OFFSET(PW_TYPE_SHORT, ldap_instance_t, port), "389" },
 
-       {"password", PW_TYPE_STRING_PTR | PW_TYPE_SECRET, offsetof(ldap_instance_t,password), NULL, ""},
-       {"identity", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t,admin_dn), NULL, ""},
+       { "password", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_SECRET, ldap_instance_t, password), "" },
+       { "identity", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, admin_dn), "" },
 
-       {"valuepair_attribute", PW_TYPE_STRING_PTR, offsetof(ldap_instance_t, valuepair_attr), NULL, NULL},
+       { "valuepair_attribute", FR_CONF_OFFSET(PW_TYPE_STRING, ldap_instance_t, valuepair_attr), NULL },
 
 #ifdef WITH_EDIR
        /* support for eDirectory Universal Password */
-       {"edir", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t,edir), NULL, NULL}, /* NULL defaults to "no" */
+       { "edir", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, edir), NULL }, /* NULL defaults to "no" */
 
        /*
         *      Attempt to bind with the cleartext password we got from eDirectory
         *      Universal password for additional authorization checks.
         */
-       {"edir_autz", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t,edir_autz), NULL, NULL}, /* NULL defaults to "no" */
+       { "edir_autz", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, edir_autz), NULL }, /* NULL defaults to "no" */
 #endif
 
-       {"read_clients", PW_TYPE_BOOLEAN, offsetof(ldap_instance_t,do_clients), NULL, NULL}, /* NULL defaults to "no" */
+       { "read_clients", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, ldap_instance_t, do_clients), NULL }, /* NULL defaults to "no" */
 
-       { "user", PW_TYPE_SUBSECTION, 0, NULL, (void const *) user_config },
+       { "user", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) user_config },
 
-       { "group", PW_TYPE_SUBSECTION, 0, NULL, (void const *) group_config },
+       { "group", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) group_config },
 
-       { "client", PW_TYPE_SUBSECTION, 0, NULL, (void const *) client_config },
+       { "client", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) client_config },
 
-       { "profile", PW_TYPE_SUBSECTION, 0, NULL, (void const *) profile_config },
+       { "profile", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) profile_config },
 
-       { "options", PW_TYPE_SUBSECTION, 0, NULL, (void const *) option_config },
+       { "options", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) option_config },
 
-       { "tls", PW_TYPE_SUBSECTION, 0, NULL, (void const *) tls_config },
+       { "tls", FR_CONF_POINTER(PW_TYPE_SUBSECTION, NULL), (void const *) tls_config },
 
        {NULL, -1, 0, NULL, NULL}
 };
@@ -283,7 +297,7 @@ static ssize_t ldap_xlat(void *instance, REQUEST *request, char const *fmt, char
 
        if (ldap_url->lud_host &&
            ((strncmp(inst->server, ldap_url->lud_host, strlen(inst->server)) != 0) ||
-            (ldap_url->lud_port != inst->port))) {
+            ((uint32_t) ldap_url->lud_port != inst->port))) {
                RDEBUG("Requested server/port is \"%s:%i\"", ldap_url->lud_host, inst->port);
 
                goto free_urldesc;
@@ -483,7 +497,7 @@ static int mod_detach(void *instance)
  * @return 0 on success, else < 0 on failure.
  */
 static int parse_sub_section(ldap_instance_t *inst, CONF_SECTION *parent, ldap_acct_section_t **config,
-                            rlm_components_t comp)
+                            rlm_components_t comp)
 {
        CONF_SECTION *cs;
 
@@ -519,6 +533,8 @@ static int parse_sub_section(ldap_instance_t *inst, CONF_SECTION *parent, ldap_a
  */
 static int mod_instantiate(CONF_SECTION *conf, void *instance)
 {
+       static bool version_done;
+
        CONF_SECTION *options;
        ldap_instance_t *inst = instance;
 
@@ -535,6 +551,39 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        }
 
        /*
+        *      Get version info from the LDAP API.
+        */
+       if (!version_done) {
+               int ldap_errno;
+               LDAPAPIInfo info;
+
+               version_done = true;
+
+               ldap_errno = ldap_get_option(NULL, LDAP_OPT_API_INFO, &info);
+               if (ldap_errno == LDAP_OPT_SUCCESS) {
+                       if (strcmp(info.ldapai_vendor_name, LDAP_VENDOR_NAME) != 0) {
+                               WARN("rlm_ldap: libldap vendor changed since the server was built");
+                               WARN("rlm_ldap: linked: %s built: %s", info.ldapai_vendor_name, LDAP_VENDOR_NAME);
+                       }
+
+                       if (info.ldapai_vendor_version != LDAP_VENDOR_VERSION) {
+                               WARN("rlm_ldap: libldap version changed since the server was built");
+                               WARN("rlm_ldap: linked: %i built: %i",
+                                    info.ldapai_vendor_version, LDAP_VENDOR_VERSION);
+                       }
+
+                       INFO("rlm_ldap: libldap vendor: %s version: %i", info.ldapai_vendor_name,
+                            info.ldapai_vendor_version);
+                       ldap_memfree(info.ldapai_vendor_name);
+                       ldap_memfree(info.ldapai_extensions);
+               } else {
+                       WARN("rlm_ldap: Falling back to build time libldap version info.  Query for LDAP_OPT_API_INFO "
+                            "returned: %i", ldap_errno);
+                       INFO("rlm_ldap: libldap vendor: %s version: %i", LDAP_VENDOR_NAME, LDAP_VENDOR_VERSION);
+               }
+       }
+
+       /*
         *      If the configuration parameters can't be parsed, then fail.
         */
        if ((parse_sub_section(inst, conf, &inst->accounting, RLM_COMPONENT_ACCT) < 0) ||
@@ -569,6 +618,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
 #endif
        }
 
+#ifdef LDAP_OPT_X_TLS_NEVER
        /*
         *      Workaround for servers which support LDAPS but not START TLS
         */
@@ -577,6 +627,19 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        } else {
                inst->tls_mode = 0;
        }
+#endif
+
+       /*
+        *      Convert dereference strings to enumerated constants
+        */
+       if (inst->dereference_str) {
+               inst->dereference = fr_str2int(ldap_dereference, inst->dereference_str, -1);
+               if (inst->dereference < 0) {
+                       LDAP_ERR("Invalid 'dereference' value \"%s\", expected 'never', 'searching', "
+                                "'finding' or 'always'", inst->dereference_str);
+                       goto error;
+               }
+       }
 
 #if LDAP_SET_REBIND_PROC_ARGS != 3
        /*
@@ -596,22 +659,37 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
         */
        inst->userobj_scope = fr_str2int(ldap_scope, inst->userobj_scope_str, -1);
        if (inst->userobj_scope < 0) {
-               LDAP_ERR("Invalid 'user.scope' value \"%s\", expected 'sub', 'one', 'base' or 'children'",
-                        inst->userobj_scope_str);
+               LDAP_ERR("Invalid 'user.scope' value \"%s\", expected 'sub', 'one'"
+#ifdef LDAP_SCOPE_CHILDREN
+                        ", 'base' or 'children'"
+#else
+                        " or 'base'"
+#endif
+                        , inst->userobj_scope_str);
                goto error;
        }
 
        inst->groupobj_scope = fr_str2int(ldap_scope, inst->groupobj_scope_str, -1);
        if (inst->groupobj_scope < 0) {
-               LDAP_ERR("Invalid 'group.scope' value \"%s\", expected 'sub', 'one', 'base' or 'children'",
-                        inst->groupobj_scope_str);
+               LDAP_ERR("Invalid 'group.scope' value \"%s\", expected 'sub', 'one'"
+#ifdef LDAP_SCOPE_CHILDREN
+                        ", 'base' or 'children'"
+#else
+                        " or 'base'"
+#endif
+                        , inst->groupobj_scope_str);
                goto error;
        }
 
        inst->clientobj_scope = fr_str2int(ldap_scope, inst->clientobj_scope_str, -1);
        if (inst->clientobj_scope < 0) {
-               LDAP_ERR("Invalid 'client.scope' value \"%s\", expected 'sub', 'one', 'base' or 'children'",
-                        inst->clientobj_scope_str);
+               LDAP_ERR("Invalid 'client.scope' value \"%s\", expected 'sub', 'one'"
+#ifdef LDAP_SCOPE_CHILDREN
+                        ", 'base' or 'children'"
+#else
+                        " or 'base'"
+#endif
+                        , inst->clientobj_scope_str);
                goto error;
        }
 
@@ -628,7 +706,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                }
 #else
                LDAP_ERR("Modifying 'tls.require_cert' is not supported by current version of libldap. "
-                        "Please upgrade libldap and rebuild this module");
+                        "Please upgrade or substitute current libldap and rebuild this module");
 
                goto error;
 #endif
@@ -644,14 +722,15 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
         *      Group comparison checks.
         */
        if (cf_section_name2(conf)) {
-               ATTR_FLAGS flags;
+               static ATTR_FLAGS flags;
                char buffer[256];
 
-               snprintf(buffer, sizeof(buffer), "%s-Ldap-Group",
-                        inst->xlat_name);
-               memset(&flags, 0, sizeof(flags));
+               snprintf(buffer, sizeof(buffer), "%s-Ldap-Group", inst->xlat_name);
+               if (dict_addattr(buffer, -1, 0, PW_TYPE_STRING, flags) < 0) {
+                       LDAP_ERR("Error creating group attribute: %s", fr_strerror());
 
-               dict_addattr(buffer, -1, 0, PW_TYPE_STRING, flags);
+                       return -1;
+               }
                inst->group_da = dict_attrbyname(buffer);
                if (!inst->group_da) {
                        LDAP_ERR("Failed creating attribute %s", buffer);
@@ -672,9 +751,25 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        xlat_register(inst->xlat_name, ldap_xlat, rlm_ldap_escape_func, inst);
 
        /*
+        *      Setup the cache attribute
+        */
+       if (inst->cache_attribute) {
+               static ATTR_FLAGS flags;
+
+               if (dict_addattr(inst->cache_attribute, -1, 0, PW_TYPE_STRING, flags) < 0) {
+                       LDAP_ERR("Error creating cache attribute: %s", fr_strerror());
+
+                       return -1;
+               }
+               inst->cache_da = dict_attrbyname(inst->cache_attribute);
+       } else {
+               inst->cache_da = inst->group_da;        /* Default to the group_da */
+       }
+
+       /*
         *      Initialize the socket pool.
         */
-       inst->pool = fr_connection_pool_init(inst->cs, inst, mod_conn_create, NULL, mod_conn_delete, NULL);
+       inst->pool = fr_connection_pool_init(inst->cs, inst, mod_conn_create, NULL, NULL);
        if (!inst->pool) {
                return -1;
        }
@@ -696,13 +791,7 @@ error:
        return -1;
 }
 
-/** Check the user's password against ldap directory
- *
- * @param instance rlm_ldap configuration.
- * @param request Current request.
- * @return one of the RLM_MODULE_* values.
- */
-static rlm_rcode_t mod_authenticate(void *instance, REQUEST *request)
+static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *request)
 {
        rlm_rcode_t     rcode;
        ldap_rcode_t    status;
@@ -723,13 +812,13 @@ static rlm_rcode_t mod_authenticate(void *instance, REQUEST *request)
 
        if (!request->password ||
            (request->password->da->attr != PW_USER_PASSWORD)) {
-               RWDEBUG("You have set \"Auth-Type := LDAP\" somewhere.");
+               RWDEBUG("You have set \"Auth-Type := LDAP\" somewhere");
                RWDEBUG("*********************************************");
                RWDEBUG("* THAT CONFIGURATION IS WRONG.  DELETE IT.   ");
-               RWDEBUG("* YOU ARE PREVENTING THE SERVER FROM WORKING.");
+               RWDEBUG("* YOU ARE PREVENTING THE SERVER FROM WORKING");
                RWDEBUG("*********************************************");
 
-               REDEBUG("Attribute \"User-Password\" is required for authentication.");
+               REDEBUG("Attribute \"User-Password\" is required for authentication");
 
                return RLM_MODULE_INVALID;
        }
@@ -792,10 +881,7 @@ static rlm_rcode_t mod_authenticate(void *instance, REQUEST *request)
        return rcode;
 }
 
-/** Check if user is authorized for remote access
- *
- */
-static rlm_rcode_t mod_authorize(void *instance, REQUEST *request)
+static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, REQUEST *request)
 {
        rlm_rcode_t     rcode = RLM_MODULE_OK;
        ldap_rcode_t    status;
@@ -810,7 +896,7 @@ static rlm_rcode_t mod_authorize(void *instance, REQUEST *request)
        rlm_ldap_map_xlat_t     expanded; /* faster than mallocing every time */
 
        if (!request->username) {
-               RDEBUG2("Attribute \"User-Name\" is required for authorization.");
+               RDEBUG2("Attribute \"User-Name\" is required for authorization");
 
                return RLM_MODULE_NOOP;
        }
@@ -1093,13 +1179,13 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
         *      Iterate over all the pairs, building our mods array
         */
        for (ci = cf_item_find_next(cs, NULL); ci != NULL; ci = cf_item_find_next(cs, ci)) {
-               bool do_xlat = false;
+               bool do_xlat = false;
 
-               if (total == LDAP_MAX_ATTRMAP) {
-                       REDEBUG("Modify map size exceeded");
+               if (total == LDAP_MAX_ATTRMAP) {
+                       REDEBUG("Modify map size exceeded");
 
-                       goto error;
-               }
+                       goto error;
+               }
 
                if (!cf_item_is_pair(ci)) {
                        REDEBUG("Entry is not in \"ldap-attribute = value\" format");
@@ -1121,18 +1207,19 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
                        continue;
                }
 
-               switch (cf_pair_value_type(cp))
-               {
-                       case T_BARE_WORD:
-                       case T_SINGLE_QUOTED_STRING:
+               switch (cf_pair_value_type(cp)) {
+               case T_BARE_WORD:
+               case T_SINGLE_QUOTED_STRING:
                        break;
-                       case T_BACK_QUOTED_STRING:
-                       case T_DOUBLE_QUOTED_STRING:
-                               do_xlat = true;
+
+               case T_BACK_QUOTED_STRING:
+               case T_DOUBLE_QUOTED_STRING:
+                       do_xlat = true;
                        break;
-                       default:
-                               rad_assert(0);
-                               goto error;
+
+               default:
+                       rad_assert(0);
+                       goto error;
                }
 
                if (op == T_OP_CMP_FALSE) {
@@ -1140,7 +1227,7 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
                } else if (do_xlat) {
                        char *exp = NULL;
 
-                       if (radius_xlat(exp, 0, request, value, NULL, NULL) <= 0) {
+                       if (radius_axlat(&exp, request, value, NULL, NULL) <= 0) {
                                RDEBUG("Skipping attribute \"%s\"", attr);
 
                                talloc_free(exp);
@@ -1163,8 +1250,7 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
 
                last_pass += 2;
 
-               switch (op)
-               {
+               switch (op) {
                /*
                 *  T_OP_EQ is *NOT* supported, it is impossible to
                 *  support because of the lack of transactions in LDAP
@@ -1189,7 +1275,7 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
 #endif
                default:
                        REDEBUG("Operator '%s' is not supported for LDAP modify operations",
-                               fr_int2str(fr_tokens, op, "<INVALID>"));
+                               fr_int2str(fr_tokens, op, "<INVALID>"));
 
                        goto error;
                }
@@ -1198,7 +1284,7 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
                 *      Now we know the value is ok, copy the pointers into
                 *      the ldapmod struct.
                 */
-               memcpy(&(mod_s[total].mod_type), &(attr), sizeof(mod_s[total].mod_type));
+               memcpy(&(mod_s[total].mod_type), &attr, sizeof(mod_s[total].mod_type));
 
                mod_p[total] = &(mod_s[total]);
                total++;
@@ -1249,7 +1335,7 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
        return rcode;
 }
 
-static rlm_rcode_t mod_accounting(void *instance, REQUEST * request) {
+static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST * request) {
        ldap_instance_t *inst = instance;
 
        if (inst->accounting) {
@@ -1259,7 +1345,7 @@ static rlm_rcode_t mod_accounting(void *instance, REQUEST * request) {
        return RLM_MODULE_NOOP;
 }
 
-static rlm_rcode_t mod_post_auth(void *instance, REQUEST * request)
+static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST * request)
 {
        ldap_instance_t *inst = instance;
 
@@ -1275,7 +1361,7 @@ static rlm_rcode_t mod_post_auth(void *instance, REQUEST * request)
 module_t rlm_ldap = {
        RLM_MODULE_INIT,
        "ldap",
-       RLM_TYPE_THREAD_SAFE | RLM_TYPE_CHECK_CONFIG_SAFE,      /* type: reserved        */
+       RLM_TYPE_THREAD_SAFE,   /* type: reserved        */
        sizeof(ldap_instance_t),
        module_config,
        mod_instantiate,        /* instantiation         */