# Checks for libraries.
have_libconfi=no
-PKG_CHECK_MODULES(LIBZAKAUTHE, [gmodule-2.0 >= 2.10.0
- gtk+-3.0 >= 3.0.0])
+PKG_CHECK_MODULES(LIBZAKAUTHE, [gtk+-3.0 >= 3.0.0
+ libpeas-1.0 >= 1.12.0])
AC_SUBST(LIBZAKAUTHE_CFLAGS)
AC_SUBST(LIBZAKAUTHE_LIBS)
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
+pluginsdir=@libdir@/@PACKAGE@/plugins
Name: @PACKAGE_NAME@
Description: Library to manage authentication through plugins
AM_CPPFLAGS = $(LIBZAKAUTHE_CFLAGS) \
$(LIBZAKCONFI_CFLAGS) \
- -DLIB_ZAK_AUTHE_PLUGINS_DIR=\""$(libdir)/libzakauthe/plugins"\"
+ -DLIB_ZAK_AUTHE_PLUGINS_DIR=\""$(libdir)/$(PACKAGE)/plugins"\"
LIBS = $(LIBZAKAUTHE_LIBS) \
$(LIBZAKCONFI_LIBS)
lib_LTLIBRARIES = libzakauthe.la
-libzakauthe_la_SOURCES = aute.c
+libzakauthe_la_SOURCES = aute.c \
+ authepluggable.c
libzakauthe_la_LDFLAGS = -no-undefined
-include_HEADERS = libzakauthe.h
+libzakauthe_includedir = $(includedir)/$(PACKAGE)
+
+libzakauthe_include_HEADERS = libzakauthe.h \
+ authe.h \
+ authepluggable.h
#include <stdio.h>
#include <glib/gprintf.h>
+#include <libpeas/peas.h>
+
#ifdef HAVE_LIBZAKCONFI
#include <libzakconfi/libzakconfi.h>
#endif
GParamSpec *pspec);
static void zak_authe_finalize (GObject *object);
-static gchar *zak_authe_get_module_from_confi (ZakAuthe *aute);
+#ifdef HAVE_LIBZAKCONFI
+static gchar *zak_authe_get_pluggable_from_confi (ZakAuthe *authe);
+#endif
#define ZAK_AUTHE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_TYPE_AUTHE, ZakAuthePrivate))
typedef struct _ZakAuthePrivate ZakAuthePrivate;
struct _ZakAuthePrivate
{
- GModule *module;
+ ZakAuthePluggable *pluggable;
GSList *parameters;
{
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (form);
- priv->module = NULL;
+ priv->pluggable = NULL;
priv->parameters = NULL;
#ifdef HAVE_LIBZAKCONFI
gboolean
zak_authe_set_config (ZakAuthe *aute, GSList *parameters)
{
+ gboolean ret;
+
+ PeasEngine *peas_engine;
+
gchar *module_name;
+ const GList *lst_plugins;
+
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (aute);
g_return_val_if_fail (parameters != NULL && parameters->data != NULL, FALSE);
if (ZAK_IS_CONFI ((ZakConfi *)g_slist_nth_data (priv->parameters, 1)))
{
priv->confi = ZAK_CONFI ((ZakConfi *)g_slist_nth_data (priv->parameters, 1));
- module_name = zak_authe_get_module_from_confi (aute);
+ module_name = zak_authe_get_pluggable_from_confi (aute);
}
}
#endif
return FALSE;
}
- /* loading library */
- priv->module = g_module_open (module_name, G_MODULE_BIND_LAZY);
- if (!priv->module)
+ peas_engine = peas_engine_get_default ();
+ if (peas_engine == NULL)
{
- /* TO DO */
- g_warning ("Error g_module_open.");
return FALSE;
}
+ ret = TRUE;
+
+ peas_engine_add_search_path (peas_engine, LIB_ZAK_AUTHE_PLUGINS_DIR, NULL);
+
+ lst_plugins = peas_engine_get_plugin_list (peas_engine);
+ while (lst_plugins)
+ {
+ PeasPluginInfo *ppinfo;
+
+ ppinfo = (PeasPluginInfo *)lst_plugins->data;
+
+ if (g_strcmp0 (module_name, peas_plugin_info_get_module_name (ppinfo)) == 0)
+ {
+ if (peas_engine_load_plugin (peas_engine, ppinfo))
+ {
+ PeasExtension *ext;
+ ext = peas_engine_create_extension (peas_engine, ppinfo, ZAK_AUTHE_TYPE_PLUGGABLE,
+ NULL);
+ priv->pluggable = (ZakAuthePluggable *)ext;
+ break;
+ }
+ }
+
+ lst_plugins = g_list_next (lst_plugins);
+ }
+
+ if (priv->pluggable == NULL)
+ {
+ g_warning ("No plugin found with name \"%s\".", module_name);
+ ret = FALSE;
+ }
+
g_free (module_name);
- return TRUE;
+ return ret;
}
/**
gchar
*zak_authe_authe (ZakAuthe *aute)
{
- gchar *(*autentica) (GSList *parameters);
gchar *ret;
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (aute);
- g_return_val_if_fail (priv->module != NULL, NULL);
+ g_return_val_if_fail (priv->pluggable != NULL, NULL);
ret = NULL;
- /* loading the function */
- if (!g_module_symbol (priv->module, "zak_authe_plg_authe", (gpointer *)&autentica))
- {
- /* TO DO */
- g_warning ("Error g_module_symbol\n");
- return NULL;
- }
-
/* calling plugin's function */
- ret = (*autentica) (priv->parameters);
+ ret = zak_authe_pluggable_authe (priv->pluggable, priv->parameters);
return ret;
}
gchar
*zak_authe_get_password (ZakAuthe *aute, gchar **password)
{
- gchar *(*zak_authe_plg_get_password) (GSList *parameters, gchar **password);
gchar *ret;
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (aute);
- g_return_val_if_fail (priv->module != NULL, NULL);
+ g_return_val_if_fail (priv->pluggable != NULL, NULL);
ret = NULL;
- /* loading the function */
- if (!g_module_symbol (priv->module, "zak_authe_plg_get_password", (gpointer *)&zak_authe_plg_get_password))
- {
- /* TO DO */
- g_warning ("Error g_module_symbol: zak_authe_plg_get_password.\n");
-
- /* try zak_authe_authe */
- ret = zak_authe_authe (aute);
- }
- else
- {
- /* calling plugin's function */
- ret = (*zak_authe_plg_get_password) (priv->parameters, password);
- }
+ /* calling plugin's function */
+ ret = zak_authe_pluggable_authe_get_password (priv->pluggable, priv->parameters, password);
return ret;
}
{
gboolean ret;
- gboolean (*zak_authe_plg_authe_nogui) (GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password);
-
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (zakauthe);
- g_return_val_if_fail (priv->module != NULL, FALSE);
+ g_return_val_if_fail (priv->pluggable != NULL, FALSE);
- /* loading the function */
- if (!g_module_symbol (priv->module, "zak_authe_plg_authe_nogui", (gpointer *)&zak_authe_plg_authe_nogui))
- {
- /* TO DO */
- g_warning ("Error g_module_symbol: zak_authe_plg_authe_nogui.\n");
-
- ret = FALSE;
- }
- else
- {
- /* calling plugin's function */
- ret = (*zak_authe_plg_authe_nogui) (priv->parameters, username, password, new_password);
- }
+ /* calling plugin's function */
+ ret = zak_authe_pluggable_authe_nogui (priv->pluggable, priv->parameters, username, password, new_password);
return ret;
}
GtkWidget
*zak_authe_get_management_gui (ZakAuthe *aute)
{
- GtkWidget *(*get_management_gui) (GSList *parameters);
GtkWidget *ret;
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (aute);
- g_return_val_if_fail (priv->module != NULL, NULL);
+ g_return_val_if_fail (priv->pluggable != NULL, NULL);
ret = NULL;
- /* loading the function */
- if (!g_module_symbol (priv->module, "zak_authe_plg_get_management_gui", (gpointer *)&get_management_gui))
- {
- /* TO DO */
- g_warning ("Error g_module_symbol: zak_authe_plg_get_management_gui.\n");
- return NULL;
- }
-
/* calling plugin's function */
- ret = (*get_management_gui) (priv->parameters);
+ ret = zak_authe_pluggable_get_management_gui (priv->pluggable, priv->parameters);
return ret;
-
}
/* PRIVATE */
ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (aute);
- /* closing the library */
- if (priv->module != NULL)
- {
- if (!g_module_close (priv->module))
- {
- g_fprintf (stderr, "Error g_module_close\n");
- }
- else
- {
- priv->module = NULL;
- }
- }
-
/* Chain up to the parent class */
G_OBJECT_CLASS (zak_authe_parent_class)->finalize (object);
}
#ifdef HAVE_LIBZAKCONFI
/**
- * zak_authe_get_plugin_module:
- * @aute: a #ZakAuthe object.
+ * zak_authe_get_pluggable_from_confi:
+ * @authe: a #ZakAuthe object.
*
* Returns: plugin path.
*/
static gchar
-*zak_authe_get_module_from_confi (ZakAuthe *aute)
+*zak_authe_get_pluggable_from_confi (ZakAuthe *authe)
{
gchar *libname;
- ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (aute);
+ ZakAuthePrivate *priv = ZAK_AUTHE_GET_PRIVATE (authe);
g_return_val_if_fail (ZAK_IS_CONFI (priv->confi), NULL);
--- /dev/null
+/*
+ * Copyright 2005-2016 Andrea Zagli <azagli@libero.it>
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __ZAKAUTHE_H__
+#define __ZAKAUTHE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define ZAK_TYPE_AUTHE (zak_authe_get_type ())
+#define ZAK_AUTHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_TYPE_AUTHE, ZakAuthe))
+#define ZAK_AUTHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_TYPE_AUTHE, ZakAutheClass))
+#define ZAK_IS_AUTHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_TYPE_AUTHE))
+#define ZAK_IS_AUTHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_TYPE_AUTHE))
+#define ZAKAUTHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_TYPE_AUTHE, ZakAutheClass))
+
+
+typedef struct _ZakAuthe ZakAuthe;
+typedef struct _ZakAutheClass ZakAutheClass;
+
+struct _ZakAuthe
+ {
+ GObject parent;
+ };
+
+struct _ZakAutheClass
+ {
+ GObjectClass parent_class;
+ };
+
+GType zak_authe_get_type (void) G_GNUC_CONST;
+
+ZakAuthe *zak_authe_new (void);
+
+gboolean zak_authe_set_config (ZakAuthe *zakauthe, GSList *parameters);
+
+gchar *zak_authe_authe (ZakAuthe *zakauthe);
+gchar *zak_authe_get_password (ZakAuthe *zakauthe, gchar **password);
+gboolean zak_authe_authe_nogui (ZakAuthe *zakauthe, const gchar *username, const gchar *password, const gchar *new_password);
+
+GtkWidget *zak_authe_get_management_gui (ZakAuthe *zakauthe);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAKAUTHE_H__ */
--- /dev/null
+/*
+ * authepluggable.c
+ * This file is part of libzakauthe
+ *
+ * Copyright (C) 2016 Andrea Zagli <azagli@libero.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "authepluggable.h"
+
+/**
+ * SECTION:authepluggable
+ * @short_description: Interface for pluggable plugins.
+ * @see_also: #PeasExtensionSet
+ *
+ **/
+
+G_DEFINE_INTERFACE(ZakAuthePluggable, zak_authe_pluggable, G_TYPE_OBJECT)
+
+void
+zak_authe_pluggable_default_init (ZakAuthePluggableInterface *iface)
+{
+ static gboolean initialized = FALSE;
+
+ if (!initialized)
+ {
+ initialized = TRUE;
+ }
+}
+
+/**
+ * zak_authe_pluggable_authe:
+ * @pluggable: A #ZakAuthePluggable.
+ * @parameters:
+ *
+ * Returns:
+ */
+gchar
+*zak_authe_pluggable_authe (ZakAuthePluggable *pluggable, GSList *parameters)
+{
+ ZakAuthePluggableInterface *iface;
+
+ g_return_val_if_fail (ZAK_AUTHE_IS_PLUGGABLE (pluggable), FALSE);
+
+ iface = ZAK_AUTHE_PLUGGABLE_GET_IFACE (pluggable);
+ g_return_val_if_fail (iface->authe != NULL, FALSE);
+
+ return iface->authe (pluggable, parameters);
+}
+
+/**
+ * zak_authe_pluggable_authe_get_password:
+ * @pluggable: A #ZakAuthePluggable.
+ * @parameters:
+ * @password:
+ *
+ * Returns:
+*/
+gchar
+*zak_authe_pluggable_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password)
+{
+ ZakAuthePluggableInterface *iface;
+
+ g_return_val_if_fail (ZAK_AUTHE_IS_PLUGGABLE (pluggable), FALSE);
+
+ iface = ZAK_AUTHE_PLUGGABLE_GET_IFACE (pluggable);
+ g_return_val_if_fail (iface->authe_get_password != NULL, FALSE);
+
+ return iface->authe_get_password (pluggable, parameters, password);
+}
+
+/**
+ * zak_authe_pluggable_authe_nogui:
+ * @pluggable: A #ZakAuthePluggable.
+ * @parameters:
+ * @username:
+ * @password:
+ * @new_password:
+ *
+ * Returns:
+*/
+gboolean
+zak_authe_pluggable_authe_nogui (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password)
+{
+ ZakAuthePluggableInterface *iface;
+
+ g_return_val_if_fail (ZAK_AUTHE_IS_PLUGGABLE (pluggable), FALSE);
+
+ iface = ZAK_AUTHE_PLUGGABLE_GET_IFACE (pluggable);
+ g_return_val_if_fail (iface->authe_nogui != NULL, FALSE);
+
+ return iface->authe_nogui (pluggable, parameters, username, password, new_password);
+}
+
+/**
+ * zak_authe_pluggable_get_management_gui:
+ * @pluggable: a #ZakAuthePluggable object.
+ * @parameters:
+ *
+ * Returns:
+ */
+GtkWidget
+*zak_authe_pluggable_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters)
+{
+ ZakAuthePluggableInterface *iface;
+
+ g_return_val_if_fail (ZAK_AUTHE_IS_PLUGGABLE (pluggable), FALSE);
+
+ iface = ZAK_AUTHE_PLUGGABLE_GET_IFACE (pluggable);
+ g_return_val_if_fail (iface->get_management_gui != NULL, FALSE);
+
+ return iface->get_management_gui (pluggable, parameters);
+}
--- /dev/null
+/*
+ * authepluggable.h
+ * This file is part of libzakauthe
+ *
+ * Copyright (C) 2016 - Andrea Zagli <azagli@libero.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __ZAK_AUTHE_PLUGGABLE_H__
+#define __ZAK_AUTHE_PLUGGABLE_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define ZAK_AUTHE_TYPE_PLUGGABLE (zak_authe_pluggable_get_type ())
+#define ZAK_AUTHE_PLUGGABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_AUTHE_TYPE_PLUGGABLE, ZakAuthePluggable))
+#define ZAK_AUTHE_PLUGGABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), ZAK_AUTHE_TYPE_PLUGGABLE, ZakAuthePluggableInterface))
+#define ZAK_AUTHE_IS_PLUGGABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_AUTHE_TYPE_PLUGGABLE))
+#define ZAK_AUTHE_PLUGGABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ZAK_AUTHE_TYPE_PLUGGABLE, ZakAuthePluggableInterface))
+
+/**
+ * ZakAuthePluggable:
+ *
+ * Interface for pluggable plugins.
+ */
+typedef struct _ZakAuthePluggable ZakAuthePluggable; /* dummy typedef */
+typedef struct _ZakAuthePluggableInterface ZakAuthePluggableInterface;
+
+/**
+ * ZakAuthePluggableInterface:
+ * @g_iface: The parent interface.
+ * @initialize: Construct the plugin.
+ *
+ * Provides an interface for pluggable plugins.
+ */
+struct _ZakAuthePluggableInterface {
+ GTypeInterface g_iface;
+
+ /* Virtual public methods */
+ gchar *(*authe) (ZakAuthePluggable *pluggable, GSList *parameters);
+ gchar *(*authe_get_password) (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password);
+ gboolean (*authe_nogui) (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password);
+ GtkWidget *(*get_management_gui) (ZakAuthePluggable *pluggable, GSList *parameters);
+};
+
+/*
+ * Public methods
+ */
+GType zak_authe_pluggable_get_type (void) G_GNUC_CONST;
+
+gchar *zak_authe_pluggable_authe (ZakAuthePluggable *pluggable,
+ GSList *parameters);
+gchar *zak_authe_pluggable_authe_get_password (ZakAuthePluggable *pluggable,
+ GSList *parameters,
+ gchar **password);
+gboolean zak_authe_pluggable_authe_nogui (ZakAuthePluggable *pluggable,
+ GSList *parameters,
+ const gchar *username,
+ const gchar *password,
+ const gchar *new_password);
+GtkWidget *zak_authe_pluggable_get_management_gui (ZakAuthePluggable *pluggable,
+ GSList *parameters);
+
+
+G_END_DECLS
+
+#endif /* __ZAK_AUTHE_PLUGGABLE_H__ */
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef __ZAKAUTHE_H__
-#define __ZAKAUTHE_H__
+#ifndef __LIBZAKAUTHE_H__
+#define __LIBZAKAUTHE_H__
-#include <glib.h>
-#include <glib-object.h>
-#include <gmodule.h>
-#include <gtk/gtk.h>
-G_BEGIN_DECLS
+#include "authe.h"
+#include "authepluggable.h"
-#define ZAK_TYPE_AUTHE (zak_authe_get_type ())
-#define ZAK_AUTHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_TYPE_AUTHE, ZakAuthe))
-#define ZAK_AUTHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_TYPE_AUTHE, ZakAutheClass))
-#define ZAK_IS_AUTHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_TYPE_AUTHE))
-#define ZAK_IS_AUTHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_TYPE_AUTHE))
-#define ZAKAUTHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_TYPE_AUTHE, ZakAutheClass))
-
-typedef struct _ZakAuthe ZakAuthe;
-typedef struct _ZakAutheClass ZakAutheClass;
-
-struct _ZakAuthe
- {
- GObject parent;
- };
-
-struct _ZakAutheClass
- {
- GObjectClass parent_class;
- };
-
-GType zak_authe_get_type (void) G_GNUC_CONST;
-
-ZakAuthe *zak_authe_new (void);
-
-gboolean zak_authe_set_config (ZakAuthe *zakauthe, GSList *parameters);
-
-gchar *zak_authe_authe (ZakAuthe *zakauthe);
-gchar *zak_authe_get_password (ZakAuthe *zakauthe, gchar **password);
-gboolean zak_authe_authe_nogui (ZakAuthe *zakauthe, const gchar *username, const gchar *password, const gchar *new_password);
-
-GtkWidget *zak_authe_get_management_gui (ZakAuthe *zakauthe);
-
-
-G_END_DECLS
-
-
-#endif /* __ZAKAUTHE_H__ */
+#endif /* __LIBZAKAUTHE_H__ */