summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2013-03-03 22:55:13 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2013-03-04 10:11:41 +0100
commitd89079acf5d418df849c7f89ff5784963de70b07 (patch)
tree4d505af654032f47f54fe55dda6357ce4a3f01bf
parent4436104929fb437fd0e323fcc6e542323db1aed6 (diff)
downloadeurephia-d89079acf5d418df849c7f89ff5784963de70b07.tar.gz
eurephia-d89079acf5d418df849c7f89ff5784963de70b07.tar.xz
eurephia-d89079acf5d418df849c7f89ff5784963de70b07.zip
auth plug-in: Made the PluginInfo() function more informative
This new PluginInfo() will return a struct instead, containing all the needed plug-in info. It also replaces the APIversion() function completely. Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
-rw-r--r--auth/eurephia_authplugin.c8
-rw-r--r--auth/eurephia_authplugin_driver.c19
-rw-r--r--auth/eurephia_authplugin_driver.h37
3 files changed, 44 insertions, 20 deletions
diff --git a/auth/eurephia_authplugin.c b/auth/eurephia_authplugin.c
index 996e6ba..f459e7b 100644
--- a/auth/eurephia_authplugin.c
+++ b/auth/eurephia_authplugin.c
@@ -26,6 +26,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
@@ -77,9 +78,12 @@ eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx)
// If we got a handle to the plug-in, it up
apctx->plugin = __eAuthPlugin_Setup(ctx, apctx->filename, apctx->dlhandle);
if (apctx->plugin != NULL) {
+ ePluginInfo *plginfo = apctx->plugin->PluginInfo();
+
eurephia_log(ctx, LOG_INFO, 1,
- "Loaded eurephia plugin %s",
- apctx->plugin->PluginInfo());
+ "Loaded eurephia %s plugin: %s (v%s) %s",
+ ePluginTypeString(plginfo),
+ plginfo->name, plginfo->version, plginfo->copyright);
// On success, add this plug-in to the context chain
if( apctxhead != NULL ) {
apctx->next = apctxhead;
diff --git a/auth/eurephia_authplugin_driver.c b/auth/eurephia_authplugin_driver.c
index a1c7829..7f21a60 100644
--- a/auth/eurephia_authplugin_driver.c
+++ b/auth/eurephia_authplugin_driver.c
@@ -52,7 +52,7 @@
eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, void * dlhandle)
{
eAuthPlugin *ret = NULL;
- unsigned int apiver = 0;
+ ePluginInfo *plginfo = NULL;
// Ensure we have sane contexts
assert(ctx != NULL);
@@ -62,7 +62,6 @@ eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, vo
// Allocate memory to the plug-in function pointers,
// saved in a eAuthPlugin struct
ret = malloc_nullsafe(ctx, sizeof(struct __eAuthPlugin)+2);
- ret->APIversion = eGetSym(ctx, dlhandle, "APIversion");
ret->PluginInfo = eGetSym(ctx, dlhandle, "PluginInfo");
// If any of the eGetSym() triggered a fatal error,
@@ -74,14 +73,20 @@ eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, vo
}
// Grap the API version for this plugin
- apiver = ret->APIversion();
+ plginfo = ret->PluginInfo();
+ if (plginfo->pluginType != eptAUTH) {
+ eurephia_log(ctx, LOG_FATAL, 0,
+ "Plug-in %s is not an authentication plug-in", dlfilename);
+ free_nullsafe(ctx, ret);
+ return NULL;
+ }
// Only allow the following functions if the eurephia context is
// based on a admin interface or the openvpn authentication plug-in.
if ((ctx->context_type == ECTX_PLUGIN_AUTH) ||
(ctx->context_type == ECTX_ADMIN_CONSOLE) ||
(ctx->context_type == ECTX_ADMIN_WEB) ) {
- switch( apiver ) {
+ switch( plginfo->APIversion ) {
case 1:
ret->AuthenticateUser = eGetSym(ctx, dlhandle,
"AuthenticateUser");
@@ -89,7 +94,7 @@ eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, vo
default:
eurephia_log(ctx, LOG_CRIT, 0, "Invalid API version reported "
"in %s: APIversion=%i. Plug-in disabled",
- dlfilename, apiver);
+ dlfilename, plginfo->APIversion);
memset(ret, 0, sizeof(eAuthPlugin));
free_nullsafe(ctx, ret);
return NULL;
@@ -100,7 +105,7 @@ eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, vo
// administration context
if ((ctx->context_type == ECTX_ADMIN_CONSOLE) ||
(ctx->context_type == ECTX_ADMIN_WEB)) {
- switch( apiver ) {
+ switch( plginfo->APIversion ) {
case 1:
ret->ChangePassword = eGetSym_optional(ctx, dlhandle,
"ChangePassword");
@@ -108,7 +113,7 @@ eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, vo
default:
eurephia_log(ctx, LOG_CRIT, 0, "Invalid API version reported "
"in %s: APIversion=%i. Plug-in disabled",
- dlfilename, apiver);
+ dlfilename, plginfo->APIversion);
memset(ret, 0, sizeof(eAuthPlugin));
free_nullsafe(ctx, ret);
return NULL;
diff --git a/auth/eurephia_authplugin_driver.h b/auth/eurephia_authplugin_driver.h
index 02211d2..eae4513 100644
--- a/auth/eurephia_authplugin_driver.h
+++ b/auth/eurephia_authplugin_driver.h
@@ -28,6 +28,27 @@
#ifndef EUREPHIA_AUTHPLUGIN_DRIVER_H_
#define EUREPHIA_AUTHPLUGIN_DRIVER_H_
+typedef enum { eptAUTH } ePluginType;
+static const char *___ePluginTypeString[] = {
+ "authentication",
+ NULL
+};
+
+
+typedef const struct __ePluginInfo {
+ const char *name;
+ const char *version;
+ const char *copyright;
+ const ePluginType pluginType;
+ const int APIversion;
+} ePluginInfo;
+
+static inline const char * ePluginTypeString(ePluginInfo *plginf)
+{
+ return ___ePluginTypeString[plginf->pluginType];
+}
+
+
typedef enum { eAUTH_FAILED, /**< Authentication failed */
eAUTH_SUCCESS, /**< Authentication successful */
eAUTH_PLGERROR /**< An error occured in the auth plug-in */
@@ -47,19 +68,13 @@ typedef struct __eAuthResult {
*/
typedef struct __eAuthPlugin {
/**
- * Returns the API version of the authentication plug-in. Used to
- * ensure the core eurephia framework is compatible with the auth plug-in
- *
- * @return An integer with the defined auth plug-in API level support.
- */
- unsigned int (*APIversion)(); // Mandatory
-
- /**
- * Returns information about the authentication plug-in. Used for
- * informative log messages
+ * Returns information about the authentication plug-in. All
+ * authentication plug-ins must provide this function.
*
+ * @return Will always return a pointer to a const struct containing
+ * the plug-in information.
*/
- char * (*PluginInfo)(); // Mandatory
+ ePluginInfo * (*PluginInfo)();
/**
* Mandatory auth plug-in function. Authenticates a user account based