etc/services - sync with NetBSD-8
[minix.git] / external / bsd / bind / dist / contrib / dlz / drivers / dlz_stub_driver.c
blob031c17e6f085b52bd2bbbb03df1aef022c84272e
1 /* $NetBSD: dlz_stub_driver.c,v 1.5 2014/12/10 04:37:55 christos Exp $ */
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,
153 dns_clientinfomethods_t *methods,
154 dns_clientinfo_t *clientinfo)
157 config_data_t *cd;
159 UNUSED(driverarg);
160 UNUSED(methods);
161 UNUSED(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);
172 else
173 return (ISC_R_NOTFOUND);
177 static isc_result_t
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)
182 isc_result_t result;
183 config_data_t *cd;
185 UNUSED(zone);
186 UNUSED(driverarg);
187 UNUSED(methods);
188 UNUSED(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);
204 static isc_result_t
205 stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
206 void *driverarg, void **dbdata)
209 config_data_t *cd;
211 UNUSED(driverarg);
213 if (argc < 4)
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));
225 if ((cd) == NULL) {
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);
254 *dbdata = cd;
256 return(ISC_R_SUCCESS);
259 static void
260 stub_dlz_destroy(void *driverarg, void *dbdata)
262 config_data_t *cd;
263 isc_mem_t *mctx;
265 UNUSED(driverarg);
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);
279 mctx = cd->mctx;
280 isc_mem_put(mctx, cd, sizeof(config_data_t));
281 isc_mem_detach(&mctx);
284 static dns_sdlzmethods_t dlz_stub_methods = {
285 stub_dlz_create,
286 stub_dlz_destroy,
287 stub_dlz_findzonedb,
288 stub_dlz_lookup,
289 stub_dlz_authority,
290 stub_dlz_allnodes,
291 stub_dlz_allowzonexfr,
292 NULL,
293 NULL,
294 NULL,
295 NULL,
296 NULL,
297 NULL,
298 NULL,
302 * Wrapper around dns_sdlzregister().
304 isc_result_t
305 dlz_stub_init(void) {
306 isc_result_t result;
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;
327 return result;
331 * Wrapper around dns_sdlzunregister().
333 void
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);
347 #endif