From 7b566f222666a1c16c7911f9d99cae4799d06ec8 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 1 Nov 2016 10:26:25 +0100 Subject: [PATCH] Migrated to libpeas. --- configure.ac | 4 +- data/libzakautheldap/gui/zakautheldap.gui | 196 ++++++++++---------- src/Makefile.am | 15 +- src/aute_ldap.c | 216 ++++++++++++++++++++-- src/aute_ldap.h | 53 ++++++ src/zakautheldap.plugin | 8 + tests/Makefile.am | 2 - tests/test.c | 2 +- 8 files changed, 374 insertions(+), 122 deletions(-) create mode 100644 src/aute_ldap.h create mode 100644 src/zakautheldap.plugin 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 @@ - + + - - + True + False Autenticazione True dialog - + True + False vertical - - + + True - 5 - 3 - 2 - 5 - 5 + False + end - + + gtk-cancel True - 0 - Utente + True + True + False + True - GTK_FILL - + False + False + 0 - + + gtk-ok True - 0 - Password + True + True + True + False + True - 1 - 2 - GTK_FILL - + False + False + 1 + + + + + False + False + end + 0 + + + + + True + False + 5 + 5 + 5 + + + True + False + start + Utente + + + 0 + 0 True True + True True 1 - 2 - + 0 True True + True False True 1 - 2 1 - 2 - + + + + + True + False + start + Password + + + 0 + 1 @@ -75,63 +118,60 @@ True True - + True + False 5 - 2 - 2 - 5 5 + 5 True - 0 + False + start Nuova - GTK_FILL - - - - - - True - 0 - Conferma - - - 1 - 2 - GTK_FILL - + 0 + 0 True True + True False True 1 - 2 - + 0 True True + True False True 1 - 2 1 - 2 - + + + + + True + False + start + Conferma + + + 0 + 1 @@ -139,63 +179,23 @@ True + False _Cambia password True - 2 + 0 2 - 3 - GTK_FILL - - - - - 2 - - - - - True - end - - - gtk-cancel - True - True - True - False - True - - - False - False - 0 - - - - - gtk-ok - True - True - True - True - False - True - - - False - False - 1 + 2 False - end - 0 + True + 2 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 +#endif + #include #include +#include + +#include + #ifdef HAVE_LIBZAKCONFI #include #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 + * + * 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 + + +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 +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 -#include +#include int main (int argc, char **argv) -- 2.49.0