Same fix for eap session and handler trees
[freeradius.git] / src / modules / rlm_eap / rlm_eap.c
index 2423964..b3ff531 100644 (file)
@@ -30,16 +30,11 @@ RCSID("$Id$")
 #include "rlm_eap.h"
 
 static const CONF_PARSER module_config[] = {
-       { "default_eap_type", PW_TYPE_STRING_PTR,
-         offsetof(rlm_eap_t, default_method_name), NULL, "md5" },
-       { "timer_expire", PW_TYPE_INTEGER,
-         offsetof(rlm_eap_t, timer_limit), NULL, "60"},
-       { "ignore_unknown_eap_types", PW_TYPE_BOOLEAN,
-         offsetof(rlm_eap_t, ignore_unknown_types), NULL, "no" },
-       { "mod_accounting_username_bug", PW_TYPE_BOOLEAN,
-         offsetof(rlm_eap_t, mod_accounting_username_bug), NULL, "no" },
-       { "max_sessions", PW_TYPE_INTEGER,
-         offsetof(rlm_eap_t, max_sessions), NULL, "2048"},
+       { "default_eap_type", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_eap_t, default_method_name), "md5" },
+       { "timer_expire", FR_CONF_OFFSET(PW_TYPE_INTEGER, rlm_eap_t, timer_limit), "60" },
+       { "ignore_unknown_eap_types", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_t, ignore_unknown_types), "no" },
+       { "mod_accounting_username_bug", FR_CONF_OFFSET(PW_TYPE_BOOLEAN, rlm_eap_t, mod_accounting_username_bug), "no" },
+       { "max_sessions", FR_CONF_OFFSET(PW_TYPE_INTEGER, rlm_eap_t, max_sessions), "2048" },
 
        { NULL, -1, 0, NULL, NULL }        /* end the list */
 };
@@ -59,7 +54,14 @@ static int mod_detach(void *instance)
 #endif
 
        rbtree_free(inst->session_tree);
-       if (inst->handler_tree) rbtree_free(inst->handler_tree);
+       if (inst->handler_tree) {
+               rbtree_free(inst->handler_tree);
+               /*
+                *  Must be NULL else when nodes are freed they try to
+                *  delete themselves from the tree.
+                */
+               inst->handler_tree = NULL;
+       }
        inst->session_tree = NULL;
        eaplist_free(inst);
 
@@ -224,18 +226,20 @@ static int mod_instantiate(CONF_SECTION *cs, void *instance)
         *      Lookup sessions in the tree.  We don't free them in
         *      the tree, as that's taken care of elsewhere...
         */
-       inst->session_tree = rbtree_create(eap_handler_cmp, NULL, 0);
+       inst->session_tree = rbtree_create(NULL, eap_handler_cmp, NULL, 0);
        if (!inst->session_tree) {
                ERROR("rlm_eap (%s): Cannot initialize tree", inst->xlat_name);
                return -1;
        }
+       fr_link_talloc_ctx_free(inst, inst->session_tree);
 
        if (fr_debug_flag) {
-               inst->handler_tree = rbtree_create(eap_handler_ptr_cmp, NULL, 0);
+               inst->handler_tree = rbtree_create(NULL, eap_handler_ptr_cmp, NULL, 0);
                if (!inst->handler_tree) {
                        ERROR("rlm_eap (%s): Cannot initialize tree", inst->xlat_name);
                        return -1;
                }
+               fr_link_talloc_ctx_free(inst, inst->handler_tree);
 
 #ifdef HAVE_PTHREAD_H
                if (pthread_mutex_init(&(inst->handler_mutex), NULL) < 0) {
@@ -315,8 +319,8 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re
        /*
         *      If we're doing horrible tunneling work, remember it.
         */
-       if ((request->options & RAD_REQUEST_OPTION_PROXY_EAP) != 0) {
-               RDEBUG2("  Not-EAP proxy set.  Not composing EAP");
+       if ((request->log.lvl & RAD_REQUEST_OPTION_PROXY_EAP) != 0) {
+               RDEBUG2("No EAP proxy set.  Not composing EAP");
                /*
                 *      Add the handle to the proxied list, so that we
                 *      can retrieve it in the post-proxy stage, and
@@ -373,7 +377,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re
                 */
                pairdelete(&request->proxy->vps, PW_FREERADIUS_PROXIED_TO, VENDORPEC_FREERADIUS, TAG_ANY);
 
-               RDEBUG2("  Tunneled session will be proxied.  Not doing EAP.");
+               RDEBUG2("Tunneled session will be proxied.  Not doing EAP");
                return RLM_MODULE_HANDLED;
        }
 #endif
@@ -432,7 +436,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *re
         *      says that we MUST include a User-Name attribute in the
         *      Access-Accept.
         */
-       if ((request->reply->code == PW_CODE_AUTHENTICATION_ACK) &&
+       if ((request->reply->code == PW_CODE_ACCESS_ACCEPT) &&
            request->username) {
                VALUE_PAIR *vp;
 
@@ -551,11 +555,6 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_proxy(void *inst, REQUEST *request)
        vp_cursor_t     cursor;
 
        /*
-        *      Just in case the admin lists EAP in post-proxy-type Fail.
-        */
-       if (!request->proxy_reply) return RLM_MODULE_NOOP;
-
-       /*
         *      If there was a handler associated with this request,
         *      then it's a tunneled request which was proxied...
         */
@@ -618,7 +617,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_proxy(void *inst, REQUEST *request)
                 *      says that we MUST include a User-Name attribute in the
                 *      Access-Accept.
                 */
-               if ((request->reply->code == PW_CODE_AUTHENTICATION_ACK) &&
+               if ((request->reply->code == PW_CODE_ACCESS_ACCEPT) &&
                    request->username) {
                        /*
                         *      Doesn't exist, add it in.