1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef LIBIDAV_PWDSTORE_H
30 #define LIBIDAV_PWDSTORE_H
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #include <stdlib.h>
37 #include <inttypes.h>
38
39 #include <cx/map.h>
40 #include <cx/buffer.h>
41 #include <cx/linked_list.h>
42 #include "crypto.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #define PWDSTORE_MAX_LEN 4096
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 #define PWDS_HEADER_SIZE 24
81
82 typedef struct PwdStore PwdStore;
83 typedef struct PwdEntry PwdEntry;
84 typedef struct PwdIndexEntry PwdIndexEntry;
85
86 struct PwdStore {
87
88
89
90
91
92 CxMap *ids;
93
94
95
96
97
98 CxList *locations;
99
100
101
102
103
104 CxList *noloc;
105
106
107
108
109
110 CxMap *index;
111
112
113
114
115 CxBuffer *content;
116
117
118
119
120 DavKey *key;
121
122
123
124
125 char *unlock_cmd;
126
127
128
129
130 char *lock_cmd;
131
132
133
134
135 uint32_t encoffset;
136
137
138
139
140 uint8_t isdecrypted;
141 };
142
143 #define PWDS_MAGIC(p) (p)->content->space[
0]
144 #define PWDS_VERSION(p) (p)->content->space[
1]
145 #define PWDS_ENC(p) (p)->content->space[
2]
146 #define PWDS_PWFUNC(p) (p)->content->space[
3]
147
148 #define PWDS_MAGIC_CHAR 'P'
149
150 struct PwdEntry {
151 char *id;
152 char *user;
153 char *password;
154 };
155
156 struct PwdIndexEntry {
157 char *id;
158 CxList *locations;
159 };
160
161
162
163
164
165 PwdStore* pwdstore_open(
const char *file);
166
167 PwdStore* pwdstore_new(
void);
168
169 PwdStore* pwdstore_clone(PwdStore *p);
170
171
172
173
174 int pwdstore_decrypt(PwdStore *p);
175
176 int pwdstore_setpassword(PwdStore *p,
const char *password);
177
178 void pwdstore_encsettings(PwdStore *p,
uint8_t enc,
uint8_t pwfunc);
179
180 void pwdstore_free_entry(PwdEntry *e);
181 void pwdstore_free(PwdStore* p);
182
183 int pwdstore_has_id(PwdStore *s,
const char *id);
184
185 PwdEntry* pwdstore_get(PwdStore *p,
const char *id);
186
187 void pwdstore_put(PwdStore *p,
const char *id,
const char *username,
const char *password);
188 void pwdstore_put_index(PwdStore *p,
char *id, CxList *locations);
189
190 void pwdstore_remove_entry(PwdStore *s,
const char *id);
191
192 int pwdstore_store(PwdStore *p,
const char *file);
193
194
195 int pwdstore_decrypt_secrets(PwdStore *secrets);
196
197
198
199
200
201
202 typedef char*(*pwdstore_pwinput_func)(
void *userdata);
203
204 void pwdstore_set_pwinput_func(pwdstore_pwinput_func func,
void *userdata);
205
206 char * pwdstore_default_pwinput(
char *prompt);
207
208
209
210
211 int pwdstore_getindex(PwdStore *s);
212
213 #ifdef __cplusplus
214 }
215 #endif
216
217 #endif
218
219