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 PWD_H
30 #define PWD_H
31
32 #include <stdlib.h>
33 #include <inttypes.h>
34
35 #include <cx/map.h>
36 #include <cx/buffer.h>
37 #include <cx/linked_list.h>
38 #include <libidav/crypto.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define PWDSTORE_MAX_LEN 4096
45
46
47
48
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 #define PWDS_HEADER_SIZE 24
77
78 typedef struct PwdStore PwdStore;
79 typedef struct PwdEntry PwdEntry;
80 typedef struct PwdIndexEntry PwdIndexEntry;
81
82 struct PwdStore {
83
84
85
86
87
88 CxMap *ids;
89
90
91
92
93
94 CxList *locations;
95
96
97
98
99
100 CxList *noloc;
101
102
103
104
105
106 CxMap *index;
107
108
109
110
111 CxBuffer *content;
112
113
114
115
116 DavKey *key;
117
118
119
120
121 char *unlock_cmd;
122
123
124
125
126 char *lock_cmd;
127
128
129
130
131 uint32_t encoffset;
132
133
134
135
136 uint8_t isdecrypted;
137 };
138
139 #define PWDS_MAGIC(p) (p)->content->space[
0]
140 #define PWDS_VERSION(p) (p)->content->space[
1]
141 #define PWDS_ENC(p) (p)->content->space[
2]
142 #define PWDS_PWFUNC(p) (p)->content->space[
3]
143
144 #define PWDS_MAGIC_CHAR 'P'
145
146 struct PwdEntry {
147 char *id;
148 char *user;
149 char *password;
150 };
151
152 struct PwdIndexEntry {
153 char *id;
154 CxList *locations;
155 };
156
157
158
159
160
161 PwdStore* pwdstore_open(
const char *file);
162
163 PwdStore* pwdstore_new(
void);
164
165
166
167
168 int pwdstore_decrypt(PwdStore *p);
169
170 int pwdstore_setpassword(PwdStore *p,
const char *password);
171
172 void pwdstore_encsettings(PwdStore *p,
uint8_t enc,
uint8_t pwfunc);
173
174 void pwdstore_free_entry(PwdEntry *e);
175 void pwdstore_free(PwdStore* p);
176
177 int pwdstore_has_id(PwdStore *s,
const char *id);
178 int pwdstore_has_location(PwdStore *s,
const char *location);
179
180 PwdEntry* pwdstore_get(PwdStore *p,
const char *id);
181
182 void pwdstore_put(PwdStore *p,
const char *id,
const char *username,
const char *password);
183 void pwdstore_put_index(PwdStore *p,
char *id, CxList *locations);
184
185 void pwdstore_remove_entry(PwdStore *s,
const char *id);
186
187 int pwdstore_store(PwdStore *p,
const char *file);
188
189
190 int pwdstore_getindex(PwdStore *s);
191
192 #ifdef __cplusplus
193 }
194 #endif
195
196 #endif
197
198