Wed, 28 Dec 2016 12:23:51 +0100
using host header to select virtual server
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
1 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
29 | #include "../public/nsapi.h" |
1 | 30 | |
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
33 | ||
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
34 | #include <fcntl.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
35 | #include <sys/types.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
36 | #include <sys/file.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
37 | #include <sys/stat.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
38 | #include <sys/mman.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
39 | |
92
382bff43c6eb
fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
40 | #include <ucx/string.h> |
99 | 41 | #include <ucx/utils.h> |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
42 | |
1 | 43 | #include "httplistener.h" |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
44 | #include "config.h" |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
45 | #include "func.h" |
28 | 46 | #include "log.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
47 | #include "event.h" |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
48 | #include "threadpools.h" |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
49 | #include "ldap_auth.h" |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
50 | #include "configmanager.h" |
1 | 51 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
52 | #include "vserver.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
53 | #include "../util/pblock.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
54 | #include "../util/util.h" |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
55 | #include "../util/atomic.h" |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
56 | #include "ucx/buffer.h" |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
57 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
58 | pool_handle_t *cfg_pool; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
59 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
60 | // TODO: Funktion für ConfigDirective -> directive |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
61 | // TODO: Funktion für UcxList parameter list -> pblock |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
62 | |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
63 | int load_init_conf(char *file) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
64 | log_ereport(LOG_VERBOSE, "load_init_conf"); |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
65 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
66 | InitConfig *cfg = load_init_config(file); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
67 | if(cfg == NULL) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
68 | log_ereport(LOG_FAILURE, "Cannot load init.conf"); |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
69 | return 1; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
70 | } |
91 | 71 | UcxAllocator *mp = cfg->parser.mp; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
72 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
73 | cfg_pool = pool_create(); // one pool for one Configuration |
91 | 74 | UcxList *dirs = cfg->directives; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
75 | while(dirs != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
76 | ConfigDirective *dir = dirs->data; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
77 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
78 | /* create NSAPI directive */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
79 | directive *d = malloc(sizeof(directive)); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
80 | d->param = pblock_create_pool(cfg_pool, 8); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
81 | UcxList *param = cfg_param_list(dir->value, mp); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
82 | while(param != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
83 | ConfigParam *p = param->data; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
84 | pblock_nvlinsert( |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
85 | p->name.ptr, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
86 | p->name.length, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
87 | p->value.ptr, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
88 | p->value.length, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
89 | d->param); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
90 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
91 | param = param->next; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
92 | } |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
93 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
94 | /* get function */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
95 | char *func_name = pblock_findval("fn", d->param); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
96 | d->func = get_function(func_name); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
97 | if(d->func == NULL) { |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
98 | pblock_free(d->param); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
99 | free(d); |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
100 | //dirs = dirs->next; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
101 | log_ereport( |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
102 | LOG_MISCONFIG, |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
103 | "Cannot find Init function %s", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
104 | func_name); |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
105 | return 1; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
106 | } |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
107 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
108 | /* execute init directive */ |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
109 | int ret = d->func->func(d->param, NULL, NULL); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
110 | if(ret != REQ_PROCEED && ret != REQ_NOACTION) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
111 | log_ereport( |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
112 | LOG_FAILURE, |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
113 | "Error running Init function %s", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
114 | func_name); |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
115 | pblock_free(d->param); |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
116 | free(d); |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
117 | return 1; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
118 | } |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
119 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
120 | pblock_free(d->param); |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
121 | free(d); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
122 | dirs = dirs->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
123 | } |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
124 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
125 | free_init_config(cfg); |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
126 | |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
127 | return 0; |
1 | 128 | } |
129 | ||
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
130 | ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
131 | log_ereport(LOG_VERBOSE, "load_server_conf"); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
132 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
133 | ServerConfig *serverconf = load_server_config(file); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
134 | if(serverconf == NULL) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
135 | log_ereport(LOG_FAILURE, "Cannot load server.conf"); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
136 | } |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
137 | ServerConfiguration *serverconfig = calloc(1, sizeof(ServerConfiguration)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
138 | serverconfig->ref = 1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
139 | serverconfig->pool = pool_create(); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
140 | serverconfig->listeners = NULL; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
141 | serverconfig->host_vs = ucx_map_new(16); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
142 | serverconfig->authdbs = ucx_map_new(16); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
143 | // TODO: init serverconfig stuff |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
144 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
145 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
146 | /* |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
147 | * convert ServerConfig to ServerConfiguration |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
148 | * |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
149 | * its important to do this in the correct order: |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
150 | * LogFile (open log file first to log possible errors) |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
151 | * Runtime |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
152 | * Threadpool |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
153 | * EventHandler |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
154 | * AuthDB |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
155 | * Listener (we set the VirtualServer later) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
156 | * VirtualServer (dependencies: Listener) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
157 | */ |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
158 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
159 | /* |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
160 | * free stuff on error |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
161 | */ |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
162 | |
72 | 163 | // init logfile first |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
164 | UcxList *lfl = ucx_map_sstr_get(serverconf->objects, sstrn("LogFile", 7)); |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
165 | if(lfl != NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
166 | ServerConfigObject *logobj = lfl->data; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
167 | if(logobj == NULL) { |
72 | 168 | // error |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
169 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
170 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
171 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
172 | int ret = cfg_handle_logfile(serverconfig, logobj); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
173 | if(ret != 0) { |
72 | 174 | // cannot initialize log file |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
175 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
176 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
177 | } else { |
72 | 178 | // horrible error |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
179 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
180 | } |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
181 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
182 | UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7)); |
91 | 183 | UCX_FOREACH(elm, list) { |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
184 | ServerConfigObject *scfgobj = elm->data; |
72 | 185 | if(cfg_handle_runtime(serverconfig, scfgobj)) { |
186 | // error | |
187 | return NULL; | |
188 | } | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
189 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
190 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
191 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10)); |
91 | 192 | UCX_FOREACH(elm, list) { |
72 | 193 | if(cfg_handle_threadpool(serverconfig, elm->data)) { |
194 | return NULL; | |
195 | } | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
196 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
197 | // check thread pool config |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
198 | if(check_thread_pool_cfg() != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
199 | /* critical error */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
200 | return NULL; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
201 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
202 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
203 | list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12)); |
91 | 204 | UCX_FOREACH(elm, list) { |
72 | 205 | if(cfg_handle_eventhandler( |
206 | serverconfig, (ServerConfigObject*)elm->data)) { | |
207 | // error | |
208 | return NULL; | |
209 | } | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
210 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
211 | // check event handler config |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
212 | if(check_event_handler_cfg() != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
213 | /* critical error */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
214 | return NULL; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
215 | } |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
216 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
217 | list = ucx_map_sstr_get(serverconf->objects, sstrn("AccessLog", 9)); |
91 | 218 | UCX_FOREACH(elm, list) { |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
219 | ServerConfigObject *scfgobj = elm->data; |
72 | 220 | if(cfg_handle_accesslog(serverconfig, scfgobj)) { |
221 | return NULL; | |
222 | } | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
223 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
224 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
225 | list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6)); |
91 | 226 | UCX_FOREACH(elm, list) { |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
227 | ServerConfigObject *scfgobj = elm->data; |
72 | 228 | if(cfg_handle_authdb(serverconfig, scfgobj)) { |
229 | return NULL; | |
230 | } | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
231 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
232 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
233 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8)); |
91 | 234 | UCX_FOREACH(elm, list) { |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
235 | ServerConfigObject *scfgobj = elm->data; |
72 | 236 | if(cfg_handle_listener(serverconfig, scfgobj)) { |
237 | return NULL; | |
238 | } | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
239 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
240 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
241 | list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13)); |
91 | 242 | UCX_FOREACH(elm, list) { |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
243 | ServerConfigObject *scfgobj = elm->data; |
72 | 244 | if(cfg_handle_vs(serverconfig, scfgobj)) { |
245 | return NULL; | |
246 | } | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
247 | } |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
248 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
249 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
250 | // set VirtualServer for all listeners |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
251 | UcxList *ls = serverconfig->listeners; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
252 | while(ls) { |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
253 | HttpListener *listener = ls->data; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
254 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
255 | sstr_t vsname = sstr(listener->default_vs.vs_name); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
256 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
257 | // search for VirtualServer |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
258 | //int b = 0; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
259 | UcxMapIterator iter = ucx_map_iterator(serverconfig->host_vs); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
260 | VirtualServer *vs; |
88 | 261 | UCX_MAP_FOREACH(key, vs, iter) { |
31 | 262 | if(!sstrcmp(vsname, vs->name)) { |
263 | listener->default_vs.vs = vs; | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
264 | break; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
265 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
266 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
267 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
268 | ls = ls->next; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
269 | } |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
270 | |
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
271 | free_server_config(serverconf); |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
272 | return serverconfig; |
1 | 273 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
274 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
275 | void cfg_ref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
276 | ws_atomic_inc32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
277 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
278 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
279 | void cfg_unref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
280 | uint32_t ref = ws_atomic_dec32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
281 | if(ref == 0) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
282 | // TODO: free configuration |
71 | 283 | printf("free ServerConfiguration %"PRIxPTR"\n", (intptr_t)cfg); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
284 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
285 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
286 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
287 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
288 | void init_server_config_parser() { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
289 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
290 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
291 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
292 | int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) { |
72 | 293 | sstr_t user = cfg_directivelist_get_str(obj->directives, sstr("User")); |
294 | if(user.ptr) { | |
91 | 295 | //cfg->user = sstrdup_pool(cfg->pool, user); |
72 | 296 | } |
297 | sstr_t tmp = cfg_directivelist_get_str(obj->directives, sstr("Temp")); | |
298 | if(tmp.ptr) { | |
299 | cfg->tmp = sstrdup_pool(cfg->pool, tmp); | |
300 | } else { | |
301 | log_ereport(LOG_MISCONFIG, "no temporary directory specified"); | |
302 | return -1; | |
303 | } | |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
304 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
305 | // mime file |
99 | 306 | sstr_t mf = cfg_directivelist_get_str(obj->directives, sstr("MimeFile")); |
307 | sstr_t base = sstr("config/"); | |
308 | sstr_t file = sstrcat(2, base, mf); | |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
309 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
310 | ConfigFile *f = cfgmgr_get_file(file); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
311 | if(f == NULL) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
312 | f = malloc(sizeof(ConfigFile)); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
313 | f->data = NULL; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
314 | f->file = sstrdup(file); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
315 | f->reload = mime_conf_reload; |
88 | 316 | f->last_modified = 0; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
317 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
318 | // load the file content |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
319 | //f->reload(f, cfg); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
320 | if(cfgmgr_reload_file(f, cfg, NULL)) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
321 | free(f->file.ptr); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
322 | free(f); |
99 | 323 | |
324 | free(file.ptr); | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
325 | return -1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
326 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
327 | cfgmgr_attach_file(f); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
328 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
329 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
330 | cfg->mimetypes = f->data; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
331 | |
99 | 332 | free(file.ptr); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
333 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
334 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
335 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
336 | int cfg_handle_logfile(ServerConfiguration *cfg, ServerConfigObject *obj) { |
28 | 337 | sstr_t file = cfg_directivelist_get_str(obj->directives, sstr("File")); |
338 | sstr_t lvl = cfg_directivelist_get_str(obj->directives, sstr("Level")); | |
339 | ||
340 | if(file.ptr == NULL || lvl.ptr == NULL) { | |
341 | /* missing log file parameters */ | |
342 | return -1; | |
343 | } | |
344 | ||
345 | LogConfig logcfg; | |
346 | logcfg.file = sstrdup(file).ptr; | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
347 | logcfg.level = sstrdup(lvl).ptr; |
28 | 348 | /* TODO: stdout, stderr config */ |
349 | ||
350 | int ret = init_log_file(&logcfg); | |
351 | ||
352 | free(logcfg.file); | |
353 | free(logcfg.level); | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
354 | |
28 | 355 | return ret; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
356 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
357 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
358 | int cfg_handle_threadpool(ServerConfiguration *cfg, ServerConfigObject *obj) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
359 | ThreadPoolConfig poolcfg; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
360 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
361 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
362 | poolcfg.max_threads = 8; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
363 | poolcfg.queue_size = 64; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
364 | poolcfg.stack_size = 262144; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
365 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
366 | sstr_t name = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
367 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
368 | sstr("Name")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
369 | sstr_t min = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
370 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
371 | sstr("MinThreads")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
372 | sstr_t max = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
373 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
374 | sstr("MaxThreads")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
375 | sstr_t stack = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
376 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
377 | sstr("StackSize")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
378 | sstr_t queue = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
379 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
380 | sstr("QueueSize")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
381 | // TODO: Type |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
382 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
383 | if(name.length == 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
384 | // TODO: log error |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
385 | return 1; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
386 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
387 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
388 | if(min.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
389 | min = sstrdup(min); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
390 | poolcfg.min_threads = atoi(min.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
391 | free(min.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
392 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
393 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
394 | if(max.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
395 | max = sstrdup(max); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
396 | poolcfg.max_threads = atoi(max.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
397 | free(max.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
398 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
399 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
400 | if(stack.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
401 | stack = sstrdup(stack); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
402 | poolcfg.stack_size = atoi(stack.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
403 | free(stack.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
404 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
405 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
406 | if(queue.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
407 | queue = sstrdup(queue); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
408 | poolcfg.queue_size = atoi(queue.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
409 | free(queue.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
410 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
411 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
412 | create_threadpool(name, &poolcfg); |
70
4e6e812c1d97
fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
413 | |
4e6e812c1d97
fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
414 | return 0; |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
415 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
416 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
417 | int cfg_handle_eventhandler(ServerConfiguration *c, ServerConfigObject *obj) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
418 | EventHandlerConfig evcfg; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
419 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
420 | sstr_t name = cfg_directivelist_get_str(obj->directives, sstr("Name")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
421 | sstr_t threads = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
422 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
423 | sstr("Threads")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
424 | sstr_t isdefault = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
425 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
426 | sstr("Default")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
427 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
428 | evcfg.name = name; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
429 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
430 | sstr_t s = sstrdup(threads); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
431 | evcfg.nthreads = atoi(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
432 | free(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
433 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
434 | evcfg.isdefault = util_getboolean(isdefault.ptr, 0); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
435 | |
72 | 436 | return create_event_handler(&evcfg); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
437 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
438 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
439 | int cfg_handle_accesslog(ServerConfiguration *cfg, ServerConfigObject *obj) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
440 | // TODO: use a name to identify the log file |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
441 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
442 | sstr_t file = cfg_directivelist_get_str(obj->directives, sstr("File")); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
443 | if(file.ptr == NULL) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
444 | return 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
445 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
446 | sstr_t format; |
77 | 447 | format.ptr = NULL; |
448 | format.length = 0; | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
449 | |
77 | 450 | //AccessLog *log = get_access_log(file, format); |
451 | LogFile *log_file = get_access_log_file(file); | |
452 | if(!log_file) { | |
453 | // TODO: error/warning | |
454 | return 0; | |
455 | } | |
456 | AccessLog *log = pool_malloc(cfg->pool, sizeof(AccessLog)); | |
457 | log->file = sstrdup_pool(cfg->pool, file); | |
458 | log->format = format; | |
459 | log->log = log_file; | |
460 | cfg->logfiles = ucx_list_append(cfg->logfiles, log); | |
461 | ||
462 | if(!cfg->default_log) { | |
463 | cfg->default_log = log; | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
464 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
465 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
466 | return 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
467 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
468 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
469 | int cfg_handle_authdb(ServerConfiguration *cfg, ServerConfigObject *obj) { |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
470 | sstr_t name = cfg_directivelist_get_str(obj->directives, sstr("Name")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
471 | sstr_t type = cfg_directivelist_get_str(obj->directives, sstr("Type")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
472 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
473 | if(!sstrcmp(type, sstr("ldap"))) { |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
474 | LDAPConfig conf; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
475 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
476 | sstr_t host = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
477 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
478 | sstr("Host")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
479 | sstr_t port = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
480 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
481 | sstr("Port")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
482 | sstr_t basedn = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
483 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
484 | sstr("BaseDN")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
485 | sstr_t binddn = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
486 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
487 | sstr("BindDN")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
488 | sstr_t basepw = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
489 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
490 | sstr("BindPW")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
491 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
492 | host = sstrdup(host); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
493 | port = sstrdup(port); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
494 | basedn = sstrdup(basedn); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
495 | binddn = sstrdup(binddn); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
496 | basepw = sstrdup(basepw); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
497 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
498 | conf.hostname = host.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
499 | conf.port = atoi(port.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
500 | conf.basedn = basedn.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
501 | conf.binddn = binddn.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
502 | conf.bindpw = basepw.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
503 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
504 | name = sstrdup(name); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
505 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
506 | AuthDB *authdb = create_ldap_authdb(name.ptr, &conf); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
507 | ucx_map_sstr_put(cfg->authdbs, name, authdb); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
508 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
509 | // TODO: create_ldap_authdb should copy the strings |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
510 | /* |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
511 | free(host.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
512 | free(port.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
513 | free(basedn.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
514 | free(binddn.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
515 | free(basepw.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
516 | free(name.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
517 | */ |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
518 | |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
519 | } else if(!sstrcmp(type, sstr("keyfile"))) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
520 | // we only need the file parameter |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
521 | sstr_t file = cfg_directivelist_get_str( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
522 | obj->directives, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
523 | sstr("File")); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
524 | if(file.length == 0) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
525 | log_ereport( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
526 | LOG_MISCONFIG, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
527 | "missing File parameter for keyfile authdb"); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
528 | return 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
529 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
530 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
531 | // load keyfile |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
532 | ConfigFile *f = cfgmgr_get_file(file); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
533 | if(f == NULL) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
534 | f = malloc(sizeof(ConfigFile)); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
535 | f->data = NULL; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
536 | f->file = sstrdup(file); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
537 | f->reload = keyfile_reload; |
88 | 538 | f->last_modified = 0; |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
539 | //f->reload(f, cfg); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
540 | if(cfgmgr_reload_file(f, cfg, NULL)) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
541 | free(f->file.ptr); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
542 | free(f); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
543 | return -1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
544 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
545 | cfgmgr_attach_file(f); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
546 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
547 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
548 | // add keyfile authdb |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
549 | Keyfile *keyfile = f->data; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
550 | keyfile->authdb.name = sstrdup(name).ptr; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
551 | ucx_map_sstr_put(cfg->authdbs, name, keyfile); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
552 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
553 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
554 | return 0; |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
555 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
556 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
557 | int cfg_handle_listener(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
558 | ListenerConfig lc; |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
559 | ZERO(&lc, sizeof(ListenerConfig)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
560 | lc.cfg = cfg; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
561 | lc.port = 8080; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
562 | lc.nacceptors = 1; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
563 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
564 | // TODO: use sstrdup_pool? |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
565 | lc.name = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
566 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
567 | sstr("Name"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
568 | lc.port = atoi(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
569 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
570 | sstr("Port")).ptr); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
571 | lc.vs = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
572 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
573 | sstr("DefaultVS"))); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
574 | lc.threadpool = sstrdup(cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
575 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
576 | sstr("Threadpool"))); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
577 | |
134
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
578 | sstr_t blockingio = cfg_directivelist_get_str( |
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
579 | obj->directives, |
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
580 | sstr("BlockingIO")); |
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
581 | if(blockingio.ptr) { |
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
582 | lc.blockingio = util_getboolean_s(blockingio, WS_FALSE); |
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
583 | } |
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
584 | |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
585 | sstr_t ssl = cfg_directivelist_get_str(obj->directives, S("SSL")); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
586 | if(util_getboolean_s(ssl, WS_FALSE)) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
587 | sstr_t cert = cfg_directivelist_get_str(obj->directives, S("Cert")); |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
588 | sstr_t privkey = cfg_directivelist_get_str(obj->directives, S("Key")); |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
589 | sstr_t chain = cfg_directivelist_get_str(obj->directives, S("CertChain")); |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
590 | sstr_t disableprot = cfg_directivelist_get_str( |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
591 | obj->directives, |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
592 | S("SSLDisableProtocol")); |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
593 | |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
594 | WSBool config_ok = WS_TRUE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
595 | // TODO: log error |
129
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
596 | if(!cert.ptr && !chain.ptr) { |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
597 | log_ereport( |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
598 | LOG_MISCONFIG, |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
599 | "SSL Listener %s: Missing Cert or ChainCert directive", |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
600 | lc.name.ptr); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
601 | config_ok = WS_FALSE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
602 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
603 | if(!privkey.ptr) { |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
604 | log_ereport( |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
605 | LOG_MISCONFIG, |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
606 | "SSL Listener %s: Missing Key directive", |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
607 | lc.name.ptr); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
608 | config_ok = WS_FALSE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
609 | } |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
610 | |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
611 | if(config_ok) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
612 | lc.certfile = cert; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
613 | lc.privkeyfile = privkey; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
614 | lc.chainfile = chain; |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
615 | lc.disable_proto = disableprot; |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
616 | lc.ssl = WS_TRUE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
617 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
618 | } else { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
619 | lc.ssl = WS_FALSE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
620 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
621 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
622 | // TODO: check if all important configs are set |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
623 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
624 | HttpListener *listener = http_listener_create(&lc); |
129
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
625 | if(!listener) { |
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
626 | return 1; |
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
627 | } |
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
628 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
629 | listener->default_vs.vs_name = lc.vs.ptr; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
630 | cfg->listeners = ucx_list_append(cfg->listeners, listener); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
631 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
632 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
633 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
634 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
635 | int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
636 | VirtualServer *vs = vs_new(); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
637 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
638 | vs->name = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
639 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
640 | sstr("Name"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
641 | vs->host = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
642 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
643 | sstr("Host"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
644 | vs->document_root = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
645 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
646 | sstr("DocRoot"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
647 | sstr_t objfile = cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
648 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
649 | sstr("ObjectFile")); |
51 | 650 | sstr_t aclfile = cfg_directivelist_get_str( |
651 | obj->directives, | |
652 | sstr("ACLFile")); | |
653 | ||
654 | // load the object config file | |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
655 | sstr_t base = sstr("config/"); |
99 | 656 | sstr_t file = sstrcat(2, base, objfile); |
657 | file = sstrcat(2, base, objfile); | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
658 | |
51 | 659 | // the file is managed by the configuration manager |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
660 | ConfigFile *f = cfgmgr_get_file(file); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
661 | if(f == NULL) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
662 | f = malloc(sizeof(ConfigFile)); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
663 | f->data = NULL; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
664 | f->file = sstrdup(file); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
665 | f->reload = object_conf_reload; |
88 | 666 | f->last_modified = 0; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
667 | //f->reload(f, cfg); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
668 | if(cfgmgr_reload_file(f, cfg, NULL)) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
669 | free(f->file.ptr); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
670 | free(f); |
99 | 671 | |
672 | free(file.ptr); | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
673 | return -1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
674 | } |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
675 | cfgmgr_attach_file(f); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
676 | } |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
677 | vs->objectfile = sstrdup(file); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
678 | vs->objects = (HTTPObjectConfig*)f->data; |
99 | 679 | free(file.ptr); |
680 | ||
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
681 | |
51 | 682 | // load acl config file |
99 | 683 | file = sstrcat(2, base, aclfile); |
51 | 684 | |
685 | ConfigFile *aclf = cfgmgr_get_file(file); | |
686 | if(aclf == NULL) { | |
687 | aclf = malloc(sizeof(ConfigFile)); | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
688 | aclf->data = NULL; |
51 | 689 | aclf->file = sstrdup(file); |
690 | aclf->reload = acl_conf_reload; | |
88 | 691 | aclf->last_modified = 0; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
692 | //aclf->reload(aclf, cfg); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
693 | if(cfgmgr_reload_file(aclf, cfg, NULL)) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
694 | free(aclf->file.ptr); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
695 | free(aclf); |
99 | 696 | |
697 | free(file.ptr); | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
698 | return -1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
699 | } |
51 | 700 | cfgmgr_attach_file(aclf); |
701 | } | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
702 | vs->acls = aclf->data; |
99 | 703 | free(file.ptr); |
51 | 704 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
705 | // set the access log for the virtual server |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
706 | // TODO: don't use always the default |
77 | 707 | vs->log = cfg->default_log; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
708 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
709 | ucx_map_sstr_put(cfg->host_vs, vs->host, vs); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
710 | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
711 | return 0; |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
712 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
713 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
714 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
715 | int object_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
716 | HTTPObjectConfig *old_conf = file->data; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
717 | file->data = load_obj_conf(file->file.ptr); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
718 | if(old_conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
719 | object_conf_unref(old_conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
720 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
721 | if(file->data) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
722 | return 0; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
723 | } else { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
724 | return 1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
725 | } |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
726 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
727 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
728 | void object_conf_ref(HTTPObjectConfig *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
729 | if(conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
730 | ws_atomic_inc32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
731 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
732 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
733 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
734 | void object_conf_unref(HTTPObjectConfig *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
735 | uint32_t ref = ws_atomic_dec32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
736 | if(ref == 0) { |
71 | 737 | printf("free HTTPObjectConfig %"PRIxPTR"\n", (intptr_t)conf); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
738 | pool_destroy(conf->pool); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
739 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
740 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
741 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
742 | HTTPObjectConfig* load_obj_conf(char *file) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
743 | log_ereport(LOG_VERBOSE, "load_obj_conf"); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
744 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
745 | // new conf function test |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
746 | ObjectConfig *cfg = load_object_config(file); |
91 | 747 | UcxAllocator *mp = cfg->parser.mp; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
748 | if(cfg == NULL) { |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
749 | return NULL; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
750 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
751 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
752 | // create object config |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
753 | pool_handle_t *pool = pool_create(); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
754 | HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
755 | conf->pool = pool; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
756 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
757 | // convert ObjectConfig to HTTPObjectConfig |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
758 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
759 | // add objects |
91 | 760 | conf->nobj = ucx_list_size(cfg->objects); |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
761 | conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*)); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
762 | |
91 | 763 | UcxList *objlist = cfg->objects; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
764 | int i = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
765 | while(objlist != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
766 | ConfigObject *cob = objlist->data; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
767 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
768 | // get name and ppath |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
769 | char *name = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
770 | char *ppath = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
771 | if(cob->name.length > 0) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
772 | name = sstrdup_pool(pool, cob->name).ptr; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
773 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
774 | if(cob->ppath.length > 0) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
775 | ppath = sstrdup_pool(pool, cob->ppath).ptr; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
776 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
777 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
778 | // create and add object |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
779 | httpd_object *obj = object_new(pool, name); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
780 | obj->path = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
781 | |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
782 | conf->objects[i] = obj; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
783 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
784 | // add directives |
133
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
130
diff
changeset
|
785 | for(int j=0;j<NUM_NSAPI_TYPES-1;j++) { |
87b405d61f64
improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
130
diff
changeset
|
786 | UcxList *dirs = cob->directives[j]; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
787 | while(dirs != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
788 | ConfigDirective *cfgdir = dirs->data; |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
789 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
790 | directive *d = pool_malloc(pool, sizeof(directive)); |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
791 | if(cfgdir->condition) { |
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
792 | sstr_t expr = cfgdir->condition->param_str; |
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
793 | d->cond = condition_from_str(pool, expr.ptr, expr.length); |
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
794 | } else { |
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
795 | d->cond = NULL; |
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
796 | } |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
797 | d->param = pblock_create_pool(pool, 8); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
798 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
799 | // add params |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
800 | UcxList *param = cfg_param_list(cfgdir->value, mp); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
801 | while(param != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
802 | ConfigParam *p = param->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
803 | pblock_nvlinsert( |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
804 | p->name.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
805 | p->name.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
806 | p->value.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
807 | p->value.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
808 | d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
809 | param = param->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
810 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
811 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
812 | // get function |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
813 | char *func_name = pblock_findval("fn", d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
814 | d->func = get_function(func_name); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
815 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
816 | dirs = dirs->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
817 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
818 | // add function to dtable |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
819 | object_add_directive(obj, d, cfgdir->type_num); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
820 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
821 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
822 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
823 | // next |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
824 | i++; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
825 | objlist = objlist->next; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
826 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
827 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
828 | free_object_config(cfg); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
829 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
830 | return conf; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
831 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
832 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
833 | int mime_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
834 | MimeConfig *mimecfg = load_mime_config(file->file.ptr); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
835 | MimeMap *old_conf = file->data; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
836 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
837 | MimeMap *mimemap = malloc(sizeof(MimeMap)); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
838 | mimemap->ref = 1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
839 | UcxMap *map = ucx_map_new((mimecfg->ntypes * 3) / 2); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
840 | mimemap->map = map; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
841 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
842 | // add ext type pairs |
91 | 843 | UCX_FOREACH(md, mimecfg->directives) { |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
844 | MimeDirective *d = md->data; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
845 | // add the type for each extension to the map |
91 | 846 | UCX_FOREACH(xl, d->exts) { |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
847 | sstr_t ext = sstr(xl->data); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
848 | sstr_t value = sstrdup(d->type); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
849 | ucx_map_sstr_put(map, ext, value.ptr); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
850 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
851 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
852 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
853 | file->data = mimemap; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
854 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
855 | if(old_conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
856 | mime_conf_unref(old_conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
857 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
858 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
859 | free_mime_config(mimecfg); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
860 | return 0; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
861 | } |
51 | 862 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
863 | void mime_conf_ref(MimeMap *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
864 | if(conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
865 | ws_atomic_inc32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
866 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
867 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
868 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
869 | void mime_conf_unref(MimeMap *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
870 | uint32_t ref = ws_atomic_dec32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
871 | if(ref == 0) { |
71 | 872 | printf("free MimeConfig %"PRIxPTR"\n", (intptr_t)conf); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
873 | UcxMapIterator i = ucx_map_iterator(conf->map); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
874 | char *str; |
88 | 875 | UCX_MAP_FOREACH(key, str, i) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
876 | free(str); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
877 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
878 | ucx_map_free(conf->map); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
879 | free(conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
880 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
881 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
882 | |
51 | 883 | int acl_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
884 | ACLFile *aclfile = load_acl_file(file->file.ptr); | |
885 | ||
886 | ACLData *acldata = acl_data_new(); | |
91 | 887 | UCX_FOREACH(elm, aclfile->namedACLs) { |
51 | 888 | ACLConfig *ac = elm->data; |
889 | ACLList *acl = acl_config_convert(cfg, ac); | |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
890 | log_ereport(LOG_VERBOSE, "add acl: %.*s", (int)ac->id.length, ac->id.ptr); |
51 | 891 | ucx_map_sstr_put(acldata->namedACLs, ac->id, acl); |
892 | } | |
893 | free_acl_file(aclfile); | |
894 | ||
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
895 | ACLData *old_data = file->data; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
896 | file->data = acldata; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
897 | if(old_data) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
898 | acl_data_unref(old_data); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
899 | } |
51 | 900 | |
901 | return 0; | |
902 | } | |
903 | ||
904 | ACLList* acl_config_convert(ServerConfiguration *cfg, ACLConfig *acl) { | |
54 | 905 | WSAcl *acllist = malloc(sizeof(WSAcl)); |
906 | acllist->acl.check = (acl_check_f)wsacl_check; | |
907 | acllist->acl.authdb = NULL; | |
908 | acllist->acl.authprompt = NULL; | |
909 | acllist->acl.isextern = 0; | |
51 | 910 | acllist->ace = NULL; |
911 | acllist->ece = NULL; | |
912 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
913 | if(acl->type.ptr && !sstrcmp(acl->type, sstr("fs"))) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
914 | acllist->acl.isextern = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
915 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
916 | |
51 | 917 | size_t s = ucx_list_size(acl->entries); |
54 | 918 | WSAce **aces = calloc(s, sizeof(WSAce*)); |
919 | WSAce **eces = calloc(s, sizeof(WSAce*)); | |
51 | 920 | int ai = 0; |
921 | int ei = 0; | |
922 | ||
923 | // convert entries | |
91 | 924 | UCX_FOREACH(elm, acl->entries) { |
51 | 925 | ACEConfig *acecfg = elm->data; |
926 | ||
927 | // copy data | |
54 | 928 | WSAce *ace = malloc(sizeof(WSAce)); |
51 | 929 | ace->access_mask = acecfg->access_mask; |
930 | ace->flags = acecfg->flags; | |
931 | ace->type = acecfg->type; | |
932 | ace->who = sstrdup(acecfg->who).ptr; | |
933 | ||
934 | // add the entry to the correct array | |
935 | if(ace->type >= ACL_TYPE_AUDIT) { | |
936 | eces[ei] = ace; | |
937 | ei++; | |
938 | } else { | |
939 | aces[ai] = ace; | |
940 | ai++; | |
941 | } | |
942 | } | |
943 | ||
944 | // create new entrie arrays with perfect fitting size | |
945 | if(ai > 0) { | |
54 | 946 | acllist->ace = calloc(ai, sizeof(WSAce*)); |
51 | 947 | } |
948 | if(ei > 0) { | |
54 | 949 | acllist->ece = calloc(ei, sizeof(WSAce*)); |
51 | 950 | } |
54 | 951 | memcpy(acllist->ace, aces, ai*sizeof(WSAce*)); |
952 | memcpy(acllist->ece, eces, ei*sizeof(WSAce*)); | |
51 | 953 | acllist->acenum = ai; |
954 | acllist->ecenum = ei; | |
955 | ||
956 | free(aces); | |
957 | free(eces); | |
958 | ||
959 | // get authentication information | |
960 | if(acl->authparam) { | |
961 | sstr_t authdb_str = cfg_param_get(acl->authparam, sstr("authdb")); | |
962 | sstr_t prompt_str = cfg_param_get(acl->authparam, sstr("prompt")); | |
963 | ||
964 | if(authdb_str.ptr) { | |
965 | AuthDB *authdb = ucx_map_sstr_get(cfg->authdbs, authdb_str); | |
54 | 966 | acllist->acl.authdb = authdb; |
51 | 967 | if(authdb && prompt_str.ptr) { |
54 | 968 | acllist->acl.authprompt = sstrdup(prompt_str).ptr; |
51 | 969 | } |
970 | } | |
971 | } | |
972 | ||
54 | 973 | return &acllist->acl; |
51 | 974 | } |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
975 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
976 | int keyfile_reload(ConfigFile *file, ServerConfiguration *cfg) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
977 | KeyfileConfig *conf = load_keyfile_config(file->file.ptr); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
978 | if(!conf) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
979 | return 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
980 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
981 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
982 | Keyfile *keyfile = keyfile_new(); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
983 | |
91 | 984 | UCX_FOREACH(elm, conf->users) { |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
985 | KeyfileEntry *user = elm->data; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
986 | keyfile_add_user( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
987 | keyfile, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
988 | user->name, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
989 | user->hashtype, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
990 | user->hashdata, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
991 | user->groups, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
992 | user->numgroups); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
993 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
994 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
995 | free_keyfile_config(conf); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
996 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
997 | Keyfile *old_data = file->data; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
998 | file->data = keyfile; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
999 | if(old_data) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1000 | keyfile_unref(old_data); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1001 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1002 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1003 | return 0; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1004 | } |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1005 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1006 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1007 | sstr_t cfg_load_file(sstr_t file) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1008 | sstr_t r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1009 | r.ptr = NULL; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1010 | r.length = 0; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1011 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1012 | if(!file.ptr) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1013 | return r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1014 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1015 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1016 | sstr_t f = sstrdup(file); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1017 | FILE *in = fopen(f.ptr, "r"); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1018 | if(!in) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1019 | return r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1020 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1021 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1022 | UcxBuffer *buf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1023 | if(!buf) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1024 | fclose(in); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1025 | return r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1026 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1027 | |
135 | 1028 | if(ucx_stream_copy(in, buf, (read_func)fread, (write_func)ucx_buffer_write) == 0) { |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1029 | fclose(in); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1030 | ucx_buffer_free(buf); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1031 | return r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1032 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1033 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1034 | r.ptr = buf->space; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1035 | r.length = buf->pos; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1036 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1037 | free(buf); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1038 | fclose(in); |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1039 | |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1040 | return r; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
1041 | } |