rndc-confgen.c revision f8644da8d948dbc973f6dd4c94a79774e16ec07b
/*
* Copyright (C) 2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rndc-confgen.c,v 1.1 2001/06/22 17:19:08 tale Exp $ */
#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"
#define DEFAULT_KEYNAME "rndc-key"
#define DEFAULT_SERVER "127.0.0.1"
#define DEFAULT_PORT 953
unsigned char progname[256];
static void
Usage:\n\
%s [-b bits] [-k keyname] [-P] [-p port] [-r randomfile] [-s addr]\n\
-b bits: from 1 through 512, default %d; total length of the secret\n\
-k keyname: the name as it will be used in named.conf and rndc.conf\n\
-P: using pseudorandom data for key generation is ok\n\
-p port: the port named will listen on and rndc will connect to\n\
-r randomfile: a file containing random data\n\
-s addr: the address to which rndc should connect\n",
}
int
const char *randomfile = NULL;
const char *serveraddr = NULL;
char key_rawsecret[64];
char key_txtsecret[256];
char *p;
int ch;
int port;
int keysize;
int entropy_flags = 0;
if (result != ISC_R_SUCCESS)
port = DEFAULT_PORT;
!= -1) {
switch (ch) {
case 'b':
if (*p != '\0' || keysize < 0)
fatal("-b requires a non-negative number");
fatal("-b must be in the range 1 through 512");
break;
case 'h':
usage(0);
case 'k':
case 'y': /* Compatible with rndc -y. */
break;
case 'M':
isc_mem_debugging = 1;
break;
case 'm':
break;
case 'P':
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 'V':
break;
case '?':
usage(1);
break;
default:
fatal("unexpected error parsing command arguments: "
"got %c\n", ch);
break;
}
}
if (argc > 0)
usage(1);
if (! pseudorandom)
keysize, 0, 0,
&key_txtbuffer));
/*
* Shut down the entropy source now so the "stop typing" message
* does not muck with the output.
*/
if (entropy_source != NULL)
dst_key_free(&key);
if (open_keyboard)
/*
* Add a little vertical whitespace to separate it
* from the "stop typing" message".
*/
printf("\n\n");
printf("\
# Start of rndc.conf\n\
key \"%s\" {\n\
algorithm hmac-md5;\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 hmac-md5;\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);
}