1 /* $NetBSD: dlz_stub_driver.c,v 1.5 2014/12/10 04:37:55 christos Exp $ */
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
,
153 dns_clientinfomethods_t
*methods
,
154 dns_clientinfo_t
*clientinfo
)
163 cd
= (config_data_t
*) dbdata
;
165 /* Write info message to log */
166 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
167 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
168 "dlz_stub findzone looking for '%s'", name
);
170 if (strcmp(cd
->myzone
, name
) == 0)
171 return (ISC_R_SUCCESS
);
173 return (ISC_R_NOTFOUND
);
178 stub_dlz_lookup(const char *zone
, const char *name
, void *driverarg
,
179 void *dbdata
, dns_sdlzlookup_t
*lookup
,
180 dns_clientinfomethods_t
*methods
, dns_clientinfo_t
*clientinfo
)
190 cd
= (config_data_t
*) dbdata
;
192 if (strcmp(name
, cd
->myname
) == 0) {
193 result
= dns_sdlz_putrr(lookup
, "a", 1, cd
->myip
);
194 if (result
!= ISC_R_SUCCESS
)
195 return (ISC_R_FAILURE
);
197 return (ISC_R_SUCCESS
);
199 return (ISC_R_FAILURE
);
205 stub_dlz_create(const char *dlzname
, unsigned int argc
, char *argv
[],
206 void *driverarg
, void **dbdata
)
214 return (ISC_R_FAILURE
);
216 * Write info message to log
218 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
219 DNS_LOGMODULE_DLZ
, ISC_LOG_INFO
,
220 "Loading '%s' using DLZ_stub driver. "
221 "Zone: %s, Name: %s IP: %s",
222 dlzname
, argv
[1], argv
[2], argv
[3]);
224 cd
= isc_mem_get(ns_g_mctx
, sizeof(config_data_t
));
226 return (ISC_R_NOMEMORY
);
229 memset(cd
, 0, sizeof(config_data_t
));
231 cd
->myzone
= isc_mem_strdup(ns_g_mctx
, argv
[1]);
232 if (cd
->myzone
== NULL
) {
233 isc_mem_put(ns_g_mctx
, cd
, sizeof(config_data_t
));
234 return (ISC_R_NOMEMORY
);
237 cd
->myname
= isc_mem_strdup(ns_g_mctx
, argv
[2]);
238 if (cd
->myname
== NULL
) {
239 isc_mem_put(ns_g_mctx
, cd
, sizeof(config_data_t
));
240 isc_mem_free(ns_g_mctx
, cd
->myzone
);
241 return (ISC_R_NOMEMORY
);
244 cd
->myip
= isc_mem_strdup(ns_g_mctx
, argv
[3]);
245 if (cd
->myip
== NULL
) {
246 isc_mem_put(ns_g_mctx
, cd
, sizeof(config_data_t
));
247 isc_mem_free(ns_g_mctx
, cd
->myname
);
248 isc_mem_free(ns_g_mctx
, cd
->myzone
);
249 return (ISC_R_NOMEMORY
);
252 isc_mem_attach(ns_g_mctx
, &cd
->mctx
);
256 return(ISC_R_SUCCESS
);
260 stub_dlz_destroy(void *driverarg
, void *dbdata
)
267 cd
= (config_data_t
*) dbdata
;
270 * Write debugging message to log
272 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
273 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
274 "Unloading DLZ_stub driver.");
276 isc_mem_free(ns_g_mctx
, cd
->myzone
);
277 isc_mem_free(ns_g_mctx
, cd
->myname
);
278 isc_mem_free(ns_g_mctx
, cd
->myip
);
280 isc_mem_put(mctx
, cd
, sizeof(config_data_t
));
281 isc_mem_detach(&mctx
);
284 static dns_sdlzmethods_t dlz_stub_methods
= {
291 stub_dlz_allowzonexfr
,
302 * Wrapper around dns_sdlzregister().
305 dlz_stub_init(void) {
309 * Write debugging message to log
311 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
312 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
313 "Registering DLZ_stub driver.");
315 result
= dns_sdlzregister("dlz_stub", &dlz_stub_methods
, NULL
,
316 DNS_SDLZFLAG_RELATIVEOWNER
|
317 DNS_SDLZFLAG_RELATIVERDATA
,
318 ns_g_mctx
, &dlz_stub
);
319 if (result
!= ISC_R_SUCCESS
) {
320 UNEXPECTED_ERROR(__FILE__
, __LINE__
,
321 "dns_sdlzregister() failed: %s",
322 isc_result_totext(result
));
323 result
= ISC_R_UNEXPECTED
;
331 * Wrapper around dns_sdlzunregister().
334 dlz_stub_clear(void) {
337 * Write debugging message to log
339 isc_log_write(dns_lctx
, DNS_LOGCATEGORY_DATABASE
,
340 DNS_LOGMODULE_DLZ
, ISC_LOG_DEBUG(2),
341 "Unregistering DLZ_stub driver.");
343 if (dlz_stub
!= NULL
)
344 dns_sdlzunregister(&dlz_stub
);