#include <ldap.h>
#include <libssh/libssh.h>
+#include <libpeas/peas.h>
+
+#include <libzakauthe/libzakauthe.h>
+
#ifdef HAVE_LIBZAKCONFI
#include <libzakconfi/libzakconfi.h>
#endif
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;
#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)
}
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;
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;
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)
{
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;
}
}
/* 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 ();
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:
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
{
}
}
+ 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
* @parameters:
*
*/
-GtkWidget
-*zak_aute_plg_get_management_gui (GSList *parameters)
+static GtkWidget
+*zak_authe_smbldap_get_management_gui (ZakAuthePluggable *pluggable, GSList *parameters)
{
GError *error;
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);
+}
/*
- * Copyright (C) 2010-2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-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
#ifndef __ZAKAUTHESMBLDAP_H__
#define __ZAKAUTHESMBLDAP_H__
+
+#include <libpeas/peas.h>
+
+
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