32 #include <sys/types.h> |
32 #include <sys/types.h> |
33 #include <ucx/map.h> |
33 #include <ucx/map.h> |
34 #include <errno.h> |
34 #include <errno.h> |
35 #include <libxml/tree.h> |
35 #include <libxml/tree.h> |
36 |
36 |
|
37 #include "pwd.h" |
37 #include "config.h" |
38 #include "config.h" |
38 #include "main.h" |
39 #include "main.h" |
39 #include <libidav/utils.h> |
40 #include <libidav/utils.h> |
40 |
41 |
41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
42 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
97 int load_config(DavContext *ctx) { |
100 int load_config(DavContext *ctx) { |
98 context = ctx; |
101 context = ctx; |
99 // TODO: free the config somewhere |
102 // TODO: free the config somewhere |
100 repos = ucx_map_new(16); |
103 repos = ucx_map_new(16); |
101 keys = ucx_map_new(16); |
104 keys = ucx_map_new(16); |
|
105 |
|
106 char *pwfile = util_concat_path(ENV_HOME, ".dav/pw.crypt"); |
|
107 pstore = pwdstore_open(pwfile); |
|
108 free(pwfile); |
102 |
109 |
103 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
110 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
104 |
111 |
105 struct stat s; |
112 struct stat s; |
106 if(stat(file, &s)) { |
113 if(stat(file, &s)) { |
214 repo->url = strdup(value); |
221 repo->url = strdup(value); |
215 } else if(xstreq(key, "user")) { |
222 } else if(xstreq(key, "user")) { |
216 repo->user = strdup(value); |
223 repo->user = strdup(value); |
217 } else if(xstreq(key, "password")) { |
224 } else if(xstreq(key, "password")) { |
218 repo->password = util_base64decode(value); |
225 repo->password = util_base64decode(value); |
|
226 } else if(xstreq(key, "stored-user")) { |
|
227 repo->stored_user = strdup(value); |
219 } else if(xstreq(key, "default-key")) { |
228 } else if(xstreq(key, "default-key")) { |
220 repo->default_key = strdup(value); |
229 repo->default_key = strdup(value); |
221 } else if(xstreq(key, "full-encryption")) { |
230 } else if(xstreq(key, "full-encryption")) { |
222 if(util_getboolean(value)) { |
231 if(util_getboolean(value)) { |
223 repo->encrypt_name = true; |
232 repo->encrypt_name = true; |
749 UCX_MAP_FOREACH(key, repo, i) { |
758 UCX_MAP_FOREACH(key, repo, i) { |
750 list = ucx_list_append(list, repo); |
759 list = ucx_list_append(list, repo); |
751 } |
760 } |
752 return list; |
761 return list; |
753 } |
762 } |
|
763 |
|
764 PwdStore* get_pwdstore(void) { |
|
765 return pstore; |
|
766 } |
|
767 |
|
768 int pwdstore_save(PwdStore *pwdstore) { |
|
769 char *pwfile = util_concat_path(ENV_HOME, ".dav/pw.crypt"); |
|
770 int ret = pwdstore_store(pwdstore, pwfile); |
|
771 free(pwfile); |
|
772 return ret; |
|
773 } |