]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/bind9/bin/named/tkeyconf.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / bind9 / bin / named / tkeyconf.c
1 /*
2  * Copyright (C) 2004-2006  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
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.
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: tkeyconf.c,v 1.20.18.6 2006/03/02 00:37:21 marka Exp $ */
19
20 /*! \file */
21
22 #include <config.h>
23
24 #include <isc/buffer.h>
25 #include <isc/string.h>         /* Required for HP/UX (and others?) */
26 #include <isc/mem.h>
27
28 #include <isccfg/cfg.h>
29
30 #include <dns/fixedname.h>
31 #include <dns/keyvalues.h>
32 #include <dns/name.h>
33 #include <dns/tkey.h>
34
35 #include <dst/gssapi.h>
36
37 #include <named/tkeyconf.h>
38
39 #define RETERR(x) do { \
40         result = (x); \
41         if (result != ISC_R_SUCCESS) \
42                 goto failure; \
43         } while (0)
44
45
46 isc_result_t
47 ns_tkeyctx_fromconfig(const cfg_obj_t *options, isc_mem_t *mctx,
48                       isc_entropy_t *ectx, dns_tkeyctx_t **tctxp)
49 {
50         isc_result_t result;
51         dns_tkeyctx_t *tctx = NULL;
52         const char *s;
53         isc_uint32_t n;
54         dns_fixedname_t fname;
55         dns_name_t *name;
56         isc_buffer_t b;
57         const cfg_obj_t *obj;
58         int type;
59
60         result = dns_tkeyctx_create(mctx, ectx, &tctx);
61         if (result != ISC_R_SUCCESS)
62                 return (result);
63
64         obj = NULL;
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,
74                                          ISC_FALSE, NULL));
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));
78         }
79
80         obj = NULL;
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,
89                                          NULL));
90                 tctx->domain = isc_mem_get(mctx, sizeof(dns_name_t));
91                 if (tctx->domain == NULL) {
92                         result = ISC_R_NOMEMORY;
93                         goto failure;
94                 }
95                 dns_name_init(tctx->domain, NULL);
96                 RETERR(dns_name_dup(name, mctx, tctx->domain));
97         }
98
99         obj = NULL;
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,
108                                          NULL));
109                 RETERR(dst_gssapi_acquirecred(name, ISC_FALSE,
110                                               &tctx->gsscred));
111         }
112
113         *tctxp = tctx;
114         return (ISC_R_SUCCESS);
115
116  failure:
117         dns_tkeyctx_destroy(&tctx);
118         return (result);
119 }
120