Wed, 19 Jul 2023 20:48:20 +0200
replace printf with log_printf in sync.c
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:
319
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 | #ifndef CONFIG_H |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #define CONFIG_H |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
32 | #include <cx/string.h> |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <stdbool.h> |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
34 | #include <libidav/webdav.h> |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
35 | #include "pwd.h" |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
36 | #include "opt.h" |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #ifdef __cplusplus |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | extern "C" { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #endif |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | typedef struct Repository Repository; |
40
a95ee94b9204
supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
43 | typedef struct DavKey Key; |
36 | 44 | typedef struct Proxy Proxy; |
45 | ||
46 | #define HTTP_PROXY 1 | |
47 | #define HTTPS_PROXY 2 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | enum key_type { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | KEY_AES128 = 0, |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | KEY_AES256, |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | }; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | typedef enum key_type KeyType; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | struct Repository { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | char *name; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | char *url; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | char *user; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | char *password; |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
61 | char *stored_user; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | char *default_key; |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
63 | char *cert; |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
64 | bool verification; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
65 | bool encrypt_content; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
66 | bool encrypt_name; |
606
aa49966e4e85
add new session flags for properties encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
470
diff
changeset
|
67 | bool encrypt_properties; |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
68 | bool decrypt_content; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
69 | bool decrypt_name; |
606
aa49966e4e85
add new session flags for properties encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
470
diff
changeset
|
70 | bool decrypt_properties; |
73
41e88442ad4e
ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
43
diff
changeset
|
71 | int ssl_version; |
154
3cfb4670d9e6
added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents:
119
diff
changeset
|
72 | unsigned long authmethods; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | }; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
74 | |
319
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
75 | int check_config_dir(void); |
2433b5969d44
disables automatic creation of .dav directory in dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
317
diff
changeset
|
76 | |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
77 | char* config_file_path(char *name); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | |
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:
228
diff
changeset
|
79 | int load_config(DavContext *ctx); |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
80 | void free_config(void); |
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
|
81 | int load_repository(const xmlNode *reponode); |
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
|
82 | int load_key(const xmlNode *keynode); |
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
|
83 | int load_proxy(DavProxy*, const xmlNode *proxynode, int type); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
84 | cxmutstr load_key_file(const char *filename); |
317
7eea57f6d847
adds namespace config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
85 | int load_namespace(const xmlNode *node); |
730
83f832e345e0
implement secretstore config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
606
diff
changeset
|
86 | int load_secretstore(const xmlNode *node); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
88 | Repository* repository_new(void); |
119
451607eeff05
added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
75
diff
changeset
|
89 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
90 | Repository* get_repository(cxstring name); |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
91 | int get_repository_flags(Repository *repo); |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
40
diff
changeset
|
92 | DavSession *repository_session(Repository *repo); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
93 | Key* get_key(const char *name); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
95 | int add_repository(Repository *repo); |
398
26fdeed98cd7
adds remove-repository command
Mike Becker <universe@uap-core.de>
parents:
364
diff
changeset
|
96 | int remove_repository(Repository *repo); |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
97 | int list_repositories(void); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
98 | CxIterator get_repositories(void); |
194
1950f483d3c4
added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
99 | |
470
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
100 | PwdStore* get_pwdstore(void); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
101 | int pwdstore_save(PwdStore *pwdstore); |
6bf798ad3aec
adds encrypted password store
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
398
diff
changeset
|
102 | |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
103 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
104 | Repository* url2repo_s(cxstring url, char **path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
105 | Repository* url2repo(const char *url, char **path); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
106 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
107 | DavSession* connect_to_repo(DavContext *ctx, Repository *repo, char *path, dav_auth_func authfunc, CmdArgs *a); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
108 | |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
109 | int request_auth(DavSession *sn, void *userdata); |
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
730
diff
changeset
|
110 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | #ifdef __cplusplus |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | #endif |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | #endif /* CONFIG_H */ |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 |