Debian Codegraph @

src/domain.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013-2022 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/param.h>
18 #include <sys/types.h>
19
20 #include <fnmatch.h>
21
22 #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/
23
24 #if !defined(KORE_NO_HTTP)
25 #include "http.h"cxx . . $ `<file>/include/kore/http.h`/
26 #endif
27
28 #if defined(KORE_USE_ACME)
29 #include "acme.h"
30 #endif
31
32 #define KORE_DOMAIN_CACHEcxx . . $ `src/domain.c:32:9`! 16
33
34 static u_int16_tcxx . . $ u_int16_t# domain_idcxx . . $ domain_id. = 0;
35 struct kore_domaincxx . . $ kore_domain# *primary_domcxx . . $ primary_dom. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
36 static struct kore_domaincxx . . $ kore_domain# *cachedcxx . . $ cached.[KORE_DOMAIN_CACHEcxx . . $ `src/domain.c:32:9`!];
37
38 void
39 kore_domain_initcxx . . $ kore_domain_init(49f6e7a06ebc5aa8).(void)
40 {
41 int i;
42
43 for (i = 0; i < KORE_DOMAIN_CACHEcxx . . $ `src/domain.c:32:9`!; i++)
44 cachedcxx . . $ cached.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
45 }
46
47 void
48 kore_domain_cleanupcxx . . $ kore_domain_cleanup(49f6e7a06ebc5aa8).(void)
49 {
50 }
51
52 struct kore_domaincxx . . $ kore_domain# *
53 kore_domain_newcxx . . $ kore_domain_new(59fea26fae744361).(const char *domain)
54 {
55 struct kore_domaincxx . . $ kore_domain# *dom;
56
57 dom = kore_calloccxx . . $ kore_calloc(63a7bf2941bfcd7a).(1, sizeof(*dom));
58 dom->idcxx . . $ kore_domain#id. = domain_idcxx . . $ domain_id.++;
59
60 dom->accesslogcxx . . $ kore_domain#accesslog. = -1;
61 dom->x509_verify_depthcxx . . $ kore_domain#x509_verify_depth. = 1;
62
63 dom->domaincxx . . $ kore_domain#domain. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(domain);
64
65 #if !defined(KORE_NO_HTTP)
66 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&dom->routes);
67 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&dom->redirects);
68 #endif
69
70 if (dom->idcxx . . $ kore_domain#id. < KORE_DOMAIN_CACHEcxx . . $ `src/domain.c:32:9`!) {
71 if (cachedcxx . . $ cached.[dom->idcxx . . $ kore_domain#id.] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
72 fatalcxx . . $ fatal(f6bc48f0426f26ee).("non free domain cache slot");
73 cachedcxx . . $ cached.[dom->idcxx . . $ kore_domain#id.] = dom;
74 }
75
76 if (primary_domcxx . . $ primary_dom. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
77 primary_domcxx . . $ primary_dom. = dom;
78
79 return (dom);
80 }
81
82 int
83 kore_domain_attachcxx . . $ kore_domain_attach(7b0627fda9656f95).(struct kore_domaincxx . . $ kore_domain# *dom, struct kore_servercxx . . $ kore_server# *server)
84 {
85 struct kore_domaincxx . . $ kore_domain# *d;
86
87 if (dom->servercxx . . $ kore_domain#server. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
88 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
89
90 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(d, &server->domains, list) {
91 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(d->domaincxx . . $ kore_domain#domain., dom->domaincxx . . $ kore_domain#domain.))
92 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
93 }
94
95 dom->servercxx . . $ kore_domain#server. = server;
96 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&server->domains, dom, list);
97
98 /* The primary domain should be attached to a TLS context. */
99 if (server->tlscxx . . $ kore_server#tls. == 0 && dom == primary_domcxx . . $ primary_dom.)
100 primary_domcxx . . $ primary_dom. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
101
102 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
103 }
104
105 void
106 kore_domain_freecxx . . $ kore_domain_free(be08e46f67814b96).(struct kore_domaincxx . . $ kore_domain# *dom)
107 {
108 #if !defined(KORE_NO_HTTP)
109 struct kore_routecxx . . $ kore_route# *rt;
110 struct http_redirectcxx . . $ http_redirect# *rdr;
111 #endif
112 if (dom == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
113 return;
114
115 if (primary_domcxx . . $ primary_dom. == dom)
116 primary_domcxx . . $ primary_dom. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
117
118 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&dom->server->domains, dom, list);
119
120 if (dom->domaincxx . . $ kore_domain#domain. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
121 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(dom->domaincxx . . $ kore_domain#domain.);
122
123 kore_tls_domain_cleanupcxx . . $ kore_tls_domain_cleanup(be08e46f67814b96).(dom);
124
125 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(dom->cafilecxx . . $ kore_domain#cafile.);
126 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(dom->certkeycxx . . $ kore_domain#certkey.);
127 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(dom->certfilecxx . . $ kore_domain#certfile.);
128 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(dom->crlfilecxx . . $ kore_domain#crlfile.);
129
130 #if !defined(KORE_NO_HTTP)
131 /* Drop all handlers associated with this domain */
132 while ((rt = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&dom->routes)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
133 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&dom->routes, rt, list);
134 kore_route_freecxx . . $ kore_route_free(7f61c70a4656f6ea).(rt);
135 }
136
137 while ((rdr = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&(dom->redirects))) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
138 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&(dom->redirects), rdr, list);
139 regfreecxx . . $ regfree(b1814a8fd6af504b).(&rdr->rctxcxx . . $ http_redirect#rctx.);
140 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(rdr->targetcxx . . $ http_redirect#target.);
141 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(rdr);
142 }
143 #endif
144 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(dom);
145 }
146
147 void
148 kore_domain_callbackcxx . . $ kore_domain_callback(2a5b70316e33bad0).(void (*cb)(struct kore_domaincxx . . $ kore_domain# *))
149 {
150 struct kore_servercxx . . $ kore_server# *srv;
151 struct kore_domaincxx . . $ kore_domain# *dom;
152
153 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
154 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(dom, &srv->domains, list) {
155 cb(dom);
156 }
157 }
158 }
159
160 struct kore_domaincxx . . $ kore_domain# *
161 kore_domain_lookupcxx . . $ kore_domain_lookup(1312d99c9b0d5185).(struct kore_servercxx . . $ kore_server# *srv, const char *domain)
162 {
163 struct kore_domaincxx . . $ kore_domain# *dom;
164
165 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(dom, &srv->domains, list) {
166 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(dom->domaincxx . . $ kore_domain#domain., domain))
167 return (dom);
168 if (!fnmatchcxx . . $ fnmatch(f0be30763a490cce).(dom->domaincxx . . $ kore_domain#domain., domain, FNM_CASEFOLDcxx . . $ `<external>/16949266674305116258/fnmatch.h:39:10`!))
169 return (dom);
170 }
171
172 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
173 }
174
175 struct kore_domaincxx . . $ kore_domain# *
176 kore_domain_byidcxx . . $ kore_domain_byid(d843cb0e8b808413).(u_int16_tcxx . . $ u_int16_t# id)
177 {
178 struct kore_servercxx . . $ kore_server# *srv;
179 struct kore_domaincxx . . $ kore_domain# *dom;
180
181 if (id < KORE_DOMAIN_CACHEcxx . . $ `src/domain.c:32:9`!)
182 return (cachedcxx . . $ cached.[id]);
183
184 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
185 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(dom, &srv->domains, list) {
186 if (dom->idcxx . . $ kore_domain#id. == id)
187 return (dom);
188 }
189 }
190
191 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
192 }
193
194 /*
195 * Called by the worker processes to close the file descriptor towards
196 * the accesslog as they do not need it locally.
197 */
198 void
199 kore_domain_closelogscxx . . $ kore_domain_closelogs(49f6e7a06ebc5aa8).(void)
200 {
201 struct kore_servercxx . . $ kore_server# *srv;
202 struct kore_domaincxx . . $ kore_domain# *dom;
203
204 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
205 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(dom, &srv->domains, list) {
206 if (dom->accesslogcxx . . $ kore_domain#accesslog. != -1) {
207 (void)closecxx . . $ close(7864480464b09eea).(dom->accesslogcxx . . $ kore_domain#accesslog.);
208 /*
209 * Turn into flag to indicate accesslogs
210 * are active.
211 */
212 dom->accesslogcxx . . $ kore_domain#accesslog. = 1;
213 } else {
214 dom->accesslogcxx . . $ kore_domain#accesslog. = 0;
215 }
216 }
217 }
218 }