aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-passwords.c
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2002-12-10 05:39:41 +0800
committerChris Toshok <toshok@src.gnome.org>2002-12-10 05:39:41 +0800
commit2efdf9ac4a886cf7277c596b6b805f24e9f9bf03 (patch)
tree1f1910b4b15802e8c798be5bd2aff104bae638d5 /e-util/e-passwords.c
parent3bb567307b06a04c5df4057615c27a3a74a4b732 (diff)
downloadgsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.tar
gsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.tar.gz
gsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.tar.bz2
gsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.tar.lz
gsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.tar.xz
gsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.tar.zst
gsoc2013-evolution-2efdf9ac4a886cf7277c596b6b805f24e9f9bf03.zip
track changes to api (e_passwords_init is gone, and several functions take
2002-12-09 Chris Toshok <toshok@ximian.com> * e-passwords.h: track changes to api (e_passwords_init is gone, and several functions take the component name as an arg.) * e-passwords.c (e_passwords_init): make this static, and allow multiple calls. Also, it no longer takes the component name. (e_passwords_shutdown): make this deal with the case where e_passwords_init wasn't called (no hashtable), and it no longer needs to free component_name. (e_passwords_forget_passwords): call e_passwords_init. (e_passwords_clear_component_passwords): take component_name as an arg, and call e_passwords_init. (password_path): take component_name as an arg. (e_passwords_remember_password): same, and call e_passwords_init. (e_passwords_forget_password): same. (e_passwords_get_password): same. (e_passwords_add_password): call e_passwords_init. (e_passwords_ask_password): take component_name as an arg. svn path=/trunk/; revision=19071
Diffstat (limited to 'e-util/e-passwords.c')
-rw-r--r--e-util/e-passwords.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/e-util/e-passwords.c b/e-util/e-passwords.c
index 48acd6297b..9dae5db6f3 100644
--- a/e-util/e-passwords.c
+++ b/e-util/e-passwords.c
@@ -37,7 +37,6 @@
static char *decode_base64 (char *base64);
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);
@@ -48,13 +47,14 @@ static int base64_encode_step(unsigned char *in, int len, gboolean break_lines,
* Initializes the e_passwords routines. Must be called before any other
* e_passwords_* function.
**/
-void
-e_passwords_init (const char *component)
+static void
+e_passwords_init ()
{
+ if (passwords)
+ return;
+
/* create the per-session hash table */
passwords = g_hash_table_new (g_str_hash, g_str_equal);
-
- component_name = g_strdup (component);
}
static gboolean
@@ -77,13 +77,12 @@ e_passwords_shutdown ()
/* shouldn't need this really - everything is synchronous */
gnome_config_private_sync_file ("/Evolution");
- /* and destroy our per session hash */
- g_hash_table_foreach_remove (passwords, free_entry, NULL);
- g_hash_table_destroy (passwords);
- passwords = NULL;
-
- g_free (component_name);
- component_name = NULL;
+ if (passwords) {
+ /* and destroy our per session hash */
+ g_hash_table_foreach_remove (passwords, free_entry, NULL);
+ g_hash_table_destroy (passwords);
+ passwords = NULL;
+ }
}
@@ -95,6 +94,8 @@ e_passwords_shutdown ()
void
e_passwords_forget_passwords ()
{
+ e_passwords_init ();
+
gnome_config_private_clean_section ("/Evolution/Passwords");
gnome_config_private_sync_file ("/Evolution");
@@ -108,10 +109,12 @@ e_passwords_forget_passwords ()
* Forgets all disk cached passwords.
**/
void
-e_passwords_clear_component_passwords ()
+e_passwords_clear_component_passwords (const char *component_name)
{
char *path;
+ e_passwords_init ();
+
path = g_strdup_printf ("/Evolution/Passwords-%s", component_name);
gnome_config_private_clean_section (path);
@@ -121,7 +124,7 @@ e_passwords_clear_component_passwords ()
}
static char *
-password_path (const char *key)
+password_path (const char *component_name, const char *key)
{
char *keycopy, *path;
int i;
@@ -145,17 +148,19 @@ password_path (const char *key)
* Saves the password associated with @key to disk.
**/
void
-e_passwords_remember_password (const char *key)
+e_passwords_remember_password (const char *component_name, const char *key)
{
gpointer okey, value;
char *path, *pass64;
int len, state, save;
+ e_passwords_init ();
+
if (!g_hash_table_lookup_extended (passwords, key, &okey, &value))
return;
/* add it to the on-disk cache of passwords */
- path = password_path (okey);
+ path = password_path (component_name, okey);
len = strlen (value);
pass64 = g_malloc0 ((len + 2) * 4 / 3 + 1);
@@ -183,11 +188,13 @@ e_passwords_remember_password (const char *key)
* Forgets the password associated with @key, in memory and on disk.
**/
void
-e_passwords_forget_password (const char *key)
+e_passwords_forget_password (const char *component_name, const char *key)
{
gpointer okey, value;
char *path;
+ e_passwords_init ();
+
if (g_hash_table_lookup_extended (passwords, key, &okey, &value)) {
g_hash_table_remove (passwords, key);
memset (value, 0, strlen (value));
@@ -196,7 +203,7 @@ e_passwords_forget_password (const char *key)
}
/* clear it in the on disk db */
- path = password_path (key);
+ path = password_path (component_name, key);
gnome_config_private_clean_key (path);
gnome_config_private_sync_file ("/Evolution");
g_free (path);
@@ -210,21 +217,21 @@ e_passwords_forget_password (const char *key)
* must free the returned password.
**/
char *
-e_passwords_get_password (const char *key)
+e_passwords_get_password (const char *component_name, const char *key)
{
char *path, *passwd = g_hash_table_lookup (passwords, key);
char *encoded = NULL;
+
+ e_passwords_init ();
if (passwd)
return g_strdup (passwd);
/* not part of the session hash, look it up in the on disk db */
- path = password_path (key);
+ path = password_path (component_name, key);
encoded = gnome_config_private_get_string_with_default (path, NULL);
- printf ("getting password for (%s): %s\n", path, encoded);
-
g_free (path);
if (!encoded)
@@ -249,6 +256,8 @@ e_passwords_add_password (const char *key, const char *passwd)
{
gpointer okey, value;
+ e_passwords_init ();
+
/* FIXME: shouldn't this be g_return_if_fail? */
if (!key || !passwd)
return;
@@ -272,6 +281,8 @@ entry_activate (GtkEntry *entry, GtkDialog *dialog)
/**
* e_passwords_ask_password:
* @title: title for the password dialog
+ * @component_name: the name of the component for which we're storing
+ * the password (e.g. Mail, Addressbook, etc.)
* @key: key to store the password under
* @prompt: prompt string
* @secret: whether or not the password text should be ***ed out
@@ -289,7 +300,8 @@ entry_activate (GtkEntry *entry, GtkDialog *dialog)
* E_PASSWORDS_DO_NOT_REMEMBER.
**/
char *
-e_passwords_ask_password (const char *title, const char *key,
+e_passwords_ask_password (const char *title, const char *component_name,
+ const char *key,
const char *prompt, gboolean secret,
EPasswordsRememberType remember_type,
gboolean *remember,
@@ -350,7 +362,7 @@ e_passwords_ask_password (const char *title, const char *key,
if (*remember || remember_type == E_PASSWORDS_REMEMBER_FOREVER)
e_passwords_add_password (key, password);
if (*remember && remember_type == E_PASSWORDS_REMEMBER_FOREVER)
- e_passwords_remember_password (key);
+ e_passwords_remember_password (component_name, key);
}
} else
password = NULL;