]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bind9/bin/named/config.c
Copy device support from head in to 6
[FreeBSD/FreeBSD.git] / contrib / bind9 / bin / named / config.c
1 /*
2  * Copyright (C) 2004, 2006-2008  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2001-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: config.c,v 1.11.2.4.8.36.4.3 2008/07/23 23:47:49 tbox Exp $ */
19
20 #include <config.h>
21
22 #include <stdlib.h>
23
24 #include <isc/buffer.h>
25 #include <isc/log.h>
26 #include <isc/mem.h>
27 #include <isc/region.h>
28 #include <isc/result.h>
29 #include <isc/sockaddr.h>
30 #include <isc/string.h>
31 #include <isc/util.h>
32
33 #include <isccfg/namedconf.h>
34
35 #include <dns/fixedname.h>
36 #include <dns/name.h>
37 #include <dns/rdataclass.h>
38 #include <dns/rdatatype.h>
39 #include <dns/tsig.h>
40 #include <dns/zone.h>
41
42 #include <named/config.h>
43 #include <named/globals.h>
44
45 static char defaultconf[] = "\
46 options {\n\
47 #       blackhole {none;};\n"
48 #ifndef WIN32
49 "       coresize default;\n\
50         datasize default;\n\
51         files unlimited;\n\
52         stacksize default;\n"
53 #endif
54 "       deallocate-on-exit true;\n\
55 #       directory <none>\n\
56         dump-file \"named_dump.db\";\n\
57         fake-iquery no;\n\
58         has-old-clients false;\n\
59         heartbeat-interval 60;\n\
60         host-statistics no;\n\
61         interface-interval 60;\n\
62         listen-on {any;};\n\
63         listen-on-v6 {none;};\n\
64         match-mapped-addresses no;\n\
65         memstatistics-file \"named.memstats\";\n\
66         multiple-cnames no;\n\
67 #       named-xfer <obsolete>;\n\
68 #       pid-file \"" NS_LOCALSTATEDIR "/named.pid\"; /* or /lwresd.pid */\n\
69         port 53;\n\
70         recursing-file \"named.recursing\";\n\
71 "
72 #ifdef PATH_RANDOMDEV
73 "\
74         random-device \"" PATH_RANDOMDEV "\";\n\
75 "
76 #endif
77 "\
78         recursive-clients 1000;\n\
79         rrset-order {order cyclic;};\n\
80         serial-queries 20;\n\
81         serial-query-rate 20;\n\
82         server-id none;\n\
83         statistics-file \"named.stats\";\n\
84         statistics-interval 60;\n\
85         tcp-clients 100;\n\
86         tcp-listen-queue 3;\n\
87 #       tkey-dhkey <none>\n\
88 #       tkey-gssapi-credential <none>\n\
89 #       tkey-domain <none>\n\
90         transfers-per-ns 2;\n\
91         transfers-in 10;\n\
92         transfers-out 10;\n\
93         treat-cr-as-space true;\n\
94         use-id-pool true;\n\
95         use-ixfr true;\n\
96         edns-udp-size 4096;\n\
97         reserved-sockets 512;\n\
98 \n\
99         /* view */\n\
100         allow-notify {none;};\n\
101         allow-update-forwarding {none;};\n\
102         allow-recursion {any;};\n\
103 #       allow-v6-synthesis <obsolete>;\n\
104 #       sortlist <none>\n\
105 #       topology <none>\n\
106         auth-nxdomain false;\n\
107         minimal-responses false;\n\
108         recursion true;\n\
109         provide-ixfr true;\n\
110         request-ixfr true;\n\
111         fetch-glue no;\n\
112         rfc2308-type1 no;\n\
113         additional-from-auth true;\n\
114         additional-from-cache true;\n\
115         query-source address *;\n\
116         query-source-v6 address *;\n\
117         notify-source *;\n\
118         notify-source-v6 *;\n\
119         cleaning-interval 60;\n\
120         min-roots 2;\n\
121         lame-ttl 600;\n\
122         max-ncache-ttl 10800; /* 3 hours */\n\
123         max-cache-ttl 604800; /* 1 week */\n\
124         transfer-format many-answers;\n\
125         max-cache-size 0;\n\
126         check-names master fail;\n\
127         check-names slave warn;\n\
128         check-names response ignore;\n\
129         dnssec-enable no; /* Make yes for 9.4. */ \n\
130 "
131
132 "       /* zone */\n\
133         allow-query {any;};\n\
134         allow-transfer {any;};\n\
135         notify yes;\n\
136 #       also-notify <none>\n\
137         dialup no;\n\
138 #       forward <none>\n\
139 #       forwarders <none>\n\
140         maintain-ixfr-base no;\n\
141 #       max-ixfr-log-size <obsolete>\n\
142         transfer-source *;\n\
143         transfer-source-v6 *;\n\
144         alt-transfer-source *;\n\
145         alt-transfer-source-v6 *;\n\
146         max-transfer-time-in 120;\n\
147         max-transfer-time-out 120;\n\
148         max-transfer-idle-in 60;\n\
149         max-transfer-idle-out 60;\n\
150         max-retry-time 1209600; /* 2 weeks */\n\
151         min-retry-time 500;\n\
152         max-refresh-time 2419200; /* 4 weeks */\n\
153         min-refresh-time 300;\n\
154         multi-master no;\n\
155         sig-validity-interval 30; /* days */\n\
156         zone-statistics false;\n\
157         max-journal-size unlimited;\n\
158         ixfr-from-differences false;\n\
159 };\n\
160 "
161
162 "#\n\
163 #  Zones in the \"_bind\" view are NOT counted in the count of zones.\n\
164 #\n\
165 view \"_bind\" chaos {\n\
166         recursion no;\n\
167         notify no;\n\
168 \n\
169         zone \"version.bind\" chaos {\n\
170                 type master;\n\
171                 database \"_builtin version\";\n\
172         };\n\
173 \n\
174         zone \"hostname.bind\" chaos {\n\
175                 type master;\n\
176                 database \"_builtin hostname\";\n\
177         };\n\
178 \n\
179         zone \"authors.bind\" chaos {\n\
180                 type master;\n\
181                 database \"_builtin authors\";\n\
182         };\n\
183         zone \"id.server\" chaos {\n\
184                 type master;\n\
185                 database \"_builtin id\";\n\
186         };\n\
187 };\n\
188 ";
189
190 isc_result_t
191 ns_config_parsedefaults(cfg_parser_t *parser, cfg_obj_t **conf) {
192         isc_buffer_t b;
193
194         isc_buffer_init(&b, defaultconf, sizeof(defaultconf) - 1);
195         isc_buffer_add(&b, sizeof(defaultconf) - 1);
196         return (cfg_parse_buffer(parser, &b, &cfg_type_namedconf, conf));
197 }
198
199 isc_result_t
200 ns_config_get(const cfg_obj_t **maps, const char *name, const cfg_obj_t **obj) {
201         int i;
202
203         for (i = 0;; i++) {
204                 if (maps[i] == NULL)
205                         return (ISC_R_NOTFOUND);
206                 if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
207                         return (ISC_R_SUCCESS);
208         }
209 }
210
211 isc_result_t
212 ns_checknames_get(const cfg_obj_t **maps, const char *which,
213                   const cfg_obj_t **obj)
214 {
215         const cfg_listelt_t *element;
216         const cfg_obj_t *checknames;
217         const cfg_obj_t *type;
218         const cfg_obj_t *value;
219         int i;
220
221         for (i = 0;; i++) {
222                 if (maps[i] == NULL)
223                         return (ISC_R_NOTFOUND);
224                 checknames = NULL;
225                 if (cfg_map_get(maps[i], "check-names", &checknames) == ISC_R_SUCCESS) {
226                         /*
227                          * Zone map entry is not a list.
228                          */
229                         if (checknames != NULL && !cfg_obj_islist(checknames)) {
230                                 *obj = checknames;
231                                 return (ISC_R_SUCCESS);
232                         }
233                         for (element = cfg_list_first(checknames);
234                              element != NULL;
235                              element = cfg_list_next(element)) {
236                                 value = cfg_listelt_value(element);
237                                 type = cfg_tuple_get(value, "type");
238                                 if (strcasecmp(cfg_obj_asstring(type), which) == 0) {
239                                         *obj = cfg_tuple_get(value, "mode");
240                                         return (ISC_R_SUCCESS);
241                                 }
242                         }
243
244                 }
245         }
246 }
247
248 int
249 ns_config_listcount(const cfg_obj_t *list) {
250         const cfg_listelt_t *e;
251         int i = 0;
252
253         for (e = cfg_list_first(list); e != NULL; e = cfg_list_next(e))
254                 i++;
255
256         return (i);
257 }
258
259 isc_result_t
260 ns_config_getclass(const cfg_obj_t *classobj, dns_rdataclass_t defclass,
261                    dns_rdataclass_t *classp) {
262         const char *str;
263         isc_textregion_t r;
264         isc_result_t result;
265
266         if (!cfg_obj_isstring(classobj)) {
267                 *classp = defclass;
268                 return (ISC_R_SUCCESS);
269         }
270         str = cfg_obj_asstring(classobj);
271         DE_CONST(str, r.base);
272         r.length = strlen(str);
273         result = dns_rdataclass_fromtext(classp, &r);
274         if (result != ISC_R_SUCCESS)
275                 cfg_obj_log(classobj, ns_g_lctx, ISC_LOG_ERROR,
276                             "unknown class '%s'", str);
277         return (result);
278 }
279
280 isc_result_t
281 ns_config_gettype(const cfg_obj_t *typeobj, dns_rdatatype_t deftype,
282                    dns_rdatatype_t *typep) {
283         const char *str;
284         isc_textregion_t r;
285         isc_result_t result;
286
287         if (!cfg_obj_isstring(typeobj)) {
288                 *typep = deftype;
289                 return (ISC_R_SUCCESS);
290         }
291         str = cfg_obj_asstring(typeobj);
292         DE_CONST(str, r.base);
293         r.length = strlen(str);
294         result = dns_rdatatype_fromtext(typep, &r);
295         if (result != ISC_R_SUCCESS)
296                 cfg_obj_log(typeobj, ns_g_lctx, ISC_LOG_ERROR,
297                             "unknown type '%s'", str);
298         return (result);
299 }
300
301 dns_zonetype_t
302 ns_config_getzonetype(const cfg_obj_t *zonetypeobj) {
303         dns_zonetype_t ztype = dns_zone_none;
304         const char *str;
305
306         str = cfg_obj_asstring(zonetypeobj);
307         if (strcasecmp(str, "master") == 0)
308                 ztype = dns_zone_master;
309         else if (strcasecmp(str, "slave") == 0)
310                 ztype = dns_zone_slave;
311         else if (strcasecmp(str, "stub") == 0)
312                 ztype = dns_zone_stub;
313         else
314                 INSIST(0);
315         return (ztype);
316 }
317
318 isc_result_t
319 ns_config_getiplist(const cfg_obj_t *config, const cfg_obj_t *list,
320                     in_port_t defport, isc_mem_t *mctx,
321                     isc_sockaddr_t **addrsp, isc_uint32_t *countp)
322 {
323         int count, i = 0;
324         const cfg_obj_t *addrlist;
325         const cfg_obj_t *portobj;
326         const cfg_listelt_t *element;
327         isc_sockaddr_t *addrs;
328         in_port_t port;
329         isc_result_t result;
330
331         INSIST(addrsp != NULL && *addrsp == NULL);
332         INSIST(countp != NULL);
333
334         addrlist = cfg_tuple_get(list, "addresses");
335         count = ns_config_listcount(addrlist);
336
337         portobj = cfg_tuple_get(list, "port");
338         if (cfg_obj_isuint32(portobj)) {
339                 isc_uint32_t val = cfg_obj_asuint32(portobj);
340                 if (val > ISC_UINT16_MAX) {
341                         cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
342                                     "port '%u' out of range", val);
343                         return (ISC_R_RANGE);
344                 }
345                 port = (in_port_t) val;
346         } else if (defport != 0)
347                 port = defport;
348         else {
349                 result = ns_config_getport(config, &port);
350                 if (result != ISC_R_SUCCESS)
351                         return (result);
352         }
353
354         addrs = isc_mem_get(mctx, count * sizeof(isc_sockaddr_t));
355         if (addrs == NULL)
356                 return (ISC_R_NOMEMORY);
357
358         for (element = cfg_list_first(addrlist);
359              element != NULL;
360              element = cfg_list_next(element), i++)
361         {
362                 INSIST(i < count);
363                 addrs[i] = *cfg_obj_assockaddr(cfg_listelt_value(element));
364                 if (isc_sockaddr_getport(&addrs[i]) == 0)
365                         isc_sockaddr_setport(&addrs[i], port);
366         }
367         INSIST(i == count);
368
369         *addrsp = addrs;
370         *countp = count;
371
372         return (ISC_R_SUCCESS);
373 }
374
375 void
376 ns_config_putiplist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,
377                     isc_uint32_t count)
378 {
379         INSIST(addrsp != NULL && *addrsp != NULL);
380
381         isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));
382         *addrsp = NULL;
383 }
384
385 static isc_result_t
386 get_masters_def(const cfg_obj_t *cctx, const char *name,
387                 const cfg_obj_t **ret)
388 {
389         isc_result_t result;
390         const cfg_obj_t *masters = NULL;
391         const cfg_listelt_t *elt;
392
393         result = cfg_map_get(cctx, "masters", &masters);
394         if (result != ISC_R_SUCCESS)
395                 return (result);
396         for (elt = cfg_list_first(masters);
397              elt != NULL;
398              elt = cfg_list_next(elt)) {
399                 const cfg_obj_t *list;
400                 const char *listname;
401
402                 list = cfg_listelt_value(elt);
403                 listname = cfg_obj_asstring(cfg_tuple_get(list, "name"));
404
405                 if (strcasecmp(listname, name) == 0) {
406                         *ret = list;
407                         return (ISC_R_SUCCESS);
408                 }
409         }
410         return (ISC_R_NOTFOUND);
411 }
412
413 isc_result_t
414 ns_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list,
415                           isc_mem_t *mctx, isc_sockaddr_t **addrsp,
416                           dns_name_t ***keysp, isc_uint32_t *countp)
417 {
418         isc_uint32_t addrcount = 0, keycount = 0, i = 0;
419         isc_uint32_t listcount = 0, l = 0, j;
420         isc_uint32_t stackcount = 0, pushed = 0;
421         isc_result_t result;
422         const cfg_listelt_t *element;
423         const cfg_obj_t *addrlist;
424         const cfg_obj_t *portobj;
425         in_port_t port;
426         dns_fixedname_t fname;
427         isc_sockaddr_t *addrs = NULL;
428         dns_name_t **keys = NULL;
429         const char **lists = NULL;
430         struct {
431                 const cfg_listelt_t *element;
432                 in_port_t port;
433         } *stack = NULL;
434
435         REQUIRE(addrsp != NULL && *addrsp == NULL);
436         REQUIRE(keysp != NULL && *keysp == NULL);
437         REQUIRE(countp != NULL);
438
439  newlist:
440         addrlist = cfg_tuple_get(list, "addresses");
441         portobj = cfg_tuple_get(list, "port");
442         if (cfg_obj_isuint32(portobj)) {
443                 isc_uint32_t val = cfg_obj_asuint32(portobj);
444                 if (val > ISC_UINT16_MAX) {
445                         cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
446                                     "port '%u' out of range", val);
447                         result = ISC_R_RANGE;
448                         goto cleanup;
449                 }
450                 port = (in_port_t) val;
451         } else {
452                 result = ns_config_getport(config, &port);
453                 if (result != ISC_R_SUCCESS)
454                         goto cleanup;
455         }
456
457         result = ISC_R_NOMEMORY;
458
459         element = cfg_list_first(addrlist);
460  resume:
461         for ( ;
462              element != NULL;
463              element = cfg_list_next(element))
464         {
465                 const cfg_obj_t *addr;
466                 const cfg_obj_t *key;
467                 const char *keystr;
468                 isc_buffer_t b;
469
470                 addr = cfg_tuple_get(cfg_listelt_value(element),
471                                      "masterselement");
472                 key = cfg_tuple_get(cfg_listelt_value(element), "key");
473
474                 if (!cfg_obj_issockaddr(addr)) {
475                         const char *listname = cfg_obj_asstring(addr);
476                         isc_result_t tresult;
477
478                         /* Grow lists? */
479                         if (listcount == l) {
480                                 void * new;
481                                 isc_uint32_t newlen = listcount + 16;
482                                 size_t newsize, oldsize;
483
484                                 newsize = newlen * sizeof(*lists);
485                                 oldsize = listcount * sizeof(*lists);
486                                 new = isc_mem_get(mctx, newsize);
487                                 if (new == NULL)
488                                         goto cleanup;
489                                 if (listcount != 0) {
490                                         memcpy(new, lists, oldsize);
491                                         isc_mem_put(mctx, lists, oldsize);
492                                 }
493                                 lists = new;
494                                 listcount = newlen;
495                         }
496                         /* Seen? */
497                         for (j = 0; j < l; j++)
498                                 if (strcasecmp(lists[j], listname) == 0)
499                                         break;
500                         if (j < l)
501                                 continue;
502                         tresult = get_masters_def(config, listname, &list);
503                         if (tresult == ISC_R_NOTFOUND) {
504                                 cfg_obj_log(addr, ns_g_lctx, ISC_LOG_ERROR,
505                                     "masters \"%s\" not found", listname);
506
507                                 result = tresult;
508                                 goto cleanup;
509                         }
510                         if (tresult != ISC_R_SUCCESS)
511                                 goto cleanup;
512                         lists[l++] = listname;
513                         /* Grow stack? */
514                         if (stackcount == pushed) {
515                                 void * new;
516                                 isc_uint32_t newlen = stackcount + 16;
517                                 size_t newsize, oldsize;
518
519                                 newsize = newlen * sizeof(*stack);
520                                 oldsize = stackcount * sizeof(*stack);
521                                 new = isc_mem_get(mctx, newsize);
522                                 if (new == NULL)
523                                         goto cleanup;
524                                 if (stackcount != 0) {
525                                         memcpy(new, stack, oldsize);
526                                         isc_mem_put(mctx, stack, oldsize);
527                                 }
528                                 stack = new;
529                                 stackcount = newlen;
530                         }
531                         /*
532                          * We want to resume processing this list on the
533                          * next element.
534                          */
535                         stack[pushed].element = cfg_list_next(element);
536                         stack[pushed].port = port;
537                         pushed++;
538                         goto newlist;
539                 }
540
541                 if (i == addrcount) {
542                         void * new;
543                         isc_uint32_t newlen = addrcount + 16;
544                         size_t newsize, oldsize;
545
546                         newsize = newlen * sizeof(isc_sockaddr_t);
547                         oldsize = addrcount * sizeof(isc_sockaddr_t);
548                         new = isc_mem_get(mctx, newsize);
549                         if (new == NULL)
550                                 goto cleanup;
551                         if (addrcount != 0) {
552                                 memcpy(new, addrs, oldsize);
553                                 isc_mem_put(mctx, addrs, oldsize);
554                         }
555                         addrs = new;
556                         addrcount = newlen;
557
558                         newsize = newlen * sizeof(dns_name_t *);
559                         oldsize = keycount * sizeof(dns_name_t *);
560                         new = isc_mem_get(mctx, newsize);
561                         if (new == NULL)
562                                 goto cleanup;
563                         if (keycount != 0) {
564                                 memcpy(new, keys, oldsize);
565                                 isc_mem_put(mctx, keys, oldsize);
566                         }
567                         keys = new;
568                         keycount = newlen;
569                 }
570
571                 addrs[i] = *cfg_obj_assockaddr(addr);
572                 if (isc_sockaddr_getport(&addrs[i]) == 0)
573                         isc_sockaddr_setport(&addrs[i], port);
574                 keys[i] = NULL;
575                 if (!cfg_obj_isstring(key)) {
576                         i++;
577                         continue;
578                 }
579                 keys[i] = isc_mem_get(mctx, sizeof(dns_name_t));
580                 if (keys[i] == NULL)
581                         goto cleanup;
582                 dns_name_init(keys[i], NULL);
583
584                 keystr = cfg_obj_asstring(key);
585                 isc_buffer_init(&b, keystr, strlen(keystr));
586                 isc_buffer_add(&b, strlen(keystr));
587                 dns_fixedname_init(&fname);
588                 result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
589                                            dns_rootname, ISC_FALSE, NULL);
590                 if (result != ISC_R_SUCCESS)
591                         goto cleanup;
592                 result = dns_name_dup(dns_fixedname_name(&fname), mctx,
593                                       keys[i]);
594                 if (result != ISC_R_SUCCESS)
595                         goto cleanup;
596                 i++;
597         }
598         if (pushed != 0) {
599                 pushed--;
600                 element = stack[pushed].element;
601                 port = stack[pushed].port;
602                 goto resume;
603         }
604         if (i < addrcount) {
605                 void * new;
606                 size_t newsize, oldsize;
607
608                 newsize = i * sizeof(isc_sockaddr_t);
609                 oldsize = addrcount * sizeof(isc_sockaddr_t);
610                 if (i != 0) {
611                         new = isc_mem_get(mctx, newsize);
612                         if (new == NULL)
613                                 goto cleanup;
614                         memcpy(new, addrs, newsize);
615                 } else
616                         new = NULL;
617                 isc_mem_put(mctx, addrs, oldsize);
618                 addrs = new;
619                 addrcount = i;
620
621                 newsize = i * sizeof(dns_name_t *);
622                 oldsize = keycount * sizeof(dns_name_t *);
623                 if (i != 0) {
624                         new = isc_mem_get(mctx, newsize);
625                         if (new == NULL)
626                                 goto cleanup;
627                         memcpy(new, keys,  newsize);
628                 } else
629                         new = NULL;
630                 isc_mem_put(mctx, keys, oldsize);
631                 keys = new;
632                 keycount = i;
633         }
634
635         if (lists != NULL)
636                 isc_mem_put(mctx, lists, listcount * sizeof(*lists));
637         if (stack != NULL)
638                 isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
639
640         INSIST(keycount == addrcount);
641
642         *addrsp = addrs;
643         *keysp = keys;
644         *countp = addrcount;
645
646         return (ISC_R_SUCCESS);
647
648  cleanup:
649         if (addrs != NULL)
650                 isc_mem_put(mctx, addrs, addrcount * sizeof(isc_sockaddr_t));
651         if (keys != NULL) {
652                 for (j = 0; j <= i; j++) {
653                         if (keys[j] == NULL)
654                                 continue;
655                         if (dns_name_dynamic(keys[j]))
656                                 dns_name_free(keys[j], mctx);
657                         isc_mem_put(mctx, keys[j], sizeof(dns_name_t));
658                 }
659                 isc_mem_put(mctx, keys, keycount * sizeof(dns_name_t *));
660         }
661         if (lists != NULL)
662                 isc_mem_put(mctx, lists, listcount * sizeof(*lists));
663         if (stack != NULL)
664                 isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
665         return (result);
666 }
667
668 void
669 ns_config_putipandkeylist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,
670                           dns_name_t ***keysp, isc_uint32_t count)
671 {
672         unsigned int i;
673         dns_name_t **keys = *keysp;
674
675         INSIST(addrsp != NULL && *addrsp != NULL);
676
677         isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));
678         for (i = 0; i < count; i++) {
679                 if (keys[i] == NULL)
680                         continue;
681                 if (dns_name_dynamic(keys[i]))
682                         dns_name_free(keys[i], mctx);
683                 isc_mem_put(mctx, keys[i], sizeof(dns_name_t));
684         }
685         isc_mem_put(mctx, *keysp, count * sizeof(dns_name_t *));
686         *addrsp = NULL;
687         *keysp = NULL;
688 }
689
690 isc_result_t
691 ns_config_getport(const cfg_obj_t *config, in_port_t *portp) {
692         const cfg_obj_t *maps[3];
693         const cfg_obj_t *options = NULL;
694         const cfg_obj_t *portobj = NULL;
695         isc_result_t result;
696         int i;
697
698         (void)cfg_map_get(config, "options", &options);
699         i = 0;
700         if (options != NULL)
701                 maps[i++] = options;
702         maps[i++] = ns_g_defaults;
703         maps[i] = NULL;
704
705         result = ns_config_get(maps, "port", &portobj);
706         INSIST(result == ISC_R_SUCCESS);
707         if (cfg_obj_asuint32(portobj) >= ISC_UINT16_MAX) {
708                 cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
709                             "port '%u' out of range",
710                             cfg_obj_asuint32(portobj));
711                 return (ISC_R_RANGE);
712         }
713         *portp = (in_port_t)cfg_obj_asuint32(portobj);
714         return (ISC_R_SUCCESS);
715 }
716
717 isc_result_t
718 ns_config_getkeyalgorithm(const char *str, dns_name_t **name)
719 {
720         if (strcasecmp(str, "hmac-md5") == 0 ||
721             strcasecmp(str, "hmac-md5.sig-alg.reg.int") == 0 ||
722             strcasecmp(str, "hmac-md5.sig-alg.reg.int.") == 0)
723         {
724                 if (name != NULL)
725                         *name = dns_tsig_hmacmd5_name;
726                 return (ISC_R_SUCCESS);
727         }
728         return (ISC_R_NOTFOUND);
729 }