No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / contrib / dlz / drivers / dlz_stub_driver.c
blob15552968a93956989bb2decda1dd7d46e8b68b0e
1 /* $NetBSD$ */
3 /*
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
9 * copies.
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
26 * copies.
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.
55 #ifdef DLZ_STUB
57 #include <config.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include <stdlib.h>
62 #include <dns/log.h>
63 #include <dns/sdlz.h>
64 #include <dns/result.h>
66 #include <isc/mem.h>
67 #include <isc/print.h>
68 #include <isc/result.h>
69 #include <isc/util.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 {
78 char *myzone;
79 char *myname;
80 char *myip;
81 isc_mem_t *mctx;
82 } config_data_t;
85 * SDLZ methods
88 static isc_result_t
89 stub_dlz_allnodes(const char *zone, void *driverarg, void *dbdata,
90 dns_sdlzallnodes_t *allnodes)
92 config_data_t *cd;
93 isc_result_t result;
95 UNUSED(zone);
96 UNUSED(driverarg);
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);
114 static isc_result_t
115 stub_dlz_allowzonexfr(void *driverarg, void *dbdata, const char *name,
116 const char *client)
118 UNUSED(driverarg);
119 UNUSED(dbdata);
120 UNUSED(name);
121 UNUSED(client);
122 return ISC_R_SUCCESS;
125 static isc_result_t
126 stub_dlz_authority(const char *zone, void *driverarg, void *dbdata,
127 dns_sdlzlookup_t *lookup)
129 isc_result_t result;
130 config_data_t *cd;
132 UNUSED(driverarg);
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);
151 static isc_result_t
152 stub_dlz_findzonedb(void *driverarg, void *dbdata, const char *name)
155 config_data_t *cd;
157 UNUSED(driverarg);
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);
168 else
169 return (ISC_R_SUCCESS);
173 static isc_result_t
174 stub_dlz_lookup(const char *zone, const char *name, void *driverarg,
175 void *dbdata, dns_sdlzlookup_t *lookup)
177 isc_result_t result;
178 config_data_t *cd;
180 UNUSED(zone);
181 UNUSED(driverarg);
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);
197 static isc_result_t
198 stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
199 void *driverarg, void **dbdata)
202 config_data_t *cd;
204 UNUSED(driverarg);
206 if (argc < 4)
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));
218 if ((cd) == NULL) {
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);
247 *dbdata = cd;
249 return(ISC_R_SUCCESS);
252 static void
253 stub_dlz_destroy(void *driverarg, void *dbdata)
255 config_data_t *cd;
256 isc_mem_t *mctx;
258 UNUSED(driverarg);
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);
272 mctx = cd->mctx;
273 isc_mem_put(mctx, cd, sizeof(config_data_t));
274 isc_mem_detach(&mctx);
277 static dns_sdlzmethods_t dlz_stub_methods = {
278 stub_dlz_create,
279 stub_dlz_destroy,
280 stub_dlz_findzonedb,
281 stub_dlz_lookup,
282 stub_dlz_authority,
283 stub_dlz_allnodes,
284 stub_dlz_allowzonexfr
288 * Wrapper around dns_sdlzregister().
290 isc_result_t
291 dlz_stub_init(void) {
292 isc_result_t result;
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;
313 return result;
317 * Wrapper around dns_sdlzunregister().
319 void
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);
333 #endif