From ff862138ae7459963837ec25fa61d12002339add Mon Sep 17 00:00:00 2001 From: root Date: Wed, 20 May 2009 17:08:50 +0200 Subject: [PATCH] Initial import --- AUTHORS | 1 + ChangeLog | 0 Makefile.am | 1 + NEWS | 0 README | 2 + autogen.sh | 98 ++++++++ config.h.in | 58 +++++ configure.ac | 50 ++++ data/Makefile.am | 4 + data/autedb.sql | 10 + data/autedb_confi_schema.xml | 19 ++ data/libautedb/Makefile.am | 1 + data/libautedb/glade/Makefile.am | 5 + data/libautedb/glade/autedb.glade | 336 +++++++++++++++++++++++++++ src/Makefile.am | 13 ++ src/aute_db.c | 367 ++++++++++++++++++++++++++++++ tests/Makefile.am | 11 + tests/test.c | 31 +++ tools/Makefile.am | 11 + tools/aute_db_mkpwd.c | 80 +++++++ 20 files changed, 1098 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 config.h.in create mode 100644 configure.ac create mode 100644 data/Makefile.am create mode 100644 data/autedb.sql create mode 100644 data/autedb_confi_schema.xml create mode 100644 data/libautedb/Makefile.am create mode 100644 data/libautedb/glade/Makefile.am create mode 100644 data/libautedb/glade/autedb.glade create mode 100644 src/Makefile.am create mode 100644 src/aute_db.c create mode 100644 tests/Makefile.am create mode 100644 tests/test.c create mode 100644 tools/Makefile.am create mode 100644 tools/aute_db_mkpwd.c 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..a3c385a --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src tests data tools 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..c8462f7 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir +PROJECT=libautedb +TEST_TYPE=-f +FILE=configure.ac + +DIE=0 + +have_libtool=false +if libtoolize --version < /dev/null > /dev/null 2>&1 ; then + libtool_version=`libtoolize --version | sed 's/^[^0-9]*\([0-9.][0-9.]*\).*/\1/'` + case $libtool_version in + 1.4*|1.5*) + have_libtool=true + ;; + esac +fi +if $have_libtool ; then : ; else + echo + echo "You must have libtool 1.4 installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/" + DIE=1 +fi + +(gtkdocize --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have gtk-doc installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/" + DIE=1 +} + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/" + DIE=1 +} + +if automake --version < /dev/null > /dev/null 2>&1 ; then + AUTOMAKE=automake + ACLOCAL=aclocal +else + echo + echo "You must have automake 1.7.x installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/" + DIE=1 +fi + +if test "$DIE" -eq 1; then + exit 1 +fi + +test $TEST_TYPE $FILE || { + echo "You must run this script in the top-level $PROJECT directory" + exit 1 +} + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." + fi +fi + +rm -rf autom4te.cache + +# README and INSTALL are required by automake, but may be deleted by clean +# up rules. to get automake to work, simply touch these here, they will be +# regenerated from their corresponding *.in files by ./configure anyway. +touch README INSTALL + +$ACLOCAL || exit $? + +libtoolize --force || exit $? +gtkdocize || exit $? + +autoheader || exit $? + +$AUTOMAKE --add-missing || exit $? +autoconf || exit $? +cd $ORIGDIR || exit $? + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $? + + echo + echo "Now type 'make' to compile $PROJECT." +fi diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..0e1824b --- /dev/null +++ b/config.h.in @@ -0,0 +1,58 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..dddfc04 --- /dev/null +++ b/configure.ac @@ -0,0 +1,50 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([libaute-db], [0.0.1], [azagli@libero.it]) +AC_CONFIG_SRCDIR([src/aute_db.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.8.0 + libglade-2.0 >= 2.6.0 + libgdaobj >= 0.0.2 + libaute >= 0.0.1]) + +AC_SUBST(LIBAUTEDB_CFLAGS) +AC_SUBST(LIBAUTEDB_LIBS) + +AM_PATH_LIBGCRYPT(1.2.1, :, [AC_MSG_ERROR([libgcrypt >= 1.2.1 not found.])]) + +AC_SUBST(LIBGCRYPT_CFLAGS) +AC_SUBST(LIBGCRYPT_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 + tools/Makefile + data/Makefile + data/libaute-db/Makefile + data/libaute-db/glade/Makefile +]) +AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..f327fab --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = libautedb + +EXTRA_DIST = autedb_confi_schema.xml \ + autedb.sql diff --git a/data/autedb.sql b/data/autedb.sql new file mode 100644 index 0000000..e1fcc83 --- /dev/null +++ b/data/autedb.sql @@ -0,0 +1,10 @@ +CREATE TABLE utenti +( + codice varchar(20) NOT NULL DEFAULT '', + "password" varchar(32) DEFAULT '', + status char(1) DEFAULT '', + CONSTRAINT utenti_pkey PRIMARY KEY (codice) +); + +/* utente iniziale con password 'root' */ +INSERT INTO utenti VALUES ('root', '63a9f0ea7bb98050796b649e85481845', ''); diff --git a/data/autedb_confi_schema.xml b/data/autedb_confi_schema.xml new file mode 100644 index 0000000..6a8ed70 --- /dev/null +++ b/data/autedb_confi_schema.xml @@ -0,0 +1,19 @@ + + + aute-db + Plugin di libaute di autenticazione su database + + + db + Parametri per la connessione al database + + + provider_id + Id del provider + + + cnc_string + La stringa di connessione al database + + + diff --git a/data/libautedb/Makefile.am b/data/libautedb/Makefile.am new file mode 100644 index 0000000..21cc77b --- /dev/null +++ b/data/libautedb/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = glade diff --git a/data/libautedb/glade/Makefile.am b/data/libautedb/glade/Makefile.am new file mode 100644 index 0000000..3c3e458 --- /dev/null +++ b/data/libautedb/glade/Makefile.am @@ -0,0 +1,5 @@ +gladedir = $(datadir)/libaute-db/glade + +glade_DATA = autedb.glade + +EXTRA_DIST = $(glade_DATA) diff --git a/data/libautedb/glade/autedb.glade b/data/libautedb/glade/autedb.glade new file mode 100644 index 0000000..1eb9497 --- /dev/null +++ b/data/libautedb/glade/autedb.glade @@ -0,0 +1,336 @@ + + + + + + + True + Autenticazione + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 5 + True + 3 + 2 + False + 3 + 3 + + + + True + Utente + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Password + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + True + True + 0 + + True + * + True + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + False + 0 + + True + * + True + + + 1 + 2 + 1 + 2 + + + + + + + True + True + False + 0 + + + + 5 + True + 2 + 2 + False + 3 + 3 + + + + True + Nuova + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Conferma + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + True + False + 0 + + True + * + True + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + False + 0 + + True + * + True + + + 1 + 2 + 1 + 2 + + + + + + + + + True + _Cambia password + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + 2 + 2 + 3 + fill + + + + + 0 + True + True + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..ea52079 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,13 @@ +gladedir = $(datadir)/libaute-db/glade + +AM_CPPFLAGS = $(LIBAUTEDB_CFLAGS) \ + $(LIBGCRYPT_CFLAGS) \ + -DGLADEDIR=\""$(gladedir)"\" + +LIBS = $(LIBAUTEDB_LIBS) \ + $(LIBGCRYPT_LIBS) + +libaute_pluginsdir = $(libdir)/libaute/plugins +libaute_plugins_LTLIBRARIES = libaute-db.la + +libaute_db_la_SOURCES = aute_db.c diff --git a/src/aute_db.c b/src/aute_db.c new file mode 100644 index 0000000..811b9f6 --- /dev/null +++ b/src/aute_db.c @@ -0,0 +1,367 @@ +/* + * Copyright (C) 2005-2006 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 +#include +#include +#include + +static GtkWidget *txt_utente, + *txt_password, + *exp_cambio, + *txt_password_nuova, + *txt_password_conferma; + +/* PRIVATE */ +static gboolean +get_connection_parameters (Confi *confi, gchar **provider_id, gchar **cnc_string) +{ + gboolean ret = TRUE; + + *provider_id = confi_path_get_value (confi, "aute/aute-db/db/provider_id"); + *cnc_string = confi_path_get_value (confi, "aute/aute-db/db/cnc_string"); + + if (*provider_id == NULL || *cnc_string == NULL + || strcmp (g_strstrip (*provider_id), "") == 0 + || strcmp (g_strstrip (*cnc_string), "") == 0) + { + ret = FALSE; + } + + return ret; +} + +/** + * cifra_password: + * @password: una stringa da cifrare. + * + * Return: la @password cifrata. + */ +static gchar +*cifra_password (const gchar *password) +{ + gchar digest[17] = ""; + gchar pwd_gcrypt[33] = ""; + gint i; + + if (strcmp (password, "") != 0) + { + gcry_md_hash_buffer (GCRY_MD_MD5, &digest, password, strlen (password)); + for (i = 0; i < 16; i++) + { + g_sprintf (pwd_gcrypt + (i * 2), "%02x", digest[i] & 0xFF); + } + pwd_gcrypt[32] = '\0'; + } + + return g_strdup (&pwd_gcrypt[0]); +} + +static gchar +*controllo (Confi *confi) +{ + gchar *sql; + gchar *utente = ""; + gchar *password; + gchar *password_nuova; + gchar *provider_id; + gchar *cnc_string; + GdaO *gdao; + GdaDataModel *dm; + + 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)))); + + /* leggo i parametri di connessione dalla configurazione */ + if (!get_connection_parameters (confi, &provider_id, &cnc_string)) return NULL; + + /* creo un oggetto GdaO */ + gdao = gdao_new_from_string (NULL, provider_id, cnc_string); + if (gdao == NULL) return NULL; + + sql = g_strdup_printf ("SELECT codice FROM utenti " + "WHERE codice = '%s' AND " + "password = '%s' AND " + "status <> 'E'", + gdao_strescape (utente, NULL), + gdao_strescape (cifra_password (password), NULL)); + dm = gdao_query (gdao, sql); + if (dm == NULL || gda_data_model_get_n_rows (dm) <= 0) + { + g_warning ("Utente o password non validi."); + return NULL; + } + + utente = g_strstrip (g_strdup (gdao_data_model_get_field_value_stringify_at (dm, 0, "codice"))); + + 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) + { + /* TO DO */ + 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) + { + /* TO DO */ + g_warning ("La nuova password e la conferma non coincidono."); + } + else + { + /* cambio la password */ + sql = g_strdup_printf ("UPDATE utenti " + "SET password = '%s' " + "WHERE codice = '%s'", + gdao_strescape (cifra_password (password_nuova), NULL), + gdao_strescape (utente, NULL)); + if (gdao_execute (gdao, sql) == -1) + { + /* TO DO */ + g_warning ("Errore durante la modifica della password."); + return NULL; + } + } + } + + return utente; +} + +/* PUBLIC */ +gchar +*autentica (Confi *confi) +{ + gchar *ret = NULL; + + GladeXML *gla_main = glade_xml_new (GLADEDIR "/autedb.glade", NULL, NULL); + GtkWidget *diag = glade_xml_get_widget (gla_main, "diag_main"); + + txt_utente = glade_xml_get_widget (gla_main, "txt_utente"); + txt_password = glade_xml_get_widget (gla_main, "txt_password"); + exp_cambio = glade_xml_get_widget (gla_main, "exp_cambio"); + txt_password_nuova = glade_xml_get_widget (gla_main, "txt_password_nuova"); + txt_password_conferma = glade_xml_get_widget (gla_main, "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 (confi); + break; + + case GTK_RESPONSE_CANCEL: + ret = g_strdup (""); + break; + + default: + break; + } + + gtk_widget_destroy (diag); + g_object_unref (gla_main); + + return ret; +} + +/** + * crea_utente: + * @confi: + * @codice: + * @password: + */ +gboolean +crea_utente (Confi *confi, const gchar *codice, const gchar *password) +{ + gchar *codice_; + gchar *password_; + gchar *provider_id; + gchar *cnc_string; + gchar *sql; + GdaO *gdao; + GdaDataModel *dm; + + if (!IS_CONFI (confi)) + { + g_warning ("confi non è un oggetto Confi valido."); + return FALSE; + } + + if (codice == FALSE || password == NULL) + { + g_warning ("codice o password nulli."); + return FALSE; + } + + codice_ = g_strstrip (g_strdup (codice)); + password_ = g_strstrip (g_strdup (password)); + + if (strcmp (codice_, "") == 0 || strcmp (password_, "") == 0) + { + g_warning ("codice o password vuoti."); + return FALSE; + } + + /* leggo i parametri di connessione dalla configurazione */ + if (!get_connection_parameters (confi, &provider_id, &cnc_string)) return FALSE; + + /* creo un oggetto GdaO */ + gdao = gdao_new_from_string (NULL, provider_id, cnc_string); + if (gdao == NULL) return FALSE; + + /* controllo se esiste gia' */ + sql = g_strdup_printf ("SELECT codice FROM utenti WHERE codice = '%s'", + gdao_strescape (codice_, NULL)); + dm = gdao_query (gdao, sql); + if (dm != NULL && gda_data_model_get_n_rows (dm) > 0) + { + /* aggiorno l'utente */ + sql = g_strdup_printf ("UPDATE utenti SET password = '%s' WHERE codice = '%s'", + gdao_strescape (cifra_password (password_), NULL), + gdao_strescape (codice_, NULL)); + } + else + { + /* creo l'utente */ + sql = g_strdup_printf ("INSERT INTO utenti VALUES ('%s', '%s', '')", + gdao_strescape (codice_, NULL), + gdao_strescape (cifra_password (password_), NULL)); + } + + return (gdao_execute (gdao, sql) >= 0); +} + +/** + * modifice_utente: + * @confi: + * @codice: + * @password: + */ +gboolean +modifica_utente (Confi *confi, const gchar *codice, const gchar *password) +{ + gchar *codice_; + gchar *password_; + gchar *provider_id; + gchar *cnc_string; + gchar *sql; + GdaO *gdao; + GdaDataModel *dm; + + if (!IS_CONFI (confi)) + { + g_warning ("confi non è un oggetto Confi valido."); + return FALSE; + } + + if (codice == FALSE || password == NULL) + { + g_warning ("codice o password nulli."); + return FALSE; + } + + codice_ = g_strstrip (g_strdup (codice)); + password_ = g_strstrip (g_strdup (password)); + + if (strcmp (codice_, "") == 0 || strcmp (password_, "") == 0) + { + g_warning ("codice o password vuoti."); + return FALSE; + } + + /* leggo i parametri di connessione dalla configurazione */ + if (!get_connection_parameters (confi, &provider_id, &cnc_string)) return FALSE; + + /* creo un oggetto GdaO */ + gdao = gdao_new_from_string (NULL, provider_id, cnc_string); + if (gdao == NULL) return FALSE; + + /* controllo se non esiste */ + sql = g_strdup_printf ("SELECT codice FROM utenti WHERE codice = '%s'", + gdao_strescape (codice_, NULL)); + dm = gdao_query (gdao, sql); + if (dm == NULL || gda_data_model_get_n_rows (dm) <= 0) + { + /* creo l'utente */ + sql = g_strdup_printf ("INSERT INTO utenti VALUES ('%s', '%s', '')", + gdao_strescape (codice_, NULL), + gdao_strescape (cifra_password (password_), NULL)); + } + else + { + /* aggiorno l'utente */ + sql = g_strdup_printf ("UPDATE utenti SET password = '%s' WHERE codice = '%s'", + gdao_strescape (cifra_password (password_), NULL), + gdao_strescape (codice_, NULL)); + } + + return (gdao_execute (gdao, sql) >= 0); +} + +/** + * elimina_utente: + * @confi: + * @codice: + */ +gboolean +elimina_utente (Confi *confi, const gchar *codice) +{ + gchar *codice_; + gchar *provider_id; + gchar *cnc_string; + gchar *sql; + GdaO *gdao; + + if (!IS_CONFI (confi)) + { + g_warning ("confi non è un oggetto Confi valido."); + return FALSE; + } + + if (codice == FALSE) + { + g_warning ("codice nullo."); + return FALSE; + } + + codice_ = g_strstrip (g_strdup (codice)); + + if (strcmp (codice_, "") == 0) + { + g_warning ("codice vuoto."); + return FALSE; + } + + /* leggo i parametri di connessione dalla configurazione */ + if (!get_connection_parameters (confi, &provider_id, &cnc_string)) return FALSE; + + /* creo un oggetto GdaO */ + gdao = gdao_new_from_string (NULL, provider_id, cnc_string); + if (gdao == NULL) return FALSE; + + /* elimino _logicamente_ l'utente */ + sql = g_strdup_printf ("UPDATE utenti SET status = 'E' WHERE codice = '%s'", + gdao_strescape (codice_, NULL)); + + return (gdao_execute (gdao, sql) >= 0); +} diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..f22be27 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,11 @@ +AM_CPPFLAGS = $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ + $(LIBAUTEDB_CFLAGS) \ + -I../src + +LIBS = $(GTK_LIBS) \ + $(LIBAUTEDB_LIBS) + +LDADD = ../src/libaute-db.la + +noinst_PROGRAMS = test diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..a2ec033 --- /dev/null +++ b/tests/test.c @@ -0,0 +1,31 @@ +/* + * Copyright (C)2005 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) +{ + gtk_init (&argc, &argv); + + g_fprintf (stderr, "Utente %s\n", aute_autentica (NULL)); + + return 0; +} diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..ea3d520 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,11 @@ +AM_CPPFLAGS = $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ + $(LIBAUTEDB_CFLAGS) \ + $(LIBGCRYPT_CFLAGS) + +LIBS = $(LIBAUTEDB_LIBS) \ + $(LIBGCRYPT_LIBS) + +noinst_PROGRAMS = aute-db-mkpwd + +aute_db_mkpwd_SOURCES = aute_db_mkpwd.c diff --git a/tools/aute_db_mkpwd.c b/tools/aute_db_mkpwd.c new file mode 100644 index 0000000..ddedbcc --- /dev/null +++ b/tools/aute_db_mkpwd.c @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2006 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 + +/** + * cifra_password: + * @password: una stringa da cifrare. + * + * Return: la @password cifrata. + */ +static gchar +*cifra_password (const gchar *password) +{ + gchar digest[17] = ""; + gchar pwd_gcrypt[33] = ""; + gint i; + + if (strcmp (password, "") != 0) + { + gcry_md_hash_buffer (GCRY_MD_MD5, &digest, password, strlen (password)); + for (i = 0; i < 16; i++) + { + g_sprintf (pwd_gcrypt + (i * 2), "%02x", digest[i] & 0xFF); + } + pwd_gcrypt[32] = '\0'; + } + + return g_strdup (&pwd_gcrypt[0]); +} + +int +main (int argc, char **argv) +{ + gchar *pwd = NULL; + GOptionEntry entries[] = + { + { "password", 'p', 0, G_OPTION_ARG_STRING, &pwd, "La stringa da cifrare", NULL }, + { NULL } + }; + + GOptionContext *context; + GError *error = NULL; + + /* gestione degli argomenti della riga di comando */ + context = g_option_context_new (""); + g_option_context_add_main_entries (context, entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + /* TO DO */ + g_printf ("Errore argomenti riga comando.\n"); + return 0; + } + + if (pwd == NULL || strcmp (g_strstrip (pwd), "") == 0) + { + g_printf ("Occorre specificare la stringa da cifrare.\n"); + return 0; + } + + g_printf ("%s\n", cifra_password (pwd)); + + return 0; +} -- 2.49.0