2 * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
9 * THE SOFTWARE IS PROVIDED "AS IS" AND STICHTING NLNET
10 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
11 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
12 * STICHTING NLNET BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
16 * USE OR PERFORMANCE OF THIS SOFTWARE.
18 * The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
19 * conceived and contributed by Rob Butler.
21 * Permission to use, copy, modify, and distribute this software for any
22 * purpose with or without fee is hereby granted, provided that the
23 * above copyright notice and this permission notice appear in all
26 * THE SOFTWARE IS PROVIDED "AS IS" AND ROB BUTLER
27 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
29 * ROB BUTLER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
30 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
31 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
32 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
33 * USE OR PERFORMANCE OF THIS SOFTWARE.
37 * Copyright (C) 1999-2001 Internet Software Consortium.
39 * Permission to use, copy, modify, and distribute this software for any
40 * purpose with or without fee is hereby granted, provided that the above
41 * copyright notice and this permission notice appear in all copies.
43 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
44 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
46 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
47 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
48 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
49 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
50 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
62 #include <dns/result.h>
65 #include <isc/print.h>
66 #include <isc/result.h>
69 #include <named/globals.h>
71 #include <dlz/dlz_stub_driver.h>
73 static dns_sdlzimplementation_t *dlz_stub = NULL;
75 typedef struct config_data {
87 stub_dlz_allnodes(const char *zone, void *driverarg, void *dbdata,
88 dns_sdlzallnodes_t *allnodes)
96 cd = (config_data_t *) dbdata;
98 result = dns_sdlz_putnamedrr(allnodes, cd->myname, "soa", 86400,
99 "web root.localhost. "
100 "0 28800 7200 604800 86400");
101 if (result != ISC_R_SUCCESS)
102 return (ISC_R_FAILURE);
103 result = dns_sdlz_putnamedrr(allnodes, "ns", "ns", 86400, cd->myname);
104 if (result != ISC_R_SUCCESS)
105 return (ISC_R_FAILURE);
106 result = dns_sdlz_putnamedrr(allnodes, cd->myname, "a", 1, cd->myip);
107 if (result != ISC_R_SUCCESS)
108 return (ISC_R_FAILURE);
109 return (ISC_R_SUCCESS);
113 stub_dlz_allowzonexfr(void *driverarg, void *dbdata, const char *name,
120 return ISC_R_SUCCESS;
124 stub_dlz_authority(const char *zone, void *driverarg, void *dbdata,
125 dns_sdlzlookup_t *lookup)
132 cd = (config_data_t *) dbdata;
134 if (strcmp(zone, cd->myzone) == 0) {
135 result = dns_sdlz_putsoa(lookup, cd->myname,
136 "root.localhost.", 0);
137 if (result != ISC_R_SUCCESS)
138 return (ISC_R_FAILURE);
140 result = dns_sdlz_putrr(lookup, "ns", 86400, cd->myname);
141 if (result != ISC_R_SUCCESS)
142 return (ISC_R_FAILURE);
144 return (ISC_R_SUCCESS);
146 return (ISC_R_NOTFOUND);
150 stub_dlz_findzonedb(void *driverarg, void *dbdata, const char *name)
157 cd = (config_data_t *) dbdata;
159 /* Write info message to log */
160 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
161 DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
162 "dlz_stub findzone looking for '%s'", name);
164 if (strcmp(cd->myzone, name) == 0)
165 return (ISC_R_SUCCESS);
167 return (ISC_R_SUCCESS);
172 stub_dlz_lookup(const char *zone, const char *name, void *driverarg,
173 void *dbdata, dns_sdlzlookup_t *lookup)
181 cd = (config_data_t *) dbdata;
183 if (strcmp(name, cd->myname) == 0) {
184 result = dns_sdlz_putrr(lookup, "a", 1, cd->myip);
185 if (result != ISC_R_SUCCESS)
186 return (ISC_R_FAILURE);
188 return (ISC_R_SUCCESS);
190 return (ISC_R_FAILURE);
196 stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
197 void *driverarg, void **dbdata)
205 return (ISC_R_FAILURE);
207 * Write info message to log
209 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
210 DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
211 "Loading '%s' using DLZ_stub driver. "
212 "Zone: %s, Name: %s IP: %s",
213 dlzname, argv[1], argv[2], argv[3]);
215 cd = isc_mem_get(ns_g_mctx, sizeof(config_data_t));
217 return (ISC_R_NOMEMORY);
220 memset(cd, 0, sizeof(config_data_t));
222 cd->myzone = isc_mem_strdup(ns_g_mctx, argv[1]);
223 if (cd->myzone == NULL) {
224 isc_mem_put(ns_g_mctx, cd, sizeof(config_data_t));
225 return (ISC_R_NOMEMORY);
228 cd->myname = isc_mem_strdup(ns_g_mctx, argv[2]);
229 if (cd->myname == NULL) {
230 isc_mem_put(ns_g_mctx, cd, sizeof(config_data_t));
231 isc_mem_free(ns_g_mctx, cd->myzone);
232 return (ISC_R_NOMEMORY);
235 cd->myip = isc_mem_strdup(ns_g_mctx, argv[3]);
236 if (cd->myip == NULL) {
237 isc_mem_put(ns_g_mctx, cd, sizeof(config_data_t));
238 isc_mem_free(ns_g_mctx, cd->myname);
239 isc_mem_free(ns_g_mctx, cd->myzone);
240 return (ISC_R_NOMEMORY);
243 isc_mem_attach(ns_g_mctx, &cd->mctx);
247 return(ISC_R_SUCCESS);
251 stub_dlz_destroy(void *driverarg, void *dbdata)
258 cd = (config_data_t *) dbdata;
261 * Write debugging message to log
263 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
264 DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
265 "Unloading DLZ_stub driver.");
267 isc_mem_free(ns_g_mctx, cd->myzone);
268 isc_mem_free(ns_g_mctx, cd->myname);
269 isc_mem_free(ns_g_mctx, cd->myip);
271 isc_mem_put(mctx, cd, sizeof(config_data_t));
272 isc_mem_detach(&mctx);
275 static dns_sdlzmethods_t dlz_stub_methods = {
282 stub_dlz_allowzonexfr
286 * Wrapper around dns_sdlzregister().
289 dlz_stub_init(void) {
293 * Write debugging message to log
295 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
296 DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
297 "Registering DLZ_stub driver.");
299 result = dns_sdlzregister("dlz_stub", &dlz_stub_methods, NULL,
300 DNS_SDLZFLAG_RELATIVEOWNER |
301 DNS_SDLZFLAG_RELATIVERDATA,
302 ns_g_mctx, &dlz_stub);
303 if (result != ISC_R_SUCCESS) {
304 UNEXPECTED_ERROR(__FILE__, __LINE__,
305 "dns_sdlzregister() failed: %s",
306 isc_result_totext(result));
307 result = ISC_R_UNEXPECTED;
315 * Wrapper around dns_sdlzunregister().
318 dlz_stub_clear(void) {
321 * Write debugging message to log
323 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
324 DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
325 "Unregistering DLZ_stub driver.");
327 if (dlz_stub != NULL)
328 dns_sdlzunregister(&dlz_stub);