Implement a password store.
[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 /* Reencrypts all stored passwords using new_mpwd as an encryption
61  * password. */
62 void passwd_store_reencrypt_all(const gchar *old_mpwd,
63                 const gchar *new_mpwd);
64
65 /* Writes/reads password store to/from file. */
66 void passwd_store_write_config(void);
67 void passwd_store_read_config(void);
68
69 /* Macros for standard, predefined password IDs. */
70 #define PWS_ACCOUNT_RECV      "recv"
71 #define PWS_ACCOUNT_SEND      "send"
72 #define PWS_ACCOUNT_RECV_CERT "recv_cert"
73 #define PWS_ACCOUNT_SEND_CERT "send_cert"
74
75 #endif /* __PASSWORDSTORE_H */