]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Pass a more flexible, arbitrary pointer to enum_name_get_t's
authorMartin Willi <martin@revosec.ch>
Mon, 3 Sep 2012 08:31:33 +0000 (10:31 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 3 Sep 2012 14:13:58 +0000 (16:13 +0200)
13 files changed:
src/libcharon/encoding/message.c
src/libcharon/plugins/eap_dynamic/eap_dynamic.c
src/libcharon/plugins/eap_peap/eap_peap_peer.c
src/libcharon/plugins/eap_peap/eap_peap_server.c
src/libcharon/plugins/eap_ttls/eap_ttls_server.c
src/libcharon/plugins/stroke/stroke_list.c
src/libcharon/plugins/tnc_pdp/tnc_pdp.c
src/libcharon/sa/ikev2/authenticators/eap_authenticator.c
src/libstrongswan/eap/eap.c
src/libstrongswan/eap/eap.h
src/libstrongswan/enum.c
src/libstrongswan/enum.h
src/libstrongswan/library.c

index 26f8a5f81b21cadf9852fb99ef038da84e6817cc..6531971e088aa46cb869049e2c0bddd6bd228c22 100644 (file)
@@ -1230,7 +1230,7 @@ static char* get_string(private_message_t *this, char *buf, int len)
                        if (type)
                        {
                                snprintf(method, sizeof(method), "/%M",
-                                               eap_type_get_names, vendor, type);
+                                                eap_type_get_names, &vendor, type);
                        }
                        written = snprintf(pos, len, "/%N%s", eap_code_short_names,
                                                           eap->get_code(eap), method);
index 37f1e3d4353dabc9a234a127145dc446a01bed51..9c167a68c6246e9b29d8d7012ca7db25d9e631d5 100644 (file)
@@ -92,7 +92,7 @@ static eap_method_t *load_method(private_eap_dynamic_t *this,
        if (!method)
        {
                DBG1(DBG_IKE, "loading EAP-%M method failed",
-                        eap_type_get_names, vendor, type);
+                        eap_type_get_names, &vendor, type);
        }
        return method;
 }
@@ -121,7 +121,7 @@ static void select_method(private_eap_dynamic_t *this)
                                                                  NULL, entry) != SUCCESS)
                        {
                                DBG2(DBG_IKE, "proposed EAP-%M method not supported "
-                                        "by %s, skipped", eap_type_get_names, entry->vendor,
+                                        "by %s, skipped", eap_type_get_names, &entry->vendor,
                                         entry->type, who);
                                free(entry);
                                continue;
@@ -131,7 +131,7 @@ static void select_method(private_eap_dynamic_t *this)
                if (this->method)
                {
                        DBG1(DBG_IKE, "EAP-%M method selected",
-                                eap_type_get_names, entry->vendor, entry->type);
+                                eap_type_get_names, &entry->vendor, entry->type);
                        free(entry);
                        break;
                }
index 3fd83fb37f7d4a462b33ced9c61857f23ea60abb..936c0caac9e91f5f7576e751e3990858c79892b9 100644 (file)
@@ -97,7 +97,7 @@ static status_t process_phase2(private_eap_peap_peer_t *this, eap_payload_t *in)
        received_type = in->get_type(in, &received_vendor);
        DBG1(DBG_IKE, "received tunneled EAP-PEAP AVP [ EAP/%N/%M ]",
                 eap_code_short_names, code,
-                eap_type_get_names, received_vendor, received_type);
+                eap_type_get_names, &received_vendor, received_type);
 
        /* yet another phase2 authentication? */
        if (this->ph2)
@@ -114,7 +114,7 @@ static status_t process_phase2(private_eap_peap_peer_t *this, eap_payload_t *in)
        if (this->ph2 == NULL)
        {
                DBG1(DBG_IKE, "server requested EAP method %M (id 0x%02X)",
-                        eap_type_get_names, received_vendor, received_type,
+                        eap_type_get_names, &received_vendor, received_type,
                         in->get_identifier(in));
                this->ph2 = charon->eap->create_instance(charon->eap,
                                                                        received_type, received_vendor,
@@ -143,7 +143,7 @@ static status_t process_phase2(private_eap_peap_peer_t *this, eap_payload_t *in)
                        return NEED_MORE;
                case FAILED:
                default:
-                       DBG1(DBG_IKE, "EAP-%M failed", eap_type_get_names, vendor, type);
+                       DBG1(DBG_IKE, "EAP-%M failed", eap_type_get_names, &vendor, type);
                        return FAILED;
        }
 }
@@ -280,7 +280,7 @@ static status_t process_eap_with_header(private_eap_peap_peer_t *this,
                        }
                        DBG1(DBG_IKE, "received tunneled EAP-PEAP AVP [ EAP/%N/%M ]",
                                 eap_code_short_names, code,
-                                eap_type_get_names, vendor, type);
+                                eap_type_get_names, &vendor, type);
                        if (vendor == PEN_MICROSOFT && type == EAP_MS_CAPABILITES)
                        {
                                return process_capabilities(this, reader);
@@ -340,7 +340,7 @@ METHOD(tls_application_t, build, status_t,
                type = this->out->get_type(this->out, &vendor);
                DBG1(DBG_IKE, "sending tunneled EAP-PEAP AVP [ EAP/%N/%M ]",
                         eap_code_short_names, code,
-                        eap_type_get_names, vendor, type);
+                        eap_type_get_names, &vendor, type);
 
                data = this->out->get_data(this->out);
 
index ed0559345e3a02c22af4c10b542235cf1f74d997..d6ae65d68a7e96d12fd01d4491d13817b5dae1c0 100644 (file)
@@ -100,13 +100,13 @@ static status_t start_phase2_auth(private_eap_peap_server_t *this)
                DBG1(DBG_IKE, "unrecognized phase2 method \"%s\"", eap_type_str);
                return FAILED;
        }
-       DBG1(DBG_IKE, "phase2 method %M selected", eap_type_get_names, vendor, type);
+       DBG1(DBG_IKE, "phase2 method %M selected", eap_type_get_names, &vendor, type);
                this->ph2_method = charon->eap->create_instance(charon->eap, type,
                                                                vendor, EAP_SERVER, this->server, this->peer);
        if (this->ph2_method == NULL)
        {
                DBG1(DBG_IKE, "%M method not available",
-                        eap_type_get_names, vendor, type);
+                        eap_type_get_names, &vendor, type);
                return FAILED;
        }
 
@@ -120,7 +120,7 @@ static status_t start_phase2_auth(private_eap_peap_server_t *this)
        }
        else
        {
-               DBG1(DBG_IKE, "%M method failed", eap_type_get_names, vendor, type);
+               DBG1(DBG_IKE, "%M method failed", eap_type_get_names, &vendor, type);
                return FAILED;
        }
 }
index 35aee1067e00a816cd4bed24f5ebe3f2b41e92bf..0e9ac45c5344247b291ff56b9d643a8a820d1462 100644 (file)
@@ -87,13 +87,13 @@ static status_t start_phase2_auth(private_eap_ttls_server_t *this)
                DBG1(DBG_IKE, "unrecognized phase2 method \"%s\"", eap_type_str);
                return FAILED;
        }
-       DBG1(DBG_IKE, "phase2 method %M selected", eap_type_get_names, vendor, type);
+       DBG1(DBG_IKE, "phase2 method %M selected", eap_type_get_names, &vendor, type);
                this->method = charon->eap->create_instance(charon->eap, type, vendor,
                                                                EAP_SERVER, this->server, this->peer);
        if (this->method == NULL)
        {
                DBG1(DBG_IKE, "%M method not available",
-                        eap_type_get_names, vendor, type);
+                        eap_type_get_names, &vendor, type);
                return FAILED;
        }
        if (this->method->initiate(this->method, &this->out) == NEED_MORE)
@@ -102,7 +102,7 @@ static status_t start_phase2_auth(private_eap_ttls_server_t *this)
        }
        else
        {
-               DBG1(DBG_IKE, "%M method failed", eap_type_get_names, vendor, type);
+               DBG1(DBG_IKE, "%M method failed", eap_type_get_names, &vendor, type);
                return FAILED;
        }
 }
index 7c856d07e85cdfe9902c97e2327172d810348b92..a99483a18dce96fa02df0f26313ceceddfbb3c06 100644 (file)
@@ -355,10 +355,14 @@ static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
                        }
                        else
                        {
+                               u_int32_t vendor;
+                               eap_type_t type;
+
+                               vendor = (uintptr_t)auth->get(auth, AUTH_RULE_EAP_VENDOR);
+                               type = (uintptr_t)auth->get(auth, AUTH_RULE_EAP_TYPE);
+
                                fprintf(out, "EAP-%M authentication",
-                                               eap_type_get_names,
-                                               (uintptr_t)auth->get(auth, AUTH_RULE_EAP_VENDOR),
-                                               (uintptr_t)auth->get(auth, AUTH_RULE_EAP_TYPE));
+                                               eap_type_get_names, &vendor, type);
                        }
                        id = auth->get(auth, AUTH_RULE_EAP_IDENTITY);
                        if (id)
index 952d2ad49d50a166364337a50ab711e60757af3b..bd61f5abbab4e511ca523d1157e071b6287e515c 100644 (file)
@@ -275,7 +275,7 @@ static void send_response(private_tnc_pdp_t *this, radius_message_t *request,
        {
                data = eap->get_data(eap);
                DBG3(DBG_CFG, "%M payload %B",
-                        eap_type_get_names, this->vendor, this->type, &data);
+                        eap_type_get_names, &this->vendor, this->type, &data);
 
                /* fragment data suitable for RADIUS */
                while (data.len > MAX_RADIUS_ATTRIBUTE_SIZE)
@@ -365,7 +365,7 @@ static void process_eap(private_tnc_pdp_t *this, radius_message_t *request,
                eap_type = in->get_type(in, &eap_vendor);
 
                DBG3(DBG_CFG, "EAP-%M payload %B",
-                        eap_type_get_names, eap_vendor, eap_type, &message);
+                        eap_type_get_names, &eap_vendor, eap_type, &message);
 
                if (eap_type == EAP_IDENTITY)
                {
@@ -651,7 +651,7 @@ tnc_pdp_t *tnc_pdp_create(u_int16_t port)
                return NULL;
        }
        DBG1(DBG_IKE, "eap method %M selected",
-                eap_type_get_names, this->vendor, this->type);
+                eap_type_get_names, &this->vendor, this->type);
 
        lib->processor->queue_job(lib->processor,
                (job_t*)callback_job_create_with_prio((callback_job_cb_t)receive, this,
index 84b2f02c58096d51ed4e1442d2786a205847d516..408785e3d3bde30d32d091f422b148253754f7f7 100644 (file)
@@ -191,14 +191,14 @@ static eap_payload_t* server_initiate_eap(private_eap_authenticator_t *this,
                {
                        type = this->method->get_type(this->method, &vendor);
                        DBG1(DBG_IKE, "%s EAP-%M method (id 0x%02X)", action,
-                                eap_type_get_names, vendor, type, out->get_identifier(out));
+                                eap_type_get_names, &vendor, type, out->get_identifier(out));
                        return out;
                }
                /* type might have changed for virtual methods */
                type = this->method->get_type(this->method, &vendor);
        }
        DBG1(DBG_IKE, "%s EAP-%M method failed", action,
-                eap_type_get_names, vendor, type);
+                eap_type_get_names, &vendor, type);
        return eap_payload_create_code(EAP_FAILURE, 0);
 }
 
@@ -285,7 +285,7 @@ static eap_payload_t* server_process_eap(private_eap_authenticator_t *this,
                                this->msk = chunk_clone(this->msk);
                        }
                        DBG1(DBG_IKE, "EAP method %M succeeded, %sMSK established",
-                                eap_type_get_names, vendor, type, this->msk.ptr ? "" : "no ");
+                                eap_type_get_names, &vendor, type, this->msk.ptr ? "" : "no ");
                        this->ike_sa->set_condition(this->ike_sa, COND_EAP_AUTHENTICATED,
                                                                                TRUE);
                        this->eap_complete = TRUE;
@@ -294,7 +294,7 @@ static eap_payload_t* server_process_eap(private_eap_authenticator_t *this,
                default:
                        /* type might have changed for virtual methods */
                        DBG1(DBG_IKE, "EAP method %M failed for peer %Y",
-                                eap_type_get_names, vendor, type,
+                                eap_type_get_names, &vendor, type,
                                 this->ike_sa->get_other_id(this->ike_sa));
                        return eap_payload_create_code(EAP_FAILURE, in->get_identifier(in));
        }
@@ -348,7 +348,7 @@ static eap_payload_t* client_process_eap(private_eap_authenticator_t *this,
        if (this->method == NULL)
        {
                DBG1(DBG_IKE, "server requested %M authentication (id 0x%02X)",
-                        eap_type_get_names, vendor, type, in->get_identifier(in));
+                        eap_type_get_names, &vendor, type, in->get_identifier(in));
 
                auth = this->ike_sa->get_auth_cfg(this->ike_sa, TRUE);
                conf_type = (uintptr_t)auth->get(auth, AUTH_RULE_EAP_TYPE);
@@ -357,7 +357,7 @@ static eap_payload_t* client_process_eap(private_eap_authenticator_t *this,
                   (conf_type != type || conf_vendor != vendor))
                {
                        DBG1(DBG_IKE, "requesting EAP-%M authentication, sending EAP_NAK",
-                                eap_type_get_names, conf_vendor, conf_type);
+                                eap_type_get_names, &conf_vendor, conf_type);
                        return eap_payload_create_nak(in->get_identifier(in), conf_type,
                                                                                  conf_vendor, in->is_expanded(in));
                }
@@ -377,7 +377,7 @@ static eap_payload_t* client_process_eap(private_eap_authenticator_t *this,
                return out;
        }
 
-       DBG1(DBG_IKE, "EAP-%M method failed", eap_type_get_names, vendor, type);
+       DBG1(DBG_IKE, "EAP-%M method failed", eap_type_get_names, &vendor, type);
        return NULL;
 }
 
@@ -528,7 +528,7 @@ METHOD(authenticator_t, process_client, status_t,
                        type = this->method->get_type(this->method, &vendor);
                        DBG1(DBG_IKE, "EAP-only authentication requires a mutual and "
                                 "MSK deriving EAP method, but %M is not",
-                                eap_type_get_names, vendor, type);
+                                eap_type_get_names, &vendor, type);
                        return FAILED;
                }
                return SUCCESS;
@@ -561,7 +561,7 @@ METHOD(authenticator_t, process_client, status_t,
                                }
                                type = this->method->get_type(this->method, &vendor);
                                DBG1(DBG_IKE, "EAP method %M succeeded, %sMSK established",
-                                        eap_type_get_names, vendor, type,
+                                        eap_type_get_names, &vendor, type,
                                         this->msk.ptr ? "" : "no ");
                                cfg = this->ike_sa->get_auth_cfg(this->ike_sa, TRUE);
                                cfg->add(cfg, AUTH_RULE_EAP_TYPE, type);
index a566626329e2740b360b9345c6ae8ba472a25727..eb7781d7b0c50311252422eb867c8b171d5ad093 100644 (file)
@@ -24,8 +24,8 @@
 /**
  * Forward declaration of enum name fallback callback.
  */
-static int eap_type_names_cb(printf_hook_data_t *data, int vendor,
-                                                        enum_name_t *e, int type);
+static int eap_type_names_cb(printf_hook_data_t *data, enum_name_t *e, int type,
+                                                        void *vendor);
 
 ENUM(eap_code_names, EAP_REQUEST, EAP_FAILURE,
        "EAP_REQUEST",
@@ -110,10 +110,10 @@ ENUM_CB(eap_vendor_names_ms, eap_type_names_cb, EAP_MS_SOH, EAP_MS_CAPABILITES,
 /**
  * Callback function if mapping EAP type to enum name failed
  */
-static int eap_type_names_cb(printf_hook_data_t *data, int vendor,
-                                                        enum_name_t *e, int type)
+static int eap_type_names_cb(printf_hook_data_t *data, enum_name_t *e, int type,
+                                                        void *vendor)
 {
-       if (e == eap_type_short_names)
+       if (e == eap_type_short_names || !vendor)
        {
                return print_in_hook(data, "%d", type);
        }
@@ -121,15 +121,15 @@ static int eap_type_names_cb(printf_hook_data_t *data, int vendor,
        {
                return print_in_hook(data, "MS-%d", type);
        }
-       return print_in_hook(data, "%d-%d", type, vendor);
+       return print_in_hook(data, "%d-%d", type, *(u_int32_t*)vendor);
 }
 
 /*
  * See header
  */
-enum_name_t* eap_type_get_names(pen_t vendor)
+enum_name_t* eap_type_get_names(u_int32_t *vendor)
 {
-       switch (vendor)
+       switch (*vendor)
        {
                case PEN_IETF:
                        return eap_type_short_names;
@@ -178,7 +178,7 @@ eap_type_t eap_type_from_string(char *name, u_int32_t *vendor)
        /* check IETF and vendor specific names */
        for (i = 0; i < countof(vendors); i++)
        {
-               enum_name = eap_type_get_names(vendors[i]);
+               enum_name = eap_type_get_names(&vendors[i]);
                if (enum_name != eap_vendor_names_unknown)
                {
                        type = enum_from_name(enum_name, name);
index 8e735daa678bd4190d306936845dc9f7f25d5b54..2529c17e8af5b305833e2c92afbddf73a8a85099 100644 (file)
@@ -97,9 +97,12 @@ enum eap_vendor_type_t {
 };
 
 /**
- * Get the enum names for a specific vendor
+ * Get the enum names for a specific vendor, implementing enum_name_get_t.
+ *
+ * @param vendor               pointer to vendor ID
+ * @return                             enum name for given vendor
  */
-enum_name_t* eap_type_get_names(pen_t vendor);
+enum_name_t* eap_type_get_names(u_int32_t *vendor);
 
 /**
  * EAP packet format
index 31f2d09c666d8e9adea90eb7f9dfb66e78365605..57aaf9f99c9901596aa767532a5667409e121a72 100644 (file)
@@ -80,7 +80,7 @@ int enum_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
        {
                if (e->cb)
                {
-                       return e->cb(data, 0, e, val);
+                       return e->cb(data, e, val, NULL);
                }
                return print_in_hook(data, "(%d)", val);
        }
@@ -98,14 +98,15 @@ int enum_dynamic_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
 {
        enum_name_t *e;
        enum_name_get_t e_get;
-       int val, id = 0;
+       int val;
        char *name = NULL;
+       void *user;
 
        e_get = *((enum_name_get_t*)(args[0]));
-       id = *((int*)(args[1]));
+       user = *((void**)(args[1]));
        val = *((int*)(args[2]));
 
-       e = e_get(id);
+       e = e_get(user);
        if (e)
        {
                name = enum_to_name(e, val);
@@ -114,7 +115,7 @@ int enum_dynamic_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
        {
                if (e && e->cb)
                {
-                       return e->cb(data, id, e, val);
+                       return e->cb(data, e, val, user);
                }
                return print_in_hook(data, "(%d)", val);
        }
index 69cf5a62b57cef9badd962ddc728b437d1eb6339..1751da6bce4d45e031e9c11fd4209cc6f8fcba16 100644 (file)
@@ -28,12 +28,12 @@ typedef struct enum_name_t enum_name_t;
 typedef struct enum_name_elem_t enum_name_elem_t;
 
 /**
- * Callback function to get an enum name using an index variable.
+ * Callback function to get an enum name.
  *
- * @param                      index variable to select enum_name_t
+ * @param user         function specific pointer value to select enum name
  * @return                     enum name
  */
-typedef enum_name_t* (*enum_name_get_t)(int id);
+typedef enum_name_t* (*enum_name_get_t)(void *user);
 
 /**
  * Fallback callback to call if enum could not be mapped to a string.
@@ -42,13 +42,13 @@ typedef enum_name_t* (*enum_name_get_t)(int id);
  * with the supplied data to write to the output stream.
  *
  * @param data         printf hook data to pass to print_in_hook()
- * @param id           index variable, as passed to enum_name_get function, or 0
  * @param e                    enum name for which callback is invoked
  * @param val          enum value to map
+ * @param user         function specific pointer, as passed to enum_name_get_t
  * @return                     number of characters written
  */
-typedef int (*enum_name_cb_t)(printf_hook_data_t *data, int id, enum_name_t *e,
-                                                         int val);
+typedef int (*enum_name_cb_t)(printf_hook_data_t *data, enum_name_t *e,
+                                                         int val, void *user);
 
 /**
  * Struct to store names for enums.
@@ -79,8 +79,8 @@ typedef int (*enum_name_cb_t)(printf_hook_data_t *data, int id, enum_name_t *e,
  *
  * To select an enum name dynamically, the %M printf format specifier can be
  * used. Instead of an enum_name_t, the printf hook expects a enum_name_get_t
- * followed by an index, followed by the enum value. The enum_name_t is looked
- * up using the function and the index argument.
+ * followed by a pointer, followed by the enum value. The enum_name_t is looked
+ * up using the function and the function specific pointer argument.
  */
 struct enum_name_t {
        /** first enum_name_elem_t in chain */
index 9a19f6b6d52ab951ec1001b396dcc666e2a7028d..f8ef8c1cf877ef77277e070c6012ae17193a3a88 100644 (file)
@@ -169,7 +169,7 @@ bool library_init(char *settings)
                                         PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,
                                         PRINTF_HOOK_ARGTYPE_END);
        pfh->add_handler(pfh, 'M', enum_dynamic_printf_hook,
-                                        PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,
+                                        PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_POINTER,
                                         PRINTF_HOOK_ARGTYPE_INT, PRINTF_HOOK_ARGTYPE_END);
        pfh->add_handler(pfh, 'T', time_printf_hook,
                                         PRINTF_HOOK_ARGTYPE_POINTER, PRINTF_HOOK_ARGTYPE_INT,