123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- #include "includes.h"
- #ifdef CONFIG_DYNAMIC_EAP_METHODS
- #include <dlfcn.h>
- #endif
- #include "common.h"
- #include "eap_i.h"
- #include "eap_methods.h"
- static struct eap_method *eap_methods = NULL;
- const struct eap_method * eap_peer_get_eap_method(int vendor, EapType method)
- {
- struct eap_method *m;
- for (m = eap_methods; m; m = m->next) {
- if (m->vendor == vendor && m->method == method)
- return m;
- }
- return NULL;
- }
- EapType eap_peer_get_type(const char *name, int *vendor)
- {
- struct eap_method *m;
- for (m = eap_methods; m; m = m->next) {
- if (os_strcmp(m->name, name) == 0) {
- *vendor = m->vendor;
- return m->method;
- }
- }
- *vendor = EAP_VENDOR_IETF;
- return EAP_TYPE_NONE;
- }
- const char * eap_get_name(int vendor, EapType type)
- {
- struct eap_method *m;
- if (vendor == EAP_VENDOR_IETF && type == EAP_TYPE_EXPANDED)
- return "expanded";
- for (m = eap_methods; m; m = m->next) {
- if (m->vendor == vendor && m->method == type)
- return m->name;
- }
- return NULL;
- }
- size_t eap_get_names(char *buf, size_t buflen)
- {
- char *pos, *end;
- struct eap_method *m;
- int ret;
- if (buflen == 0)
- return 0;
- pos = buf;
- end = pos + buflen;
- for (m = eap_methods; m; m = m->next) {
- ret = os_snprintf(pos, end - pos, "%s%s",
- m == eap_methods ? "" : " ", m->name);
- if (ret < 0 || ret >= end - pos)
- break;
- pos += ret;
- }
- buf[buflen - 1] = '\0';
- return pos - buf;
- }
- char ** eap_get_names_as_string_array(size_t *num)
- {
- struct eap_method *m;
- size_t array_len = 0;
- char **array;
- int i = 0, j;
- for (m = eap_methods; m; m = m->next)
- array_len++;
- array = os_zalloc(sizeof(char *) * (array_len + 1));
- if (array == NULL)
- return NULL;
- for (m = eap_methods; m; m = m->next) {
- array[i++] = os_strdup(m->name);
- if (array[i - 1] == NULL) {
- for (j = 0; j < i; j++)
- os_free(array[j]);
- os_free(array);
- return NULL;
- }
- }
- array[i] = NULL;
- if (num)
- *num = array_len;
- return array;
- }
- const struct eap_method * eap_peer_get_methods(size_t *count)
- {
- int c = 0;
- struct eap_method *m;
- for (m = eap_methods; m; m = m->next)
- c++;
-
- *count = c;
- return eap_methods;
- }
- #ifdef CONFIG_DYNAMIC_EAP_METHODS
- int eap_peer_method_load(const char *so)
- {
- void *handle;
- int (*dyn_init)(void);
- int ret;
- handle = dlopen(so, RTLD_LAZY);
- if (handle == NULL) {
- wpa_printf(MSG_ERROR, "EAP: Failed to open dynamic EAP method "
- "'%s': %s", so, dlerror());
- return -1;
- }
- dyn_init = dlsym(handle, "eap_peer_method_dynamic_init");
- if (dyn_init == NULL) {
- dlclose(handle);
- wpa_printf(MSG_ERROR, "EAP: Invalid EAP method '%s' - no "
- "eap_peer_method_dynamic_init()", so);
- return -1;
- }
- ret = dyn_init();
- if (ret) {
- dlclose(handle);
- wpa_printf(MSG_ERROR, "EAP: Failed to add EAP method '%s' - "
- "ret %d", so, ret);
- return ret;
- }
-
- eap_methods->dl_handle = handle;
- wpa_printf(MSG_DEBUG, "EAP: Loaded dynamic EAP method: '%s'", so);
- return 0;
- }
- int eap_peer_method_unload(struct eap_method *method)
- {
- struct eap_method *m, *prev;
- void *handle;
- m = eap_methods;
- prev = NULL;
- while (m) {
- if (m == method)
- break;
- prev = m;
- m = m->next;
- }
- if (m == NULL || m->dl_handle == NULL)
- return -1;
- if (prev)
- prev->next = m->next;
- else
- eap_methods = m->next;
- handle = m->dl_handle;
- if (m->free)
- m->free(m);
- else
- eap_peer_method_free(m);
- dlclose(handle);
- return 0;
- }
- #endif
- struct eap_method * eap_peer_method_alloc(int version, int vendor,
- EapType method, const char *name)
- {
- struct eap_method *eap;
- eap = os_zalloc(sizeof(*eap));
- if (eap == NULL)
- return NULL;
- eap->version = version;
- eap->vendor = vendor;
- eap->method = method;
- eap->name = name;
- return eap;
- }
- void eap_peer_method_free(struct eap_method *method)
- {
- os_free(method);
- }
- int eap_peer_method_register(struct eap_method *method)
- {
- struct eap_method *m, *last = NULL;
- if (method == NULL || method->name == NULL ||
- method->version != EAP_PEER_METHOD_INTERFACE_VERSION)
- return -1;
- for (m = eap_methods; m; m = m->next) {
- if ((m->vendor == method->vendor &&
- m->method == method->method) ||
- os_strcmp(m->name, method->name) == 0)
- return -2;
- last = m;
- }
- if (last)
- last->next = method;
- else
- eap_methods = method;
- return 0;
- }
- void eap_peer_unregister_methods(void)
- {
- struct eap_method *m;
- #ifdef CONFIG_DYNAMIC_EAP_METHODS
- void *handle;
- #endif
- while (eap_methods) {
- m = eap_methods;
- eap_methods = eap_methods->next;
- #ifdef CONFIG_DYNAMIC_EAP_METHODS
- handle = m->dl_handle;
- #endif
- if (m->free)
- m->free(m);
- else
- eap_peer_method_free(m);
- #ifdef CONFIG_DYNAMIC_EAP_METHODS
- if (handle)
- dlclose(handle);
- #endif
- }
- }
|