talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit fa7bec8685ac1b2dfda2c113ed5a876f33c506a7
parent babfcbc9c9822157da38bbfe946a8dd781ca2ab9
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Sun,  1 Jul 2018 21:56:16 +0200

Added a password store function to check if a password exists.

Diffstat:
Msrc/passwordstore.c | 36++++++++++++++++++++++++++++++++++++
Msrc/passwordstore.h | 11++++++++++-
2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/passwordstore.c b/src/passwordstore.c @@ -208,6 +208,33 @@ gchar *passwd_store_get(PasswordBlockType block_type, return password; } +/* Checks if a password exists in the password store. + * No decryption happens. */ +gboolean passwd_store_has_password(PasswordBlockType block_type, + const gchar *block_name, + const gchar *password_id) +{ + PasswordBlock *block; + + g_return_val_if_fail(block_type < NUM_PWS_TYPES, FALSE); + g_return_val_if_fail(block_name != NULL, FALSE); + g_return_val_if_fail(password_id != NULL, FALSE); + + /* find correct block */ + if ((block = _get_block(block_type, block_name)) == NULL) { + debug_print("Block (%d/%s) not found.\n", block_type, block_name); + return FALSE; + } + + /* do we have specified password in this block? */ + if (g_hash_table_lookup(block->entries, password_id) != NULL) { + return TRUE; /* yes */ + } + + return FALSE; /* no */ +} + + gboolean passwd_store_delete_block(PasswordBlockType block_type, const gchar *block_name) { @@ -250,6 +277,15 @@ gchar *passwd_store_get_account(gint account_id, return ret; } +gboolean passwd_store_has_password_account(gint account_id, + const gchar *password_id) +{ + gchar *uid = g_strdup_printf("%d", account_id); + gboolean ret = passwd_store_has_password(PWS_ACCOUNT, uid, password_id); + g_free(uid); + return ret; +} + /* Reencrypts all stored passwords. */ void passwd_store_reencrypt_all(const gchar *old_mpwd, const gchar *new_mpwd) diff --git a/src/passwordstore.h b/src/passwordstore.h @@ -57,6 +57,12 @@ gchar *passwd_store_get(PasswordBlockType block_type, const gchar *block_name, const gchar *password_id); +/* Returns TRUE if such password exists in the password store, + * false otherwise. No decryption happens. */ +gboolean passwd_store_has_password(PasswordBlockType block_type, + const gchar *block_name, + const gchar *password_id); + gboolean passwd_store_delete_block(PasswordBlockType block_type, const gchar *block_name); @@ -76,7 +82,10 @@ gboolean passwd_store_set_account(gint account_id, const gchar *password_id, const gchar *password, gboolean encrypted); -gchar *passwd_store_get_account(gint account_id, const gchar *block_name); +gchar *passwd_store_get_account(gint account_id, + const gchar *password_id); +gboolean passwd_store_has_password_account(gint account_id, + const gchar *password_id); /* Macros for standard, predefined password IDs. */ #define PWS_ACCOUNT_RECV "recv"