diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 13 | ||||
-rw-r--r-- | e-util/e-html-utils.c | 15 | ||||
-rw-r--r-- | e-util/e-passwords.c | 116 |
3 files changed, 81 insertions, 63 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 4f5ef92e7c..a32a858c40 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,16 @@ +2001-10-22 Dan Winship <danw@ximian.com> + + * e-passwords.c (e_passwords_get_password): Pass a + CORBA_Environment to bonobo_config_get_string so it doesn't g_warn + on error. (Since the "error" is most likely just that the password + isn't cached.) + (e_passwords_remember_password, e_passwords_get_password, + e_passwords_add_password): Change "if (foo) { entire function; }" + to "if (!foo) return;" + + * e-html-utils.c (special_chars): Don't allow single quote or + backtick in email addresses, or pipes following URLs. + 2001-10-22 JP Rosevear <jpr@ximian.com> * e-dbhash.c (e_dbhash_foreach_key): null out DBT memory prior to diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c index a2759f91a8..c9e61a5372 100644 --- a/e-util/e-html-utils.c +++ b/e-util/e-html-utils.c @@ -40,21 +40,20 @@ check_size (char **buffer, int *buffer_size, char *out, int len) return out; } -/* 1 = non-email-address chars: ()<>@,;:\"[] */ -/* 2 = trailing garbage: ,.!?;:>)]}`'-_ */ +/* 1 = non-email-address chars: ()<>@,;:\"[]`'| */ +/* 2 = trailing url garbage: ,.!?;:>)]}`'-_| */ static int special_chars[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* nul - 0x0f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */ - 1, 2, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 3, 2, 2, 0, /* sp - / */ + 1, 2, 1, 0, 0, 0, 0, 3, 1, 3, 0, 0, 3, 2, 2, 0, /* sp - / */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 0, 3, 2, /* 0 - ? */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 0, 2, /* P - _ */ - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 /* p - del */ + 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0 /* p - del */ }; #define is_addr_char(c) (isprint (c) && !(special_chars[c] & 1)) -#define is_addr_char_no_pipes(c) (is_addr_char(c) && (c) != '|') #define is_trailing_garbage(c) (!isprint(c) || (special_chars[c] & 2)) static char * @@ -89,13 +88,13 @@ email_address_extract (const unsigned char **cur, char **out, const unsigned cha char *addr; /* *cur points to the '@'. Look backward for a valid local-part */ - for (start = *cur; start - 1 >= linestart && is_addr_char_no_pipes (*(start - 1)); start--) + for (start = *cur; start - 1 >= linestart && is_addr_char (*(start - 1)); start--) ; if (start == *cur) return NULL; /* Now look forward for a valid domain part */ - for (end = *cur + 1, dot = NULL; is_addr_char_no_pipes (*end); end++) { + for (end = *cur + 1, dot = NULL; is_addr_char (*end); end++) { if (*end == '.' && !dot) dot = end; } diff --git a/e-util/e-passwords.c b/e-util/e-passwords.c index 2222b6e211..363c5592c7 100644 --- a/e-util/e-passwords.c +++ b/e-util/e-passwords.c @@ -168,35 +168,34 @@ e_passwords_clear_component_passwords () void e_passwords_remember_password (const char *key) { - char *okey, *value; - - if (g_hash_table_lookup_extended (passwords, key, - (gpointer*)&okey, (gpointer*)&value)) { - char *path, *key64, *pass64; - int len, state, save; - - /* add it to the on-disk cache of passwords */ - len = strlen (okey); - 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/%s", component_name, key64); - g_free (key64); - - len = strlen (value); - pass64 = g_malloc0 ((len + 2) * 4 / 3 + 1); - state = save = 0; - base64_encode_close (value, len, FALSE, pass64, &state, &save); - - bonobo_config_set_string (db, path, pass64, NULL); - g_free (path); - g_free (pass64); + gpointer okey, value; + char *path, *key64, *pass64; + int len, state, save; - /* now remove it from our session hash */ - g_hash_table_remove (passwords, key); - g_free (okey); - g_free (value); - } + if (!g_hash_table_lookup_extended (passwords, key, &okey, &value)) + return; + + /* add it to the on-disk cache of passwords */ + len = strlen (okey); + 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/%s", component_name, key64); + g_free (key64); + + len = strlen (value); + pass64 = g_malloc0 ((len + 2) * 4 / 3 + 1); + state = save = 0; + base64_encode_close (value, len, FALSE, pass64, &state, &save); + + bonobo_config_set_string (db, path, pass64, NULL); + g_free (path); + g_free (pass64); + + /* now remove it from our session hash */ + g_hash_table_remove (passwords, key); + g_free (okey); + g_free (value); } /** @@ -230,29 +229,34 @@ char * e_passwords_get_password (const char *key) { char *passwd = g_hash_table_lookup (passwords, key); - if (!passwd) { - char *path, *key64; - int len, state, save; + char *path, *key64; + int len, state, save; + CORBA_Environment ev; + + if (passwd) + return g_strdup (passwd); - /* not part of the session hash, look it up in the on disk db */ - len = strlen (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/%s", component_name, key64); - g_free (key64); + /* not part of the session hash, look it up in the on disk db */ + len = strlen (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/%s", component_name, key64); + g_free (key64); - passwd = bonobo_config_get_string (db, path, NULL); + /* We need to pass an ev to bonobo-conf, or it will emit a + * g_warning if the data isn't found. + */ + CORBA_exception_init (&ev); + passwd = bonobo_config_get_string (db, path, &ev); + CORBA_exception_free (&ev); - g_free (path); + g_free (path); - if (passwd) - return decode_base64 (passwd); - else - return NULL; - } + if (passwd) + return decode_base64 (passwd); else - return g_strdup (passwd); + return NULL; } /** @@ -266,17 +270,19 @@ e_passwords_get_password (const char *key) void e_passwords_add_password (const char *key, const char *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); - } + gpointer okey, value; - g_hash_table_insert (passwords, g_strdup (key), g_strdup (passwd)); + /* FIXME: shouldn't this be g_return_if_fail? */ + if (!key || !passwd) + return; + + 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)); } |