4 * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the
8 * above copyright notice and this permission notice appear in all
11 * THE SOFTWARE IS PROVIDED "AS IS" AND STICHTING NLNET
12 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
13 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14 * STICHTING NLNET BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
15 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
16 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
18 * USE OR PERFORMANCE OF THIS SOFTWARE.
20 * The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
21 * conceived and contributed by Rob Butler.
23 * Permission to use, copy, modify, and distribute this software for any
24 * purpose with or without fee is hereby granted, provided that the
25 * above copyright notice and this permission notice appear in all
28 * THE SOFTWARE IS PROVIDED "AS IS" AND ROB BUTLER
29 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
31 * ROB BUTLER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
32 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
33 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
34 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
35 * USE OR PERFORMANCE OF THIS SOFTWARE.
39 * Copyright (C) 1999-2001 Internet Software Consortium.
41 * Permission to use, copy, modify, and distribute this software for any
42 * purpose with or without fee is hereby granted, provided that the above
43 * copyright notice and this permission notice appear in all copies.
45 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
46 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
48 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
49 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
50 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
51 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
52 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
64 #include <dns/result.h>
67 #include <isc/print.h>
68 #include <isc/result.h>
71 #include <named/globals.h>
73 #include <dlz/dlz_stub_driver.h>
75 static dns_sdlzimplementation_t
*dlz_stub
= NULL
;
77 typedef struct config_data
{
89 stub_dlz_allnodes(const char *zone
, void *driverarg
, void *dbdata
,
90 dns_sdlzallnodes_t
*allnodes
)
98 cd
= (config_data_t
*) dbdata
;
100 result
= dns_sdlz_putnamedrr(allnodes
, cd
->myname
, "soa", 86400,
101 "web root.localhost. "
102 "0 28800 7200 604800 86400");
103 if (result
!= ISC_R_SUCCESS
)
104 return (ISC_R_FAILURE
);
105 result
= dns_sdlz_putnamedrr(allnodes
, "ns", "ns", 86400, cd
->myname
);
106 if (result
!= ISC_R_SUCCESS
)
107 return (ISC_R_FAILURE
);
108 result
= dns_sdlz_putnamedrr(allnodes
, cd
->myname
, "a", 1, cd
->myip
);
109 if (result
!= ISC_R_SUCCESS
)
110 return (ISC_R_FAILURE
);
111 return (ISC_R_SUCCESS
);
115 stub_dlz_allowzonexfr(void *driverarg
, void *dbdata
, const char *name
,
122 return ISC_R_SUCCESS
;
126 stub_dlz_authority(const char *zone
, void *driverarg
, void *dbdata
,
127 dns_sdlzlookup_t
*lookup
)
134 cd
= (config_data_t
*) dbdata
;
136 if (strcmp(zone
, cd
->myzone
) == 0) {
137 result
= dns_sdlz_putsoa(lookup
, cd
->myname
,
138 "root.localhost.", 0);
139 if (result
!= ISC_R_SUCCESS
)
140 return (ISC_R_FAILURE
);
142 result
= dns_sdlz_putrr(lookup
, "ns", 86400, cd
->myname
);
143 if (result
!= ISC_R_SUCCESS
)
144 return (ISC_R_FAILURE
);
146 return (ISC_R_SUCCESS
);
148 return (ISC_R_NOTFOUND
);
152 stub_dlz_findzonedb(void *driverarg
, void *dbdata
, const char *name
)
159 cd
= (config_data_t
*) dbdata
;
161 /* Write info message to log */
162 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
163 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
164 "dlz_stub findzone looking for '%s'", name
);
166 if (strcmp(cd
->myzone
, name
) == 0)
167 return (ISC_R_SUCCESS
);
169 return (ISC_R_SUCCESS
);
174 stub_dlz_lookup(const char *zone
, const char *name
, void *driverarg
,
175 void *dbdata
, dns_sdlzlookup_t
*lookup
)
183 cd
= (config_data_t
*) dbdata
;
185 if (strcmp(name
, cd
->myname
) == 0) {
186 result
= dns_sdlz_putrr(lookup
, "a", 1, cd
->myip
);
187 if (result
!= ISC_R_SUCCESS
)
188 return (ISC_R_FAILURE
);
190 return (ISC_R_SUCCESS
);
192 return (ISC_R_FAILURE
);
198 stub_dlz_create(const char *dlzname
, unsigned int argc
, char *argv
[],
199 void *driverarg
, void **dbdata
)
207 return (ISC_R_FAILURE
);
209 * Write info message to log
211 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
212 DNS_LOGMODULE_DLZ
, ISC_LOG_INFO
,
213 "Loading '%s' using DLZ_stub driver. "
214 "Zone: %s, Name: %s IP: %s",
215 dlzname
, argv
[1], argv
[2], argv
[3]);
217 cd
= isc_mem_get(ns_g_mctx
, sizeof(config_data_t
));
219 return (ISC_R_NOMEMORY
);
222 memset(cd
, 0, sizeof(config_data_t
));
224 cd
->myzone
= isc_mem_strdup(ns_g_mctx
, argv
[1]);
225 if (cd
->myzone
== NULL
) {
226 isc_mem_put(ns_g_mctx
, cd
, sizeof(config_data_t
));
227 return (ISC_R_NOMEMORY
);
230 cd
->myname
= isc_mem_strdup(ns_g_mctx
, argv
[2]);
231 if (cd
->myname
== NULL
) {
232 isc_mem_put(ns_g_mctx
, cd
, sizeof(config_data_t
));
233 isc_mem_free(ns_g_mctx
, cd
->myzone
);
234 return (ISC_R_NOMEMORY
);
237 cd
->myip
= isc_mem_strdup(ns_g_mctx
, argv
[3]);
238 if (cd
->myip
== NULL
) {
239 isc_mem_put(ns_g_mctx
, cd
, sizeof(config_data_t
));
240 isc_mem_free(ns_g_mctx
, cd
->myname
);
241 isc_mem_free(ns_g_mctx
, cd
->myzone
);
242 return (ISC_R_NOMEMORY
);
245 isc_mem_attach(ns_g_mctx
, &cd
->mctx
);
249 return(ISC_R_SUCCESS
);
253 stub_dlz_destroy(void *driverarg
, void *dbdata
)
260 cd
= (config_data_t
*) dbdata
;
263 * Write debugging message to log
265 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
266 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
267 "Unloading DLZ_stub driver.");
269 isc_mem_free(ns_g_mctx
, cd
->myzone
);
270 isc_mem_free(ns_g_mctx
, cd
->myname
);
271 isc_mem_free(ns_g_mctx
, cd
->myip
);
273 isc_mem_put(mctx
, cd
, sizeof(config_data_t
));
274 isc_mem_detach(&mctx
);
277 static dns_sdlzmethods_t dlz_stub_methods
= {
284 stub_dlz_allowzonexfr
288 * Wrapper around dns_sdlzregister().
291 dlz_stub_init(void) {
295 * Write debugging message to log
297 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
298 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
299 "Registering DLZ_stub driver.");
301 result
= dns_sdlzregister("dlz_stub", &dlz_stub_methods
, NULL
,
302 DNS_SDLZFLAG_RELATIVEOWNER
|
303 DNS_SDLZFLAG_RELATIVERDATA
,
304 ns_g_mctx
, &dlz_stub
);
305 if (result
!= ISC_R_SUCCESS
) {
306 UNEXPECTED_ERROR(__FILE__
, __LINE__
,
307 "dns_sdlzregister() failed: %s",
308 isc_result_totext(result
));
309 result
= ISC_R_UNEXPECTED
;
317 * Wrapper around dns_sdlzunregister().
320 dlz_stub_clear(void) {
323 * Write debugging message to log
325 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
326 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
327 "Unregistering DLZ_stub driver.");
329 if (dlz_stub
!= NULL
)
330 dns_sdlzunregister(&dlz_stub
);