dav/config.c

Sun, 28 Feb 2016 11:21:05 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 28 Feb 2016 11:21:05 +0100
changeset 199
f448fc8c9191
parent 198
44054c452de1
child 205
bf756f6c3581
permissions
-rw-r--r--

enabled cert verification

libcurl peer and host verification is now enabled. Also added new configuration elements for repositories. Additional certs can be added with <cert>certfile</cert> and cert verification can be disabled with <verification>false</verification>. Also added a new cmd option to dav to disable verification.

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 *
185
cd42cccee550 updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
4 * Copyright 2016 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>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ucx/map.h>
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
34 #include <errno.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include <libxml/tree.h>
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "config.h"
33
0bbbb0341606 some code cleanup and bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 32
diff changeset
38 #include <libidav/utils.h>
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #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
41 #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
42
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
43 #ifdef _WIN32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
44 #define ENV_HOME getenv("USERPROFILE")
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
45 #else
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
46 #define ENV_HOME getenv("HOME")
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
47 #endif /* _WIN32 */
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
48
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 static UcxMap *repos;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 static UcxMap *keys;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
51 static Proxy *http_proxy;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
52 static Proxy *https_proxy;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
54 int check_config_dir() {
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
55 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
56 int ret = 0;
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
57 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
58 if(errno != EEXIST) {
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
59 ret = 1;
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
60 }
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
61 }
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
62 free(file);
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
63 return ret;
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
64 }
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
65
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
66 static DavContext *context;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
67
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
68 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
69 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
70 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
71 xmlDocSetRootElement(doc, root);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
72 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
73 xmlFreeDoc(doc);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
74 }
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
75
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
76 void load_config(DavContext *ctx) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
77 context = ctx;
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
78 // TODO: free the config somewhere
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 repos = ucx_map_new(16);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 keys = ucx_map_new(16);
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
81 http_proxy = calloc(1, sizeof(Proxy));
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
82 https_proxy = calloc(1, sizeof(Proxy));
8
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
83 if(check_config_dir()) {
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
84 return;
4503498deb22 creates a .dav dir if it doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
85 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
87 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
88
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
89 struct stat s;
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
90 if(stat(file, &s)) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
91 switch(errno) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
92 case ENOENT: {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
93 create_default_config(file);
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
94 break;
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
95 }
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
96 default: {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
97 perror("Cannot load config.xml");
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
98 }
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
99 }
6
9c64d2a3d101 creates an empty configuration file if needed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
100 return;
9c64d2a3d101 creates an empty configuration file if needed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
101 }
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
102
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
103 xmlDoc *doc = xmlReadFile(file, NULL, 0);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 free(file);
142
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
105 if(!doc) {
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
106 fprintf(stderr, "Cannot load config.xml\n");
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
107 return;
0c0ccb7f71ba startup doesn't override broken config.xml anymore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 119
diff changeset
108 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 xmlNode *xml_root = xmlDocGetRootElement(doc);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 xmlNode *node = xml_root->children;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 while(node) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 if(node->type == XML_ELEMENT_NODE) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 if(xstreq(node->name, "repository")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 load_repository(node);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 } else if(xstreq(node->name, "key")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 load_key(node);
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
118 } else if (xstreq(node->name, "http-proxy")) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
119 load_proxy(node, HTTP_PROXY);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
120 } else if (xstreq(node->name, "https-proxy")) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
121 load_proxy(node, HTTPS_PROXY);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 node = node->next;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
9
6aec77cfa95b fixed build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
127 xmlFreeDoc(doc);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
74
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
130 void free_config() {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
131 UcxMapIterator i = ucx_map_iterator(repos);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
132 UcxKey k;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
133 Repository *repo;
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
134 UCX_MAP_FOREACH(k, repo, i) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
135 if(repo->default_key) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
136 free(repo->default_key);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
137 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
138 if(repo->name) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
139 free(repo->name);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
140 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
141 if(repo->password) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
142 free(repo->password);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
143 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
144 if(repo->url) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
145 free(repo->url);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
146 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
147 if(repo->user) {
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
148 free(repo->user);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
149 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
150 free(repo);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
151 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
152 ucx_map_free(repos);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
153
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
154 ucx_map_free(keys);
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
155 }
da079dc0724c fixed many memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 73
diff changeset
156
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
157 Repository* repository_new() {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 Repository *repo = calloc(1, sizeof(Repository));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
159 repo->encrypt_name = false;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
160 repo->encrypt_content = false;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
161 repo->decrypt_name = false;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
162 repo->decrypt_content = true;
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
163 repo->verification = true;
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
164 repo->ssl_version = CURL_SSLVERSION_DEFAULT;
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
165 repo->authmethods = CURLAUTH_BASIC;
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
166 return repo;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
167 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
168
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
169 void load_repository(xmlNode *reponode) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
170 xmlNode *node = reponode->children;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
171 Repository *repo = repository_new();
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 while(node) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 if(node->type == XML_ELEMENT_NODE) {
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
174 char *name = (char*)node->name;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 char *value = util_xml_get_text(node);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
176 if(value) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
177 if(repo_add_config(repo, name, value)) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
178 fprintf(
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
179 stderr,
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
180 "Unkown repository config element: %s\n",
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
181 name);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
182 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 node = node->next;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187
21
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
188 if(!repo->name) {
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
189 fprintf(
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
190 stderr,
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
191 "Cannot load config.xml: missing name for repository.\n");
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
192 fprintf(stderr, "Abort.\n");
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
193 exit(-1);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 }
21
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
195 if(!repo->url) {
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
196 fprintf(
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
197 stderr,
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
198 "Cannot load config.xml: "
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
199 "missing url for repository '%s'.\n", repo->name);
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
200 fprintf(stderr, "Abort.\n");
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
201 exit(-1);
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
202 }
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
203
78935b45e2ce fixed put bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
204 ucx_map_cstr_put(repos, repo->name, repo);
5
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
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
207 int repo_add_config(Repository *repo, char *key, char *value) {
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
208 if(xstreq(key, "name")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
209 repo->name = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
210 } else if(xstreq(key, "url")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
211 repo->url = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
212 } else if(xstreq(key, "user")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
213 repo->user = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
214 } else if(xstreq(key, "password")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
215 repo->password = util_base64decode(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
216 } else if(xstreq(key, "default-key")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
217 repo->default_key = strdup(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
218 } else if(xstreq(key, "full-encryption")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
219 if(util_getboolean(value)) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
220 repo->encrypt_name = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
221 repo->encrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
222 repo->decrypt_name = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
223 repo->decrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
224 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
225 } else if(xstreq(key, "content-encryption")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
226 if(util_getboolean(value)) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
227 repo->encrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
228 repo->decrypt_content = true;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
229 } else {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
230 repo->encrypt_content = false;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
231 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
232 } else if(xstreq(key, "decrypt-content")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
233 repo->decrypt_content = util_getboolean(value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
234 } else if(xstreq(key, "decrypt-name")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
235 repo->decrypt_name = util_getboolean(value);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
236 } else if(xstreq(key, "cert")) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
237 char *configdir = util_concat_path(ENV_HOME, ".dav");
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
238 char *certfile = util_concat_path(configdir, value);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
239 repo->cert = certfile;
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
240 free(configdir);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
241 } else if(xstreq(key, "verification")) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
242 repo->verification = util_getboolean(value);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
243 } else if(xstreq(key, "ssl-version")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
244 if(xstrEQ(value, "TLSv1")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
245 repo->ssl_version = CURL_SSLVERSION_TLSv1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
246 } else if(xstrEQ(value, "SSLv2")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
247 repo->ssl_version = CURL_SSLVERSION_SSLv2;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
248 } else if(xstrEQ(value, "SSLv3")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
249 repo->ssl_version = CURL_SSLVERSION_SSLv3;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
250 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
251 #if LIBCURL_VERSION_MAJOR >= 7
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
252 #if LIBCURL_VERSION_MINOR >= 34
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
253 else if(xstrEQ(value, "TLSv1.0")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
254 repo->ssl_version = CURL_SSLVERSION_TLSv1_0;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
255 } else if(xstrEQ(value, "TLSv1.1")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
256 repo->ssl_version = CURL_SSLVERSION_TLSv1_1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
257 } else if(xstrEQ(value, "TLSv1.2")) {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
258 repo->ssl_version = CURL_SSLVERSION_TLSv1_2;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
259 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
260 #endif
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
261 #endif
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
262 else {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
263 fprintf(stderr, "Unknown ssl version: %s\n", value);
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
264 }
154
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
265 } else if(xstreq(key, "authmethods")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
266 repo->authmethods = CURLAUTH_NONE;
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
267 const char *delims = " ,\r\n";
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
268 char *meths = strdup(value);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
269 char *meth = strtok(meths, delims);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
270 while (meth) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
271 if(xstrEQ(value, "basic")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
272 repo->authmethods |= CURLAUTH_BASIC;
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
273 } else if(xstrEQ(value, "digest")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
274 repo->authmethods |= CURLAUTH_DIGEST;
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
275 } else if(xstrEQ(value, "negotiate")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
276 repo->authmethods |= CURLAUTH_GSSNEGOTIATE;
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
277 } else if(xstrEQ(value, "ntlm")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
278 repo->authmethods |= CURLAUTH_NTLM;
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
279 } else if(xstrEQ(value, "any")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
280 repo->authmethods = CURLAUTH_ANY;
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
281 } else if(xstrEQ(value, "none")) {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
282 /* skip */
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
283 } else {
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
284 fprintf(stderr, "Unknown authentication method: %s\n", value);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
285 }
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
286 meth = strtok(NULL, delims);
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
287 }
3cfb4670d9e6 added possibility to configure authentication methods via coma separated list in config.xml
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
288 free(meths);
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
289 } else {
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
290 return -1;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
291 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
292 return 0;
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
293 }
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
294
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
295 void load_proxy(xmlNode *proxynode, int type) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
296 Proxy *proxy;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
297 const char *stype;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
298 if (type == HTTPS_PROXY) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
299 proxy = https_proxy;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
300 stype = "https";
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
301 } else if (type == HTTP_PROXY) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
302 proxy = http_proxy;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
303 stype = "http";
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
304 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
305
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
306 xmlNode *node = proxynode->children;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
307 while(node) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
308 if(node->type == XML_ELEMENT_NODE) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
309 char *value = util_xml_get_text(node);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
310 if(!value) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
311 // next
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
312 } else if(xstreq(node->name, "url")) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
313 proxy->url = strdup(value);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
314 } else if(xstreq(node->name, "user")) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
315 proxy->user = strdup(value);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
316 } else if(xstreq(node->name, "password")) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
317 proxy->password = util_base64decode(value);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
318 } else if(xstreq(node->name, "no")) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
319 proxy->no = strdup(value);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
320 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
321 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
322 node = node->next;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
323 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
324
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
325 if(!proxy->url) {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
326 fprintf(stderr,
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
327 "Cannot load config.xml: missing url for %s proxy.\n", stype);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
328 fprintf(stderr, "Abort.\n");
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
329 exit(-1);
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
330 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
331 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
332
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 void load_key(xmlNode *keynode) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 xmlNode *node = keynode->children;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 Key *key = calloc(1, sizeof(Key));
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 key->type = KEY_AES256;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
338 int error = 0;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 while(node) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 if(node->type == XML_ELEMENT_NODE) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 char *value = util_xml_get_text(node);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 if(!value) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 // next
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 } else if(xstreq(node->name, "name")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 key->name = strdup(value);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 } else if(xstreq(node->name, "file")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 // load key file
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 sstr_t key_data = load_key_file(value);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 if(key_data.length > 0) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 key->data = key_data.ptr;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 key->length = key_data.length;
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
352 } else {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
353 fprintf(stderr, "Error: Cannot key from file: %s\n", value);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
354 error = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 } else if(xstreq(node->name, "type")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 if(!strcmp(value, "aes128")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 key->type = KEY_AES128;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 } else if(!strcmp(value, "aes256")) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 key->type = KEY_AES256;
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
361 } else if(!strcmp(value, "password")) {
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
362 key->type = KEY_PASSWORD;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 node = node->next;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
370 if(!error && key->name) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
371 error = 0;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 if(key->type == KEY_AES128) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 if(key->length < 16) {
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
374 fprintf(
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
375 stderr,
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
376 "Error: Key %s is too small (%zu < 16)\n",
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
377 key->name,
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
378 key->length);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
379 error = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 key->length = 16;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 if(key->type == KEY_AES256) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 if(key->length < 32) {
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
385 fprintf(
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
386 stderr,
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
387 "Error: Key %s is too small (%zu < 32)\n",
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
388 key->name,
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
389 key->length);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
390 error = 1;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 key->length = 32;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 }
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
394 if(key->type == KEY_PASSWORD) {
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
395 key->length = 0;
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
396 if(key->data) {
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
397 // make sure the pw-key is not loaded from a file
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
398 free(key->data);
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
399 key->data = NULL;
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
400 }
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
401 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
402
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
403 // add key to context
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
404 if(!error) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
405 ucx_map_cstr_put(keys, key->name, key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
406 dav_context_add_key(context, key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
407 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
408 }
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
409
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
410 // cleanup
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
411 if(error) {
147
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
412 if(key->data) {
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
413 free(key->data);
458a8dc68048 added password based keys and fixed crash when keys are missing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
414 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 147
diff changeset
415 free(key);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 sstr_t load_key_file(char *filename) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 sstr_t k;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 k.ptr = NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422 k.length = 0;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424 FILE *file = NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425 if(filename[0] == '/') {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 file = fopen(filename, "r");
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 } else {
32
c9d37bb97ea8 mingw support
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
428 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
429 char *p2 = util_concat_path(path, filename);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 file = fopen(p2, "r");
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 free(path);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 free(p2);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
435 if(!file) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
436 return k;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 char *data = malloc(256);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 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
441 k.ptr = data;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 k.length = r;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 fclose(file);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 return k;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
448 Repository* get_repository(sstr_t name) {
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
449 if(!name.ptr) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 return NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451 }
38
b855f76e965b code cleanup + experimental login prompt
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
452 return ucx_map_sstr_get(repos, name);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
453 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
455 int get_repository_flags(Repository *repo) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
456 int flags = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
457 if(repo->decrypt_content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
458 flags |= DAV_SESSION_DECRYPT_CONTENT;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
459 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
460 if(repo->decrypt_name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
461 flags |= DAV_SESSION_DECRYPT_NAME;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
462 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
463 if(repo->encrypt_content) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
464 flags |= DAV_SESSION_ENCRYPT_CONTENT;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
465 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
466 if(repo->encrypt_name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
467 flags |= DAV_SESSION_ENCRYPT_NAME;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
468 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
469 return flags;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
470 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
471
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
472
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 Key* get_key(char *name) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 if(!name) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 return NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 return ucx_map_cstr_get(keys, name);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 }
36
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
479
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
480 Proxy* get_http_proxy() {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
481 return http_proxy;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
482 }
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
483
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
484 Proxy* get_https_proxy() {
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
485 return https_proxy;
c8755c87ce7f added proxy config
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
486 }
119
451607eeff05 added initial code for config commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
487
194
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
488
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
489 int add_repository(Repository *repo) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
490 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
491 xmlDoc *doc = xmlReadFile(file, NULL, 0);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
492 if(!doc) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
493 free(file);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
494 fprintf(stderr, "Cannot load config.xml\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
495 return 1;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
496 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
497
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
498 xmlNode *root = xmlDocGetRootElement(doc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
499
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
500 xmlNode *repoNode = xmlNewNode(NULL, BAD_CAST "repository");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
501 xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
502 xmlNewTextChild(repoNode, NULL, BAD_CAST "name", BAD_CAST repo->name);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
503 xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
504 xmlNewTextChild(repoNode, NULL, BAD_CAST "url", BAD_CAST repo->url);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
505 xmlNodeAddContent(repoNode, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
506 if(repo->user) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
507 xmlNodeAddContent(repoNode, BAD_CAST "\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
508 xmlNewChild(repoNode, NULL, BAD_CAST "user", BAD_CAST repo->user);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
509 xmlNodeAddContent(repoNode, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
510 if(repo->password) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
511 char *pwenc = util_base64encode(
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
512 repo->password,
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
513 strlen(repo->password));
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
514 xmlNodeAddContent(repoNode, BAD_CAST "\t\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
515 xmlNewTextChild(repoNode, NULL, BAD_CAST "password", BAD_CAST pwenc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
516 free(pwenc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
517 xmlNodeAddContent(repoNode, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
518 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
519 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
520 xmlNodeAddContent(repoNode, BAD_CAST "\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
521
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
522 xmlNodeAddContent(root, "\n\t");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
523 xmlAddChild(root, repoNode);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
524 xmlNodeAddContent(root, BAD_CAST "\n");
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
525
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
526 int ret = 0;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
527 if(xmlSaveFormatFileEnc(file, doc, "UTF-8", 1) == -1) {
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
528 ret = 1;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
529 }
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
530 xmlFreeDoc(doc);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
531 free(file);
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
532
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
533 return ret;
1950f483d3c4 added add-repository command to dav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
534 }
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
535
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
536 int list_repositories() {
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
537 UcxMapIterator i = ucx_map_iterator(repos);
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
538 Repository *repo;
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
539 UCX_MAP_FOREACH(key, repo, i) {
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
540 printf("%s\n", repo->name);
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
541 }
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
542 return 0;
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 194
diff changeset
543 }

mercurial