rndc-confgen.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2001, 2003-2005, 2007-2009, 2011, 2013, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: rndc-confgen.c,v 1.7 2011/03/12 04:59:46 tbox Exp $ */
/*! \file */
/**
* rndc-confgen generates configuration files for rndc. It can be used
* as a convenient alternative to writing the rndc.conf file and the
* corresponding controls and key statements in named.conf by hand.
* Alternatively, it can be run with the -a option to set up a
* rndc.key file and avoid the need for a rndc.conf file and a
* controls statement altogether.
*/
#include <config.h>
#include <stdlib.h>
#include <stdarg.h>
#include <isc/assertions.h>
#include <isc/commandline.h>
#include <isc/keyboard.h>
#include <dns/keyvalues.h>
#include "util.h"
#include "keygen.h"
#define DEFAULT_KEYNAME "rndc-key"
#define DEFAULT_SERVER "127.0.0.1"
#define DEFAULT_PORT 953
static char program[256];
const char *progname;
ISC_PLATFORM_NORETURN_PRE static void
static void
Usage:\n\
%s [-a] [-b bits] [-c keyfile] [-k keyname] [-p port] [-r randomfile] \
[-s addr] [-t chrootdir] [-u user]\n\
-a: generate just the key clause and write it to keyfile (%s)\n\
-A alg: algorithm (default hmac-md5)\n\
-b bits: from 1 through 512, default 256; total length of the secret\n\
-c keyfile: specify an alternate key file (requires -a)\n\
-k keyname: the name as it will be used in named.conf and rndc.conf\n\
-p port: the port named will listen on and rndc will connect to\n\
-r randomfile: source of random data (use \"keyboard\" for key timing)\n\
-s addr: the address to which rndc should connect\n\
-t chrootdir: write a keyfile in chrootdir as well (requires -a)\n\
-u user: set the keyfile owner to \"user\" (requires -a)\n",
}
int
char key_txtsecret[256];
const char *randomfile = NULL;
const char *serveraddr = NULL;
const char *algname;
char *p;
int ch;
int port;
int keysize = -1;
struct in_addr addr4_dummy;
struct in6_addr addr6_dummy;
int len;
if (result != ISC_R_SUCCESS)
port = DEFAULT_PORT;
"aA:b:c:hk:Mmp:r:s:t:u:Vy")) != -1)
{
switch (ch) {
case 'a':
break;
case 'A':
if (alg == DST_ALG_UNKNOWN)
break;
case 'b':
if (*p != '\0' || keysize < 0)
fatal("-b requires a non-negative number");
break;
case 'c':
break;
case 'h':
usage(0);
case 'k':
case 'y': /* Compatible with rndc -y. */
break;
case 'M':
break;
case 'm':
break;
case 'p':
fatal("port '%s' out of range",
break;
case 'r':
break;
case 's':
fatal("-s should be an IPv4 or IPv6 address");
break;
case 't':
break;
case 'u':
break;
case 'V':
break;
case '?':
if (isc_commandline_option != '?') {
usage(1);
} else
usage(0);
break;
default:
exit(1);
}
}
if (argc > 0)
usage(1);
if (keysize < 0)
if (keyonly) {
char *buf;
}
} else {
printf("\
# Start of rndc.conf\n\
key \"%s\" {\n\
algorithm %s;\n\
secret \"%.*s\";\n\
};\n\
\n\
options {\n\
default-key \"%s\";\n\
default-server %s;\n\
default-port %d;\n\
};\n\
# End of rndc.conf\n\
\n\
# Use with the following in named.conf, adjusting the allow list as needed:\n\
# key \"%s\" {\n\
# algorithm %s;\n\
# secret \"%.*s\";\n\
# };\n\
# \n\
# controls {\n\
# inet %s port %d\n\
# allow { %s; } keys { \"%s\"; };\n\
# };\n\
# End of named.conf\n",
(int)isc_buffer_usedlength(&key_txtbuffer),
(char *)isc_buffer_base(&key_txtbuffer),
(int)isc_buffer_usedlength(&key_txtbuffer),
(char *)isc_buffer_base(&key_txtbuffer),
}
if (show_final_mem)
return (0);
}