2 * Copyright (C) 2004 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.19.208.2 2004/06/11 00:30:51 marka Exp $ */
22 #include <isc/buffer.h>
23 #include <isc/string.h> /* Required for HP/UX (and others?) */
26 #include <isccfg/cfg.h>
28 #include <dns/fixedname.h>
29 #include <dns/keyvalues.h>
33 #include <dst/gssapi.h>
35 #include <named/tkeyconf.h>
37 #define RETERR(x) do { \
39 if (result != ISC_R_SUCCESS) \
45 ns_tkeyctx_fromconfig(cfg_obj_t *options, isc_mem_t *mctx, isc_entropy_t *ectx,
46 dns_tkeyctx_t **tctxp)
49 dns_tkeyctx_t *tctx = NULL;
52 dns_fixedname_t fname;
58 result = dns_tkeyctx_create(mctx, ectx, &tctx);
59 if (result != ISC_R_SUCCESS)
63 result = cfg_map_get(options, "tkey-dhkey", &obj);
64 if (result == ISC_R_SUCCESS) {
65 s = cfg_obj_asstring(cfg_tuple_get(obj, "name"));
66 n = cfg_obj_asuint32(cfg_tuple_get(obj, "keyid"));
67 isc_buffer_init(&b, s, strlen(s));
68 isc_buffer_add(&b, strlen(s));
69 dns_fixedname_init(&fname);
70 name = dns_fixedname_name(&fname);
71 RETERR(dns_name_fromtext(name, &b, dns_rootname,
73 type = DST_TYPE_PUBLIC|DST_TYPE_PRIVATE|DST_TYPE_KEY;
74 RETERR(dst_key_fromfile(name, (dns_keytag_t) n, DNS_KEYALG_DH,
75 type, NULL, mctx, &tctx->dhkey));
79 result = cfg_map_get(options, "tkey-domain", &obj);
80 if (result == ISC_R_SUCCESS) {
81 s = cfg_obj_asstring(obj);
82 isc_buffer_init(&b, s, strlen(s));
83 isc_buffer_add(&b, strlen(s));
84 dns_fixedname_init(&fname);
85 name = dns_fixedname_name(&fname);
86 RETERR(dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE,
88 tctx->domain = isc_mem_get(mctx, sizeof(dns_name_t));
89 if (tctx->domain == NULL) {
90 result = ISC_R_NOMEMORY;
93 dns_name_init(tctx->domain, NULL);
94 RETERR(dns_name_dup(name, mctx, tctx->domain));
98 result = cfg_map_get(options, "tkey-gssapi-credential", &obj);
99 if (result == ISC_R_SUCCESS) {
100 s = cfg_obj_asstring(obj);
101 isc_buffer_init(&b, s, strlen(s));
102 isc_buffer_add(&b, strlen(s));
103 dns_fixedname_init(&fname);
104 name = dns_fixedname_name(&fname);
105 RETERR(dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE,
107 RETERR(dst_gssapi_acquirecred(name, ISC_FALSE,
112 return (ISC_R_SUCCESS);
115 dns_tkeyctx_destroy(&tctx);