/*
* nsd-control.c - remote control utility for nsd.
*
* Copyright (c) 2011, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file
*
* The remote control utility contacts the nsd server over ssl and
* sends the command, receives the answer, and displays the result
* from the commandline.
*/
static void usage(void) ATTR_NORETURN;
#ifdef HAVE_SSL
static void ssl_err(const char* s) ATTR_NORETURN;
static void ssl_path_err(const char* s, const char *path) ATTR_NORETURN;
#else
/* define SSL to use as a boolean to turn it off in function calls. */
#define SSL int
#endif
/** timeout to wait for connection over stream, in msec */
#define NSD_CONTROL_CONNECT_TIMEOUT 5000
/** Give nsd-control usage, and exit (1). */
static void
usage()
{
printf("Usage: nsd-control [options] command\n");
printf(" Remote control utility for nsd server.\n");
printf("Version %s. Report bugs to <%s>.\n",
PACKAGE_VERSION, PACKAGE_BUGREPORT);
printf("Options:\n");
printf(" -c file config file, default is %s\n", CONFIGFILE);
printf(" -s ip[@port] server address, if omitted config is used.\n");
printf(" -h show this usage help.\n");
printf("Commands:\n");
printf(" start start server; runs nsd(8)\n");
printf(" stop stops the server\n");
printf(" reload [<zone>] reload modified zonefiles from disk\n");
printf(" reconfig reload the config file\n");
printf(" repattern the same as reconfig\n");
printf(" log_reopen reopen logfile (for log rotate)\n");
printf(" status display status of server\n");
printf(" stats print statistics\n");
printf(" stats_noreset peek at statistics\n");
printf(" addzone <name> <pattern> add a new zone\n");
printf(" delzone <name> remove a zone\n");
printf(" changezone <name> <pattern> change zone to use pattern\n");
printf(" addzones add zone list on stdin {name space pattern newline}\n");
printf(" delzones remove zone list on stdin {name newline}\n");
printf(" write [<zone>] write changed zonefiles to disk\n");
printf(" notify [<zone>] send NOTIFY messages to slave servers\n");
printf(" transfer [<zone>] try to update slave zones to newer serial\n");
printf(" force_transfer [<zone>] update slave zones with AXFR, no serial check\n");
printf(" zonestatus [<zone>] print state, serial, activity\n");
printf(" serverpid get pid of server process\n");
printf(" verbosity <number> change logging detail\n");
printf(" print_tsig [<key_name>] print tsig with <name> the secret and algo\n");
printf(" update_tsig <name> <secret> change existing tsig with <name> to a new <secret>\n");
printf(" add_tsig <name> <secret> [algo] add new key with the given parameters\n");
printf(" assoc_tsig <zone> <key_name> associate <zone> with given tsig <key_name> name\n");
printf(" del_tsig <key_name> delete tsig <key_name> from configuration\n");
printf(" add_cookie_secret <secret> add (or replace) a new cookie secret <secret>\n");
printf(" drop_cookie_secret drop a staging cookie secret\n");
printf(" activate_cookie_secret make a staging cookie secret active\n");
printf(" print_cookie_secrets show all cookie secrets with their status\n");
exit(1);
}
/** getopt global, in case header files fail to declare it. */
extern int optind;
/** getopt global, in case header files fail to declare it. */
extern char* optarg;
/** Main routine for nsd-control */
int main(int argc, char* argv[])
{
int c;
const char* cfgfile = CONFIGFILE;
char* svr = NULL;
log_init("nsd-control");