From: Andrea Zagli Date: Sun, 6 Sep 2015 09:00:39 +0000 (+0200) Subject: Changed names consequently to libzakauth. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=b1410a9d62a6e2ef1017fca3ef6b401922c40359;p=zakauthe%2Fplugins%2Fdb Changed names consequently to libzakauth. --- diff --git a/.gitignore b/.gitignore index a41bfdd..00390e9 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ missing config.h stamp-h1 tests/test -tools/aute-db-mkpwd +tools/zakauthdb-mkpwd *.tar.gz -*.exe \ No newline at end of file +*.exe +compile \ No newline at end of file diff --git a/autogen.sh b/autogen.sh index 2b9d0ee..c92d9c6 100755 --- a/autogen.sh +++ b/autogen.sh @@ -4,7 +4,7 @@ srcdir=`dirname $0` test -z "$srcdir" && srcdir=. -PKG_NAME="libaute-db" +PKG_NAME="libzakauthdb" (test -f $srcdir/configure.ac \ && test -d $srcdir/src \ diff --git a/configure.ac b/configure.ac index 8a994bc..1391083 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libaute-db], [0.5.0], [azagli@libero.it]) +AC_INIT([libzakauthdb], [0.5.0], [azagli@libero.it]) AC_CONFIG_SRCDIR([src/aute_db.c]) AC_CONFIG_HEADER([config.h]) @@ -21,7 +21,7 @@ AC_PROG_CC AC_PROG_LIBTOOL # Checks for libraries. -PKG_CHECK_MODULES(LIBAUTEDB, [libaute >= 0.2.0 +PKG_CHECK_MODULES(LIBAUTEDB, [libzakauth >= 0.5.0 libgtkform >= 0.5.0]) AC_SUBST(LIBAUTEDB_CFLAGS) @@ -56,8 +56,8 @@ AC_CONFIG_FILES([ tests/Makefile tools/Makefile data/Makefile - data/libaute-db/Makefile - data/libaute-db/form/Makefile - data/libaute-db/gui/Makefile + data/libzakauthdb/Makefile + data/libzakauthdb/form/Makefile + data/libzakauthdb/gui/Makefile ]) AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am index cffdde5..fd72b0a 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = libaute-db +SUBDIRS = libzakauthdb EXTRA_DIST = autedb_confi_schema.xml \ autedb.sql diff --git a/data/libaute-db/Makefile.am b/data/libaute-db/Makefile.am deleted file mode 100644 index 45a8045..0000000 --- a/data/libaute-db/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = gui form diff --git a/data/libaute-db/form/Makefile.am b/data/libaute-db/form/Makefile.am deleted file mode 100644 index cb7c395..0000000 --- a/data/libaute-db/form/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -formdir = $(datadir)/libaute-db/form - -form_DATA = user.form - -EXTRA_DIST = $(form_DATA) diff --git a/data/libaute-db/form/user.form b/data/libaute-db/form/user.form deleted file mode 100644 index 3c8a122..0000000 --- a/data/libaute-db/form/user.form +++ /dev/null @@ -1,45 +0,0 @@ - - - - users
- - - - t - t - - - - - - - - - - - t - - - - - - - - - - t - - - - - - datetime - %d/%m/%Y %H.%M.%S - - - - - - - -
diff --git a/data/libaute-db/gui/Makefile.am b/data/libaute-db/gui/Makefile.am deleted file mode 100644 index 2134957..0000000 --- a/data/libaute-db/gui/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -guidir = $(datadir)/libaute-db/gui - -gui_DATA = autedb.gui - -EXTRA_DIST = $(gui_DATA) diff --git a/data/libaute-db/gui/autedb.gui b/data/libaute-db/gui/autedb.gui deleted file mode 100644 index 8e05d6d..0000000 --- a/data/libaute-db/gui/autedb.gui +++ /dev/null @@ -1,606 +0,0 @@ - - - - - - True - Autenticazione - True - center - 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/data/libzakauthdb/Makefile.am b/data/libzakauthdb/Makefile.am new file mode 100644 index 0000000..45a8045 --- /dev/null +++ b/data/libzakauthdb/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = gui form diff --git a/data/libzakauthdb/form/Makefile.am b/data/libzakauthdb/form/Makefile.am new file mode 100644 index 0000000..cb7c395 --- /dev/null +++ b/data/libzakauthdb/form/Makefile.am @@ -0,0 +1,5 @@ +formdir = $(datadir)/libaute-db/form + +form_DATA = user.form + +EXTRA_DIST = $(form_DATA) diff --git a/data/libzakauthdb/form/user.form b/data/libzakauthdb/form/user.form new file mode 100644 index 0000000..3c8a122 --- /dev/null +++ b/data/libzakauthdb/form/user.form @@ -0,0 +1,45 @@ + + + + users
+ + + + t + t + + + + + + + + + + + t + + + + + + + + + + t + + + + + + datetime + %d/%m/%Y %H.%M.%S + + + + + + + +
diff --git a/data/libzakauthdb/gui/Makefile.am b/data/libzakauthdb/gui/Makefile.am new file mode 100644 index 0000000..2134957 --- /dev/null +++ b/data/libzakauthdb/gui/Makefile.am @@ -0,0 +1,5 @@ +guidir = $(datadir)/libaute-db/gui + +gui_DATA = autedb.gui + +EXTRA_DIST = $(gui_DATA) diff --git a/data/libzakauthdb/gui/autedb.gui b/data/libzakauthdb/gui/autedb.gui new file mode 100644 index 0000000..8e05d6d --- /dev/null +++ b/data/libzakauthdb/gui/autedb.gui @@ -0,0 +1,606 @@ + + + + + + True + Autenticazione + True + center + 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 index 3d6dd25..909b4ee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -guidir = $(datadir)/libaute-db/gui -formdir = $(datadir)/libaute-db/form +guidir = $(datadir)/libzakauthdb/gui +formdir = $(datadir)/libzakauthdb/form AM_CPPFLAGS = $(LIBAUTEDB_CFLAGS) \ $(LIBGCRYPT_CFLAGS) \ @@ -13,12 +13,12 @@ LIBS = $(LIBAUTEDB_LIBS) \ $(GPG_ERROR_LIBS) \ $(LIBCONFI_LIBS) -libaute_pluginsdir = $(libdir)/libaute/plugins -libaute_plugins_LTLIBRARIES = libaute-db.la +libzakauth_pluginsdir = $(libdir)/libzakauth/plugins +libzakauth_plugins_LTLIBRARIES = libzakauthdb.la -libaute_db_la_SOURCES = aute_db.c \ +libzakauthdb_la_SOURCES = aute_db.c \ aute_db.h \ user.c \ user.h -libaute_db_la_LDFLAGS = -no-undefined +libzakauthdb_la_LDFLAGS = -no-undefined diff --git a/src/aute_db.c b/src/aute_db.c index aaf284c..138755e 100644 --- a/src/aute_db.c +++ b/src/aute_db.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Andrea Zagli + * Copyright (C) 2005-2015 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 @@ -19,7 +19,8 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif - + +#include #include #include #include @@ -34,6 +35,7 @@ static GtkBuilder *gtkbuilder; static GdaEx *gdaex; +static gchar *guidir; static gchar *guifile; static gchar *formdir; @@ -64,7 +66,7 @@ get_connection_parameters_from_confi (Confi *confi, gchar **cnc_string) { gboolean ret = TRUE; - *cnc_string = confi_path_get_value (confi, "aute/aute-db/db/cnc_string"); + *cnc_string = confi_path_get_value (confi, "libzakauth/libzakauthdb/db/cnc_string"); if (*cnc_string == NULL || strcmp (g_strstrip (*cnc_string), "") == 0) @@ -147,13 +149,13 @@ static GtkWindow } /** - * autedb_cifra_password: + * zak_auth_db_encrypt_password: * @password: una stringa da cifrare. * - * Return: la @password cifrata. + * Returns: the @password encrypted. */ gchar -*autedb_cifra_password (const gchar *password) +*zak_auth_db_encrypt_password (const gchar *password) { gchar digest[17] = ""; gchar pwd_gcrypt[33] = ""; @@ -190,11 +192,16 @@ static gchar " AND password = '%s'" " AND status <> 'E'", gdaex_strescape (utente, NULL), - gdaex_strescape (autedb_cifra_password (password), NULL)); + gdaex_strescape (zak_auth_db_encrypt_password (password), NULL)); dm = gdaex_query (gdaex, sql); + g_free (sql); if (dm == NULL || gda_data_model_get_n_rows (dm) <= 0) { - g_warning ("Utente o password non validi."); + if (dm != NULL) + { + g_object_unref (dm); + } + g_warning ("User name or password aren't valids."); return NULL; } @@ -212,7 +219,7 @@ static gchar 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."); + g_warning ("The new and confirm password don't match."); } else { @@ -220,7 +227,7 @@ static gchar sql = g_strdup_printf ("UPDATE users" " SET password = '%s'" " WHERE code = '%s'", - gdaex_strescape (autedb_cifra_password (password_nuova), NULL), + gdaex_strescape (zak_auth_db_encrypt_password (password_nuova), NULL), gdaex_strescape (utente, NULL)); if (gdaex_execute (gdaex, sql) == -1) { @@ -322,14 +329,14 @@ autedb_on_btn_new_clicked (GtkButton *button, gtk_window_set_transient_for (GTK_WINDOW (w), autedb_get_gtkwidget_parent_gtkwindow (w_users)); gtk_widget_show (w); } - + static void autedb_on_btn_edit_clicked (GtkButton *button, gpointer user_data) { autedb_edit_user (); } - + static void autedb_on_btn_delete_clicked (GtkButton *button, gpointer user_data) @@ -387,10 +394,10 @@ autedb_on_btn_find_clicked (GtkButton *button, gpointer user_data) { } - + /* PUBLIC */ gchar -*autentica (GSList *parameters) +*zak_auth_auth (GSList *parameters) { GError *error; gchar *ret = NULL; @@ -409,7 +416,6 @@ gchar gtkbuilder = gtk_builder_new (); #ifdef G_OS_WIN32 - gchar *guidir; gchar *moddir; gchar *p; @@ -490,7 +496,7 @@ gchar * */ GtkWidget -*get_management_gui (GSList *parameters) +*zak_auth_plg_get_management_gui (GSList *parameters) { GError *error; @@ -503,7 +509,7 @@ GtkWidget gchar *GUIDIR; - GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libaute-db", "gu", NULL); + GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libzakauthdb", "gui", NULL); #endif if (!gtk_builder_add_objects_from_file (gtkbuilder, g_build_filename (GUIDIR, "autedb.gui", NULL), diff --git a/src/aute_db.h b/src/aute_db.h index 6678484..d8be47b 100644 --- a/src/aute_db.h +++ b/src/aute_db.h @@ -1,5 +1,5 @@ -/* - * Copyright (C) 2010 Andrea Zagli +/* + * Copyright (C) 2010-2015 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,15 +17,15 @@ * */ -#ifndef __AUTEDB_H__ -#define __AUTEDB_H__ +#ifndef __ZAKAUTHDB_H__ +#define __ZAKAUTHDB_H__ G_BEGIN_DECLS -gchar *autedb_cifra_password (const gchar *password); +gchar *zak_auth_db_encrypt_password (const gchar *password); G_END_DECLS -#endif /* __AUTEDB_H__ */ +#endif /* __ZAKAUTHDB_H__ */ diff --git a/src/user.c b/src/user.c index 251c9d3..e1b96e9 100644 --- a/src/user.c +++ b/src/user.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2010 Andrea Zagli * * This library is free software; you can redistribute it and/or @@ -230,7 +230,7 @@ user_salva (User *user) 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])))); + zak_auth_db_encrypt_password (gtk_entry_get_text (GTK_ENTRY (priv->objects[TXT_CODE])))); sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT); } else diff --git a/tests/Makefile.am b/tests/Makefile.am index f22be27..87249fb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,6 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ LIBS = $(GTK_LIBS) \ $(LIBAUTEDB_LIBS) -LDADD = ../src/libaute-db.la +LDADD = ../src/libzakauthdb.la noinst_PROGRAMS = test diff --git a/tests/test.c b/tests/test.c index bcae4fb..1c48027 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013 Andrea Zagli + * Copyright (C) 2010-2015 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,26 +18,26 @@ #include -#include +#include int main (int argc, char **argv) { - Aute *aute; + ZakAuth *aute; GSList *params; gtk_init (&argc, &argv); - aute = aute_new (); + aute = zak_auth_new (); /* the libaute module to use */ params = g_slist_append (params, argv[1]); /* the libgda connection string */ params = g_slist_append (params, argv[2]); - aute_set_config (aute, params); + zak_auth_set_config (aute, params); - g_message ("User %s\n", aute_autentica (aute)); + g_message ("User %s\n", zak_auth_auth (aute)); return 0; } diff --git a/tools/Makefile.am b/tools/Makefile.am index ea3d520..e6ec6fc 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -6,6 +6,6 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ LIBS = $(LIBAUTEDB_LIBS) \ $(LIBGCRYPT_LIBS) -noinst_PROGRAMS = aute-db-mkpwd +noinst_PROGRAMS = zakauthdb-mkpwd -aute_db_mkpwd_SOURCES = aute_db_mkpwd.c +zakauthdb_mkpwd_SOURCES = zakauthdb_mkpwd.c diff --git a/tools/aute_db_mkpwd.c b/tools/aute_db_mkpwd.c deleted file mode 100644 index ddedbcc..0000000 --- a/tools/aute_db_mkpwd.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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; -} diff --git a/tools/zakauthdb_mkpwd.c b/tools/zakauthdb_mkpwd.c new file mode 100644 index 0000000..74f19e2 --- /dev/null +++ b/tools/zakauthdb_mkpwd.c @@ -0,0 +1,81 @@ +/* + * 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 +#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; +}