Sun, 17 Dec 2023 15:33:50 +0100
fix faulty string to int conversion utilities
Probably it was expected that errno is set to EINVAL when illegal characters are encountered. But this is not standard and does not happen on every system, allowing illegal strings to be parsed as valid integers.
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> |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
34 | #include <cx/utils.h> |
8
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
35 | #include <errno.h> |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <libxml/tree.h> |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
38 | #include "pwd.h" |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "config.h" |
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
|
40 | #include "main.h" |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
41 | #include "pwd.h" |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
42 | #include "system.h" |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
43 | |
33
0bbbb0341606
some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
44 | #include <libidav/utils.h> |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
45 | #include <libidav/config.h> |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | #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
|
48 | #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
|
49 | |
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
|
50 | #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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | 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
|
55 | } 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
|
56 | #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
|
57 | 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
|
58 | 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
|
59 | 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
|
60 | } 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
|
61 | |
32 | 62 | #ifdef _WIN32 |
63 | #define ENV_HOME getenv("USERPROFILE") | |
64 | #else | |
65 | #define ENV_HOME getenv("HOME") | |
66 | #endif /* _WIN32 */ | |
67 | ||
747
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 *repos; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
69 | static CxMap *keys; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
71 | static DavConfig *davconfig; |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
72 | static PwdStore *pstore; |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
73 | |
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
74 | static char *secretstore_unlock_cmd; |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
75 | 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
|
76 | |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
77 | int check_config_dir(void) { |
32 | 78 | 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
|
79 | int ret = 0; |
32 | 80 | 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
|
81 | if(errno != EEXIST) { |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
82 | ret = 1; |
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 | } |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
85 | free(file); |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
86 | return ret; |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
87 | } |
4503498deb22
creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
88 | |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
89 | static DavContext *context; |
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
90 | |
142
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
91 | 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
|
92 | 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
|
93 | 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
|
94 | xmlDocSetRootElement(doc, root); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
95 | 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
|
96 | xmlFreeDoc(doc); |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
97 | } |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
98 | |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
99 | 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
|
100 | 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
|
101 | if(!davd) { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
102 | return NULL; |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
103 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
104 | 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
|
105 | free(davd); |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
106 | return path; |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
107 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
108 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
109 | cxmutstr config_load_file(const char *path) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
110 | FILE *file = sys_fopen(path, "r"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
111 | if(!file) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
112 | return (cxmutstr){NULL,0}; |
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 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
115 | CxBuffer buf; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
116 | cxBufferInit(&buf, NULL, 1024, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
117 | 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
|
118 | fclose(file); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
119 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
120 | return cx_mutstrn(buf.space, buf.size); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
121 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
122 | |
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
|
123 | int load_config(DavContext *ctx) { |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
124 | context = ctx; |
36 | 125 | // 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
|
126 | 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
|
127 | 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
|
128 | |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
470
diff
changeset
|
129 | 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
|
130 | pstore = pwdstore_open(pwfile); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
131 | free(pwfile); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
132 | |
32 | 133 | 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
|
134 | |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
135 | struct stat s; |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
136 | if(stat(file, &s)) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
137 | switch(errno) { |
0c0ccb7f71ba
startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
138 | case ENOENT: { |
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 | |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
159 | 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
|
160 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
162 | DavConfig* get_config(void) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
163 | return davconfig; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
164 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
165 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
166 | int store_config(void) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
167 | if(check_config_dir()) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
168 | return 1; |
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 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
171 | CxBuffer *buf = dav_config2buf(davconfig); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
172 | if(!buf) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
173 | return 1; |
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 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
176 | 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
|
177 | FILE *cout = sys_fopen(file, "w"); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
178 | if(!cout) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
179 | cxBufferFree(buf); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
180 | return 1; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
181 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
182 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
183 | // 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
|
184 | // in that case, the config file is only destroyed |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
185 | // 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
|
186 | // rename it |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
187 | fwrite(buf->space, buf->size, 1, cout); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
188 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
189 | cxBufferFree(buf); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
190 | fclose(cout); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
191 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
192 | return 0; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
193 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
194 | |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
195 | void free_config(void) { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
196 | if(davconfig) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
197 | dav_config_free(davconfig); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
201 | 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
|
202 | cxmutstr k; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | k.ptr = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | k.length = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | FILE *file = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | if(filename[0] == '/') { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
208 | 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
|
209 | } else { |
32 | 210 | 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
|
211 | char *p2 = util_concat_path(path, filename); |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
212 | 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
|
213 | free(path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | free(p2); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | if(!file) { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
218 | 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
|
219 | return k; |
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 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | char *data = malloc(256); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | 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
|
224 | k.ptr = data; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | k.length = r; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | fclose(file); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | return k; |
317
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
229 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
230 | |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
231 | static char* get_attr_content(xmlNode *node) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
232 | // TODO: remove code duplication (util_xml_get_text) |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
233 | while(node) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
234 | if(node->type == XML_TEXT_NODE) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
235 | return (char*)node->content; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
236 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
237 | node = node->next; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
238 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
239 | return NULL; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
240 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
241 | |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
242 | int load_namespace(const xmlNode *node) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
243 | const char *prefix = NULL; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
244 | const char *uri = NULL; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
245 | |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
246 | xmlAttr *attr = node->properties; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
247 | while(attr) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
248 | if(attr->type == XML_ATTRIBUTE_NODE) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
249 | char *value = get_attr_content(attr->children); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
250 | if(!value) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
251 | print_error( |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
252 | node->line, |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
253 | "missing value for attribute %s\n", (char*)attr->name); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
254 | return 1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
255 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
256 | if(xstreq(attr->name, "prefix")) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
257 | prefix = value; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
258 | } else if(xstreq(attr->name, "uri")) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
259 | uri = value; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
260 | } else { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
261 | print_error( |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
262 | node->line, |
321
eb8885a87866
adds namespace config element to XSD + fixes error message for duplicate namespace prefixes
Mike Becker <universe@uap-core.de>
parents:
319
diff
changeset
|
263 | "unexpected attribute %s\n", (char*)attr->name); |
317
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
264 | return 1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
265 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
266 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
267 | attr = attr->next; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
268 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
269 | |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
270 | if(!prefix) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
271 | print_error(node->line, "missing prefix attribute\n"); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
272 | return 1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
273 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
274 | if(!uri) { |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
275 | print_error(node->line, "missing uri attribute\n"); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
276 | return 1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
277 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
278 | |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
279 | if(dav_get_namespace(context, prefix)) { |
321
eb8885a87866
adds namespace config element to XSD + fixes error message for duplicate namespace prefixes
Mike Becker <universe@uap-core.de>
parents:
319
diff
changeset
|
280 | print_error(node->line, "namespace prefix '%s' already used\n", prefix); |
317
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
281 | return 1; |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
282 | } |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
283 | |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
284 | return dav_add_namespace(context, prefix, uri); |
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
285 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | |
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
287 | int load_secretstore(const xmlNode *node) { |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
288 | // currently only one secretstore is supported |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
289 | |
731
e0358fa1a3b1
implement secretstore unlock command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
290 | if(!pstore) { |
e0358fa1a3b1
implement secretstore unlock command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
291 | return 0; |
e0358fa1a3b1
implement secretstore unlock command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
292 | } |
e0358fa1a3b1
implement secretstore unlock command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
293 | |
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
294 | node = node->children; |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
295 | int error = 0; |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
296 | while(node) { |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
297 | if(node->type == XML_ELEMENT_NODE) { |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
298 | char *value = util_xml_get_text(node); |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
299 | if(value) { |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
300 | if(xstreq(node->name, "unlock-command")) { |
731
e0358fa1a3b1
implement secretstore unlock command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
301 | pstore->unlock_cmd = strdup(value); |
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
302 | } else if(xstreq(node->name, "lock-command")) { |
731
e0358fa1a3b1
implement secretstore unlock command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
303 | pstore->lock_cmd = strdup(value); |
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
304 | } |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
305 | } |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
306 | } |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
307 | node = node->next; |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
308 | } |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
309 | |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
310 | return error; |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
311 | } |
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
729
diff
changeset
|
312 | |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
313 | PwdStore* get_pwdstore(void) { |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
314 | return pstore; |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
315 | } |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
316 | |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
317 | 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
|
318 | 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
|
319 | 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
|
320 | } |
b0eb645cd26e
fix error in dav add-user, if .dav dir doesn't exists
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
731
diff
changeset
|
321 | |
472
08d2d1263429
new secrets store file format
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
470
diff
changeset
|
322 | 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
|
323 | int ret = pwdstore_store(pwdstore, pwfile); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
324 | free(pwfile); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
325 | return ret; |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
326 | } |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
327 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
328 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
329 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
330 | /* |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
331 | Repository* url2repo_s(cxstring url, char **path) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
332 | *path = NULL; |
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 | int s; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
335 | if(cx_strprefix(url, CX_STR("http://"))) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
336 | s = 7; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
337 | } else if(cx_strprefix(url, CX_STR("https://"))) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
338 | s = 8; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
339 | } else { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
340 | s = 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
341 | } |
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 | // split URL into repository and 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
|
344 | cxstring r = cx_strsubs(url, s); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
345 | cxstring p = cx_strchr(r, '/'); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
346 | r = cx_strsubsl(url, 0, url.length-p.length); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
347 | if(p.length == 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
|
348 | p = cx_strn("/", 1); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
349 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
350 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
351 | Repository *repo = get_repository(r); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
352 | if(repo) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
353 | *path = cx_strdup(p).ptr; |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
354 | } else { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
355 | // TODO: who is responsible for freeing this repository? |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
356 | // how can the callee know, if he has to call free()? |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
357 | repo = calloc(1, sizeof(Repository)); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
358 | repo->name = strdup(""); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
359 | repo->decrypt_content = true; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
360 | repo->verification = true; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
361 | repo->authmethods = CURLAUTH_BASIC; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
362 | if(url.ptr[url.length-1] == '/') { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
363 | repo->url = cx_strdup(url).ptr; |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
364 | *path = strdup("/"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
365 | } else if (cx_strchr(url, '/').length > 0) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
366 | // TODO: fix the following workaround after |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
367 | // fixing the inconsistent behavior of util_url_*() |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
368 | repo->url = util_url_base_s(url); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
369 | cxmutstr truncated = cx_strdup(url); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
370 | *path = strdup(util_url_path(truncated.ptr)); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
371 | free(truncated.ptr); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
372 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
373 | repo->url = cx_strdup(url).ptr; |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
374 | *path = strdup("/"); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
375 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
376 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
377 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
378 | return repo; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
379 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
380 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
381 | Repository* url2repo(const char *url, char **path) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
382 | return url2repo_s(cx_str(url), path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
383 | } |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
384 | */ |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
385 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
386 | static int decrypt_secrets(CmdArgs *a, PwdStore *secrets) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
387 | if(cmd_getoption(a, "noinput")) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
388 | return 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
389 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
390 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
391 | char *ps_password = NULL; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
392 | if(secrets->unlock_cmd && strlen(secrets->unlock_cmd) > 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
|
393 | CxBuffer *cmd_out = cxBufferCreate(NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
394 | if(!util_exec_command(secrets->unlock_cmd, cmd_out)) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
395 | // command successful, get first line from output without newline |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
396 | // and use that as password for the secretstore |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
397 | size_t len = 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
398 | for(size_t i=0;i<=cmd_out->size;i++) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
399 | if(i == cmd_out->size || cmd_out->space[i] == '\n') { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
400 | len = i; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
401 | break; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
402 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
403 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
404 | if(len > 0) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
405 | ps_password = malloc(len + 1); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
406 | memcpy(ps_password, cmd_out->space, len); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
407 | ps_password[len] = 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
408 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
409 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
410 | cxBufferFree(cmd_out); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
411 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
412 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
413 | if(!ps_password) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
414 | ps_password = util_password_input("Master password: "); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
415 | if(!ps_password) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
416 | return 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
417 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
418 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
419 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
420 | if(pwdstore_setpassword(secrets, ps_password)) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
421 | fprintf(stderr, "Error: cannot create key from password\n"); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
422 | return 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
423 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
424 | if(pwdstore_decrypt(secrets)) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
425 | fprintf(stderr, "Error: cannot decrypt secrets store\n"); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
426 | return 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
427 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
428 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
429 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
430 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
431 | typedef struct CredLocation { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
432 | char *id; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
433 | char *location; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
434 | } CredLocation; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
435 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
436 | 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
|
437 | 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
|
438 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
439 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
440 | 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
|
441 | // 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
|
442 | free(c->location); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
443 | free(c); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
444 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
445 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
446 | static int get_stored_credentials(CmdArgs *a, char *credid, char **user, char **password) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
447 | if(!credid) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
448 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
449 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
450 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
451 | PwdStore *secrets = get_pwdstore(); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
452 | if(!secrets) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
453 | 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
|
454 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
455 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
456 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
457 | 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
|
458 | if(!secrets->isdecrypted) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
459 | if(decrypt_secrets(a, secrets)) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
460 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
461 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
462 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
463 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
464 | 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
|
465 | if(s_cred) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
466 | *user = s_cred->user; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
467 | *password = s_cred->password; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
468 | return 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
469 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
470 | } else { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
471 | 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
|
472 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
473 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
474 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
475 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
476 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
477 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
478 | static int get_location_credentials(CmdArgs *a, 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
|
479 | PwdStore *secrets = get_pwdstore(); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
480 | if(!secrets) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
481 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
482 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
483 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
484 | /* |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
485 | * 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
|
486 | * 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
|
487 | */ |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
488 | CxList *locations = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)cmp_url_cred_entry, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
489 | locations->simple_destructor = (cx_destructor_func)free_cred_location; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
490 | 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
|
491 | 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
|
492 | 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
|
493 | cx_foreach(char *, loc, entry_iter) { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
494 | cxmutstr rpath; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
495 | 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
|
496 | 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
|
497 | urlentry->id = e->id; |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
498 | 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
|
499 | cxListAdd(locations, urlentry); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
500 | free(rpath.ptr); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
501 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
502 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
503 | // 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
|
504 | cxListSort(locations); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
505 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
506 | // 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
|
507 | 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
|
508 | cxstring req_url = cx_strcast(req_url_proto); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
509 | if(cx_strprefix(req_url, CX_STR("http://"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
510 | req_url = cx_strsubs(req_url, 7); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
511 | } else if(cx_strprefix(req_url, CX_STR("https://"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
512 | 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
|
513 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
514 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
515 | // 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
|
516 | // of the requested url |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
517 | char *id = NULL; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
518 | 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
|
519 | 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
|
520 | 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
|
521 | 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
|
522 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
523 | // remove protocol prefix |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
524 | if(cx_strprefix(cred_url, CX_STR("http://"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
525 | cred_url = cx_strsubs(cred_url, 7); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
526 | } else if(cx_strprefix(cred_url, CX_STR("https://"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
527 | 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
|
528 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
529 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
735
diff
changeset
|
530 | 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
|
531 | id = cred->id; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
532 | break; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
533 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
534 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
535 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
536 | // 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
|
537 | // we can set the user/password |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
538 | if(id && (secrets->isdecrypted || !decrypt_secrets(a, secrets))) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
539 | 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
|
540 | if(cred) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
541 | *user = cred->user; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
542 | *password = cred->password; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
543 | ret = 1; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
544 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
545 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
546 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
547 | free(req_url_proto.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
|
548 | cxListDestroy(locations); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
549 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
550 | return ret; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
551 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
552 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
553 | DavSession* connect_to_repo(DavContext *ctx, DavCfgRepository *repo, const char *path, dav_auth_func authfunc, CmdArgs *a) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
554 | cxmutstr decodedpw = dav_repository_get_decodedpassword(repo); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
555 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
556 | char *user = repo->user.value.ptr; |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
557 | char *password = decodedpw.ptr; |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
558 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
559 | if(!user && !password) { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
560 | if(!get_stored_credentials(a, repo->stored_user.value.ptr, &user, &password)) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
561 | get_location_credentials(a, repo, path, &user, &password); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
562 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
563 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
564 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
565 | DavSession *sn = dav_session_new_auth(ctx, repo->url.value.ptr, user, password); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
566 | if(password) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
567 | free(password); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
568 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
569 | |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
570 | sn->flags = dav_repository_get_flags(repo); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
571 | sn->key = dav_context_get_key(ctx, repo->default_key.value.ptr); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
572 | curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
573 | curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
574 | if(repo->cert.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
575 | curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert.value.ptr); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
576 | } |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
577 | if(!repo->verification.value || cmd_getoption(a, "insecure")) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
578 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
579 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
580 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
581 | if(!cmd_getoption(a, "noinput")) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
582 | dav_session_set_authcallback(sn, authfunc, repo); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
583 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
584 | return sn; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
585 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
586 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
587 | int request_auth(DavSession *sn, void *userdata) { |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
588 | DavCfgRepository *repo = userdata; |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
589 | |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
590 | cxstring user = {NULL, 0}; |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
591 | char ubuf[256]; |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
592 | if(repo->user.value.ptr) { |
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
593 | user = cx_strcast(repo->user.value); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
594 | } else { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
595 | fprintf(stderr, "User: "); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
596 | fflush(stderr); |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
597 | user = cx_str(fgets(ubuf, 256, stdin)); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
598 | } |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
599 | if(!user.ptr) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
600 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
601 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
602 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
603 | char *password = util_password_input("Password: "); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
604 | if(!password || strlen(password) == 0) { |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
605 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
606 | } |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
607 | |
796
81e0f67386a6
remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
795
diff
changeset
|
608 | dav_session_set_auth_s(sn, user, cx_str(password)); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
609 | free(password); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
610 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
611 | return 0; |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
732
diff
changeset
|
612 | } |