fishlim: Fix saving nicks containing [ or ]

Part of #1440
This commit is contained in:
Patrick Griffis 2016-08-29 01:40:58 -04:00
parent 31dd020114
commit c81c89dc80

View File

@ -63,6 +63,22 @@ static const char *get_keystore_password(void) {
}
static char *escape_nickname(const char *nick) {
char *escaped = g_strdup(nick);
char *p = escaped;
while (*p) {
if (*p == '[')
*p = '~';
else if (*p == ']')
*p = '!';
++p;
}
return escaped;
}
/**
* Gets a value for a nick/channel from addon_fishlim.conf. Unlike
* g_key_file_get_string, this function is case insensitive.
@ -90,9 +106,13 @@ static gchar *get_nick_value(GKeyFile *keyfile, const char *nick, const char *it
char *keystore_get_key(const char *nick) {
/* Get the key */
GKeyFile *keyfile = getConfigFile();
gchar *value = get_nick_value(keyfile, nick, "key");
char *escaped_nick = escape_nickname(nick);
gchar *value = get_nick_value(keyfile, escaped_nick, "key");
g_key_file_free(keyfile);
if (!value) return NULL;
g_free(escaped_nick);
if (!value)
return NULL;
if (strncmp(value, "+OK ", 4) != 0) {
/* Key is stored in plaintext */
@ -173,9 +193,10 @@ gboolean keystore_store_key(const char *nick, const char *key) {
char *wrapped;
gboolean ok = FALSE;
GKeyFile *keyfile = getConfigFile();
char *escaped_nick = escape_nickname(nick);
/* Remove old key */
delete_nick(keyfile, nick);
delete_nick(keyfile, escaped_nick);
/* Add new key */
password = get_keystore_password();
@ -189,11 +210,11 @@ gboolean keystore_store_key(const char *nick, const char *key) {
g_free(encrypted);
/* Store encrypted in file */
g_key_file_set_string(keyfile, nick, "key", wrapped);
g_key_file_set_string(keyfile, escaped_nick, "key", wrapped);
g_free(wrapped);
} else {
/* Store unencrypted in file */
g_key_file_set_string(keyfile, nick, "key", key);
g_key_file_set_string(keyfile, escaped_nick, "key", key);
}
/* Save key store file */
@ -201,6 +222,7 @@ gboolean keystore_store_key(const char *nick, const char *key) {
end:
g_key_file_free(keyfile);
g_free(escaped_nick);
return ok;
}
@ -209,13 +231,15 @@ gboolean keystore_store_key(const char *nick, const char *key) {
*/
gboolean keystore_delete_nick(const char *nick) {
GKeyFile *keyfile = getConfigFile();
char *escaped_nick = escape_nickname(nick);
/* Delete entry */
gboolean ok = delete_nick(keyfile, nick);
gboolean ok = delete_nick(keyfile, escaped_nick);
/* Save */
if (ok) save_keystore(keyfile);
g_key_file_free(keyfile);
g_free(escaped_nick);
return ok;
}