From: Andrea Zagli Date: Mon, 7 Sep 2015 08:51:30 +0000 (+0200) Subject: Another change of name and namespace consequently to libzakauthe. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=2b3aee08871cb1025b08b288437abf228928e380;p=zakauthe%2Fplugins%2Fdb Another change of name and namespace consequently to libzakauthe. --- diff --git a/.gitignore b/.gitignore index 00390e9..b8aeb3d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ missing config.h stamp-h1 tests/test -tools/zakauthdb-mkpwd +tools/zakauthedb-mkpwd *.tar.gz *.exe -compile \ No newline at end of file +compile diff --git a/configure.ac b/configure.ac index 1391083..e43a6b7 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([libzakauthdb], [0.5.0], [azagli@libero.it]) +AC_INIT([libzakauthedb], [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, [libzakauth >= 0.5.0 +PKG_CHECK_MODULES(LIBAUTEDB, [libzakauthe >= 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/libzakauthdb/Makefile - data/libzakauthdb/form/Makefile - data/libzakauthdb/gui/Makefile + data/libzakauthedb/Makefile + data/libzakauthedb/form/Makefile + data/libzakauthedb/gui/Makefile ]) AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am index fd72b0a..1df5cd8 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = libzakauthdb +SUBDIRS = libzakauthedb EXTRA_DIST = autedb_confi_schema.xml \ autedb.sql diff --git a/data/libzakauthdb/Makefile.am b/data/libzakauthdb/Makefile.am deleted file mode 100644 index 45a8045..0000000 --- a/data/libzakauthdb/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = gui form diff --git a/data/libzakauthdb/form/Makefile.am b/data/libzakauthdb/form/Makefile.am deleted file mode 100644 index cb7c395..0000000 --- a/data/libzakauthdb/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/libzakauthdb/form/user.form b/data/libzakauthdb/form/user.form deleted file mode 100644 index 3c8a122..0000000 --- a/data/libzakauthdb/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/libzakauthdb/gui/Makefile.am b/data/libzakauthdb/gui/Makefile.am deleted file mode 100644 index 2134957..0000000 --- a/data/libzakauthdb/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/libzakauthdb/gui/autedb.gui b/data/libzakauthdb/gui/autedb.gui deleted file mode 100644 index 8e05d6d..0000000 --- a/data/libzakauthdb/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/libzakauthedb/Makefile.am b/data/libzakauthedb/Makefile.am new file mode 100644 index 0000000..45a8045 --- /dev/null +++ b/data/libzakauthedb/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = gui form diff --git a/data/libzakauthedb/form/Makefile.am b/data/libzakauthedb/form/Makefile.am new file mode 100644 index 0000000..cb7c395 --- /dev/null +++ b/data/libzakauthedb/form/Makefile.am @@ -0,0 +1,5 @@ +formdir = $(datadir)/libaute-db/form + +form_DATA = user.form + +EXTRA_DIST = $(form_DATA) diff --git a/data/libzakauthedb/form/user.form b/data/libzakauthedb/form/user.form new file mode 100644 index 0000000..3c8a122 --- /dev/null +++ b/data/libzakauthedb/form/user.form @@ -0,0 +1,45 @@ + + + + users
+ + + + t + t + + + + + + + + + + + t + + + + + + + + + + t + + + + + + datetime + %d/%m/%Y %H.%M.%S + + + + + + + +
diff --git a/data/libzakauthedb/gui/Makefile.am b/data/libzakauthedb/gui/Makefile.am new file mode 100644 index 0000000..2134957 --- /dev/null +++ b/data/libzakauthedb/gui/Makefile.am @@ -0,0 +1,5 @@ +guidir = $(datadir)/libaute-db/gui + +gui_DATA = autedb.gui + +EXTRA_DIST = $(gui_DATA) diff --git a/data/libzakauthedb/gui/autedb.gui b/data/libzakauthedb/gui/autedb.gui new file mode 100644 index 0000000..8e05d6d --- /dev/null +++ b/data/libzakauthedb/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 909b4ee..47ecae4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -guidir = $(datadir)/libzakauthdb/gui -formdir = $(datadir)/libzakauthdb/form +guidir = $(datadir)/libzakauthedb/gui +formdir = $(datadir)/libzakauthedb/form AM_CPPFLAGS = $(LIBAUTEDB_CFLAGS) \ $(LIBGCRYPT_CFLAGS) \ @@ -13,12 +13,12 @@ LIBS = $(LIBAUTEDB_LIBS) \ $(GPG_ERROR_LIBS) \ $(LIBCONFI_LIBS) -libzakauth_pluginsdir = $(libdir)/libzakauth/plugins -libzakauth_plugins_LTLIBRARIES = libzakauthdb.la +libzakauthe_pluginsdir = $(libdir)/libzakauthe/plugins +libzakauthe_plugins_LTLIBRARIES = libzakauthedb.la -libzakauthdb_la_SOURCES = aute_db.c \ +libzakauthedb_la_SOURCES = aute_db.c \ aute_db.h \ user.c \ user.h -libzakauthdb_la_LDFLAGS = -no-undefined +libzakauthedb_la_LDFLAGS = -no-undefined diff --git a/src/aute_db.c b/src/aute_db.c index 138755e..e83eb56 100644 --- a/src/aute_db.c +++ b/src/aute_db.c @@ -66,7 +66,7 @@ get_connection_parameters_from_confi (Confi *confi, gchar **cnc_string) { gboolean ret = TRUE; - *cnc_string = confi_path_get_value (confi, "libzakauth/libzakauthdb/db/cnc_string"); + *cnc_string = confi_path_get_value (confi, "libzakauthe/libzakauthedb/db/cnc_string"); if (*cnc_string == NULL || strcmp (g_strstrip (*cnc_string), "") == 0) @@ -122,7 +122,7 @@ get_gdaex (GSList *parameters) gdaex = gdaex_new_from_string (cnc_string); if (gdaex == NULL) { - g_warning ("Unable to establish a db connection."); + g_warning ("Unable to establish a connection to the database."); } } @@ -149,13 +149,13 @@ static GtkWindow } /** - * zak_auth_db_encrypt_password: + * zak_authe_db_encrypt_password: * @password: una stringa da cifrare. * * Returns: the @password encrypted. */ gchar -*zak_auth_db_encrypt_password (const gchar *password) +*zak_authe_db_encrypt_password (const gchar *password) { gchar digest[17] = ""; gchar pwd_gcrypt[33] = ""; @@ -192,7 +192,7 @@ static gchar " AND password = '%s'" " AND status <> 'E'", gdaex_strescape (utente, NULL), - gdaex_strescape (zak_auth_db_encrypt_password (password), NULL)); + gdaex_strescape (zak_authe_db_encrypt_password (password), NULL)); dm = gdaex_query (gdaex, sql); g_free (sql); if (dm == NULL || gda_data_model_get_n_rows (dm) <= 0) @@ -227,7 +227,7 @@ static gchar sql = g_strdup_printf ("UPDATE users" " SET password = '%s'" " WHERE code = '%s'", - gdaex_strescape (zak_auth_db_encrypt_password (password_nuova), NULL), + gdaex_strescape (zak_authe_db_encrypt_password (password_nuova), NULL), gdaex_strescape (utente, NULL)); if (gdaex_execute (gdaex, sql) == -1) { @@ -308,7 +308,7 @@ autedb_edit_user () GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, - "You must before select a user."); + "You need to select a user."); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } @@ -353,7 +353,7 @@ autedb_on_btn_delete_clicked (GtkButton *button, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, - "Sicuro di voler eliminare l'utente selezionato?"); + "Are you sure to want to delete the selected user?"); risp = gtk_dialog_run (GTK_DIALOG (dialog)); if (risp == GTK_RESPONSE_YES) { @@ -374,7 +374,7 @@ autedb_on_btn_delete_clicked (GtkButton *button, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, - "Occorre prima selezionare un modello"); + "You need to select a user."); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } @@ -397,7 +397,7 @@ autedb_on_btn_find_clicked (GtkButton *button, /* PUBLIC */ gchar -*zak_auth_auth (GSList *parameters) +*zak_authe_authe (GSList *parameters) { GError *error; gchar *ret = NULL; @@ -496,7 +496,7 @@ gchar * */ GtkWidget -*zak_auth_plg_get_management_gui (GSList *parameters) +*zak_authe_plg_get_management_gui (GSList *parameters) { GError *error; @@ -509,14 +509,14 @@ GtkWidget gchar *GUIDIR; - GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libzakauthdb", "gui", NULL); + GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libzakauthedb", "gui", NULL); #endif if (!gtk_builder_add_objects_from_file (gtkbuilder, g_build_filename (GUIDIR, "autedb.gui", NULL), g_strsplit ("lstore_users|vbx_users_list", "|", -1), &error)) { - g_error ("Impossibile trovare il file di definizione dell'interfaccia utente."); + g_error ("Unable to find the gui definition file."); return NULL; } diff --git a/src/aute_db.h b/src/aute_db.h index d8be47b..50a2e70 100644 --- a/src/aute_db.h +++ b/src/aute_db.h @@ -17,15 +17,15 @@ * */ -#ifndef __ZAKAUTHDB_H__ -#define __ZAKAUTHDB_H__ +#ifndef __ZAKAUTHEDB_H__ +#define __ZAKAUTHEDB_H__ G_BEGIN_DECLS -gchar *zak_auth_db_encrypt_password (const gchar *password); +gchar *zak_authe_db_encrypt_password (const gchar *password); G_END_DECLS -#endif /* __ZAKAUTHDB_H__ */ +#endif /* __ZAKAUTHEDB_H__ */ diff --git a/src/user.c b/src/user.c index e1b96e9..d27aa6c 100644 --- a/src/user.c +++ b/src/user.c @@ -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 @@ -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]), - zak_auth_db_encrypt_password (gtk_entry_get_text (GTK_ENTRY (priv->objects[TXT_CODE])))); + zak_authe_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/src/user.h b/src/user.h index 39dfb05..dc4831b 100644 --- a/src/user.h +++ b/src/user.h @@ -1,5 +1,5 @@ -/* - * Copyright (C) 2010-2011 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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 87249fb..0c43185 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,6 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ LIBS = $(GTK_LIBS) \ $(LIBAUTEDB_LIBS) -LDADD = ../src/libzakauthdb.la +LDADD = ../src/libzakauthedb.la noinst_PROGRAMS = test diff --git a/tests/test.c b/tests/test.c index 1c48027..23f4bf0 100644 --- a/tests/test.c +++ b/tests/test.c @@ -18,26 +18,26 @@ #include -#include +#include int main (int argc, char **argv) { - ZakAuth *aute; + ZakAuthe *aute; GSList *params; gtk_init (&argc, &argv); - aute = zak_auth_new (); + aute = zak_authe_new (); /* the libaute module to use */ params = g_slist_append (params, argv[1]); /* the libgda connection string */ params = g_slist_append (params, argv[2]); - zak_auth_set_config (aute, params); + zak_authe_set_config (aute, params); - g_message ("User %s\n", zak_auth_auth (aute)); + g_message ("User %s\n", zak_authe_authe (aute)); return 0; } diff --git a/tools/Makefile.am b/tools/Makefile.am index e6ec6fc..2620808 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -6,6 +6,6 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ LIBS = $(LIBAUTEDB_LIBS) \ $(LIBGCRYPT_LIBS) -noinst_PROGRAMS = zakauthdb-mkpwd +noinst_PROGRAMS = zakauthedb-mkpwd -zakauthdb_mkpwd_SOURCES = zakauthdb_mkpwd.c +zakauthedb_mkpwd_SOURCES = zakauthedb_mkpwd.c diff --git a/tools/zakauthdb_mkpwd.c b/tools/zakauthdb_mkpwd.c deleted file mode 100644 index 74f19e2..0000000 --- a/tools/zakauthdb_mkpwd.c +++ /dev/null @@ -1,81 +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 -#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/zakauthedb_mkpwd.c b/tools/zakauthedb_mkpwd.c new file mode 100644 index 0000000..82ad2b2 --- /dev/null +++ b/tools/zakauthedb_mkpwd.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2006-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 + * 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, "The string to encrypt", 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 ("Error on command line arguments.\n"); + return 0; + } + + if (pwd == NULL || strcmp (g_strstrip (pwd), "") == 0) + { + g_printf ("You need to provide the string to encrypt.\n"); + return 0; + } + + g_printf ("%s\n", cifra_password (pwd)); + + return 0; +}