aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2001-10-13 06:19:34 +0800
committerChris Toshok <toshok@src.gnome.org>2001-10-13 06:19:34 +0800
commit16419940747f03ae8abca3fad025c95f382bc79b (patch)
tree7182f0ca6413f0e6ff797341fe88650f1da7cc46
parent74d8c78022be3b37edb80876e8a21aed3323a0af (diff)
downloadgsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.tar
gsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.tar.gz
gsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.tar.bz2
gsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.tar.lz
gsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.tar.xz
gsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.tar.zst
gsoc2013-evolution-16419940747f03ae8abca3fad025c95f382bc79b.zip
new parameter to e_passwords_init, and add prototype for
2001-10-12 Chris Toshok <toshok@ximian.com> * e-passwords.h: new parameter to e_passwords_init, and add prototype for e_passwords_clear_component_passwords. * e-passwords.c (e_passwords_init): copy off the component name. (e_passwords_shutdown): free/NULL the component name. (e_passwords_clear_component_passwords): new function. remove the subtree rooted at /Passwords/<ComponentName>. (e_passwords_remember_password): use component_name when building up the path. (e_passwords_get_password): same. (e_passwords_add_password): remove/free the currently stored session password for this key if there is one, before adding the new one. svn path=/trunk/; revision=13637
-rw-r--r--e-util/ChangeLog16
-rw-r--r--e-util/e-passwords.c47
-rw-r--r--e-util/e-passwords.h3
3 files changed, 61 insertions, 5 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index b4920d4719..fed6610258 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,19 @@
+2001-10-12 Chris Toshok <toshok@ximian.com>
+
+ * e-passwords.h: new parameter to e_passwords_init, and add
+ prototype for e_passwords_clear_component_passwords.
+
+ * e-passwords.c (e_passwords_init): copy off the component name.
+ (e_passwords_shutdown): free/NULL the component name.
+ (e_passwords_clear_component_passwords): new function. remove the
+ subtree rooted at /Passwords/<ComponentName>.
+ (e_passwords_remember_password): use component_name when building
+ up the path.
+ (e_passwords_get_password): same.
+ (e_passwords_add_password): remove/free the currently stored
+ session password for this key if there is one, before adding the
+ new one.
+
2001-10-11 Chris Toshok <toshok@ximian.com>
* e-passwords.h: change prototype for e_passwords_get_password.
diff --git a/e-util/e-passwords.c b/e-util/e-passwords.c
index b201109b13..2222b6e211 100644
--- a/e-util/e-passwords.c
+++ b/e-util/e-passwords.c
@@ -45,6 +45,7 @@ static char *decode_base64 (char *base64);
Bonobo_ConfigDatabase db;
static GHashTable *passwords = NULL;
+static char *component_name = NULL;
static int base64_encode_close(unsigned char *in, int inlen, gboolean break_lines, unsigned char *out, int *state, int *save);
static int base64_encode_step(unsigned char *in, int len, gboolean break_lines, unsigned char *out, int *state, int *save);
@@ -56,7 +57,7 @@ static int base64_encode_step(unsigned char *in, int len, gboolean break_lines,
* e_passwords_* function.
**/
void
-e_passwords_init ()
+e_passwords_init (const char *component)
{
CORBA_Environment ev;
@@ -77,6 +78,8 @@ e_passwords_init ()
/* and create the per-session hash table */
passwords = g_hash_table_new (g_str_hash, g_str_equal);
+
+ component_name = g_strdup (component);
}
static gboolean
@@ -109,6 +112,9 @@ e_passwords_shutdown ()
g_hash_table_foreach_remove (passwords, free_entry, NULL);
g_hash_table_destroy (passwords);
passwords = NULL;
+
+ g_free (component_name);
+ component_name = NULL;
}
@@ -133,6 +139,27 @@ e_passwords_forget_passwords ()
}
/**
+ * e_passwords_clear_component_passwords:
+ *
+ * Forgets all disk cached passwords.
+ **/
+void
+e_passwords_clear_component_passwords ()
+{
+ CORBA_Environment ev;
+ char *path;
+
+ path = g_strdup_printf ("/Passwords/%s", component_name);
+
+ CORBA_exception_init (&ev);
+ Bonobo_ConfigDatabase_removeDir (db, path, &ev);
+ Bonobo_ConfigDatabase_sync (db, &ev);
+ CORBA_exception_free (&ev);
+
+ g_free (path);
+}
+
+/**
* e_passwords_remember_password:
* @key: the key
*
@@ -153,7 +180,7 @@ e_passwords_remember_password (const char *key)
key64 = g_malloc0 ((len + 2) * 4 / 3 + 1);
state = save = 0;
base64_encode_close (okey, len, FALSE, key64, &state, &save);
- path = g_strdup_printf ("/Passwords/%s", key64);
+ path = g_strdup_printf ("/Passwords/%s/%s", component_name, key64);
g_free (key64);
len = strlen (value);
@@ -212,7 +239,7 @@ e_passwords_get_password (const char *key)
key64 = g_malloc0 ((len + 2) * 4 / 3 + 1);
state = save = 0;
base64_encode_close ((char*)key, len, FALSE, key64, &state, &save);
- path = g_strdup_printf ("/Passwords/%s", key64);
+ path = g_strdup_printf ("/Passwords/%s/%s", component_name, key64);
g_free (key64);
passwd = bonobo_config_get_string (db, path, NULL);
@@ -221,6 +248,8 @@ e_passwords_get_password (const char *key)
if (passwd)
return decode_base64 (passwd);
+ else
+ return NULL;
}
else
return g_strdup (passwd);
@@ -237,7 +266,17 @@ e_passwords_get_password (const char *key)
void
e_passwords_add_password (const char *key, const char *passwd)
{
- g_hash_table_insert (passwords, g_strdup (key), g_strdup (passwd));
+ if (key && passwd) {
+ gpointer okey, value;
+
+ if (g_hash_table_lookup_extended (passwords, key, &okey, &value)) {
+ g_hash_table_remove (passwords, key);
+ g_free (okey);
+ g_free (value);
+ }
+
+ g_hash_table_insert (passwords, g_strdup (key), g_strdup (passwd));
+ }
}
diff --git a/e-util/e-passwords.h b/e-util/e-passwords.h
index 101a419c4a..30de524242 100644
--- a/e-util/e-passwords.h
+++ b/e-util/e-passwords.h
@@ -33,7 +33,7 @@ extern "C" {
#pragma }
#endif /* __cplusplus */
-void e_passwords_init (void);
+void e_passwords_init (const char *component);
void e_passwords_shutdown (void);
void e_passwords_remember_password (const char *key);
@@ -41,6 +41,7 @@ void e_passwords_add_password (const char *key, const char *passwd);
char *e_passwords_get_password (const char *key);
void e_passwords_forget_password (const char *key);
void e_passwords_forget_passwords (void);
+void e_passwords_clear_component_passwords (void);
typedef enum {
E_PASSWORDS_DO_NOT_REMEMBER,