From aa19ff380150d98cbd66f2d8b0d5396d181a3a35 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 8 Aug 2010 15:07:39 +0200 Subject: [PATCH] Initial import. --- AUTHORS | 1 + ChangeLog | 0 Makefile.am | 1 + NEWS | 0 README | 0 autogen.sh | 23 + configure.ac | 49 ++ data/Makefile.am | 3 + data/libaute-smbldap/Makefile.am | 1 + data/libaute-smbldap/form/Makefile.am | 5 + data/libaute-smbldap/form/user.form | 45 ++ data/libaute-smbldap/gui/Makefile.am | 5 + data/libaute-smbldap/gui/autesmbldap.gui | 605 +++++++++++++++++++++++ src/Makefile.am | 22 + src/aute_smbldap.c | 522 +++++++++++++++++++ src/aute_smbldap.h | 28 ++ src/user.c | 349 +++++++++++++ src/user.h | 65 +++ 18 files changed, 1724 insertions(+) create mode 100644 AUTHORS create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 data/Makefile.am create mode 100644 data/libaute-smbldap/Makefile.am create mode 100644 data/libaute-smbldap/form/Makefile.am create mode 100644 data/libaute-smbldap/form/user.form create mode 100644 data/libaute-smbldap/gui/Makefile.am create mode 100644 data/libaute-smbldap/gui/autesmbldap.gui create mode 100644 src/Makefile.am create mode 100644 src/aute_smbldap.c create mode 100644 src/aute_smbldap.h create mode 100644 src/user.c create mode 100644 src/user.h diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..ad1de0f --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Andrea Zagli diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..9768a98 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src data diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..625ce6d --- /dev/null +++ b/autogen.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +PKG_NAME="libaute-smbldap" + +(test -f $srcdir/configure.ac \ + && test -d $srcdir/src \ + && test -f $srcdir/src/aute_smbldap.c) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" + echo " top-level libaute-smbldap directory" + exit 1 +} + +which gnome-autogen.sh || { + echo "You need to install gnome-common from GNOME and make" + echo "sure the gnome-autogen.sh script is in your \$PATH." + exit 1 +} + +USE_GNOME2_MACROS=1 . gnome-autogen.sh diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..2117831 --- /dev/null +++ b/configure.ac @@ -0,0 +1,49 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([libaute-smbldap], [0.1.0], [azagli@libero.it]) +AC_CONFIG_SRCDIR([src/aute_smbldap.c]) +AC_CONFIG_HEADER([config.h]) + +AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE + +AC_CANONICAL_SYSTEM + +AC_LIBTOOL_WIN32_DLL + +# Checks for programs. +AC_PROG_CC +AC_PROG_LIBTOOL + +# Checks for libraries. +PKG_CHECK_MODULES(LIBAUTEDB, [gtk+-2.0 >= 2.16.0 + libaute >= 0.1.0 + libgtkform >= 0.1.4]) + +AC_SUBST(LIBAUTESMBLDAP_CFLAGS) +AC_SUBST(LIBAUTESMBLDAP_LIBS) + +PKG_CHECK_MODULES(LIBCONFI, [libconfi >= 0.0.2], [AC_DEFINE(HAVE_LIBCONFI, [1], [libconfi is present]), have_libconfi=yes], have_libconfi=no) + +AM_CONDITIONAL(HAVE_LIBCONFI, test x"$have_libconfi" = "xyes") +AC_SUBST(LIBCONFI_CFLAGS) +AC_SUBST(LIBCONFI_LIBS) + +# Checks for header files. + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +# Checks for library functions. + +AC_CONFIG_FILES([ + Makefile + src/Makefile + data/Makefile + data/libaute-smbldap/Makefile + data/libaute-smbldap/form/Makefile + data/libaute-smbldap/gui/Makefile +]) +AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..5909f74 --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = libaute-smbldap + +EXTRA_DIST = diff --git a/data/libaute-smbldap/Makefile.am b/data/libaute-smbldap/Makefile.am new file mode 100644 index 0000000..45a8045 --- /dev/null +++ b/data/libaute-smbldap/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = gui form diff --git a/data/libaute-smbldap/form/Makefile.am b/data/libaute-smbldap/form/Makefile.am new file mode 100644 index 0000000..113eb1a --- /dev/null +++ b/data/libaute-smbldap/form/Makefile.am @@ -0,0 +1,5 @@ +formdir = $(datadir)/libaute-smbldap/form + +form_DATA = user.form + +EXTRA_DIST = $(form_DATA) diff --git a/data/libaute-smbldap/form/user.form b/data/libaute-smbldap/form/user.form new file mode 100644 index 0000000..3c8a122 --- /dev/null +++ b/data/libaute-smbldap/form/user.form @@ -0,0 +1,45 @@ + + + + users
+ + + + t + t + + + + + + + + + + + t + + + + + + + + + + t + + + + + + datetime + %d/%m/%Y %H.%M.%S + + + + + + + +
diff --git a/data/libaute-smbldap/gui/Makefile.am b/data/libaute-smbldap/gui/Makefile.am new file mode 100644 index 0000000..dcf83ac --- /dev/null +++ b/data/libaute-smbldap/gui/Makefile.am @@ -0,0 +1,5 @@ +guidir = $(datadir)/libaute-smbldap/gui + +gui_DATA = autesmbldap.gui + +EXTRA_DIST = $(gui_DATA) diff --git a/data/libaute-smbldap/gui/autesmbldap.gui b/data/libaute-smbldap/gui/autesmbldap.gui new file mode 100644 index 0000000..f7c1e04 --- /dev/null +++ b/data/libaute-smbldap/gui/autesmbldap.gui @@ -0,0 +1,605 @@ + + + + + + True + Autenticazione + True + dialog + + + True + vertical + + + True + 5 + 3 + 2 + 5 + 5 + + + True + 0 + Utente + + + GTK_FILL + + + + + + True + 0 + Password + + + 1 + 2 + GTK_FILL + + + + + + True + True + True + + + 1 + 2 + + + + + + True + True + False + True + + + 1 + 2 + 1 + 2 + + + + + + True + True + + + True + 5 + 2 + 2 + 5 + 5 + + + True + 0 + Nuova + + + GTK_FILL + + + + + + True + 0 + Conferma + + + 1 + 2 + GTK_FILL + + + + + + True + True + False + True + + + 1 + 2 + + + + + + True + True + False + True + + + 1 + 2 + 1 + 2 + + + + + + + + True + _Cambia password + True + + + + + 2 + 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 + + + + + False + end + 0 + + + + + + cancelbutton1 + okbutton1 + + + + + + + + + + + + + + + + + + True + 5 + vertical + 5 + + + True + True + automatic + automatic + etched-in + + + True + True + lstore_users + + + Status + + + + 0 + + + + + + + Code + + + + 1 + + + + + + + Name + + + + 2 + + + + + + + Password expiration + + + + 3 + + + + + + + + + 0 + + + + + True + 5 + end + + + gtk-new + True + True + True + True + + + False + False + 0 + + + + + gtk-edit + True + True + True + True + + + False + False + 1 + + + + + gtk-delete + True + True + True + True + + + False + False + 2 + + + + + gtk-find + True + True + True + True + + + False + False + 3 + + + + + False + 1 + + + + + + + User + True + center-on-parent + True + + + True + 5 + vertical + 5 + + + True + 7 + 2 + 5 + 5 + + + True + 0 + Code + + + GTK_FILL + GTK_FILL + + + + + True + 0 + Surname + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + Name + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + 0 + Enabled + + + 3 + 4 + GTK_FILL + GTK_FILL + + + + + True + 0 + Password expiration + + + 4 + 5 + GTK_FILL + GTK_FILL + + + + + True + 0 + 0 + Description + + + 5 + 6 + GTK_FILL + GTK_FILL + + + + + True + True + False + True + + + 1 + 2 + 3 + 4 + + + + + True + True + 10 + + + + 1 + 2 + + + + + True + True + 100 + + + + 1 + 2 + 1 + 2 + + + + + True + True + 100 + + + + 1 + 2 + 2 + 3 + + + + + True + True + 19 + + + + 1 + 2 + 4 + 5 + + + + + True + True + automatic + automatic + etched-in + + + True + True + + + + + 1 + 2 + 5 + 6 + + + + + lbl_password + + + 6 + 7 + GTK_FILL + GTK_FILL + + + + + + + + 0 + + + + + True + 5 + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-save + True + True + True + True + + + False + False + 1 + + + + + False + 1 + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..3a07774 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,22 @@ +guidir = $(datadir)/libaute-db/gui +formdir = $(datadir)/libaute-db/form + +AM_CPPFLAGS = $(LIBAUTEDB_CFLAGS) \ + $(LIBGCRYPT_CFLAGS) \ + $(LIBCONFI_CFLAGS) \ + -DGUIDIR=\""$(guidir)"\" \ + -DFORMDIR=\""$(formdir)"\" + +LIBS = $(LIBAUTEDB_LIBS) \ + $(LIBGCRYPT_LIBS) \ + $(LIBCONFI_LIBS) + +libaute_pluginsdir = $(libdir)/libaute/plugins +libaute_plugins_LTLIBRARIES = libaute-db.la + +libaute_db_la_SOURCES = aute_db.c \ + aute_db.h \ + user.c \ + user.h + +libaute_db_la_LDFLAGS = -no-undefined diff --git a/src/aute_smbldap.c b/src/aute_smbldap.c new file mode 100644 index 0000000..0eaa046 --- /dev/null +++ b/src/aute_smbldap.c @@ -0,0 +1,522 @@ +/* + * Copyright (C) 2010 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 + * 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. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include +#include + +#include + +#ifdef HAVE_LIBCONFI + #include +#endif + +#include "user.h" + +static GtkBuilder *gtkbuilder; + +static gchar *guifile; +static gchar *formdir; + +static GtkWidget *txt_utente; +static GtkWidget *txt_password; +static GtkWidget *exp_cambio; +static GtkWidget *txt_password_nuova; +static GtkWidget *txt_password_conferma; + +static GtkWidget *w_users; + +static GtkTreeView *trv_users; +static GtkListStore *lstore_users; +static GtkTreeSelection *sel_users; + +enum +{ + COL_STATUS, + COL_CODE, + COL_NAME, + COL_PASSWORD_EXPIRATION +}; + +/* PRIVATE */ +#ifdef HAVE_LIBCONFI +static gboolean +get_connection_parameters_from_confi (Confi *confi, gchar **host, gchar **base_dn, gchar **user_field) +{ + gboolean ret = TRUE; + + *host = confi_path_get_value (confi, "aute/aute-smbldap/ldap/host"); + *base_dn = confi_path_get_value (confi, "aute/aute-smbldap/ldap/base_dn"); + *user_field = confi_path_get_value (confi, "aute/aute-smbldap/ldap/user_field"); + + if (*host == NULL + || strcmp (g_strstrip (*host), "") == 0 + || base_dn == NULL + || strcmp (g_strstrip (*base_dn), "") == 0 + || user_field == NULL + || strcmp (g_strstrip (*user_field), "") == 0) + { + *host = NULL; + *base_dn = NULL; + *user_field = NULL; + + ret = FALSE; + } + + return ret; +} +#endif + +static GtkWindow +*autesmbldap_get_gtkwidget_parent_gtkwindow (GtkWidget *widget) +{ + GtkWindow *w; + GtkWidget *w_parent; + + w = NULL; + + w_parent = gtk_widget_get_parent (widget); + while (w_parent != NULL && !GTK_IS_WINDOW (w_parent)) + { + w_parent = gtk_widget_get_parent (w_parent); + } + + if (GTK_IS_WINDOW (w_parent)) + { + w = GTK_WINDOW (w_parent); + } + + return w; +} + +static gchar +*controllo () +{ + gchar *user_dn; + gchar *utente; + gchar *password; + gchar *password_nuova; + + gchar *host; + gchar *base_dn; + gchar *user_field; + + LDAP *ldap; + int version; + int retldap; + + 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; + +#ifdef HAVE_LIBCONFI + /* the first and only parameters must be a Confi object */ + /* leggo i parametri di connessione dalla configurazione */ + if (IS_CONFI (parameters->data)) + { + if (!get_connection_parameters_from_confi (CONFI (parameters->data), &host, &base_dn, &user_field)) + { + host = NULL; + base_dn = NULL; + user_field = NULL; + } + } +#endif + + if (host == NULL) + { + GSList *param; + + param = g_slist_next (parameters); + if (param != NULL && param->data != NULL) + { + host = g_strdup ((gchar *)param->data); + host = g_strstrip (host); + if (g_strcmp0 (host, "") == 0) + { + host = NULL; + } + else + { + param = g_slist_next (param); + if (param != NULL && param->data != NULL) + { + base_dn = g_strdup ((gchar *)param->data); + base_dn = g_strstrip (base_dn); + if (g_strcmp0 (base_dn, "") == 0) + { + base_dn = NULL; + } + else + { + param = g_slist_next (param); + if (param != NULL && param->data != NULL) + { + user_field = g_strdup ((gchar *)param->data); + user_field = g_strstrip (user_field); + if (g_strcmp0 (user_field, "") == 0) + { + user_field = NULL; + } + } + } + } + } + } + } + + if (host == NULL + || base_dn == NULL + || user_field == NULL) + { + return NULL; + } + ldap = NULL; + version = 3; + + retldap = ldap_initialize (&ldap, host); + if (retldap != LDAP_SUCCESS) + { + g_warning ("Errore nell'inizializzazione.\n%s\n", ldap_err2string (retldap)); + return NULL; + } + + retldap = ldap_set_option (ldap, LDAP_OPT_PROTOCOL_VERSION, &version); + if (retldap != LDAP_OPT_SUCCESS) + { + g_warning ("Errore nell'impostazione della versione del protocollo.\n%s\n", ldap_err2string (retldap)); + return NULL; + } + + user_dn = g_strdup_printf ("%s=%s,%s", user_field, utente, base_dn); + retldap = ldap_simple_bind_s (ldap, user_dn, password); + if (retldap != LDAP_SUCCESS) + { + g_warning ("Errore nel bind.\n%s\n", ldap_err2string (retldap)); + return NULL; + } + + retldap = ldap_unbind (ldap); + if (retldap != LDAP_SUCCESS) + { + g_warning ("Errore nell'unbind.\n%s\n", ldap_err2string (retldap)); + return NULL; + } + + return user_dn; +} + +static void +autesmbldap_load_users_list () +{ + /*gchar *sql; + GdaDataModel *dm; + + guint rows; + guint row; + GtkTreeIter iter; + + gtk_list_store_clear (lstore_users); + + sql = g_strdup_printf ("SELECT * FROM users WHERE status <> 'E' ORDER BY surname, name, code"); + dm = gdaex_query (gdaex, sql); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + gtk_list_store_append (lstore_users, &iter); + gtk_list_store_set (lstore_users, &iter, + COL_STATUS, gdaex_data_model_get_field_value_boolean_at (dm, row, "enabled") ? "" : "Disabled", + COL_CODE, gdaex_data_model_get_field_value_stringify_at (dm, row, "code"), + COL_NAME, g_strdup_printf ("%s %s", + gdaex_data_model_get_field_value_stringify_at (dm, row, "surname"), + gdaex_data_model_get_field_value_stringify_at (dm, row, "name")), + COL_PASSWORD_EXPIRATION, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "password_expiration"), "%d/%m/%Y %H.%M.%S"), + -1); + } + }*/ +} + +static void +autesmbldap_on_user_aggiornato (gpointer instance, gpointer user_data) +{ +/* autesmbldap_load_users_list ();*/ +} + +static void +autesmbldap_edit_user () +{ + /*GtkTreeIter iter; + gchar *code; + + if (gtk_tree_selection_get_selected (sel_users, NULL, &iter)) + { + GtkWidget *w; + + gtk_tree_model_get (GTK_TREE_MODEL (lstore_users), &iter, + COL_CODE, &code, + -1); + + User *u = user_new (gtkbuilder, gdaex, guifile, formdir, code); + + g_signal_connect (G_OBJECT (u), "aggiornato", + G_CALLBACK (autesmbldap_on_user_aggiornato), NULL); + + w = user_get_widget (u); + gtk_window_set_transient_for (GTK_WINDOW (w), autesmbldap_get_gtkwidget_parent_gtkwindow (w_users)); + gtk_widget_show (w); + } + else + { + GtkWidget *dialog = gtk_message_dialog_new (autesmbldap_get_gtkwidget_parent_gtkwindow (w_users), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Occorre prima selezionare un modello"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + }*/ +} + +static void +autesmbldap_on_btn_new_clicked (GtkButton *button, + gpointer user_data) +{ + /*GtkWidget *w; + + User *u = user_new (gtkbuilder, gdaex, guifile, formdir, NULL); + + g_signal_connect (G_OBJECT (u), "aggiornato", + G_CALLBACK (autesmbldap_on_user_aggiornato), NULL); + + w = user_get_widget (u); + gtk_window_set_transient_for (GTK_WINDOW (w), autesmbldap_get_gtkwidget_parent_gtkwindow (w_users)); + gtk_widget_show (w);*/ +} + +static void +autesmbldap_on_btn_edit_clicked (GtkButton *button, + gpointer user_data) +{ +/* autesmbldap_edit_user ();*/ +} + +static void +autesmbldap_on_btn_delete_clicked (GtkButton *button, + gpointer user_data) +{ + /*GtkWidget *dialog; + gboolean risp; + + GtkTreeIter iter; + gchar *code; + + if (gtk_tree_selection_get_selected (sel_users, NULL, &iter)) + { + dialog = gtk_message_dialog_new (autesmbldap_get_gtkwidget_parent_gtkwindow (w_users), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "Sicuro di voler eliminare l'utente selezionato?"); + risp = gtk_dialog_run (GTK_DIALOG (dialog)); + if (risp == GTK_RESPONSE_YES) + { + gtk_tree_model_get (GTK_TREE_MODEL (lstore_users), &iter, + COL_CODE, &code, + -1); + + gdaex_execute (gdaex, + g_strdup_printf ("UPDATE users SET status = 'E' WHERE code = '%s'", code)); + + autesmbldap_load_users_list (); + } + gtk_widget_destroy (dialog); + } + else + { + dialog = gtk_message_dialog_new (autesmbldap_get_gtkwidget_parent_gtkwindow (w_users), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Occorre prima selezionare un modello"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + }*/ +} + +static void +autesmbldap_on_trv_users_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ +/* autesmbldap_edit_user ();*/ +} + +static void +autesmbldap_on_btn_find_clicked (GtkButton *button, + gpointer user_data) +{ +} + +/* PUBLIC */ +gchar +*autentica (GSList *parameters) +{ + GError *error; + gchar *ret = NULL; + + error = NULL; + + get_gdaex (parameters); + if (gdaex == NULL) + { + return NULL; + } + + gtkbuilder = gtk_builder_new (); + +#ifdef G_OS_WIN32 +#undef GUIDIR + + gchar *GUIDIR; + + GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libaute-smbldap", "gui", NULL); +#endif + +#ifdef G_OS_WIN32 +#undef FORMDIR + + gchar *FORMDIR; + + FORMDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libaute-smbldap", "form", NULL); +#endif + + formdir = g_strdup (FORMDIR); + + guifile = g_build_filename (GUIDIR, "autesmbldap.gui", NULL); + if (!gtk_builder_add_objects_from_file (gtkbuilder, guifile, + g_strsplit ("diag_main", "|", -1), + &error)) + { + g_warning ("Impossibile trovare il file di definizione dell'interfaccia utente: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + return NULL; + } + + GtkWidget *diag = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "diag_main")); + + txt_utente = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "txt_utente")); + txt_password = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "txt_password")); + exp_cambio = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "exp_cambio")); + txt_password_nuova = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "txt_password_nuova")); + txt_password_conferma = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "txt_password_conferma")); + + /* imposto di default l'utente corrente della sessione */ + gtk_entry_set_text (GTK_ENTRY (txt_utente), g_get_user_name ()); + gtk_editable_select_region (GTK_EDITABLE (txt_utente), 0, -1); + + switch (gtk_dialog_run (GTK_DIALOG (diag))) + { + case GTK_RESPONSE_OK: + /* controllo dell'utente e della password */ + ret = controllo (); + break; + + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_NONE: + case GTK_RESPONSE_DELETE_EVENT: + ret = g_strdup (""); + break; + + default: + break; + } + + gtk_widget_destroy (diag); + g_object_unref (gtkbuilder); + + return ret; +} + +/** + * get_management_gui: + * @parameters: + * + */ +GtkWidget +*get_management_gui (GSList *parameters) +{ + GError *error; + + error = NULL; + + gtkbuilder = gtk_builder_new (); + +#ifdef G_OS_WIN32 +#undef GUIDIR + + gchar *GUIDIR; + + GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libaute-db", "gu", NULL); +#endif + + if (!gtk_builder_add_objects_from_file (gtkbuilder, g_build_filename (GUIDIR, "autesmbldap.gui", NULL), + g_strsplit ("lstore_users|vbx_users_list", "|", -1), + &error)) + { + g_error ("Impossibile trovare il file di definizione dell'interfaccia utente."); + return NULL; + } + + w_users = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "vbx_users_list")); + if (w_users == NULL) + { + g_warning ("Unable to find the widget vbx_users_list."); + return NULL; + } + + trv_users = GTK_TREE_VIEW (gtk_builder_get_object (gtkbuilder, "treeview1")); + lstore_users = GTK_LIST_STORE (gtk_builder_get_object (gtkbuilder, "lstore_users")); + sel_users = gtk_tree_view_get_selection (trv_users); + + g_signal_connect (gtk_builder_get_object (gtkbuilder, "treeview1"), + "row-activated", G_CALLBACK (autesmbldap_on_trv_users_row_activated), NULL); + + g_signal_connect (G_OBJECT (gtk_builder_get_object (gtkbuilder, "button1")), "clicked", + G_CALLBACK (autesmbldap_on_btn_new_clicked), NULL); + g_signal_connect (G_OBJECT (gtk_builder_get_object (gtkbuilder, "button2")), "clicked", + G_CALLBACK (autesmbldap_on_btn_edit_clicked), NULL); + g_signal_connect (G_OBJECT (gtk_builder_get_object (gtkbuilder, "button3")), "clicked", + G_CALLBACK (autesmbldap_on_btn_delete_clicked), NULL); + g_signal_connect (G_OBJECT (gtk_builder_get_object (gtkbuilder, "button4")), "clicked", + G_CALLBACK (autesmbldap_on_btn_find_clicked), NULL); + + autesmbldap_load_users_list (); + + return w_users; +} diff --git a/src/aute_smbldap.h b/src/aute_smbldap.h new file mode 100644 index 0000000..7c2d870 --- /dev/null +++ b/src/aute_smbldap.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010 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 __AUTESMBLDAP_H__ +#define __AUTESMBLDAP_H__ + +G_BEGIN_DECLS + + +G_END_DECLS + +#endif /* __AUTESMBLDAP_H__ */ diff --git a/src/user.c b/src/user.c new file mode 100644 index 0000000..251c9d3 --- /dev/null +++ b/src/user.c @@ -0,0 +1,349 @@ +/* + * Copyright (C) 2010 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 + * + */ + +#include + +#include "user.h" +#include "aute_db.h" + +static void user_class_init (UserClass *klass); +static void user_init (User *user); + +static void user_carica (User *user); +static void user_salva (User *user); + +static gboolean user_conferma_chiusura (User *user); + +static void user_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void user_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean user_on_w_user_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); + +static void user_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void user_on_btn_salva_clicked (GtkButton *button, + gpointer user_data); + +#define USER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_USER, UserPrivate)) + +enum +{ + TXT_CODE, + LBL_PASSWORD +}; + +typedef struct _UserPrivate UserPrivate; +struct _UserPrivate + { + GtkBuilder *gtkbuilder; + GdaEx *gdaex; + gchar *guifile; + gchar *formdir; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + gchar *code; + }; + +G_DEFINE_TYPE (User, user, G_TYPE_OBJECT) + +static void +user_class_init (UserClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (UserPrivate)); + + object_class->set_property = user_set_property; + object_class->get_property = user_get_property; + + /** + * User::aggiornato: + * @user: + * + */ + klass->aggiornato_signal_id = g_signal_new ("aggiornato", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); +} + +static void +user_init (User *user) +{ + UserPrivate *priv = USER_GET_PRIVATE (user); + + priv->code = NULL; +} + +/** + * user_new: + * @gtkbuilder: + * @gdaex: + * @guifile: + * @formdir: + * @code: + * + * Returns: the newly created #User object. + */ +User +*user_new (GtkBuilder *gtkbuilder, GdaEx *gdaex, + const gchar *guifile, const gchar *formdir, const gchar *code) +{ + GError *error; + + User *a = USER (g_object_new (user_get_type (), NULL)); + + UserPrivate *priv = USER_GET_PRIVATE (a); + + priv->gtkbuilder = gtkbuilder; + priv->gdaex = gdaex; + priv->guifile = g_strdup (guifile); + priv->formdir = g_strdup (formdir); + + error = NULL; + gtk_builder_add_objects_from_file (priv->gtkbuilder, priv->guifile, + g_strsplit ("w_user", "|", -1), + &error); + if (error != NULL) + { + g_warning ("Errore: %s.", error->message); + return NULL; + } + + priv->form = gtk_form_new (); + g_object_set (priv->form, "gdaex", priv->gdaex, NULL); + gtk_form_load_from_file (priv->form, g_build_filename (priv->formdir, "user.form", NULL), priv->gtkbuilder); + + g_object_set (priv->form, "gdaex", priv->gdaex, NULL); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "w_user")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "entry1", + "label14", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (user_on_w_user_delete_event), (gpointer *)a); + + g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button5"), + "clicked", G_CALLBACK (user_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button6"), + "clicked", G_CALLBACK (user_on_btn_salva_clicked), (gpointer *)a); + + if (code != NULL) + { + priv->code = g_strstrip (g_strdup (code)); + } + if (priv->code == NULL || g_strcmp0 (priv->code, "") == 0) + { + gtk_form_clear (priv->form); + } + else + { + gtk_entry_set_text (GTK_ENTRY (priv->objects[TXT_CODE]), priv->code); + gtk_editable_set_editable (GTK_EDITABLE (priv->objects[TXT_CODE]), FALSE); + + user_carica (a); + } + + return a; +} + +/** + * user_get_widget: + * @user: + * + */ +GtkWidget +*user_get_widget (User *user) +{ + UserPrivate *priv = USER_GET_PRIVATE (user); + + return priv->w; +} + +/* PRIVATE */ +static void +user_carica (User *user) +{ + UserPrivate *priv = USER_GET_PRIVATE (user); + + if (gtk_form_fill_from_table (priv->form)) + { + } +} + +static void +user_salva (User *user) +{ + GError *error = NULL; + gchar *sql; + GtkWidget *dialog; + + GDate *da; + GDate *a; + + UserClass *klass = USER_GET_CLASS (user); + + UserPrivate *priv = USER_GET_PRIVATE (user); + + if (!gtk_form_check (priv->form, FALSE, NULL, TRUE, priv->w, TRUE)) + { + return; + } + + if (priv->code == NULL || g_strcmp0 (priv->code, "") == 0) + { + gtk_label_set_text (GTK_LABEL (priv->objects[LBL_PASSWORD]), + autedb_cifra_password (gtk_entry_get_text (GTK_ENTRY (priv->objects[TXT_CODE])))); + sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT); + } + else + { + sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE); + } + + if (gdaex_execute (priv->gdaex, sql) == 1) + { + g_signal_emit (user, klass->aggiornato_signal_id, 0); + + gtk_form_set_as_origin (priv->form); + + dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Salvataggio eseguito con successo."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + else + { + dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Errore durante il salvataggio."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +user_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + User *user = USER (object); + + UserPrivate *priv = USER_GET_PRIVATE (user); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +user_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + User *user = USER (object); + + UserPrivate *priv = USER_GET_PRIVATE (user); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +user_conferma_chiusura (User *user) +{ + GtkWidget *dialog; + + gboolean ret; + + UserPrivate *priv = USER_GET_PRIVATE (user); + + ret = TRUE; + if (gtk_form_is_changed (priv->form)) + { + dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "Sicuro di voler chiudere senza salvare?"); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_NO) + { + ret = FALSE; + } + gtk_widget_destroy (dialog); + } + + return ret; +} + +/* CALLBACK */ +static gboolean +user_on_w_user_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return !user_conferma_chiusura ((User *)user_data); +} + +static void +user_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + User *user = (User *)user_data; + + UserPrivate *priv = USER_GET_PRIVATE (user); + + if (user_conferma_chiusura (user)) gtk_widget_destroy (priv->w); +} + +static void +user_on_btn_salva_clicked (GtkButton *button, + gpointer user_data) +{ + user_salva ((User *)user_data); +} diff --git a/src/user.h b/src/user.h new file mode 100644 index 0000000..63e0d06 --- /dev/null +++ b/src/user.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 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 __USER_H__ +#define __USER_H__ + +#include +#include + +#include +#include + +G_BEGIN_DECLS + + +#define TYPE_USER (user_get_type ()) +#define USER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_USER, User)) +#define USER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_USER, UserClass)) +#define IS_USER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_USER)) +#define IS_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_USER)) +#define USER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_USER, UserClass)) + + +typedef struct _User User; +typedef struct _UserClass UserClass; + +struct _User + { + GObject parent; + }; + +struct _UserClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType user_get_type (void) G_GNUC_CONST; + +User *user_new (GtkBuilder *gtkbuilder, GdaEx *gdaex, + const gchar *guifile, const gchar *formdir, const gchar *code); + +GtkWidget *user_get_widget (User *user); + + +G_END_DECLS + +#endif /* __USER_H__ */ -- 2.49.0