Tue, 30 Dec 2025 21:27:14 +0100
replace a bunch of cxBufferWrite calls with cxBufferPutString
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
364
3769ba002fd1
updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
4 | * Copyright 2018 Olaf Wintermann. All rights reserved. |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
|
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
32 | #include <sys/types.h> |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
33 | #include <cx/hash_map.h> |
|
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
34 | #include <errno.h> |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <libxml/tree.h> |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "config.h" |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
38 | #include "system.h" |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
39 | |
|
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
40 | #include <libidav/utils.h> |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
41 | #include <libidav/config.h> |
|
843
5afacd2a8cde
fix windows build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
833
diff
changeset
|
42 | #include <libidav/pwdstore.h> |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
| 889 | 44 | #include <cx/streams.h> |
| 45 | ||
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
|
73
41e88442ad4e
ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
47 | #define xstrEQ(a,b) !xmlStrcasecmp(BAD_CAST a, BAD_CAST b) |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
|
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
49 | #define print_error(lineno, ...) \ |
|
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
50 | do {\ |
|
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
51 | fprintf(stderr, "Error (config.xml line %u): ", lineno); \ |
|
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
52 | fprintf(stderr, __VA_ARGS__); \ |
|
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
53 | fprintf(stderr, "Abort.\n"); \ |
|
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
54 | } while(0); |
|
254
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
55 | #define print_warning(lineno, ...) \ |
|
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
56 | do {\ |
|
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
57 | fprintf(stderr, "Warning (config.xml line %u): ", lineno); \ |
|
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
58 | fprintf(stderr, __VA_ARGS__); \ |
|
d7c4ba50b7d8
implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents:
252
diff
changeset
|
59 | } while(0); |
|
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
60 | |
| 32 | 61 | #ifdef _WIN32 |
| 62 | #define ENV_HOME getenv("USERPROFILE") | |
| 63 | #else | |
| 64 | #define ENV_HOME getenv("HOME") | |
| 65 | #endif /* _WIN32 */ | |
| 66 | ||
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
67 | static CxMap *repos; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
68 | static CxMap *keys; |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
70 | static DavConfig *davconfig; |
|
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
71 | static PwdStore *pstore; |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
72 | |
|
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
73 | static char *secretstore_unlock_cmd; |
|
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
74 | static char *secretstore_lock_cmd; |
|
729
5433f0f3dd48
disable error in case of unknown config elements
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
606
diff
changeset
|
75 | |
|
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
76 | int check_config_dir(void) { |
| 32 | 77 | char *file = util_concat_path(ENV_HOME, ".dav"); |
|
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
78 | int ret = 0; |
| 32 | 79 | if(util_mkdir(file, S_IRWXU)) { |
|
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
80 | if(errno != EEXIST) { |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
81 | ret = 1; |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
82 | } |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
83 | } |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
84 | free(file); |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
85 | return ret; |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
86 | } |
|
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
87 | |
|
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
88 | static DavContext *context; |
|
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
89 | |
|
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
90 | void create_default_config(char *file) { |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
91 | xmlDoc *doc = xmlNewDoc(BAD_CAST "1.0"); |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
92 | xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration"); |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
93 | xmlDocSetRootElement(doc, root); |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
94 | xmlSaveFormatFileEnc(file, doc, "UTF-8", 1); |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
95 | xmlFreeDoc(doc); |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
96 | } |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
97 | |
|
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
98 | char* config_file_path(char *name) { |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
99 | char *davd = util_concat_path(ENV_HOME, ".dav"); |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
100 | if(!davd) { |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
101 | return NULL; |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
102 | } |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
103 | char *path = util_concat_path(davd, name); |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
104 | free(davd); |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
105 | return path; |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
106 | } |
|
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
107 | |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
108 | cxmutstr config_load_file(const char *path) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
109 | FILE *file = sys_fopen(path, "r"); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
110 | if(!file) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
111 | return (cxmutstr){NULL,0}; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
112 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
113 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
114 | CxBuffer buf; |
| 891 | 115 | cxBufferInit(&buf, cxDefaultAllocator, NULL, 1024, CX_BUFFER_AUTO_EXTEND); |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
116 | cx_stream_copy(file, &buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
117 | fclose(file); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
118 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
119 | return cx_mutstrn(buf.space, buf.size); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
120 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
121 | |
|
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
122 | int load_config(DavContext *ctx) { |
|
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
123 | context = ctx; |
| 36 | 124 | // TODO: free the config somewhere |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
125 | repos = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
126 | keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
|
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
470
diff
changeset
|
128 | char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt"); |
|
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
129 | pstore = pwdstore_open(pwfile); |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
130 | free(pwfile); |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
131 | |
| 32 | 132 | char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
|
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
133 | |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
134 | struct stat s; |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
135 | if(stat(file, &s)) { |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
136 | switch(errno) { |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
137 | case ENOENT: { |
|
827
d9928f11970f
fix load_config stores wrong xml doc pointer in the config object
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
826
diff
changeset
|
138 | davconfig = dav_config_new(NULL); |
|
294
dd5c0ebdf54f
fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
139 | return 0; |
|
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
140 | } |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
141 | default: { |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
142 | perror("Cannot load config.xml"); |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
143 | } |
|
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
144 | } |
|
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
145 | return 1; |
|
6
9c64d2a3d101
creates an empty configuration file if needed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
146 | } |
|
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
147 | |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
148 | cxmutstr config_content = config_load_file(file); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
149 | int config_error; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
150 | davconfig = dav_config_load(config_content, &config_error); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
151 | free(config_content.ptr); |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
152 | free(file); |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
153 | |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
154 | if(!davconfig) { |
|
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
155 | fprintf(stderr, "Cannot load config.xml\n"); |
|
252
6b8e287269fc
improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents:
247
diff
changeset
|
156 | return 1; |
|
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
157 | } |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
|
823
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
159 | if(dav_config_register_namespaces(davconfig, ctx)) { |
|
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
160 | return 1; |
|
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
161 | } |
|
04c60a353331
add configured namespaces to the dav context
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
162 | |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
163 | return dav_config_register_keys(davconfig, ctx, load_key_file); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | } |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
166 | DavConfig* get_config(void) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
167 | return davconfig; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
168 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
169 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
170 | int store_config(void) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
171 | if(check_config_dir()) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
172 | return 1; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
173 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
174 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
175 | CxBuffer *buf = dav_config2buf(davconfig); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
176 | if(!buf) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
177 | return 1; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
178 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
179 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
180 | char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
181 | FILE *cout = sys_fopen(file, "w"); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
182 | if(!cout) { |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
183 | cxBufferFree(buf); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
184 | return 1; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
185 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
186 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
187 | // should only fail if we run out of disk space or something like that |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
188 | // in that case, the config file is only destroyed |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
189 | // could only be prevented, if we write to a temp file first and than |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
190 | // rename it |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
191 | fwrite(buf->space, buf->size, 1, cout); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
192 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
193 | cxBufferFree(buf); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
194 | fclose(cout); |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
195 | |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
196 | return 0; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
197 | } |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
198 | |
|
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
199 | void free_config(void) { |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
200 | if(davconfig) { |
|
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
201 | dav_config_free(davconfig); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | } |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | } |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
205 | cxmutstr load_key_file(const char *filename) { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
206 | cxmutstr k; |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | k.ptr = NULL; |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | k.length = 0; |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | FILE *file = NULL; |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | if(filename[0] == '/') { |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
212 | file = sys_fopen(filename, "r"); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | } else { |
| 32 | 214 | char *path = util_concat_path(ENV_HOME, ".dav/"); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | char *p2 = util_concat_path(path, filename); |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
216 | file = sys_fopen(p2, "r"); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | free(path); |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | free(p2); |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | } |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | if(!file) { |
|
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
222 | fprintf(stderr, "Error: cannot load keyfile %s\n", filename); |
|
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | return k; |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | } |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | char *data = malloc(256); |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | size_t r = fread(data, 1, 256, file); |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | k.ptr = data; |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | k.length = r; |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | fclose(file); |
|
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | return k; |
|
317
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
233 | } |
|
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
234 | |
|
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
235 | PwdStore* get_pwdstore(void) { |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
236 | return pstore; |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
237 | } |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
238 | |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
239 | int pwdstore_save(PwdStore *pwdstore) { |
|
732
b0eb645cd26e
fix error in dav add-user, if .dav dir doesn't exists
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
731
diff
changeset
|
240 | if(check_config_dir()) { |
|
b0eb645cd26e
fix error in dav add-user, if .dav dir doesn't exists
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
731
diff
changeset
|
241 | return 1; |
|
b0eb645cd26e
fix error in dav add-user, if .dav dir doesn't exists
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
731
diff
changeset
|
242 | } |
|
b0eb645cd26e
fix error in dav add-user, if .dav dir doesn't exists
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
731
diff
changeset
|
243 | |
|
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
470
diff
changeset
|
244 | char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt"); |
|
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
245 | int ret = pwdstore_store(pwdstore, pwfile); |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
246 | free(pwfile); |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
247 | return ret; |
|
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
248 | } |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
249 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
250 | typedef struct CredLocation { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
251 | char *id; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
252 | char *location; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
253 | } CredLocation; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
254 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
255 | static int cmp_url_cred_entry(CredLocation *e1, CredLocation *e2, void *n) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
256 | return strcmp(e2->location, e1->location); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
257 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
258 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
259 | static void free_cred_location(CredLocation *c) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
260 | // c->id is not a copy, therefore we don't have to free it |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
261 | free(c->location); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
262 | free(c); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
263 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
264 | |
|
832
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
827
diff
changeset
|
265 | int get_stored_credentials(char *credid, char **user, char **password) { |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
266 | if(!credid) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
267 | return 0; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
268 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
269 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
270 | PwdStore *secrets = get_pwdstore(); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
271 | if(!secrets) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
272 | fprintf(stderr, "Error: no secrets store available\n"); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
273 | return 0; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
274 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
275 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
276 | if(pwdstore_has_id(secrets, credid)) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
277 | if(!secrets->isdecrypted) { |
|
832
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
827
diff
changeset
|
278 | if(pwdstore_decrypt_secrets(secrets)) { |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
279 | return 0; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
280 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
281 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
282 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
283 | PwdEntry *s_cred = pwdstore_get(secrets, credid); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
284 | if(s_cred) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
285 | *user = s_cred->user; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
286 | *password = s_cred->password; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
287 | return 1; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
288 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
289 | } else { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
290 | fprintf(stderr, "Error: credentials id '%s' not found\n", credid); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
291 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
292 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
293 | return 0; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
294 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
295 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
296 | |
|
832
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
827
diff
changeset
|
297 | int get_location_credentials(DavCfgRepository *repo, const char *path, char **user, char **password) { |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
298 | PwdStore *secrets = get_pwdstore(); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
299 | if(!secrets) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
300 | return 0; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
301 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
302 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
303 | /* |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
304 | * The list secrets->location contains urls or repo names as |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
305 | * location strings. We need a list, that contains only urls |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
306 | */ |
| 891 | 307 | CxList *locations = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| 308 | cxSetCompareFunc(locations, (cx_compare_func)cmp_url_cred_entry); | |
| 309 | cxSetDestructor(locations, free_cred_location); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
310 | CxIterator i = cxListIterator(secrets->locations); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
311 | cx_foreach(PwdIndexEntry*, e, i) { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
312 | CxIterator entry_iter = cxListIterator(e->locations); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
313 | cx_foreach(char *, loc, entry_iter) { |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
314 | cxmutstr rpath; |
|
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
315 | DavCfgRepository *r = dav_config_url2repo_s(davconfig, cx_str(loc), &rpath); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
316 | CredLocation *urlentry = calloc(1, sizeof(CredLocation)); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
317 | urlentry->id = e->id; |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
318 | urlentry->location = util_concat_path_s(cx_strcast(r->url.value), cx_strcast(rpath)).ptr; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
319 | cxListAdd(locations, urlentry); |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
320 | free(rpath.ptr); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
321 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
322 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
323 | // the list must be sorted |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
324 | cxListSort(locations); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
325 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
326 | // create full request url string and remove protocol prefix |
|
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
327 | cxmutstr req_url_proto = util_concat_path_s(cx_strcast(repo->url.value), cx_str(path)); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
328 | cxstring req_url = cx_strcast(req_url_proto); |
| 891 | 329 | if(cx_strprefix(req_url, cx_str("http://"))) { |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
330 | req_url = cx_strsubs(req_url, 7); |
| 891 | 331 | } else if(cx_strprefix(req_url, cx_str("https://"))) { |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
332 | req_url = cx_strsubs(req_url, 8); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
333 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
334 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
335 | // iterate over sorted locations and check if a location is a prefix |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
336 | // of the requested url |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
337 | char *id = NULL; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
338 | int ret = 0; |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
339 | i = cxListIterator(locations); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
340 | cx_foreach(CredLocation*, cred, i) { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
341 | cxstring cred_url = cx_str(cred->location); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
342 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
343 | // remove protocol prefix |
| 891 | 344 | if(cx_strprefix(cred_url, cx_str("http://"))) { |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
345 | cred_url = cx_strsubs(cred_url, 7); |
| 891 | 346 | } else if(cx_strprefix(cred_url, cx_str("https://"))) { |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
347 | cred_url = cx_strsubs(cred_url, 8); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
348 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
349 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
350 | if(cx_strprefix(req_url, cred_url)) { |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
351 | id = cred->id; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
352 | break; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
353 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
354 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
355 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
356 | // if an id is found and we can access the decrypted secret store |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
357 | // we can set the user/password |
|
832
dff5f4c23aa7
move pwdstore to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
827
diff
changeset
|
358 | if(id && (secrets->isdecrypted || !pwdstore_decrypt_secrets(secrets))) { |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
359 | PwdEntry *cred = pwdstore_get(secrets, id); |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
360 | if(cred) { |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
361 | *user = cred->user; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
362 | *password = cred->password; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
363 | ret = 1; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
364 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
365 | } |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
366 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
367 | free(req_url_proto.ptr); |
| 852 | 368 | cxListFree(locations); |
|
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
369 | |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
370 | return ret; |
|
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
371 | } |