]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - util/fptr_wlist.c
Vendor import of Unbound 1.6.1.
[FreeBSD/FreeBSD.git] / util / fptr_wlist.c
1 /*
2  * util/fptr_wlist.c - function pointer whitelists.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  * 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * 
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  * 
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /**
37  * \file
38  *
39  * This file contains functions that check function pointers.
40  * The functions contain a whitelist of known good callback values.
41  * Any other values lead to an error. 
42  *
43  * Due to the listing nature, this file violates all the modularization
44  * boundaries in the program.
45  */
46 #include "config.h"
47 #include "util/fptr_wlist.h"
48 #include "util/mini_event.h"
49 #include "services/outside_network.h"
50 #include "services/mesh.h"
51 #include "services/localzone.h"
52 #include "services/cache/infra.h"
53 #include "services/cache/rrset.h"
54 #include "services/view.h"
55 #include "dns64/dns64.h"
56 #include "iterator/iterator.h"
57 #include "iterator/iter_fwd.h"
58 #include "validator/validator.h"
59 #include "validator/val_anchor.h"
60 #include "validator/val_nsec3.h"
61 #include "validator/val_sigcrypt.h"
62 #include "validator/val_kentry.h"
63 #include "validator/val_neg.h"
64 #include "validator/autotrust.h"
65 #include "util/data/msgreply.h"
66 #include "util/data/packed_rrset.h"
67 #include "util/storage/slabhash.h"
68 #include "util/storage/dnstree.h"
69 #include "util/locks.h"
70 #include "libunbound/libworker.h"
71 #include "libunbound/context.h"
72 #include "libunbound/worker.h"
73 #include "util/tube.h"
74 #include "util/config_file.h"
75 #ifdef UB_ON_WINDOWS
76 #include "winrc/win_svc.h"
77 #endif
78
79 #ifdef WITH_PYTHONMODULE
80 #include "pythonmod/pythonmod.h"
81 #endif
82 #ifdef USE_CACHEDB
83 #include "cachedb/cachedb.h"
84 #endif
85
86 int 
87 fptr_whitelist_comm_point(comm_point_callback_type *fptr)
88 {
89         if(fptr == &worker_handle_request) return 1;
90         else if(fptr == &outnet_udp_cb) return 1;
91         else if(fptr == &outnet_tcp_cb) return 1;
92         else if(fptr == &tube_handle_listen) return 1;
93         return 0;
94 }
95
96 int 
97 fptr_whitelist_comm_point_raw(comm_point_callback_type *fptr)
98 {
99         if(fptr == &tube_handle_listen) return 1;
100         else if(fptr == &tube_handle_write) return 1;
101         else if(fptr == &remote_accept_callback) return 1;
102         else if(fptr == &remote_control_callback) return 1;
103         return 0;
104 }
105
106 int 
107 fptr_whitelist_comm_timer(void (*fptr)(void*))
108 {
109         if(fptr == &pending_udp_timer_cb) return 1;
110         else if(fptr == &outnet_tcptimer) return 1;
111         else if(fptr == &pending_udp_timer_delay_cb) return 1;
112         else if(fptr == &worker_stat_timer_cb) return 1;
113         else if(fptr == &worker_probe_timer_cb) return 1;
114 #ifdef UB_ON_WINDOWS
115         else if(fptr == &wsvc_cron_cb) return 1;
116 #endif
117         return 0;
118 }
119
120 int 
121 fptr_whitelist_comm_signal(void (*fptr)(int, void*))
122 {
123         if(fptr == &worker_sighandler) return 1;
124         return 0;
125 }
126
127 int fptr_whitelist_start_accept(void (*fptr)(void*))
128 {
129         if(fptr == &worker_start_accept) return 1;
130         return 0;
131 }
132
133 int fptr_whitelist_stop_accept(void (*fptr)(void*))
134 {
135         if(fptr == &worker_stop_accept) return 1;
136         return 0;
137 }
138
139 int 
140 fptr_whitelist_event(void (*fptr)(int, short, void *))
141 {
142         if(fptr == &comm_point_udp_callback) return 1;
143         else if(fptr == &comm_point_udp_ancil_callback) return 1;
144         else if(fptr == &comm_point_tcp_accept_callback) return 1;
145         else if(fptr == &comm_point_tcp_handle_callback) return 1;
146         else if(fptr == &comm_timer_callback) return 1;
147         else if(fptr == &comm_signal_callback) return 1;
148         else if(fptr == &comm_point_local_handle_callback) return 1;
149         else if(fptr == &comm_point_raw_handle_callback) return 1;
150         else if(fptr == &tube_handle_signal) return 1;
151         else if(fptr == &comm_base_handle_slow_accept) return 1;
152 #ifdef UB_ON_WINDOWS
153         else if(fptr == &worker_win_stop_cb) return 1;
154 #endif
155         return 0;
156 }
157
158 int 
159 fptr_whitelist_pending_udp(comm_point_callback_type *fptr)
160 {
161         if(fptr == &serviced_udp_callback) return 1;
162         else if(fptr == &worker_handle_reply) return 1;
163         else if(fptr == &libworker_handle_reply) return 1;
164         return 0;
165 }
166
167 int 
168 fptr_whitelist_pending_tcp(comm_point_callback_type *fptr)
169 {
170         if(fptr == &serviced_tcp_callback) return 1;
171         else if(fptr == &worker_handle_reply) return 1;
172         else if(fptr == &libworker_handle_reply) return 1;
173         return 0;
174 }
175
176 int 
177 fptr_whitelist_serviced_query(comm_point_callback_type *fptr)
178 {
179         if(fptr == &worker_handle_service_reply) return 1;
180         else if(fptr == &libworker_handle_service_reply) return 1;
181         return 0;
182 }
183
184 int 
185 fptr_whitelist_rbtree_cmp(int (*fptr) (const void *, const void *))
186 {
187         if(fptr == &mesh_state_compare) return 1;
188         else if(fptr == &mesh_state_ref_compare) return 1;
189         else if(fptr == &addr_tree_compare) return 1;
190         else if(fptr == &local_zone_cmp) return 1;
191         else if(fptr == &local_data_cmp) return 1;
192         else if(fptr == &fwd_cmp) return 1;
193         else if(fptr == &pending_cmp) return 1;
194         else if(fptr == &serviced_cmp) return 1;
195         else if(fptr == &name_tree_compare) return 1;
196         else if(fptr == &order_lock_cmp) return 1;
197         else if(fptr == &codeline_cmp) return 1;
198         else if(fptr == &nsec3_hash_cmp) return 1;
199         else if(fptr == &mini_ev_cmp) return 1;
200         else if(fptr == &anchor_cmp) return 1;
201         else if(fptr == &canonical_tree_compare) return 1;
202         else if(fptr == &context_query_cmp) return 1;
203         else if(fptr == &val_neg_data_compare) return 1;
204         else if(fptr == &val_neg_zone_compare) return 1;
205         else if(fptr == &probetree_cmp) return 1;
206         else if(fptr == &replay_var_compare) return 1;
207         else if(fptr == &view_cmp) return 1;
208         return 0;
209 }
210
211 int 
212 fptr_whitelist_hash_sizefunc(lruhash_sizefunc_type fptr)
213 {
214         if(fptr == &msgreply_sizefunc) return 1;
215         else if(fptr == &ub_rrset_sizefunc) return 1;
216         else if(fptr == &infra_sizefunc) return 1;
217         else if(fptr == &key_entry_sizefunc) return 1;
218         else if(fptr == &rate_sizefunc) return 1;
219         else if(fptr == &ip_rate_sizefunc) return 1;
220         else if(fptr == &test_slabhash_sizefunc) return 1;
221         return 0;
222 }
223
224 int 
225 fptr_whitelist_hash_compfunc(lruhash_compfunc_type fptr)
226 {
227         if(fptr == &query_info_compare) return 1;
228         else if(fptr == &ub_rrset_compare) return 1;
229         else if(fptr == &infra_compfunc) return 1;
230         else if(fptr == &key_entry_compfunc) return 1;
231         else if(fptr == &rate_compfunc) return 1;
232         else if(fptr == &ip_rate_compfunc) return 1;
233         else if(fptr == &test_slabhash_compfunc) return 1;
234         return 0;
235 }
236
237 int 
238 fptr_whitelist_hash_delkeyfunc(lruhash_delkeyfunc_type fptr)
239 {
240         if(fptr == &query_entry_delete) return 1;
241         else if(fptr == &ub_rrset_key_delete) return 1;
242         else if(fptr == &infra_delkeyfunc) return 1;
243         else if(fptr == &key_entry_delkeyfunc) return 1;
244         else if(fptr == &rate_delkeyfunc) return 1;
245         else if(fptr == &ip_rate_delkeyfunc) return 1;
246         else if(fptr == &test_slabhash_delkey) return 1;
247         return 0;
248 }
249
250 int 
251 fptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_type fptr)
252 {
253         if(fptr == &reply_info_delete) return 1;
254         else if(fptr == &rrset_data_delete) return 1;
255         else if(fptr == &infra_deldatafunc) return 1;
256         else if(fptr == &key_entry_deldatafunc) return 1;
257         else if(fptr == &rate_deldatafunc) return 1;
258         else if(fptr == &test_slabhash_deldata) return 1;
259         return 0;
260 }
261
262 int 
263 fptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_type fptr)
264 {
265         if(fptr == NULL) return 1;
266         else if(fptr == &rrset_markdel) return 1;
267         return 0;
268 }
269
270 /** whitelist env->send_query callbacks */
271 int 
272 fptr_whitelist_modenv_send_query(struct outbound_entry* (*fptr)(
273         struct query_info* qinfo, uint16_t flags, int dnssec, int want_dnssec,
274         int nocaps, struct sockaddr_storage* addr, socklen_t addrlen,
275         uint8_t* zone, size_t zonelen, int ssl_upstream, struct module_qstate* q))
276 {
277         if(fptr == &worker_send_query) return 1;
278         else if(fptr == &libworker_send_query) return 1;
279         return 0;
280 }
281
282 int 
283 fptr_whitelist_modenv_detach_subs(void (*fptr)(
284         struct module_qstate* qstate))
285 {
286         if(fptr == &mesh_detach_subs) return 1;
287         return 0;
288 }
289
290 int 
291 fptr_whitelist_modenv_attach_sub(int (*fptr)(
292         struct module_qstate* qstate, struct query_info* qinfo,
293         uint16_t qflags, int prime, int valrec, struct module_qstate** newq))
294 {
295         if(fptr == &mesh_attach_sub) return 1;
296         return 0;
297 }
298
299 int 
300 fptr_whitelist_modenv_kill_sub(void (*fptr)(struct module_qstate* newq))
301 {
302         if(fptr == &mesh_state_delete) return 1;
303         return 0;
304 }
305
306 int 
307 fptr_whitelist_modenv_detect_cycle(int (*fptr)(        
308         struct module_qstate* qstate, struct query_info* qinfo,         
309         uint16_t flags, int prime, int valrec))
310 {
311         if(fptr == &mesh_detect_cycle) return 1;
312         return 0;
313 }
314
315 int 
316 fptr_whitelist_mod_init(int (*fptr)(struct module_env* env, int id))
317 {
318         if(fptr == &iter_init) return 1;
319         else if(fptr == &val_init) return 1;
320         else if(fptr == &dns64_init) return 1;
321 #ifdef WITH_PYTHONMODULE
322         else if(fptr == &pythonmod_init) return 1;
323 #endif
324 #ifdef USE_CACHEDB
325         else if(fptr == &cachedb_init) return 1;
326 #endif
327         return 0;
328 }
329
330 int 
331 fptr_whitelist_mod_deinit(void (*fptr)(struct module_env* env, int id))
332 {
333         if(fptr == &iter_deinit) return 1;
334         else if(fptr == &val_deinit) return 1;
335         else if(fptr == &dns64_deinit) return 1;
336 #ifdef WITH_PYTHONMODULE
337         else if(fptr == &pythonmod_deinit) return 1;
338 #endif
339 #ifdef USE_CACHEDB
340         else if(fptr == &cachedb_deinit) return 1;
341 #endif
342         return 0;
343 }
344
345 int 
346 fptr_whitelist_mod_operate(void (*fptr)(struct module_qstate* qstate,
347         enum module_ev event, int id, struct outbound_entry* outbound))
348 {
349         if(fptr == &iter_operate) return 1;
350         else if(fptr == &val_operate) return 1;
351         else if(fptr == &dns64_operate) return 1;
352 #ifdef WITH_PYTHONMODULE
353         else if(fptr == &pythonmod_operate) return 1;
354 #endif
355 #ifdef USE_CACHEDB
356         else if(fptr == &cachedb_operate) return 1;
357 #endif
358         return 0;
359 }
360
361 int 
362 fptr_whitelist_mod_inform_super(void (*fptr)(
363         struct module_qstate* qstate, int id, struct module_qstate* super))
364 {
365         if(fptr == &iter_inform_super) return 1;
366         else if(fptr == &val_inform_super) return 1;
367         else if(fptr == &dns64_inform_super) return 1;
368 #ifdef WITH_PYTHONMODULE
369         else if(fptr == &pythonmod_inform_super) return 1;
370 #endif
371 #ifdef USE_CACHEDB
372         else if(fptr == &cachedb_inform_super) return 1;
373 #endif
374         return 0;
375 }
376
377 int 
378 fptr_whitelist_mod_clear(void (*fptr)(struct module_qstate* qstate,
379         int id))
380 {
381         if(fptr == &iter_clear) return 1;
382         else if(fptr == &val_clear) return 1;
383         else if(fptr == &dns64_clear) return 1;
384 #ifdef WITH_PYTHONMODULE
385         else if(fptr == &pythonmod_clear) return 1;
386 #endif
387 #ifdef USE_CACHEDB
388         else if(fptr == &cachedb_clear) return 1;
389 #endif
390         return 0;
391 }
392
393 int 
394 fptr_whitelist_mod_get_mem(size_t (*fptr)(struct module_env* env, int id))
395 {
396         if(fptr == &iter_get_mem) return 1;
397         else if(fptr == &val_get_mem) return 1;
398         else if(fptr == &dns64_get_mem) return 1;
399 #ifdef WITH_PYTHONMODULE
400         else if(fptr == &pythonmod_get_mem) return 1;
401 #endif
402 #ifdef USE_CACHEDB
403         else if(fptr == &cachedb_get_mem) return 1;
404 #endif
405         return 0;
406 }
407
408 int 
409 fptr_whitelist_alloc_cleanup(void (*fptr)(void*))
410 {
411         if(fptr == &worker_alloc_cleanup) return 1;
412         return 0;
413 }
414
415 int fptr_whitelist_tube_listen(tube_callback_type* fptr)
416 {
417         if(fptr == &worker_handle_control_cmd) return 1;
418         else if(fptr == &libworker_handle_control_cmd) return 1;
419         return 0;
420 }
421
422 int fptr_whitelist_mesh_cb(mesh_cb_func_type fptr)
423 {
424         if(fptr == &libworker_fg_done_cb) return 1;
425         else if(fptr == &libworker_bg_done_cb) return 1;
426         else if(fptr == &libworker_event_done_cb) return 1;
427         else if(fptr == &probe_answer_cb) return 1;
428         return 0;
429 }
430
431 int fptr_whitelist_print_func(void (*fptr)(char*,void*))
432 {
433         if(fptr == &config_print_func) return 1;
434         else if(fptr == &config_collate_func) return 1;
435         else if(fptr == &remote_get_opt_ssl) return 1;
436         return 0;
437 }
438
439 int fptr_whitelist_inplace_cb_reply_generic(inplace_cb_reply_func_type* fptr,
440         enum inplace_cb_list_type type)
441 {
442 #ifndef WITH_PYTHONMODULE
443         (void)fptr;
444 #endif
445         if(type == inplace_cb_reply) {
446 #ifdef WITH_PYTHONMODULE
447                 if(fptr == &python_inplace_cb_reply_generic) return 1;
448 #endif
449         } else if(type == inplace_cb_reply_cache) {
450 #ifdef WITH_PYTHONMODULE
451                 if(fptr == &python_inplace_cb_reply_generic) return 1;
452 #endif
453         } else if(type == inplace_cb_reply_local) {
454 #ifdef WITH_PYTHONMODULE
455                 if(fptr == &python_inplace_cb_reply_generic) return 1;
456 #endif
457         } else if(type == inplace_cb_reply_servfail) {
458 #ifdef WITH_PYTHONMODULE
459                 if(fptr == &python_inplace_cb_reply_generic) return 1;
460 #endif
461         }
462         return 0;
463 }
464
465 int fptr_whitelist_inplace_cb_query(inplace_cb_query_func_type* ATTR_UNUSED(fptr))
466 {
467         return 0;
468 }