diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 20 | ||||
-rw-r--r-- | e-util/e-passwords.c | 60 | ||||
-rw-r--r-- | e-util/e-passwords.h | 16 |
3 files changed, 66 insertions, 30 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index edad602d6e..b922da3953 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,23 @@ +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. + 2002-12-07 Not Zed <NotZed@Ximian.com> * e-msgport.c (e_mutex_cond_wait): Allow an e-mutex to be used 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; diff --git a/e-util/e-passwords.h b/e-util/e-passwords.h index 12d087fe97..7a2b2aa17f 100644 --- a/e-util/e-passwords.h +++ b/e-util/e-passwords.h @@ -28,15 +28,18 @@ G_BEGIN_DECLS -void e_passwords_init (const char *component); +/* initialization is now implicit when you call any of the functions + below (except _shutdown.). e_passwords_shutdown should be called + at exit time to synch the password on-disk storage, and to free up + in-memory storage. */ void e_passwords_shutdown (void); -void e_passwords_remember_password (const char *key); +void e_passwords_remember_password (const char *component, const char *key); 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); +char *e_passwords_get_password (const char *component, const char *key); +void e_passwords_forget_password (const char *component, const char *key); void e_passwords_forget_passwords (void); -void e_passwords_clear_component_passwords (void); +void e_passwords_clear_component_passwords (const char *component); typedef enum { E_PASSWORDS_DO_NOT_REMEMBER, @@ -44,7 +47,8 @@ typedef enum { E_PASSWORDS_REMEMBER_FOREVER } EPasswordsRememberType; -char * e_passwords_ask_password (const char *title, const char *key, +char * e_passwords_ask_password (const char *title, + const char*component_name, const char *key, const char *prompt, gboolean secret, EPasswordsRememberType remember_type, gboolean *remember, |