libstrongswan_pkcs11_la_SOURCES = \
pkcs11_plugin.h pkcs11_plugin.c pkcs11.h \
- pkcs11_library.h pkcs11_library.c
+ pkcs11_library.h pkcs11_library.c \
+ pkcs11_manager.h pkcs11_manager.c
libstrongswan_pkcs11_la_LDFLAGS = -module -avoid-version
--- /dev/null
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 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
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "pkcs11_manager.h"
+
+#include <debug.h>
+#include <utils/linked_list.h>
+
+#include "pkcs11_library.h"
+
+typedef struct private_pkcs11_manager_t private_pkcs11_manager_t;
+
+/**
+ * Private data of an pkcs11_manager_t object.
+ */
+struct private_pkcs11_manager_t {
+
+ /**
+ * Public pkcs11_manager_t interface.
+ */
+ pkcs11_manager_t public;
+
+ /**
+ * List of loaded libraries
+ */
+ linked_list_t *libs;
+};
+
+
+METHOD(pkcs11_manager_t, destroy, void,
+ private_pkcs11_manager_t *this)
+{
+ this->libs->destroy_offset(this->libs, offsetof(pkcs11_library_t, destroy));
+ free(this);
+}
+
+/**
+ * See header
+ */
+pkcs11_manager_t *pkcs11_manager_create()
+{
+ private_pkcs11_manager_t *this;
+ enumerator_t *enumerator;
+ char *module, *path;
+
+ INIT(this,
+ .public = {
+ .destroy = _destroy,
+ },
+ .libs = linked_list_create(),
+ );
+
+ enumerator = lib->settings->create_section_enumerator(lib->settings,
+ "libstrongswan.plugins.pkcs11.modules");
+ while (enumerator->enumerate(enumerator, &module))
+ {
+ pkcs11_library_t *p11lib;
+
+ path = lib->settings->get_str(lib->settings,
+ "libstrongswan.plugins.pkcs11.modules.%s.path", NULL, module);
+ if (!path)
+ {
+ DBG1(DBG_CFG, "PKCS11 module '%s' misses library path", module);
+ continue;
+ }
+ p11lib = pkcs11_library_create(module, path);
+ if (p11lib)
+ {
+ this->libs->insert_last(this->libs, p11lib);
+ }
+ }
+ enumerator->destroy(enumerator);
+ return &this->public;
+}
--- /dev/null
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 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
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup pkcs11_manager pkcs11_manager
+ * @{ @ingroup pkcs11
+ */
+
+#ifndef PKCS11_MANAGER_H_
+#define PKCS11_MANAGER_H_
+
+typedef struct pkcs11_manager_t pkcs11_manager_t;
+
+/**
+ * Manages multiple PKCS#11 libraries with hot pluggable slots
+ */
+struct pkcs11_manager_t {
+
+ /**
+ * Destroy a pkcs11_manager_t.
+ */
+ void (*destroy)(pkcs11_manager_t *this);
+};
+
+/**
+ * Create a pkcs11_manager instance.
+ */
+pkcs11_manager_t *pkcs11_manager_create();
+
+#endif /** PKCS11_MANAGER_H_ @}*/
#include "pkcs11_plugin.h"
#include <library.h>
-#include <debug.h>
-#include <utils/linked_list.h>
-#include "pkcs11_library.h"
+#include "pkcs11_manager.h"
typedef struct private_pkcs11_plugin_t private_pkcs11_plugin_t;
pkcs11_plugin_t public;
/**
- * List of loaded libraries
+ * PKCS#11 library/slot manager
*/
- linked_list_t *libs;
+ pkcs11_manager_t *manager;
};
METHOD(plugin_t, destroy, void,
private_pkcs11_plugin_t *this)
{
- this->libs->destroy_offset(this->libs, offsetof(pkcs11_library_t, destroy));
+ this->manager->destroy(this->manager);
free(this);
}
plugin_t *pkcs11_plugin_create()
{
private_pkcs11_plugin_t *this;
- enumerator_t *enumerator;
- char *module, *path;
INIT(this,
.public.plugin.destroy = _destroy,
- .libs = linked_list_create(),
+ .manager = pkcs11_manager_create(),
);
- enumerator = lib->settings->create_section_enumerator(lib->settings,
- "libstrongswan.plugins.pkcs11.modules");
- while (enumerator->enumerate(enumerator, &module))
- {
- pkcs11_library_t *p11lib;
-
- path = lib->settings->get_str(lib->settings,
- "libstrongswan.plugins.pkcs11.modules.%s.path", NULL, module);
- if (!path)
- {
- DBG1(DBG_CFG, "PKCS11 module '%s' misses library path", module);
- continue;
- }
- p11lib = pkcs11_library_create(module, path);
- if (p11lib)
- {
- this->libs->insert_last(this->libs, p11lib);
- }
- }
- enumerator->destroy(enumerator);
return &this->public.plugin;
}