Annotation of src/external/mpl/bind/dist/contrib/dlz/drivers/dlz_stub_driver.c, Revision 1.2
1.2 ! christos 1: /* $NetBSD: dlz_stub_driver.c,v 1.1.1.6 2014/12/10 03:34:31 christos Exp $ */
1.1 christos 2:
3: /*
4: * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
5: *
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.
10: *
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.
19: *
20: * The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
21: * conceived and contributed by Rob Butler.
22: *
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.
27: *
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.
36: */
37:
38: /*
39: * Copyright (C) 1999-2001, 2016 Internet Systems Consortium, Inc. ("ISC")
40: *
41: * This Source Code Form is subject to the terms of the Mozilla Public
42: * License, v. 2.0. If a copy of the MPL was not distributed with this
43: * file, You can obtain one at http://mozilla.org/MPL/2.0/.
44: */
45:
46: #ifdef DLZ_STUB
47:
48: #include <config.h>
49: #include <stdio.h>
50: #include <string.h>
51: #include <stdlib.h>
52:
53: #include <dns/log.h>
54: #include <dns/sdlz.h>
55: #include <dns/result.h>
56:
57: #include <isc/mem.h>
58: #include <isc/print.h>
59: #include <isc/result.h>
60: #include <isc/util.h>
61:
62: #include <named/globals.h>
63:
64: #include <dlz/dlz_stub_driver.h>
65:
66: static dns_sdlzimplementation_t *dlz_stub = NULL;
67:
68: typedef struct config_data {
69: char *myzone;
70: char *myname;
71: char *myip;
72: isc_mem_t *mctx;
73: } config_data_t;
74:
75: /*
76: * SDLZ methods
77: */
78:
79: static isc_result_t
80: stub_dlz_allnodes(const char *zone, void *driverarg, void *dbdata,
81: dns_sdlzallnodes_t *allnodes)
82: {
83: config_data_t *cd;
84: isc_result_t result;
85:
86: UNUSED(zone);
87: UNUSED(driverarg);
88:
89: cd = (config_data_t *) dbdata;
90:
91: result = dns_sdlz_putnamedrr(allnodes, cd->myname, "soa", 86400,
92: "web root.localhost. "
93: "0 28800 7200 604800 86400");
94: if (result != ISC_R_SUCCESS)
95: return (ISC_R_FAILURE);
96: result = dns_sdlz_putnamedrr(allnodes, "ns", "ns", 86400, cd->myname);
97: if (result != ISC_R_SUCCESS)
98: return (ISC_R_FAILURE);
99: result = dns_sdlz_putnamedrr(allnodes, cd->myname, "a", 1, cd->myip);
100: if (result != ISC_R_SUCCESS)
101: return (ISC_R_FAILURE);
102: return (ISC_R_SUCCESS);
103: }
104:
105: static isc_result_t
106: stub_dlz_allowzonexfr(void *driverarg, void *dbdata, const char *name,
107: const char *client)
108: {
109: UNUSED(driverarg);
110: UNUSED(dbdata);
111: UNUSED(name);
112: UNUSED(client);
113: return ISC_R_SUCCESS;
114: }
115:
116: static isc_result_t
117: stub_dlz_authority(const char *zone, void *driverarg, void *dbdata,
118: dns_sdlzlookup_t *lookup)
119: {
120: isc_result_t result;
121: config_data_t *cd;
122:
123: UNUSED(driverarg);
124:
125: cd = (config_data_t *) dbdata;
126:
127: if (strcmp(zone, cd->myzone) == 0) {
128: result = dns_sdlz_putsoa(lookup, cd->myname,
129: "root.localhost.", 0);
130: if (result != ISC_R_SUCCESS)
131: return (ISC_R_FAILURE);
132:
133: result = dns_sdlz_putrr(lookup, "ns", 86400, cd->myname);
134: if (result != ISC_R_SUCCESS)
135: return (ISC_R_FAILURE);
136:
137: return (ISC_R_SUCCESS);
138: }
139: return (ISC_R_NOTFOUND);
140: }
141:
142: static isc_result_t
143: stub_dlz_findzonedb(void *driverarg, void *dbdata, const char *name,
144: dns_clientinfomethods_t *methods,
145: dns_clientinfo_t *clientinfo)
146: {
147:
148: config_data_t *cd;
149:
150: UNUSED(driverarg);
151: UNUSED(methods);
152: UNUSED(clientinfo);
153:
154: cd = (config_data_t *) dbdata;
155:
156: /* Write info message to log */
157: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
158: DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
159: "dlz_stub findzone looking for '%s'", name);
160:
161: if (strcmp(cd->myzone, name) == 0)
162: return (ISC_R_SUCCESS);
163: else
164: return (ISC_R_NOTFOUND);
165: }
166:
167:
168: static isc_result_t
169: stub_dlz_lookup(const char *zone, const char *name, void *driverarg,
170: void *dbdata, dns_sdlzlookup_t *lookup,
171: dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
172: {
173: isc_result_t result;
174: config_data_t *cd;
175:
176: UNUSED(zone);
177: UNUSED(driverarg);
178: UNUSED(methods);
179: UNUSED(clientinfo);
180:
181: cd = (config_data_t *) dbdata;
182:
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);
187:
188: return (ISC_R_SUCCESS);
189: }
190: return (ISC_R_FAILURE);
191:
192: }
193:
194:
195: static isc_result_t
196: stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
197: void *driverarg, void **dbdata)
198: {
199:
200: config_data_t *cd;
201:
202: UNUSED(driverarg);
203:
204: if (argc < 4)
205: return (ISC_R_FAILURE);
206: /*
207: * Write info message to log
208: */
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]);
214:
215: cd = isc_mem_get(named_g_mctx, sizeof(config_data_t));
216: if ((cd) == NULL) {
217: return (ISC_R_NOMEMORY);
218: }
219:
220: memset(cd, 0, sizeof(config_data_t));
221:
222: cd->myzone = isc_mem_strdup(named_g_mctx, argv[1]);
223: if (cd->myzone == NULL) {
224: isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
225: return (ISC_R_NOMEMORY);
226: }
227:
228: cd->myname = isc_mem_strdup(named_g_mctx, argv[2]);
229: if (cd->myname == NULL) {
230: isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
231: isc_mem_free(named_g_mctx, cd->myzone);
232: return (ISC_R_NOMEMORY);
233: }
234:
235: cd->myip = isc_mem_strdup(named_g_mctx, argv[3]);
236: if (cd->myip == NULL) {
237: isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
238: isc_mem_free(named_g_mctx, cd->myname);
239: isc_mem_free(named_g_mctx, cd->myzone);
240: return (ISC_R_NOMEMORY);
241: }
242:
243: isc_mem_attach(named_g_mctx, &cd->mctx);
244:
245: *dbdata = cd;
246:
247: return(ISC_R_SUCCESS);
248: }
249:
250: static void
251: stub_dlz_destroy(void *driverarg, void *dbdata)
252: {
253: config_data_t *cd;
254: isc_mem_t *mctx;
255:
256: UNUSED(driverarg);
257:
258: cd = (config_data_t *) dbdata;
259:
260: /*
261: * Write debugging message to log
262: */
263: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
264: DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
265: "Unloading DLZ_stub driver.");
266:
267: isc_mem_free(named_g_mctx, cd->myzone);
268: isc_mem_free(named_g_mctx, cd->myname);
269: isc_mem_free(named_g_mctx, cd->myip);
270: mctx = cd->mctx;
271: isc_mem_put(mctx, cd, sizeof(config_data_t));
272: isc_mem_detach(&mctx);
273: }
274:
275: static dns_sdlzmethods_t dlz_stub_methods = {
276: stub_dlz_create,
277: stub_dlz_destroy,
278: stub_dlz_findzonedb,
279: stub_dlz_lookup,
280: stub_dlz_authority,
281: stub_dlz_allnodes,
282: stub_dlz_allowzonexfr,
283: NULL,
284: NULL,
285: NULL,
286: NULL,
287: NULL,
288: NULL,
289: NULL,
290: };
291:
292: /*%
293: * Wrapper around dns_sdlzregister().
294: */
295: isc_result_t
296: dlz_stub_init(void) {
297: isc_result_t result;
298:
299: /*
300: * Write debugging message to log
301: */
302: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
303: DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
304: "Registering DLZ_stub driver.");
305:
306: result = dns_sdlzregister("dlz_stub", &dlz_stub_methods, NULL,
307: DNS_SDLZFLAG_RELATIVEOWNER |
308: DNS_SDLZFLAG_RELATIVERDATA,
309: named_g_mctx, &dlz_stub);
310: if (result != ISC_R_SUCCESS) {
311: UNEXPECTED_ERROR(__FILE__, __LINE__,
312: "dns_sdlzregister() failed: %s",
313: isc_result_totext(result));
314: result = ISC_R_UNEXPECTED;
315: }
316:
317:
318: return result;
319: }
320:
321: /*
322: * Wrapper around dns_sdlzunregister().
323: */
324: void
325: dlz_stub_clear(void) {
326:
327: /*
328: * Write debugging message to log
329: */
330: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
331: DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
332: "Unregistering DLZ_stub driver.");
333:
334: if (dlz_stub != NULL)
335: dns_sdlzunregister(&dlz_stub);
336: }
337:
338: #endif
CVSweb <webmaster@jp.NetBSD.org>