From: Andrea Zagli <azagli@libero.it> Date: Tue, 1 Nov 2016 09:26:25 +0000 (+0100) Subject: Migrated to libpeas. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=7b566f222666a1c16c7911f9d99cae4799d06ec8;p=zakauthe%2Fplugins%2Fldap Migrated to libpeas. --- diff --git a/configure.ac b/configure.ac index 7126a61..c934b4a 100644 --- a/configure.ac +++ b/configure.ac @@ -18,8 +18,8 @@ AC_PROG_CC AC_PROG_LIBTOOL # Checks for libraries. -PKG_CHECK_MODULES(LIBZAKAUTHELDAP, [gtk+-3.0 >= 3.0.00 - libzakauthe >= 0.5.0]) +PKG_CHECK_MODULES(LIBZAKAUTHELDAP, [gtk+-3.0 >= 3.0.0 + libzakauthe >= 0.5.99]) AC_SUBST(LIBZAKAUTHELDAP_CFLAGS) AC_SUBST(LIBZAKAUTHELDAP_LIBS) diff --git a/data/libzakautheldap/gui/zakautheldap.gui b/data/libzakautheldap/gui/zakautheldap.gui index d68387e..40393e8 100644 --- a/data/libzakautheldap/gui/zakautheldap.gui +++ b/data/libzakautheldap/gui/zakautheldap.gui @@ -1,73 +1,116 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.20.0 --> <interface> - <requires lib="gtk+" version="2.16"/> - <!-- interface-naming-policy project-wide --> + <requires lib="gtk+" version="3.0"/> <object class="GtkDialog" id="diag_main"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="title" translatable="yes">Autenticazione</property> <property name="modal">True</property> <property name="type_hint">dialog</property> <child internal-child="vbox"> - <object class="GtkVBox" id="dialog-vbox1"> + <object class="GtkBox" id="dialog-vbox1"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="orientation">vertical</property> - <child> - <object class="GtkTable" id="table1"> + <child internal-child="action_area"> + <object class="GtkButtonBox" id="dialog-action_area1"> <property name="visible">True</property> - <property name="border_width">5</property> - <property name="n_rows">3</property> - <property name="n_columns">2</property> - <property name="column_spacing">5</property> - <property name="row_spacing">5</property> + <property name="can_focus">False</property> + <property name="layout_style">end</property> <child> - <object class="GtkLabel" id="label1"> + <object class="GtkButton" id="cancelbutton1"> + <property name="label">gtk-cancel</property> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Utente</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> </object> <packing> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> </packing> </child> <child> - <object class="GtkLabel" id="label2"> + <object class="GtkButton" id="okbutton1"> + <property name="label">gtk-ok</property> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Password</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="has_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> </object> <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="table1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="row_spacing">5</property> + <property name="column_spacing">5</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="label" translatable="yes">Utente</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> </packing> </child> <child> <object class="GtkEntry" id="txt_utente"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> <property name="activates_default">True</property> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="y_options"></property> + <property name="top_attach">0</property> </packing> </child> <child> <object class="GtkEntry" id="txt_password"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> <property name="visibility">False</property> <property name="activates_default">True</property> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="label" translatable="yes">Password</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> </packing> </child> <child> @@ -75,63 +118,60 @@ <property name="visible">True</property> <property name="can_focus">True</property> <child> - <object class="GtkTable" id="table2"> + <object class="GtkGrid" id="table2"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="border_width">5</property> - <property name="n_rows">2</property> - <property name="n_columns">2</property> - <property name="column_spacing">5</property> <property name="row_spacing">5</property> + <property name="column_spacing">5</property> <child> <object class="GtkLabel" id="label4"> <property name="visible">True</property> - <property name="xalign">0</property> + <property name="can_focus">False</property> + <property name="halign">start</property> <property name="label" translatable="yes">Nuova</property> </object> <packing> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Conferma</property> - </object> - <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> + <property name="left_attach">0</property> + <property name="top_attach">0</property> </packing> </child> <child> <object class="GtkEntry" id="txt_password_nuova"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> <property name="visibility">False</property> <property name="activates_default">True</property> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="y_options"></property> + <property name="top_attach">0</property> </packing> </child> <child> <object class="GtkEntry" id="txt_password_conferma"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> <property name="visibility">False</property> <property name="activates_default">True</property> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="label" translatable="yes">Conferma</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> </packing> </child> </object> @@ -139,63 +179,23 @@ <child type="label"> <object class="GtkLabel" id="label3"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="label" translatable="yes">_Cambia password</property> <property name="use_underline">True</property> </object> </child> </object> <packing> - <property name="right_attach">2</property> + <property name="left_attach">0</property> <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">GTK_FILL</property> - </packing> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="dialog-action_area1"> - <property name="visible">True</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="cancelbutton1"> - <property name="label">gtk-cancel</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="okbutton1"> - <property name="label">gtk-ok</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="has_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> + <property name="width">2</property> </packing> </child> </object> <packing> <property name="expand">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> + <property name="fill">True</property> + <property name="position">2</property> </packing> </child> </object> diff --git a/src/Makefile.am b/src/Makefile.am index 51ae483..392494a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,13 +5,14 @@ AM_CPPFLAGS = $(LIBZAKAUTHELDAP_CFLAGS) \ $(LIBZAKCONFI_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" -LIBS = $(LIBZAKAUTHELDAP_LIBS) \ - $(LIBLDAP_LIBS) \ - $(LIBZAKCONFI_LIBS) - -libzakauthe_pluginsdir = $(libdir)/libzakauthe/plugins +libzakauthe_pluginsdir = `pkg-config --variable=pluginsdir libzakauthe` libzakauthe_plugins_LTLIBRARIES = libzakautheldap.la +libzakauthe_plugins_DATA = zakautheldap.plugin -libzakautheldap_la_SOURCES = aute_ldap.c +libzakautheldap_la_SOURCES = aute_ldap.h \ + aute_ldap.c -libzakautheldap_la_LDFLAGS = -no-undefined +libzakautheldap_la_LDFLAGS = -no-undefined -module -avoid-version +libzakautheldap_la_LDDADD = $(LIBZAKAUTHELDAP_LIBS) \ + $(LIBLDAP_LIBS) \ + $(LIBZAKCONFI_LIBS) diff --git a/src/aute_ldap.c b/src/aute_ldap.c index 84e9e4f..664bd9a 100644 --- a/src/aute_ldap.c +++ b/src/aute_ldap.c @@ -20,13 +20,50 @@ #include "config.h" #endif +#ifdef G_OS_WIN32 +#include <windows.h> +#endif + #include <gtk/gtk.h> #include <ldap.h> +#include <libpeas/peas.h> + +#include <libzakauthe/libzakauthe.h> + #ifdef HAVE_LIBZAKCONFI #include <libzakconfi/libzakconfi.h> #endif +#include "aute_ldap.h" + +static void zak_authe_pluggable_iface_init (ZakAuthePluggableInterface *iface); + +static void zak_authe_ldap_finalize (GObject *object); + +static gchar *zak_authe_ldap_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password); +static gchar *zak_authe_ldap_authe (ZakAuthePluggable *pluggable, GSList *parameters); +static gboolean zak_authe_ldap_authe_nogui (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *newppassword); +static GtkWidget *zak_authe_ldap_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters); + +#define ZAK_AUTHE_LDAP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_AUTHE_TYPE_LDAP, ZakAutheLdapPrivate)) + +typedef struct _ZakAutheLdapPrivate ZakAutheLdapPrivate; +struct _ZakAutheLdapPrivate + { + gpointer empty; + }; + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (ZakAutheLdap, + zak_authe_ldap, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (ZAK_AUTHE_TYPE_PLUGGABLE, + zak_authe_pluggable_iface_init)) + +static gchar *guidir; +static gchar *guifile; + static GtkWidget *txt_utente; static GtkWidget *txt_password; static GtkWidget *exp_cambio; @@ -34,6 +71,30 @@ static GtkWidget *txt_password_nuova; static GtkWidget *txt_password_conferma; /* PRIVATE */ +#ifdef G_OS_WIN32 +static HMODULE backend_dll = NULL; + +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved); + +BOOL WINAPI +DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + backend_dll = (HMODULE) hinstDLL; + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#endif + #ifdef HAVE_LIBZAKCONFI static gboolean get_connection_parameters_from_confi (ZakConfi *confi, gchar **host, gchar **base_dn, gchar **user_field) @@ -62,13 +123,43 @@ get_connection_parameters_from_confi (ZakConfi *confi, gchar **host, gchar **bas } #endif +static void +zak_authe_ldap_class_init (ZakAutheLdapClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (ZakAutheLdapPrivate)); + + object_class->finalize = zak_authe_ldap_finalize; +} + +static void +zak_authe_pluggable_iface_init (ZakAuthePluggableInterface *iface) +{ + iface->authe = zak_authe_ldap_authe; + iface->authe_get_password = zak_authe_ldap_authe_get_password; + iface->authe_nogui = zak_authe_ldap_authe_nogui; + iface->get_management_gui = zak_authe_ldap_get_management_gui; +} + +static void +zak_authe_ldap_init (ZakAutheLdap *plugin) +{ + ZakAutheLdapPrivate *priv = ZAK_AUTHE_LDAP_GET_PRIVATE (plugin); +} + +static void +zak_authe_ldap_finalize (GObject *object) +{ + ZakAutheLdap *plugin = ZAK_AUTHE_LDAP (object); + + G_OBJECT_CLASS (zak_authe_ldap_parent_class)->finalize (object); +} + static gchar -*controllo (GSList *parameters) +*controllo (GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password) { gchar *user_dn; - gchar *utente; - gchar *password; - gchar *password_nuova; gchar *host; gchar *base_dn; @@ -80,9 +171,6 @@ static gchar user_dn = ""; - utente = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_utente)))); - password = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password)))); - host = NULL; base_dn = NULL; user_field = NULL; @@ -166,7 +254,7 @@ static gchar return NULL; } - user_dn = g_strdup_printf ("%s=%s,%s", user_field, utente, base_dn); + user_dn = g_strdup_printf ("%s=%s,%s", user_field, username, base_dn); retldap = ldap_simple_bind_s (ldap, user_dn, password); if (retldap != LDAP_SUCCESS) { @@ -214,17 +302,51 @@ static gchar } /* PUBLIC */ -gchar -*autentica (GSList *parameters) +static gchar +*zak_authe_ldap_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password) { GError *error; gchar *ret = NULL; + gchar *password_new; + error = NULL; +#ifdef G_OS_WIN32 + gchar *moddir; + gchar *p; + + moddir = g_win32_get_package_installation_directory_of_module (backend_dll); + + p = g_strrstr (moddir, g_strdup_printf ("%c", G_DIR_SEPARATOR)); + if (p != NULL + && (g_ascii_strcasecmp (p + 1, "src") == 0 + || g_ascii_strcasecmp (p + 1, ".libs") == 0)) + { + guidir = g_strdup (GUIDIR); + +#undef GUIDIR + } + else + { + guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); + } + +#else + + guidir = g_strdup (GUIDIR); + +#endif + GtkBuilder *gtkbuilder = gtk_builder_new (); - if (!gtk_builder_add_from_file (gtkbuilder, GUIDIR "/zakautheldap.gui", &error)) + guifile = g_build_filename (guidir, "zakautheldap.ui", NULL); + if (!gtk_builder_add_objects_from_file (gtkbuilder, guifile, + g_strsplit ("diag_main", "|", -1), + &error)) { + g_warning ("Unable to find gui file definition in «%s»: %s.", + guifile, + error != NULL && error->message != NULL ? error->message : "no details"); return NULL; } @@ -240,11 +362,16 @@ gchar gtk_entry_set_text (GTK_ENTRY (txt_utente), g_get_user_name ()); gtk_editable_select_region (GTK_EDITABLE (txt_utente), 0, -1); + password_new = g_strdup (""); + switch (gtk_dialog_run (GTK_DIALOG (diag))) { case GTK_RESPONSE_OK: /* controllo dell'utente e della password */ - ret = controllo (parameters); + ret = controllo (parameters, + gtk_entry_get_text (GTK_ENTRY (txt_utente)), + gtk_entry_get_text (GTK_ENTRY (txt_password)), + gtk_entry_get_text (GTK_ENTRY (txt_password_nuova))); break; case GTK_RESPONSE_CANCEL: @@ -257,12 +384,61 @@ gchar break; } + if (ret != NULL && g_strcmp0 (ret, "") != 0 && password != NULL && *password == NULL) + { + if (password_new != NULL && g_strcmp0 (password_new, "") != 0) + { + *password = g_strdup (password_new); + } + else + { + *password = g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password))); + } + } + + g_free (password_new); + gtk_widget_destroy (diag); g_object_unref (gtkbuilder); return ret; } +static gchar +*zak_authe_ldap_authe (ZakAuthePluggable *pluggable, GSList *parameters) +{ + return zak_authe_ldap_authe_get_password (pluggable, parameters, NULL); +} + +static gboolean +zak_authe_ldap_authe_nogui (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password) +{ + if (controllo (parameters, username, password, new_password) != NULL) + { + return TRUE; + } + else + { + return FALSE; + } +} + +/** + * zak_authe_ldap_get_management_gui: + * @pluggable: + * @parameters: + * + */ +static GtkWidget +*zak_authe_ldap_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters) +{ + GError *error; + + error = NULL; + + return NULL; +} + /** * crea_utente: * @parameters: @@ -300,3 +476,19 @@ elimina_utente (GSList *parameters, const gchar *codice) /* TODO */ return FALSE; } + + +static void +zak_authe_ldap_class_finalize (ZakAutheLdapClass *klass) +{ +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + zak_authe_ldap_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + ZAK_AUTHE_TYPE_PLUGGABLE, + ZAK_AUTHE_TYPE_LDAP); +} diff --git a/src/aute_ldap.h b/src/aute_ldap.h new file mode 100644 index 0000000..d7a32cc --- /dev/null +++ b/src/aute_ldap.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 Andrea Zagli <azagli@libero.it> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __ZAKAUTHELDAP_H__ +#define __ZAKAUTHELDAP_H__ + + +#include <libpeas/peas.h> + + +G_BEGIN_DECLS + +#define ZAK_AUTHE_TYPE_LDAP (zak_authe_ldap_get_type ()) +#define ZAK_AUTHE_LDAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ZAK_AUTHE_TYPE_LDAP, ZakAutheLdap)) +#define ZAK_AUTHE_LDAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ZAK_AUTHE_TYPE_LDAP, ZakAutheLdap)) +#define ZAK_AUTHE_IS_LDAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ZAK_AUTHE_TYPE_LDAP)) +#define ZAK_AUTHE_IS_LDAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ZAK_AUTHE_TYPE_LDAP)) +#define ZAK_AUTHE_LDAP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ZAK_AUTHE_TYPE_LDAP, ZakAutheLdapClass)) + +typedef struct _ZakAutheLdap ZakAutheLdap; +typedef struct _ZakAutheLdapClass ZakAutheLdapClass; + +struct _ZakAutheLdap { + PeasExtensionBase parent_instance; +}; + +struct _ZakAutheLdapClass { + PeasExtensionBaseClass parent_class; +}; + +GType zak_authe_ldap_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + + +G_END_DECLS + +#endif /* __ZAKAUTHELDAP_H__ */ diff --git a/src/zakautheldap.plugin b/src/zakautheldap.plugin new file mode 100644 index 0000000..ba63fde --- /dev/null +++ b/src/zakautheldap.plugin @@ -0,0 +1,8 @@ +[Plugin] +Module=zakautheldap +Name=ZakAutheLdap +Description=Read users from ldap. +Authors=Andrea Zagli <azagli@libero.it> +Copyright=Copyright © 2016 Andrea Zagli +Website=http://saetta.ns0.it/ +Help=http://saetta.ns0.it/ diff --git a/tests/Makefile.am b/tests/Makefile.am index fdb1d3c..ac988c2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,4 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ LIBS = $(LIBZAKAUTHELDAP_LIBS) \ $(LIBLDAP_LIBS) -LDADD = ../src/libzakautheldap.la - noinst_PROGRAMS = test diff --git a/tests/test.c b/tests/test.c index 0ab8fd5..b4f10ca 100644 --- a/tests/test.c +++ b/tests/test.c @@ -18,7 +18,7 @@ #include <gtk/gtk.h> -#include <libzakauthe.h> +#include <libzakauthe/libzakauthe.h> int main (int argc, char **argv)