From 2501ae413f09c8aca4032e792c1f4b8ee451ee90 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Fri, 12 Feb 2010 18:28:43 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 29 +++ AUTHORS | 1 + ChangeLog | 0 Makefile.am | 1 + NEWS | 0 README | 2 + autogen.sh | 23 +++ configure.ac | 56 ++++++ data/Makefile.am | 3 + data/auteldap_confi_schema.xml | 23 +++ data/libauteldap/Makefile.am | 1 + data/libauteldap/gui/Makefile.am | 5 + data/libauteldap/gui/auteldap.gui | 207 +++++++++++++++++++++ src/Makefile.am | 15 ++ src/aute_ldap.c | 298 ++++++++++++++++++++++++++++++ tests/Makefile.am | 13 ++ tests/test.c | 41 ++++ 17 files changed, 718 insertions(+) create mode 100644 .gitignore 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/auteldap_confi_schema.xml create mode 100644 data/libauteldap/Makefile.am create mode 100644 data/libauteldap/gui/Makefile.am create mode 100644 data/libauteldap/gui/auteldap.gui create mode 100644 src/Makefile.am create mode 100644 src/aute_ldap.c create mode 100644 tests/Makefile.am create mode 100644 tests/test.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92fb8b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +COPYING +INSTALL +Makefile +aclocal.m4 +autom4te.cache/ +config.guess +config.log +config.status +config.sub +configure +depcomp +version.xml +gtk-doc.make +install-sh +libaute.pc +libtool +ltmain.sh +missing +.deps +.libs +*.lo +*.o +*.la +*~ +*.in +config.h +stamp-h1 +tests/test +tools/aute-db-mkpwd 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..c577ac6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src tests 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..5ac0213 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +La directory tools contiene il programma aute-db-mkpwd che serve per generare +l'hash md5 utilizzato per la cifratura delle password diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..a2f1aba --- /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-ldap" + +(test -f $srcdir/configure.ac \ + && test -d $srcdir/src \ + && test -f $srcdir/src/aute_ldap.c) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" + echo " top-level libauteldap 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..2441086 --- /dev/null +++ b/configure.ac @@ -0,0 +1,56 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([libaute-ldap], [0.0.1], [azagli@libero.it]) +AC_CONFIG_SRCDIR([src/aute_ldap.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(LIBAUTELDAP, [gtk+-2.0 >= 2.16.0 + libaute >= 0.0.2]) + +AC_SUBST(LIBAUTELDAP_CFLAGS) +AC_SUBST(LIBAUTELDAP_LIBS) + +with_ldap=no +AC_CHECK_LIB([ldap], [ldap_initialize], with_ldap=yes) + +if test "$with_ldap" = "yes" +then + AC_SUBST(LIBLDAP_LIBS, [" -lldap"]) +fi + +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 + tests/Makefile + data/Makefile + data/libauteldap/Makefile + data/libauteldap/gui/Makefile +]) +AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..f4a0be3 --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = libauteldap + +EXTRA_DIST = auteldap_confi_schema.xml diff --git a/data/auteldap_confi_schema.xml b/data/auteldap_confi_schema.xml new file mode 100644 index 0000000..0c1b4e4 --- /dev/null +++ b/data/auteldap_confi_schema.xml @@ -0,0 +1,23 @@ + + + aute-ldap + Plugin di libaute di autenticazione su ldap + + + ldap + Parametri per la connessione al server ldap + + + host + Host address + + + base_dn + Base DN + + + user_field + User name field + + + diff --git a/data/libauteldap/Makefile.am b/data/libauteldap/Makefile.am new file mode 100644 index 0000000..13c2b3d --- /dev/null +++ b/data/libauteldap/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = gui diff --git a/data/libauteldap/gui/Makefile.am b/data/libauteldap/gui/Makefile.am new file mode 100644 index 0000000..3f0a988 --- /dev/null +++ b/data/libauteldap/gui/Makefile.am @@ -0,0 +1,5 @@ +guidir = $(datadir)/libauteldap/gui + +gui_DATA = auteldap.gui + +EXTRA_DIST = $(gui_DATA) diff --git a/data/libauteldap/gui/auteldap.gui b/data/libauteldap/gui/auteldap.gui new file mode 100644 index 0000000..382a861 --- /dev/null +++ b/data/libauteldap/gui/auteldap.gui @@ -0,0 +1,207 @@ + + + + + + True + Autenticazione + True + dialog + + + True + + + True + 5 + 3 + 2 + 3 + 3 + + + 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 + 3 + 3 + + + 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 + + + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..8cac9e1 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,15 @@ +guidir = $(datadir)/libauteldap/gui + +AM_CPPFLAGS = $(LIBAUTELDAP_CFLAGS) \ + $(LIBLDAP_CFLAGS) \ + $(LIBCONFI_CFLAGS) \ + -DGUIDIR=\""$(guidir)"\" + +LIBS = $(LIBAUTELDAP_LIBS) \ + $(LIBLDAP_LIBS) \ + $(LIBCONFI_LIBS) + +libaute_pluginsdir = $(libdir)/libaute/plugins +libaute_plugins_LTLIBRARIES = libaute-ldap.la + +libaute_ldap_la_SOURCES = aute_ldap.c diff --git a/src/aute_ldap.c b/src/aute_ldap.c new file mode 100644 index 0000000..748427b --- /dev/null +++ b/src/aute_ldap.c @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2005-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 + +#ifdef HAVE_LIBCONFI + #include +#endif + +static GtkWidget *txt_utente; +static GtkWidget *txt_password; +static GtkWidget *exp_cambio; +static GtkWidget *txt_password_nuova; +static GtkWidget *txt_password_conferma; + +/* 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-ldap/ldap/host"); + *base_dn = confi_path_get_value (confi, "aute/aute-ldap/ldap/base_dn"); + *user_field = confi_path_get_value (confi, "aute/aute-ldap/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 gchar +*controllo (GSList *parameters) +{ + gchar *utente = ""; + gchar *password; + gchar *password_nuova; + + gchar *host; + gchar *base_dn; + gchar *user_field; + + LDAP *ldap; + int version; + int retldap; + + 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 (host); + 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; + } + + retldap = ldap_simple_bind_s (ldap, + g_strdup_printf ("%s=%s,%s", user_field, utente, base_dn), password); + if (retldap != LDAP_SUCCESS) + { + g_warning ("Errore nel bind.\n%s\n", ldap_err2string (retldap)); + return NULL; + } + +/* + if (strcmp (utente, "") != 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) + { + g_warning ("La nuova password è vuota."); + } + else if (strcmp (g_strstrip (password_nuova), g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (txt_password_conferma))))) != 0) + { + g_warning ("La nuova password e la conferma non coincidono."); + } + else + { + sql = g_strdup_printf ("UPDATE utenti " + "SET password = '%s' " + "WHERE codice = '%s'", + gdaex_strescape (cifra_password (password_nuova), NULL), + gdaex_strescape (utente, NULL)); + if (gdaex_execute (gdaex, sql) == -1) + { + g_warning ("Errore durante la modifica della password."); + return NULL; + } + } + } +*/ + + retldap = ldap_unbind (ldap); + if (retldap != LDAP_SUCCESS) + { + g_warning ("Errore nell'unbind.\n%s\n", ldap_err2string (retldap)); + return NULL; + } + + return utente; +} + +/* PUBLIC */ +gchar +*autentica (GSList *parameters) +{ + GError *error; + gchar *ret = NULL; + + error = NULL; + + GtkBuilder *gtkbuilder = gtk_builder_new (); + if (!gtk_builder_add_from_file (gtkbuilder, GUIDIR "/auteldap.gui", &error)) + { + 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 (parameters); + break; + + case GTK_RESPONSE_CANCEL: + ret = g_strdup (""); + break; + + default: + break; + } + + gtk_widget_destroy (diag); + g_object_unref (gtkbuilder); + + return ret; +} + +/** + * crea_utente: + * @parameters: + * @codice: + * @password: + */ +gboolean +crea_utente (GSList *parameters, const gchar *codice, const gchar *password) +{ + /* TODO */ + return FALSE; +} + +/** + * modifice_utente: + * @parameters: + * @codice: + * @password: + */ +gboolean +modifica_utente (GSList *parameters, const gchar *codice, const gchar *password) +{ + /* TODO */ + return FALSE; +} + +/** + * elimina_utente: + * @parameters: + * @codice: + */ +gboolean +elimina_utente (GSList *parameters, const gchar *codice) +{ + /* TODO */ + return FALSE; +} diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..10f47f9 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,13 @@ +AM_CPPFLAGS = $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ + $(LIBAUTELDAP_CFLAGS) \ + $(LIBLDAP_CFLAGS) \ + -I../src + +LIBS = $(GTK_LIBS) \ + $(LIBAUTELDAP_LIBS) \ + $(LIBLDAP_LIBS) + +LDADD = ../src/libaute-ldap.la + +noinst_PROGRAMS = test diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..46d470d --- /dev/null +++ b/tests/test.c @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#include + +#include + +int +main (int argc, char **argv) +{ + Aute *aute; + GSList *params; + + gtk_init (&argc, &argv); + + aute = aute_new (); + + params = g_slist_append (params, argv[1]); + params = g_slist_append (params, argv[2]); + + aute_set_config (aute, params); + + g_fprintf (stderr, "Utente %s\n", aute_autentica (aute)); + + return 0; +} -- 2.49.0