1 /* $NetBSD: tkeyconf.c,v 1.9 2026/01/29 18:36:27 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 /*! \file */ 17 18 #include <inttypes.h> 19 20 #include <isc/buffer.h> 21 #include <isc/mem.h> 22 #include <isc/string.h> 23 24 #include <dns/fixedname.h> 25 #include <dns/keyvalues.h> 26 #include <dns/name.h> 27 #include <dns/tkey.h> 28 29 #include <dst/gssapi.h> 30 31 #include <isccfg/cfg.h> 32 33 #include <named/log.h> 34 #include <named/tkeyconf.h> 35 #define LOG(msg) \ 36 isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, \ 37 NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "%s", msg) 38 39 isc_result_t 40 named_tkeyctx_fromconfig(const cfg_obj_t *options, isc_mem_t *mctx, 41 dns_tkeyctx_t **tctxp) { 42 isc_result_t result; 43 dns_tkeyctx_t *tctx = NULL; 44 const char *s = NULL; 45 dns_fixedname_t fname; 46 dns_name_t *name = NULL; 47 isc_buffer_t b; 48 const cfg_obj_t *obj = NULL; 49 50 result = dns_tkeyctx_create(mctx, &tctx); 51 if (result != ISC_R_SUCCESS) { 52 return result; 53 } 54 55 result = cfg_map_get(options, "tkey-gssapi-credential", &obj); 56 if (result == ISC_R_SUCCESS) { 57 s = cfg_obj_asstring(obj); 58 59 isc_buffer_constinit(&b, s, strlen(s)); 60 isc_buffer_add(&b, strlen(s)); 61 name = dns_fixedname_initname(&fname); 62 CHECK(dns_name_fromtext(name, &b, dns_rootname, 0, NULL)); 63 CHECK(dst_gssapi_acquirecred(name, false, &tctx->gsscred)); 64 } 65 66 obj = NULL; 67 result = cfg_map_get(options, "tkey-gssapi-keytab", &obj); 68 if (result == ISC_R_SUCCESS) { 69 s = cfg_obj_asstring(obj); 70 tctx->gssapi_keytab = isc_mem_strdup(mctx, s); 71 } 72 73 *tctxp = tctx; 74 return ISC_R_SUCCESS; 75 76 cleanup: 77 dns_tkeyctx_destroy(&tctx); 78 return result; 79 } 80