summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2013-03-04 11:55:54 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2013-03-04 11:55:54 +0100
commit5da59efc978fce7b4da71dc967a22647721f78af (patch)
tree8d2864dac642e2ec52c5b59f42e9bd900d825f7f
parentc4b5ca206e7d9df745a8e74b54d3e3e2fc8dc048 (diff)
downloadeurephia-5da59efc978fce7b4da71dc967a22647721f78af.tar.gz
eurephia-5da59efc978fce7b4da71dc967a22647721f78af.tar.xz
eurephia-5da59efc978fce7b4da71dc967a22647721f78af.zip
auth plug-in: Extended the API to have a PluginInit() function
This can be used to pass a configuration to the authentication plug-in. Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
-rw-r--r--auth/eurephia_authplugin.c60
-rw-r--r--auth/eurephia_authplugin_driver.c1
-rw-r--r--auth/eurephia_authplugin_driver.h10
3 files changed, 70 insertions, 1 deletions
diff --git a/auth/eurephia_authplugin.c b/auth/eurephia_authplugin.c
index f459e7b..e67b7e6 100644
--- a/auth/eurephia_authplugin.c
+++ b/auth/eurephia_authplugin.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
+#include <assert.h>
#define EUREPHIA_AUTHPLUGIN_C_
#define EUREPHIA_CONTEXT_H_
@@ -45,11 +46,58 @@ typedef struct __eurephiaCTX eurephiaCTX;
eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, void * dlhandle);
+struct __PluginDataSplit {
+ const char *dsofile;
+ const char *configstr;
+};
+
+/**
+ * Splits the plug-in data from the database into a more easily managable
+ * struct. This struct will only use pointers to the input string (dbstr)
+ * And the input string will be slightly modified.
+ *
+ * The format of the input data is:
+ * [<DSO filename>]<Configuration string>
+ *
+ * @param ret* The parsed result will be saved into in the provided struct
+ * @param dbstr* The string returned by the database, containing plug-in data
+ *
+ * @return Data is returned via the ret* pointer
+ */
+void __split_plugin_data_str(struct __PluginDataSplit *ret, char *dbstr)
+{
+ char *ptr = NULL;
+
+ assert(ret != NULL);
+ assert(dbstr != NULL);
+
+ ret->dsofile = NULL;
+ ret->configstr = NULL;
+
+ /* The input string must start with '[' */
+ if (dbstr[0] != '[') {
+ return;
+ }
+
+ /* Locate the ']' part. This will be replaced by a NULL terminator */
+ ptr = strpbrk(dbstr, "]");
+ if (ptr == NULL) {
+ /* If not found, abort */
+ return;
+ }
+
+ dbstr[0] = 0; /* NULL terminate it on purpose */
+ ret->dsofile = dbstr+1;
+ *ptr = 0; /* NULL terminate the ']' place */
+ ret->configstr = ptr+1;
+}
+
eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx)
{
eurephiaVALUES *plgs = NULL, *plgptr;
eAuthPluginCTX *apctx = NULL, *apctxhead = NULL;
+ struct __PluginDataSplit plgdata;
// Query the database for authentication plugins
plgs = eDBget_plugins(ctx, "auth");
@@ -65,16 +113,20 @@ eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx)
continue;
}
+ __split_plugin_data_str(&plgdata, plgptr->val);
+
// Create a plug-in context
apctx = malloc_nullsafe(ctx, sizeof(eAuthPluginCTX)+2);
// Save some metadata about this plugin
- apctx->filename = strdup(plgptr->val);
+ apctx->filename = strdup(plgdata.dsofile);
apctx->plgid = atoi_nullsafe(plgptr->key);
apctx->next = NULL;
// Open the plugin
apctx->dlhandle = dlopen(apctx->filename, RTLD_NOW);
if (apctx->dlhandle != NULL) {
+ int success = 0;
+
// If we got a handle to the plug-in, it up
apctx->plugin = __eAuthPlugin_Setup(ctx, apctx->filename, apctx->dlhandle);
if (apctx->plugin != NULL) {
@@ -84,6 +136,12 @@ eAuthPluginCTX * eAuthPlugin_Init(eurephiaCTX * ctx)
"Loaded eurephia %s plugin: %s (v%s) %s",
ePluginTypeString(plginfo),
plginfo->name, plginfo->version, plginfo->copyright);
+
+ // Initialise the plug-in
+ success = apctx->plugin->PluginInit(ctx, plgdata.configstr);
+ }
+
+ if (success == 1) {
// 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 7f21a60..e3f09f8 100644
--- a/auth/eurephia_authplugin_driver.c
+++ b/auth/eurephia_authplugin_driver.c
@@ -63,6 +63,7 @@ eAuthPlugin * __eAuthPlugin_Setup(eurephiaCTX * ctx, const char * dlfilename, vo
// saved in a eAuthPlugin struct
ret = malloc_nullsafe(ctx, sizeof(struct __eAuthPlugin)+2);
ret->PluginInfo = eGetSym(ctx, dlhandle, "PluginInfo");
+ ret->PluginInit = eGetSym(ctx, dlhandle, "PluginInit");
// If any of the eGetSym() triggered a fatal error,
// reset the fatality mark and return with a failure code
diff --git a/auth/eurephia_authplugin_driver.h b/auth/eurephia_authplugin_driver.h
index 69b8f7e..fbceaf8 100644
--- a/auth/eurephia_authplugin_driver.h
+++ b/auth/eurephia_authplugin_driver.h
@@ -100,6 +100,16 @@ typedef struct __eAuthPlugin {
ePluginInfo * (*PluginInfo)();
/**
+ * Initialisation function for the plug-in.
+ *
+ * @param eurephiaCTX* Pointer to the current eurephia context
+ * @param args String containing the initialisation data
+ *
+ * @return Returns 1 on success, otherwise 0
+ */
+ int (*PluginInit)(eurephiaCTX *ctx, const char *args);
+
+ /**
* Mandatory auth plug-in function. Authenticates a user account based
* on the given username and password.
*