2 * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
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.
18 /* $Id: tkeyconf.c,v 1.20.18.6 2006/03/02 00:37:21 marka Exp $ */
24 #include <isc/buffer.h>
25 #include <isc/string.h> /* Required for HP/UX (and others?) */
28 #include <isccfg/cfg.h>
30 #include <dns/fixedname.h>
31 #include <dns/keyvalues.h>
35 #include <dst/gssapi.h>
37 #include <named/tkeyconf.h>
39 #define RETERR(x) do { \
41 if (result != ISC_R_SUCCESS) \
47 ns_tkeyctx_fromconfig(const cfg_obj_t *options, isc_mem_t *mctx,
48 isc_entropy_t *ectx, dns_tkeyctx_t **tctxp)
51 dns_tkeyctx_t *tctx = NULL;
54 dns_fixedname_t fname;
60 result = dns_tkeyctx_create(mctx, ectx, &tctx);
61 if (result != ISC_R_SUCCESS)
65 result = cfg_map_get(options, "tkey-dhkey", &obj);
66 if (result == ISC_R_SUCCESS) {
67 s = cfg_obj_asstring(cfg_tuple_get(obj, "name"));
68 n = cfg_obj_asuint32(cfg_tuple_get(obj, "keyid"));
69 isc_buffer_init(&b, s, strlen(s));
70 isc_buffer_add(&b, strlen(s));
71 dns_fixedname_init(&fname);
72 name = dns_fixedname_name(&fname);
73 RETERR(dns_name_fromtext(name, &b, dns_rootname,
75 type = DST_TYPE_PUBLIC|DST_TYPE_PRIVATE|DST_TYPE_KEY;
76 RETERR(dst_key_fromfile(name, (dns_keytag_t) n, DNS_KEYALG_DH,
77 type, NULL, mctx, &tctx->dhkey));
81 result = cfg_map_get(options, "tkey-domain", &obj);
82 if (result == ISC_R_SUCCESS) {
83 s = cfg_obj_asstring(obj);
84 isc_buffer_init(&b, s, strlen(s));
85 isc_buffer_add(&b, strlen(s));
86 dns_fixedname_init(&fname);
87 name = dns_fixedname_name(&fname);
88 RETERR(dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE,
90 tctx->domain = isc_mem_get(mctx, sizeof(dns_name_t));
91 if (tctx->domain == NULL) {
92 result = ISC_R_NOMEMORY;
95 dns_name_init(tctx->domain, NULL);
96 RETERR(dns_name_dup(name, mctx, tctx->domain));
100 result = cfg_map_get(options, "tkey-gssapi-credential", &obj);
101 if (result == ISC_R_SUCCESS) {
102 s = cfg_obj_asstring(obj);
103 isc_buffer_init(&b, s, strlen(s));
104 isc_buffer_add(&b, strlen(s));
105 dns_fixedname_init(&fname);
106 name = dns_fixedname_name(&fname);
107 RETERR(dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE,
109 RETERR(dst_gssapi_acquirecred(name, ISC_FALSE,
114 return (ISC_R_SUCCESS);
117 dns_tkeyctx_destroy(&tctx);