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 int pwdstore_has_location(PwdStore *s,
const char *location);
185
186 PwdEntry* pwdstore_get(PwdStore *p,
const char *id);
187
188 void pwdstore_put(PwdStore *p,
const char *id,
const char *username,
const char *password);
189 void pwdstore_put_index(PwdStore *p,
char *id, CxList *locations);
190
191 void pwdstore_remove_entry(PwdStore *s,
const char *id);
192
193 int pwdstore_store(PwdStore *p,
const char *file);
194
195
196 int pwdstore_decrypt_secrets(PwdStore *secrets);
197
198
199
200
201
202
203 typedef char*(*pwdstore_pwinput_func)(
void *userdata);
204
205 void pwdstore_set_pwinput_func(pwdstore_pwinput_func func,
void *userdata);
206
207 char * pwdstore_default_pwinput(
char *prompt);
208
209
210
211
212 int pwdstore_getindex(PwdStore *s);
213
214 #ifdef __cplusplus
215 }
216 #endif
217
218 #endif
219
220