1 /*------------------------------------------------------------------------------
2 *
3 * Copyright (c) 2011-2021, EURid vzw. All rights reserved.
4 * The YADIFA TM software product is provided under the BSD 3-clause license:
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * 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 * * Neither the name of EURid nor the names of its contributors may be
16 * used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 *------------------------------------------------------------------------------
32 *
33 */
34
35 /** @defgroup dnsdbzone Zone related functions
36 * @ingroup dnsdb
37 * @brief Functions used to manipulate a zone
38 *
39 * Functions used to manipulate a zone
40 *
41 * @{
42 */
43
44 #include "dnsdb/dnsdb-config.h"
45 #include <dnscore/dnsname.h>
46
47 #include "dnsdb/dictionary.h"
48
49 #if HAS_NSEC3_SUPPORT
50 #include "dnsdb/nsec3_types.h"
51 #include "dnsdb/nsec3_item.h"
52 #endif
53
54 #include "dnsdb/zdb_zone.h"
55 #include "dnsdb/zdb_zone_process.h"
56
57 static ya_result
zdb_zone_process_label_children(zdb_zone_process_label_callback_parms * parms)58 zdb_zone_process_label_children(zdb_zone_process_label_callback_parms *parms)
59 {
60 ya_result return_code = SUCCESS;
61
62 dictionary_iterator iter;
63 dictionary_iterator_init(&parms->rr_label->sub, &iter);
64 while(dictionary_iterator_hasnext(&iter))
65 {
66 zdb_rr_label** sub_labelp = (zdb_rr_label**)dictionary_iterator_next(&iter);
67
68 dnsname_stack_push_label(&parms->fqdn_stack, &(*sub_labelp)->name[0]);
69
70 parms->rr_label = *sub_labelp;
71
72 return_code = parms->cb(parms);
73
74 if((FAIL(return_code) || return_code == ZDB_ZONE_PROCESS_STOP))
75 {
76 break;
77 }
78
79 return_code = zdb_zone_process_label_children(parms);
80
81 if((FAIL(return_code) || return_code == ZDB_ZONE_PROCESS_STOP))
82 {
83 break;
84 }
85
86 dnsname_stack_pop_label(&parms->fqdn_stack);
87 }
88
89 return return_code;
90 }
91
92 ya_result
zdb_zone_process_all_labels_from_zone(zdb_zone * zone,zdb_zone_process_label_callback * cb,void * args)93 zdb_zone_process_all_labels_from_zone(zdb_zone *zone, zdb_zone_process_label_callback *cb, void *args)
94 {
95 yassert(zdb_zone_islocked(zone));
96
97 ya_result ret;
98
99 if(zone != NULL)
100 {
101 if(zone->apex != NULL)
102 {
103 zdb_zone_process_label_callback_parms parms;
104 parms.cb = cb;
105 parms.zone = zone;
106 parms.args = args;
107
108 if(ISOK(ret = dnsname_to_dnsname_stack(zone->origin, &parms.fqdn_stack)))
109 {
110 parms.rr_label = zone->apex;
111
112 ret = cb(&parms);
113
114 if(!(FAIL(ret) || ret == ZDB_ZONE_PROCESS_STOP))
115 {
116 zdb_zone_process_label_children(&parms);
117 }
118 }
119 }
120 else
121 {
122 ret = INVALID_STATE_ERROR;
123 }
124 }
125 else
126 {
127 ret = UNEXPECTED_NULL_ARGUMENT_ERROR;
128 }
129
130 return ret;
131 }
132
133 /**
134 @}
135 */
136