351b62535d4c4f89883bfdba025999dd32490266Evan Hunt/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2009, 2011, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt/*! \file */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt/**
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * ddns-confgen generates configuration files for dynamic DNS. It can
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * be used as a convenient alternative to writing the ddns.key file
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * and the corresponding key and update-policy statements in named.conf.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <config.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <stdlib.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <stdarg.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/assertions.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/base64.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/buffer.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/commandline.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/entropy.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/file.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/keyboard.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/mem.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/net.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/print.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/result.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/string.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/time.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <isc/util.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
a3799a38e7b133159e535921494b6e93a239c56bMark Andrews#ifdef PKCS11CRYPTO
a3799a38e7b133159e535921494b6e93a239c56bMark Andrews#include <pk11/result.h>
a3799a38e7b133159e535921494b6e93a239c56bMark Andrews#endif
a3799a38e7b133159e535921494b6e93a239c56bMark Andrews
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <dns/keyvalues.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <dns/name.h>
e6ff1b512749cb981ef427448cd8605ef8fa1939Mark Andrews#include <dns/result.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <dst/dst.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include <confgen/os.h>
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include "util.h"
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt#include "keygen.h"
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt#define KEYGEN_DEFAULT "tsig-key"
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt#define CONFGEN_DEFAULT "ddns-key"
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Huntstatic char program[256];
351b62535d4c4f89883bfdba025999dd32490266Evan Huntconst char *progname;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Huntstatic enum { progmode_keygen, progmode_confgen} progmode;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Huntisc_boolean_t verbose = ISC_FALSE; /* needed by util.c but not used here */
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
debd489a44363870f96f75818e89ec27d3cab736Francis DupontISC_PLATFORM_NORETURN_PRE static void
debd489a44363870f96f75818e89ec27d3cab736Francis Dupontusage(int status) ISC_PLATFORM_NORETURN_POST;
debd489a44363870f96f75818e89ec27d3cab736Francis Dupont
351b62535d4c4f89883bfdba025999dd32490266Evan Huntstatic void
351b62535d4c4f89883bfdba025999dd32490266Evan Huntusage(int status) {
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (progmode == progmode_confgen) {
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt fprintf(stderr, "\
351b62535d4c4f89883bfdba025999dd32490266Evan HuntUsage:\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 %s [-a alg] [-k keyname] [-r randomfile] [-q] [-s name | -z zone]\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -a alg: algorithm (default hmac-sha256)\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 -k keyname: name of the key as it will be used in named.conf\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -r randomfile: source of random data (use \"keyboard\" for key timing)\n\
90ca8e224dec4bd9350829989a8fb43e4731801bTatuya JINMEI 神明達哉 -s name: domain name to be updated using the created key\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 -z zone: name of the zone as it will be used in named.conf\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 -q: quiet mode: print the key, with no explanatory text\n",
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt progname);
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt } else {
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt fprintf(stderr, "\
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan HuntUsage:\n\
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt %s [-a alg] [-r randomfile] [keyname]\n\
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt -a alg: algorithm (default hmac-sha256)\n\
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt -r randomfile: source of random data (use \"keyboard\" for key timing)\n",
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt progname);
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt }
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt exit (status);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt}
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Huntint
351b62535d4c4f89883bfdba025999dd32490266Evan Huntmain(int argc, char **argv) {
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt isc_result_t result = ISC_R_SUCCESS;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_boolean_t show_final_mem = ISC_FALSE;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_boolean_t quiet = ISC_FALSE;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_buffer_t key_txtbuffer;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt char key_txtsecret[256];
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_mem_t *mctx = NULL;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt const char *randomfile = NULL;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt const char *keyname = NULL;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt const char *zone = NULL;
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 const char *self_domain = NULL;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt char *keybuf = NULL;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt dns_secalg_t alg = DST_ALG_HMACSHA256;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt const char *algname;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt int keysize = 256;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt int len = 0;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt int ch;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
51e6164fd6b47121040f79b6330edf6258418a0bMark Andrews#ifdef PKCS11CRYPTO
51e6164fd6b47121040f79b6330edf6258418a0bMark Andrews pk11_result_register();
51e6164fd6b47121040f79b6330edf6258418a0bMark Andrews#endif
51e6164fd6b47121040f79b6330edf6258418a0bMark Andrews dns_result_register();
51e6164fd6b47121040f79b6330edf6258418a0bMark Andrews
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt result = isc_file_progname(*argv, program, sizeof(program));
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (result != ISC_R_SUCCESS)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt memmove(program, "tsig-keygen", 11);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt progname = program;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt /*
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt * Libtool doesn't preserve the program name prior to final
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt * installation. Remove the libtool prefix ("lt-").
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt */
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (strncmp(progname, "lt-", 3) == 0)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt progname += 3;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt#define PROGCMP(X) \
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt (strcasecmp(progname, X) == 0 || strcasecmp(progname, X ".exe") == 0)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (PROGCMP("tsig-keygen")) {
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt progmode = progmode_keygen;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt quiet = ISC_TRUE;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt } else if (PROGCMP("ddns-confgen"))
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt progmode = progmode_confgen;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt else
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt INSIST(0);
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_commandline_errprint = ISC_FALSE;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt while ((ch = isc_commandline_parse(argc, argv,
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt "a:hk:Mmr:qs:y:z:")) != -1) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt switch (ch) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'a':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt algname = isc_commandline_argument;
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater alg = alg_fromtext(algname);
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater if (alg == DST_ALG_UNKNOWN)
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt fatal("Unsupported algorithm '%s'", algname);
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater keysize = alg_bits(alg);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'h':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt usage(0);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'k':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'y':
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (progmode == progmode_confgen)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt keyname = isc_commandline_argument;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt else
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt usage(1);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'M':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_mem_debugging = ISC_MEM_DEBUGTRACE;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'm':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt show_final_mem = ISC_TRUE;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'q':
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (progmode == progmode_confgen)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt quiet = ISC_TRUE;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt else
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt usage(1);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'r':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt randomfile = isc_commandline_argument;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 's':
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (progmode == progmode_confgen)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt self_domain = isc_commandline_argument;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt else
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt usage(1);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 case 'z':
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (progmode == progmode_confgen)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt zone = isc_commandline_argument;
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt else
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt usage(1);
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case '?':
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (isc_commandline_option != '?') {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt fprintf(stderr, "%s: invalid argument -%c\n",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt program, isc_commandline_option);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt usage(1);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt } else
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt usage(0);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt break;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt default:
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt fprintf(stderr, "%s: unhandled option -%c\n",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt program, isc_commandline_option);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt exit(1);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt }
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt }
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (progmode == progmode_keygen)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt keyname = argv[isc_commandline_index++];
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews POST(argv);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (self_domain != NULL && zone != NULL)
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 usage(1); /* -s and -z cannot coexist */
0add14467b53f33ace931f9a4790113cb8b5e45dTinderbox User
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt if (argc > isc_commandline_index)
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt usage(1);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt /* Use canonical algorithm name */
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt algname = alg_totext(alg);
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt DO("create memory context", isc_mem_create(0, 0, &mctx));
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (keyname == NULL) {
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 const char *suffix = NULL;
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt keyname = ((progmode == progmode_keygen)
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt ? KEYGEN_DEFAULT
46bc64f4b1a0e84ab0397943453fe83a17baf2c4Evan Hunt : CONFGEN_DEFAULT);
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (self_domain != NULL)
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 suffix = self_domain;
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 else if (zone != NULL)
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 suffix = zone;
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (suffix != NULL) {
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 len = strlen(keyname) + strlen(suffix) + 2;
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater keybuf = isc_mem_get(mctx, len);
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (keybuf == NULL)
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 fatal("failed to allocate memory for keyname");
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 snprintf(keybuf, len, "%s.%s", keyname, suffix);
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater keyname = (const char *) keybuf;
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater }
754cb8a2b33fa6cfaa15d6470f66e5fb0eab4764Automatic Updater }
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret));
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt generate_key(mctx, randomfile, alg, keysize, &key_txtbuffer);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (!quiet)
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt printf("\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# To activate this key, place the following in named.conf, and\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# in a separate keyfile on the system or systems from which nsupdate\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# will be run:\n");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt printf("\
351b62535d4c4f89883bfdba025999dd32490266Evan Huntkey \"%s\" {\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt algorithm %s;\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt secret \"%.*s\";\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt};\n",
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt keyname, algname,
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt (int)isc_buffer_usedlength(&key_txtbuffer),
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt (char *)isc_buffer_base(&key_txtbuffer));
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (!quiet) {
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (self_domain != NULL) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt printf("\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# Then, in the \"zone\" statement for the zone containing the\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# name \"%s\", place an \"update-policy\" statement\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# like this one, adjusted as needed for your preferred permissions:\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Huntupdate-policy {\n\
6493425eaa8d09485bcbf78e4f854b1a35ef71edTatuya JINMEI 神明達哉 grant %s name %s ANY;\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt};\n",
6493425eaa8d09485bcbf78e4f854b1a35ef71edTatuya JINMEI 神明達哉 self_domain, keyname, self_domain);
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 } else if (zone != NULL) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt printf("\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# Then, in the \"zone\" definition statement for \"%s\",\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# place an \"update-policy\" statement like this one, adjusted as \n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# needed for your preferred permissions:\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Huntupdate-policy {\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 grant %s zonesub ANY;\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt};\n",
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 zone, keyname);
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 } else {
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 printf("\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# Then, in the \"zone\" statement for each zone you wish to dynamically\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# update, place an \"update-policy\" statement granting update permission\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# to this key. For example, the following statement grants this key\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# permission to update any name within the zone:\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉update-policy {\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 grant %s zonesub ANY;\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉};\n",
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 keyname);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt }
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt printf("\n\
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉# After the keyfile has been placed, the following command will\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# execute nsupdate using this key:\n\
351b62535d4c4f89883bfdba025999dd32490266Evan Huntnsupdate -k <keyfile>\n");
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt }
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
45d4d69a8d662b6a00e3723c5488af40174a63cbTatuya JINMEI 神明達哉 if (keybuf != NULL)
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_mem_put(mctx, keybuf, len);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (show_final_mem)
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_mem_stats(mctx, stderr);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt isc_mem_destroy(&mctx);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt return (0);
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt}