Merge from vendor branch INTEL_ACPICA:
[dragonfly.git] / contrib / bind-9.3 / bin / named / tkeyconf.c
1 /*
2  * Copyright (C) 2004  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.19.208.2 2004/06/11 00:30:51 marka Exp $ */
19
20 #include <config.h>
21
22 #include <isc/buffer.h>
23 #include <isc/string.h>         /* Required for HP/UX (and others?) */
24 #include <isc/mem.h>
25
26 #include <isccfg/cfg.h>
27
28 #include <dns/fixedname.h>
29 #include <dns/keyvalues.h>
30 #include <dns/name.h>
31 #include <dns/tkey.h>
32
33 #include <dst/gssapi.h>
34
35 #include <named/tkeyconf.h>
36
37 #define RETERR(x) do { \
38         result = (x); \
39         if (result != ISC_R_SUCCESS) \
40                 goto failure; \
41         } while (0)
42
43
44 isc_result_t
45 ns_tkeyctx_fromconfig(cfg_obj_t *options, isc_mem_t *mctx, isc_entropy_t *ectx,
46                        dns_tkeyctx_t **tctxp)
47 {
48         isc_result_t result;
49         dns_tkeyctx_t *tctx = NULL;
50         char *s;
51         isc_uint32_t n;
52         dns_fixedname_t fname;
53         dns_name_t *name;
54         isc_buffer_t b;
55         cfg_obj_t *obj;
56         int type;
57
58         result = dns_tkeyctx_create(mctx, ectx, &tctx);
59         if (result != ISC_R_SUCCESS)
60                 return (result);
61
62         obj = NULL;
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,
72                                          ISC_FALSE, NULL));
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));
76         }
77
78         obj = NULL;
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,
87                                          NULL));
88                 tctx->domain = isc_mem_get(mctx, sizeof(dns_name_t));
89                 if (tctx->domain == NULL) {
90                         result = ISC_R_NOMEMORY;
91                         goto failure;
92                 }
93                 dns_name_init(tctx->domain, NULL);
94                 RETERR(dns_name_dup(name, mctx, tctx->domain));
95         }
96
97         obj = NULL;
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,
106                                          NULL));
107                 RETERR(dst_gssapi_acquirecred(name, ISC_FALSE,
108                                               &tctx->gsscred));
109         }
110
111         *tctxp = tctx;
112         return (ISC_R_SUCCESS);
113
114  failure:
115         dns_tkeyctx_destroy(&tctx);
116         return (result);
117 }
118