Use a string to identify xauth backends, no need for integer types

This commit is contained in:
Martin Willi
2012-03-20 17:31:15 +01:00
parent 4e73f85b81
commit 1fe6cdfac2
11 changed files with 52 additions and 187 deletions
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2011 Martin Willi
* Copyright (C) 2011 revosec AG
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -27,17 +27,12 @@ typedef struct xauth_entry_t xauth_entry_t;
struct xauth_entry_t {
/**
* XAuth method type, vendor specific if vendor is set
* Xauth backend name
*/
xauth_type_t type;
char *name;
/**
* vendor ID, 0 for default XAuth methods
*/
u_int32_t vendor;
/**
* Role of the method returned by the constructor, XAUTH_SERVER or XAUTH_PEER
* Role of the method, XAUTH_SERVER or XAUTH_PEER
*/
xauth_role_t role;
@@ -69,15 +64,16 @@ struct private_xauth_manager_t {
};
METHOD(xauth_manager_t, add_method, void,
private_xauth_manager_t *this, xauth_type_t type, u_int32_t vendor,
xauth_role_t role, xauth_constructor_t constructor)
private_xauth_manager_t *this, char *name, xauth_role_t role,
xauth_constructor_t constructor)
{
xauth_entry_t *entry = malloc_thing(xauth_entry_t);
xauth_entry_t *entry;
entry->type = type;
entry->vendor = vendor;
entry->role = role;
entry->constructor = constructor;
INIT(entry,
.name = name,
.role = role,
.constructor = constructor,
);
this->lock->write_lock(this->lock);
this->methods->insert_last(this->methods, entry);
@@ -105,8 +101,8 @@ METHOD(xauth_manager_t, remove_method, void,
}
METHOD(xauth_manager_t, create_instance, xauth_method_t*,
private_xauth_manager_t *this, xauth_type_t type, u_int32_t vendor,
xauth_role_t role, identification_t *server, identification_t *peer)
private_xauth_manager_t *this, char *name, xauth_role_t role,
identification_t *server, identification_t *peer)
{
enumerator_t *enumerator;
xauth_entry_t *entry;
@@ -116,8 +112,7 @@ METHOD(xauth_manager_t, create_instance, xauth_method_t*,
enumerator = this->methods->create_enumerator(this->methods);
while (enumerator->enumerate(enumerator, &entry))
{
if (type == entry->type && vendor == entry->vendor &&
role == entry->role)
if (streq(name, entry->name) && role == entry->role)
{
method = entry->constructor(server, peer);
if (method)
@@ -147,14 +142,14 @@ xauth_manager_t *xauth_manager_create()
private_xauth_manager_t *this;
INIT(this,
.public = {
.add_method = _add_method,
.remove_method = _remove_method,
.create_instance = _create_instance,
.destroy = _destroy,
},
.methods = linked_list_create(),
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
.public = {
.add_method = _add_method,
.remove_method = _remove_method,
.create_instance = _create_instance,
.destroy = _destroy,
},
.methods = linked_list_create(),
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
);
return &this->public;
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2011 Martin Willi
* Copyright (C) 2011 revosec AG
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -38,34 +38,32 @@ struct xauth_manager_t {
/**
* Register a XAuth method implementation.
*
* @param method vendor specific method, if vendor != 0
* @param vendor vendor ID, 0 for non-vendor (default) XAuth methods
* @param role XAuth role of the registered method
* @param name backend name to register
* @param role XAUTH_SERVER or XAUTH_PEER
* @param constructor constructor function, returns an xauth_method_t
*/
void (*add_method)(xauth_manager_t *this, xauth_type_t type, u_int32_t vendor,
void (*add_method)(xauth_manager_t *this, char *name,
xauth_role_t role, xauth_constructor_t constructor);
/**
* Unregister a XAuth method implementation using it's constructor.
*
* @param constructor constructor function to remove, as added in add_method
* @param constructor constructor function, as added in add_method
*/
void (*remove_method)(xauth_manager_t *this, xauth_constructor_t constructor);
/**
* Create a new XAuth method instance.
*
* @param vendor vendor ID, 0 for non-vendor (default) XAuth methods
* @param role role of XAuth method, either XAUTH_SERVER or XAUTH_PEER
* @param name backend name, as it was registered with
* @param role XAUTH_SERVER or XAUTH_PEER
* @param server identity of the server
* @param peer identity of the peer (client)
* @return XAUTH method instance, NULL if no constructor found
*/
xauth_method_t* (*create_instance)(xauth_manager_t *this, xauth_type_t type,
u_int32_t vendor, xauth_role_t role,
identification_t *server,
identification_t *peer);
xauth_method_t* (*create_instance)(xauth_manager_t *this,
char *name, xauth_role_t role,
identification_t *server, identification_t *peer);
/**
* Destroy a eap_manager instance.
@@ -78,4 +76,4 @@ struct xauth_manager_t {
*/
xauth_manager_t *xauth_manager_create();
#endif /** EAP_MANAGER_H_ @}*/
#endif /** XAUTH_MANAGER_H_ @}*/
@@ -30,9 +30,9 @@ bool xauth_method_register(plugin_t *plugin, plugin_feature_t *feature,
{
if (reg)
{
charon->xauth->add_method(charon->xauth, feature->arg.xauth, 0,
feature->type == FEATURE_XAUTH_SERVER ? XAUTH_SERVER : XAUTH_PEER,
(xauth_constructor_t)data);
charon->xauth->add_method(charon->xauth, feature->arg.xauth,
feature->type == FEATURE_XAUTH_SERVER ? XAUTH_SERVER : XAUTH_PEER,
(xauth_constructor_t)data);
}
else
{
@@ -28,7 +28,6 @@ typedef enum xauth_role_t xauth_role_t;
#include <plugins/plugin.h>
#include <utils/identification.h>
#include <encoding/payloads/cp_payload.h>
#include <xauth/xauth.h>
/**
* Role of an xauth_method, SERVER or PEER (client)
@@ -37,6 +36,7 @@ enum xauth_role_t {
XAUTH_SERVER,
XAUTH_PEER,
};
/**
* enum names for xauth_role_t.
*/
@@ -46,12 +46,8 @@ extern enum_name_t *xauth_role_names;
* Interface of an XAuth method for server and client side.
*
* An XAuth method initiates an XAuth exchange and processes requests and
* responses. An XAuth method may need multiple exchanges before succeeding, and
* the xauth_authentication may use multiple XAuth methods to authenticate a peer.
* To accomplish these requirements, all XAuth methods have their own
* implementation while the xauth_authenticatior uses one or more of these
* XAuth methods. Sending of XAUTH(STATUS) message is not the job
* of the method, the xauth_authenticator does this.
* responses. An XAuth method may need multiple exchanges before succeeding.
* Sending of XAUTH(STATUS) message is done by the framework, not a method.
*/
struct xauth_method_t {
@@ -84,14 +80,6 @@ struct xauth_method_t {
status_t (*process) (xauth_method_t *this, cp_payload_t *in,
cp_payload_t **out);
/**
* Get the XAuth type implemented in this method.
*
* @param vendor pointer receiving vendor identifier for type, 0 for none
* @return type of the XAuth method
*/
xauth_type_t (*get_type) (xauth_method_t *this, u_int32_t *vendor);
/**
* Destroys a eap_method_t object.
*/
@@ -106,8 +94,6 @@ struct xauth_method_t {
* Constructors for server and peers are identical, to support both roles
* of a XAuth method, a plugin needs register two constructors in the
* xauth_manager_t.
* The passed identites are of type ID_EAP and valid only during the
* constructor invocation.
*
* @param server ID of the server to use for credential lookup
* @param peer ID of the peer to use for credential lookup
@@ -128,6 +114,6 @@ typedef xauth_method_t *(*xauth_constructor_t)(identification_t *server,
* @param data data passed to callback, an xauth_constructor_t
*/
bool xauth_method_register(plugin_t *plugin, plugin_feature_t *feature,
bool reg, void *data);
bool reg, void *data);
#endif /** XAUTH_METHOD_H_ @}*/