From: Andrea Zagli Date: Mon, 12 Sep 2016 08:44:26 +0000 (+0200) Subject: Migrated to libpeas. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=288481aaf286e075b3aab170caf2e180c0978b60;p=zakauthe%2Fplugins%2Fsmbldap Migrated to libpeas. --- diff --git a/configure.ac b/configure.ac index a66fcbb..c61079a 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ AC_PROG_LIBTOOL # Checks for libraries. PKG_CHECK_MODULES(LIBZAKAUTHESMBLDAP, [gtk+-3.0 >= 3.0.0 - libzakauthe >= 0.5.0]) + libzakauthe >= 0.5.99]) AC_SUBST(LIBZAKAUTHESMBLDAP_CFLAGS) AC_SUBST(LIBZAKAUTHESMBLDAP_LIBS) diff --git a/doc/libzakauthesmbldap/examples/libzakauthesmbldap.conf b/doc/libzakauthesmbldap/examples/libzakauthesmbldap.conf index e5b6c99..87e274a 100644 --- a/doc/libzakauthesmbldap/examples/libzakauthesmbldap.conf +++ b/doc/libzakauthesmbldap/examples/libzakauthesmbldap.conf @@ -1,5 +1,7 @@ -[AUTE] -plugin=/usr/local/lib/libaute/plugins/libaute-smbldap +[ZAKAUTHE] +plugin=zakauthesmbldap + +[libzakauthe/libzakauthesmbldap/ldap] host=ldap://10.0.0.102/ base_dn=dc=nodomain users_ou=ou=Users diff --git a/src/Makefile.am b/src/Makefile.am index 951bd7b..e92ff1a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -guidir = $(datadir)/$(PACKAGE_NAME)/gui +guidir = $(datadir)/$(PACKAGE)/gui AM_CPPFLAGS = $(LIBZAKAUTHESMBLDAP_CFLAGS) \ $(LIBLDAP_CFLAGS) \ @@ -6,13 +6,9 @@ AM_CPPFLAGS = $(LIBZAKAUTHESMBLDAP_CFLAGS) \ $(LIBZAKCONFI_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" -LIBS = $(LIBZAKAUTHESMBLDAP_LIBS) \ - $(LIBLDAP_LIBS) \ - $(LIBSSH_LIBS) \ - $(LIBZAKCONFI_LIBS) - -libzakauthe_pluginsdir = $(libdir)/libzakauthe/plugins +libzakauthe_pluginsdir = `pkg-config --variable=pluginsdir libzakauthe` libzakauthe_plugins_LTLIBRARIES = libzakauthesmbldap.la +libzakauthe_plugins_DATA = zakauthesmbldap.plugin libzakauthesmbldap_la_SOURCES = aute_smbldap.c \ aute_smbldap.h \ @@ -21,4 +17,8 @@ libzakauthesmbldap_la_SOURCES = aute_smbldap.c \ group.c \ group.h -libzakauthesmbldap_la_LDFLAGS = -no-undefined +libzakauthesmbldap_la_LDFLAGS = -no-undefined -module -avoid-version +libzakauthesmbldap_la_LIBADD = $(LIBZAKAUTHESMBLDAP_LIBS) \ + $(LIBLDAP_LIBS) \ + $(LIBSSH_LIBS) \ + $(LIBZAKCONFI_LIBS) diff --git a/src/aute_smbldap.c b/src/aute_smbldap.c index 64dbff3..664508c 100644 --- a/src/aute_smbldap.c +++ b/src/aute_smbldap.c @@ -30,6 +30,10 @@ #include #include +#include + +#include + #ifdef HAVE_LIBZAKCONFI #include #endif @@ -88,6 +92,30 @@ enum COL_GROUPS_GID }; +static void zak_authe_pluggable_iface_init (ZakAuthePluggableInterface *iface); + +static void zak_authe_smbldap_finalize (GObject *object); + +static gchar *zak_authe_smbldap_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password); +static gchar *zak_authe_smbldap_authe (ZakAuthePluggable *pluggable, GSList *parameters); +static gboolean zak_authe_smbldap_authe_nogui (ZakAuthePluggable *pluggable, GSList *parameters, const gchar *username, const gchar *password, const gchar *newppassword); +static GtkWidget *zak_authe_smbldap_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters); + +#define ZAK_AUTHE_SMBLDAP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_AUTHE_TYPE_SMBLDAP, ZakAutheSmbLdapPrivate)) + +typedef struct _ZakAutheSmbLdapPrivate ZakAutheSmbLdapPrivate; +struct _ZakAutheSmbLdapPrivate + { + gpointer empty; + }; + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (ZakAutheSmbLdap, + zak_authe_smbldap, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (ZAK_AUTHE_TYPE_PLUGGABLE, + zak_authe_pluggable_iface_init)) + /* PRIVATE */ #ifdef G_OS_WIN32 static HMODULE backend_dll = NULL; @@ -114,6 +142,39 @@ DllMain (HINSTANCE hinstDLL, #endif +static void +zak_authe_smbldap_class_init (ZakAutheSmbLdapClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (ZakAutheSmbLdapPrivate)); + + object_class->finalize = zak_authe_smbldap_finalize; +} + +static void +zak_authe_pluggable_iface_init (ZakAuthePluggableInterface *iface) +{ + iface->authe = zak_authe_smbldap_authe; + iface->authe_get_password = zak_authe_smbldap_authe_get_password; + iface->authe_nogui = zak_authe_smbldap_authe_nogui; + iface->get_management_gui = zak_authe_smbldap_get_management_gui; +} + +static void +zak_authe_smbldap_init (ZakAutheSmbLdap *plugin) +{ + ZakAutheSmbLdapPrivate *priv = ZAK_AUTHE_SMBLDAP_GET_PRIVATE (plugin); +} + +static void +zak_authe_smbldap_finalize (GObject *object) +{ + ZakAutheSmbLdap *plugin = ZAK_AUTHE_SMBLDAP (object); + + G_OBJECT_CLASS (zak_authe_smbldap_parent_class)->finalize (object); +} + #ifdef HAVE_LIBZAKCONFI static gboolean get_connection_parameters_from_confi (ZakConfi *confi, gchar **user_field) @@ -300,10 +361,9 @@ zak_authe_smbldap_disconnect_ssh () } static gchar -*controllo (GSList *parameters) +*controllo (GSList *parameters, const gchar *username, const gchar *password, const gchar *new_password) { gchar *user_dn; - gchar *password_nuova; gchar *user_field; @@ -314,9 +374,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; users_ou = NULL; @@ -447,7 +504,7 @@ static gchar return NULL; } - user_dn = g_strdup_printf ("%s=%s,%s,%s", user_field, utente, users_ou, base_dn); + user_dn = g_strdup_printf ("%s=%s,%s,%s", user_field, username, users_ou, base_dn); retldap = ldap_simple_bind_s (ldap, user_dn, password); if (retldap != LDAP_SUCCESS) { @@ -462,29 +519,6 @@ static gchar return NULL; }*/ - if (g_strcmp0 (user_dn, "") != 0 - && gtk_expander_get_expanded (GTK_EXPANDER (exp_cambio))) - { - password_nuova = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_nuova)))); - if (strlen (password_nuova) == 0 || strcmp (g_strstrip (password_nuova), "") == 0) - { - /* TO DO */ - g_warning ("The new password is empty."); - } - else if (strcmp (g_strstrip (password_nuova), g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))))) != 0) - { - /* TO DO */ - g_warning ("The new password and the confirm don't match."); - } - else - { - /* cambio la password */ - gchar *command = g_strdup_printf ("echo -e \"%s\\n\" | sudo -k -S echo -e \"%s\\\\n%s\\\\n\" | sudo /usr/sbin/smbldap-passwd \"%s\"", password, password_nuova, password_nuova, utente); - - zak_authe_smbldap_exec_ssh_command (command); - } - } - return user_dn; } @@ -905,12 +939,16 @@ zak_authe_smbldap_on_btn_find_clicked (GtkButton *button, } /* PUBLIC */ -gchar -*zak_authe_plg_get_password (GSList *parameters, gchar **password) +static gchar +*zak_authe_smbldap_authe_get_password (ZakAuthePluggable *pluggable, GSList *parameters, gchar **password) { GError *error; gchar *ret = NULL; + gchar *password_new; + + gboolean change_password; + error = NULL; gtkbuilder = gtk_builder_new (); @@ -969,11 +1007,55 @@ gchar gtk_widget_set_visible (exp_cambio, FALSE); #endif + password_new = g_strdup (""); + switch (gtk_dialog_run (GTK_DIALOG (diag))) { case GTK_RESPONSE_OK: /* controllo dell'utente e della password */ - ret = controllo (parameters); + change_password = FALSE; + if (gtk_expander_get_expanded (GTK_EXPANDER (exp_cambio))) + { + g_free (password_new); + password_new = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_nuova)))); + if (strlen (password_new) == 0 || strcmp (g_strstrip (password_new), "") == 0) + { + /* TO DO */ + g_warning ("The new password is empty."); + g_free (password_new); + password_new = g_strdup (""); + } + else if (strcmp (g_strstrip (password_new), g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))))) != 0) + { + /* TO DO */ + g_warning ("The new password and the confirm don't match."); + g_free (password_new); + password_new = g_strdup (""); + } + else + { + /* cambio la password */ + change_password = TRUE; + } + } + + 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))); + + if (ret != NULL && change_password) + { + gchar *command = g_strdup_printf ("echo -e \"%s\\n\" | sudo -k -S echo -e \"%s\\\\n%s\\\\n\" | sudo /usr/sbin/smbldap-passwd \"%s\"", + password, + password_new, + password_new, + gtk_entry_get_text (GTK_ENTRY (txt_utente))); + + zak_authe_smbldap_exec_ssh_command (command); + + g_free (command); + } break; case GTK_RESPONSE_CANCEL: @@ -988,9 +1070,9 @@ gchar if (ret != NULL && g_strcmp0 (ret, "") != 0 && password != NULL && *password == NULL) { - if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma)), "") != 0) + if (password_new != NULL && g_strcmp0 (password_new, "") != 0) { - *password = g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))); + *password = g_strdup (password_new); } else { @@ -998,16 +1080,31 @@ gchar } } + g_free (password_new); + gtk_widget_destroy (diag); g_object_unref (gtkbuilder); return ret; } -gchar -*zak_authe_plg_authe (GSList *parameters) +static gchar +*zak_authe_smbldap_authe (ZakAuthePluggable *pluggable, GSList *parameters) { - return zak_authe_plg_get_password (parameters, NULL); + return zak_authe_smbldap_authe_get_password (pluggable, parameters, NULL); +} + +static gboolean +zak_authe_smbldap_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; + } } static void @@ -1022,8 +1119,8 @@ zak_authe_smbldap_on_vbx_users_list_destroy (GtkWidget *object, * @parameters: * */ -GtkWidget -*zak_aute_plg_get_management_gui (GSList *parameters) +static GtkWidget +*zak_authe_smbldap_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters) { GError *error; @@ -1086,3 +1183,18 @@ GtkWidget return w_users; } + +static void +zak_authe_smbldap_class_finalize (ZakAutheSmbLdapClass *klass) +{ +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + zak_authe_smbldap_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + ZAK_AUTHE_TYPE_PLUGGABLE, + ZAK_AUTHE_TYPE_SMBLDAP); +} diff --git a/src/aute_smbldap.h b/src/aute_smbldap.h index 2ed27a4..4eb979a 100644 --- a/src/aute_smbldap.h +++ b/src/aute_smbldap.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Andrea Zagli + * Copyright (C) 2010-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 @@ -20,8 +20,34 @@ #ifndef __ZAKAUTHESMBLDAP_H__ #define __ZAKAUTHESMBLDAP_H__ + +#include + + G_BEGIN_DECLS +#define ZAK_AUTHE_TYPE_SMBLDAP (zak_authe_smbldap_get_type ()) +#define ZAK_AUTHE_SMBLDAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ZAK_AUTHE_TYPE_SMBLDAP, ZakAutheSmbLdap)) +#define ZAK_AUTHE_SMBLDAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ZAK_AUTHE_TYPE_SMBLDAP, ZakAutheSmbLdap)) +#define ZAK_AUTHE_IS_SMBLDAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ZAK_AUTHE_TYPE_SMBLDAP)) +#define ZAK_AUTHE_IS_SMBLDAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ZAK_AUTHE_TYPE_SMBLDAP)) +#define ZAK_AUTHE_SMBLDAP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ZAK_AUTHE_TYPE_SMBLDAP, ZakAutheSmbLdapClass)) + +typedef struct _ZakAutheSmbLdap ZakAutheSmbLdap; +typedef struct _ZakAutheSmbLdapClass ZakAutheSmbLdapClass; + +struct _ZakAutheSmbLdap { + PeasExtensionBase parent_instance; +}; + +struct _ZakAutheSmbLdapClass { + PeasExtensionBaseClass parent_class; +}; + +GType zak_authe_smbldap_get_type (void) G_GNUC_CONST; +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + + void zak_authe_smbldap_exec_ssh_command (const gchar *command); G_END_DECLS diff --git a/src/zakauthesmbldap.plugin b/src/zakauthesmbldap.plugin new file mode 100644 index 0000000..b4ebb93 --- /dev/null +++ b/src/zakauthesmbldap.plugin @@ -0,0 +1,8 @@ +[Plugin] +Module=zakauthesmbldap +Name=ZakAutheSmbLdap +Description=Read users from ldap (using smbldaptools to edit). +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 02e5ab2..eb77b08 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,8 +8,6 @@ LIBS = $(GTK_LIBS) \ $(LIBZAKAUTHESMBLDAP_LIBS) \ $(LIBZAKCONFI_LIBS) -LDADD = ../src/libzakauthesmbldap.la - noinst_PROGRAMS = test \ test_confi \ test_get_password diff --git a/tests/test.c b/tests/test.c index a2fcfd8..39662e2 100644 --- a/tests/test.c +++ b/tests/test.c @@ -18,7 +18,7 @@ #include -#include +#include int main (int argc, char **argv) diff --git a/tests/test_confi.c b/tests/test_confi.c index a90a356..a56ad14 100644 --- a/tests/test_confi.c +++ b/tests/test_confi.c @@ -20,7 +20,7 @@ #include -#include +#include int main (int argc, char **argv) diff --git a/tests/test_confi.conf b/tests/test_confi.conf index 8054de1..d6fefd2 100644 --- a/tests/test_confi.conf +++ b/tests/test_confi.conf @@ -1,5 +1,5 @@ [libzakauthe] -plugin=/usr/local/lib/libzakauthe/plugins/libzakauthesmbldap.so +plugin=zakauthesmbldap [libzakauthe/libzakauthesmbldap/ldap] host=ldap://ldap.comune.scandicci.fi.it/ diff --git a/tests/test_get_password.c b/tests/test_get_password.c index 292c73d..640bc48 100644 --- a/tests/test_get_password.c +++ b/tests/test_get_password.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 Andrea Zagli + * Copyright (C) 2013-2016 Andrea Zagli * * 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 @@ -18,7 +18,7 @@ #include -#include +#include int main (int argc, char **argv)