[libgda/LIBGDA_4.2] Modify tools' main()'s arguments to hide usernames and passwords



commit b7f76ec08f508e19309b42899e280b899eea72f2
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun May 15 14:46:08 2011 +0200

    Modify tools' main()'s arguments to hide usernames and passwords

 tools/browser/main.c |    1 +
 tools/config-info.c  |   28 ++++++++++++++++++++++++++++
 tools/config-info.h  |    2 ++
 tools/gda-sql.c      |    2 ++
 4 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/tools/browser/main.c b/tools/browser/main.c
index d2958e0..9e2ede8 100644
--- a/tools/browser/main.c
+++ b/tools/browser/main.c
@@ -215,6 +215,7 @@ main (int argc, char *argv[])
 					 error && error->message ? error->message : _("No detail"));
 				break;
 			}
+			config_info_modify_argv (argv[i]);
 		}
 		
 		if (dialog) {
diff --git a/tools/config-info.c b/tools/config-info.c
index 914e23e..14065cd 100644
--- a/tools/config-info.c
+++ b/tools/config-info.c
@@ -23,6 +23,34 @@
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
+/*
+ * Replace @argvi's contents with the connection name
+ */
+void
+config_info_modify_argv (char *argvi)
+{
+	GString *string;
+	gchar *prov, *cncparams, *user, *pass;
+	size_t size;
+	string = g_string_new ("");
+	gda_connection_string_split (argvi, &cncparams, &prov, &user, &pass);
+	g_free (user);
+	g_free (pass);
+	if (prov) {
+		g_string_append (string, prov);
+		g_free (prov);
+	}
+	if (cncparams) {
+		g_string_append (string, cncparams);
+		g_free (cncparams);
+	}
+	size = MIN (strlen (string->str), strlen (argvi));
+	strncpy (argvi, string->str, size);
+	g_string_free (string, TRUE);
+	if (size < strlen (argvi))
+		memset (argvi + size, 0, strlen (argvi) - size);
+}
+
 GdaDataModel *
 config_info_list_all_dsn (void)
 {
diff --git a/tools/config-info.h b/tools/config-info.h
index 6f83003..fd704d2 100644
--- a/tools/config-info.h
+++ b/tools/config-info.h
@@ -24,6 +24,8 @@
 
 #include <libgda/libgda.h>
 
+void          config_info_modify_argv (char *argvi);
+
 gchar        *config_info_compute_dict_directory (void);
 gchar        *config_info_compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string);
 void          config_info_update_meta_store_properties (GdaMetaStore *mstore, GdaConnection *rel_cnc);
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 2bce6c1..2f83424 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -338,6 +338,7 @@ main (int argc, char *argv[])
 		if (!data->output_stream) 
 			g_print (_("Opening connection '%s' for: %s\n"), str, argv[i]);
 		cs = open_connection (NULL, str, argv[i], &error);
+		config_info_modify_argv (argv[i]);
 		g_free (str);
 		if (!cs) {
 			g_print (_("Can't open connection %d: %s\n"), i,
@@ -346,6 +347,7 @@ main (int argc, char *argv[])
 			goto cleanup;
 		}
 	}
+
 	if (getenv ("GDA_SQL_CNC")) {
 		ConnectionSetting *cs;
 		gchar *str;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]