diff options
Diffstat (limited to 'bin/nsupdate/nsupdate.c')
-rw-r--r-- | bin/nsupdate/nsupdate.c | 97 |
1 files changed, 66 insertions, 31 deletions
diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index e11f080..e96c075 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: nsupdate.c,v 1.193.12.4 2011/11/03 04:30:09 each Exp $ */ +/* $Id$ */ /*! \file */ @@ -85,6 +85,10 @@ #endif #include <bind9/getaddresses.h> +#if defined(HAVE_READLINE) +#include <readline/readline.h> +#include <readline/history.h> +#endif #ifdef HAVE_ADDRINFO #ifdef HAVE_GETADDRINFO @@ -1805,6 +1809,8 @@ evaluate_update(char *cmdline) { } if (strcasecmp(word, "delete") == 0) isdelete = ISC_TRUE; + else if (strcasecmp(word, "del") == 0) + isdelete = ISC_TRUE; else if (strcasecmp(word, "add") == 0) isdelete = ISC_FALSE; else { @@ -1883,35 +1889,13 @@ show_message(FILE *stream, dns_message_t *msg, const char *description) { isc_buffer_free(&buf); } - static isc_uint16_t -get_next_command(void) { - char cmdlinebuf[MAXCMD]; - char *cmdline; +do_next_command(char *cmdline) { char *word; - char *tmp; - - ddebug("get_next_command()"); - if (interactive) { - fprintf(stdout, "> "); - fflush(stdout); - } - isc_app_block(); - cmdline = fgets(cmdlinebuf, MAXCMD, input); - isc_app_unblock(); - if (cmdline == NULL) - return (STATUS_QUIT); - - /* - * Normalize input by removing any eol. - */ - tmp = cmdline; - (void)nsu_strsep(&tmp, "\r\n"); + ddebug("do_next_command()"); word = nsu_strsep(&cmdline, " \t\r\n"); - if (feof(input)) - return (STATUS_QUIT); if (word == NULL || *word == 0) return (STATUS_SEND); if (word[0] == ';') @@ -1920,8 +1904,22 @@ get_next_command(void) { return (STATUS_QUIT); if (strcasecmp(word, "prereq") == 0) return (evaluate_prereq(cmdline)); + if (strcasecmp(word, "nxdomain") == 0) + return (make_prereq(cmdline, ISC_FALSE, ISC_FALSE)); + if (strcasecmp(word, "yxdomain") == 0) + return (make_prereq(cmdline, ISC_TRUE, ISC_FALSE)); + if (strcasecmp(word, "nxrrset") == 0) + return (make_prereq(cmdline, ISC_FALSE, ISC_TRUE)); + if (strcasecmp(word, "yxrrset") == 0) + return (make_prereq(cmdline, ISC_TRUE, ISC_TRUE)); if (strcasecmp(word, "update") == 0) return (evaluate_update(cmdline)); + if (strcasecmp(word, "delete") == 0) + return (update_addordelete(cmdline, ISC_TRUE)); + if (strcasecmp(word, "del") == 0) + return (update_addordelete(cmdline, ISC_TRUE)); + if (strcasecmp(word, "add") == 0) + return (update_addordelete(cmdline, ISC_FALSE)); if (strcasecmp(word, "server") == 0) return (evaluate_server(cmdline)); if (strcasecmp(word, "local") == 0) @@ -1988,18 +1986,55 @@ get_next_command(void) { "oldgsstsig (use Microsoft's GSS_TSIG to sign the request)\n" "zone name (set the zone to be updated)\n" "class CLASS (set the zone's DNS class, e.g. IN (default), CH)\n" -"prereq nxdomain name (does this name not exist)\n" -"prereq yxdomain name (does this name exist)\n" -"prereq nxrrset .... (does this RRset exist)\n" -"prereq yxrrset .... (does this RRset not exist)\n" -"update add .... (add the given record to the zone)\n" -"update delete .... (remove the given record(s) from the zone)\n"); +"[prereq] nxdomain name (does this name not exist)\n" +"[prereq] yxdomain name (does this name exist)\n" +"[prereq] nxrrset .... (does this RRset exist)\n" +"[prereq] yxrrset .... (does this RRset not exist)\n" +"[update] add .... (add the given record to the zone)\n" +"[update] del[ete] .... (remove the given record(s) from the zone)\n"); return (STATUS_MORE); } fprintf(stderr, "incorrect section name: %s\n", word); return (STATUS_SYNTAX); } +static isc_uint16_t +get_next_command(void) { + isc_uint16_t result = STATUS_QUIT; + char cmdlinebuf[MAXCMD]; + char *cmdline; + + isc_app_block(); + if (interactive) { +#ifdef HAVE_READLINE + cmdline = readline("> "); + add_history(cmdline); +#else + fprintf(stdout, "> "); + fflush(stdout); + cmdline = fgets(cmdlinebuf, MAXCMD, input); +#endif + } else + cmdline = fgets(cmdlinebuf, MAXCMD, input); + isc_app_unblock(); + + if (cmdline != NULL) { + char *tmp = cmdline; + + /* + * Normalize input by removing any eol as readline() + * removes eol but fgets doesn't. + */ + (void)nsu_strsep(&tmp, "\r\n"); + result = do_next_command(cmdline); + } +#ifdef HAVE_READLINE + if (interactive) + free(cmdline); +#endif + return (result); +} + static isc_boolean_t user_interaction(void) { isc_uint16_t result = STATUS_MORE; |