more 'SSL' to 'SSL/TLS'
[claws.git] / src / passwordstore.h
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2016 Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19
20 #ifndef __PASSWORDSTORE_H
21 #define __PASSWORDSTORE_H
22
23 #include <glib.h>
24
25 typedef enum {
26         PWS_CORE,
27         PWS_ACCOUNT,
28         PWS_PLUGIN,
29         NUM_PWS_TYPES
30 } PasswordBlockType;
31
32 typedef struct _PasswordBlock {
33         PasswordBlockType block_type;
34         gchar *block_name;
35         GHashTable *entries;
36 } PasswordBlock;
37
38 /* Saves a password into a chosen password block.
39  * The block is created if it doesn't exist.
40  * block_type - from PasswordBlockType
41  * block_name - name of the block
42  * password_id - ID of the saved password
43  * password - the actual password string
44  * encrypted - TRUE if the password string is in an already encrypted form
45  *             (useful mostly for migration from accountrc)
46  *
47  * Function will make a copy of the strings where necessary and doesn't
48  * take ownership of any of the passed arguments. */
49 gboolean passwd_store_set(PasswordBlockType block_type,
50                 const gchar *block_name,
51                 const gchar *password_id,
52                 const gchar *password,
53                 gboolean encrypted);
54
55 /* Retrieves a password. Returned string should be freed by the caller. */
56 gchar *passwd_store_get(PasswordBlockType block_type,
57                 const gchar *block_name,
58                 const gchar *password_id);
59
60 gboolean passwd_store_delete_block(PasswordBlockType block_type,
61                 const gchar *block_name);
62
63 /* Reencrypts all stored passwords using new_mpwd as an encryption
64  * password. */
65 void passwd_store_reencrypt_all(const gchar *old_mpwd,
66                 const gchar *new_mpwd);
67
68 /* Writes/reads password store to/from file. */
69 void passwd_store_write_config(void);
70 void passwd_store_read_config(void);
71
72 /* Convenience wrappers for handling account passwords.
73  * (This is to save some boilerplate code converting account_id to
74  * a string and freeing the string afterwards.) */
75 gboolean passwd_store_set_account(gint account_id,
76                 const gchar *password_id,
77                 const gchar *password,
78                 gboolean encrypted);
79 gchar *passwd_store_get_account(gint account_id, const gchar *block_name);
80
81 /* Macros for standard, predefined password IDs. */
82 #define PWS_ACCOUNT_RECV      "recv"
83 #define PWS_ACCOUNT_SEND      "send"
84 #define PWS_ACCOUNT_RECV_CERT "recv_cert"
85 #define PWS_ACCOUNT_SEND_CERT "send_cert"
86
87 #endif /* __PASSWORDSTORE_H */