123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #include "includes.h"
- #include "common.h"
- #include "eap_i.h"
- #include "eap_methods.h"
- static struct eap_method *eap_methods;
- const struct eap_method * eap_server_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_server_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;
- }
- struct eap_method * eap_server_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;
- }
- static void eap_server_method_free(struct eap_method *method)
- {
- os_free(method);
- }
- int eap_server_method_register(struct eap_method *method)
- {
- struct eap_method *m, *last = NULL;
- if (method == NULL || method->name == NULL ||
- method->version != EAP_SERVER_METHOD_INTERFACE_VERSION) {
- eap_server_method_free(method);
- 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) {
- eap_server_method_free(method);
- return -2;
- }
- last = m;
- }
- if (last)
- last->next = method;
- else
- eap_methods = method;
- return 0;
- }
- void eap_server_unregister_methods(void)
- {
- struct eap_method *m;
- while (eap_methods) {
- m = eap_methods;
- eap_methods = eap_methods->next;
- if (m->free)
- m->free(m);
- else
- eap_server_method_free(m);
- }
- }
- const char * eap_server_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 "unknown";
- }
|