From 9b2cd9e2e50ebbaed18e5cc86d302e3bfeb65b14 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Fri, 31 May 2013 23:01:47 -0400 Subject: [PATCH] [client] allow -D to be used in --save-rc-stanza mode if -n is not given This change simplifies the fwknop client usage by allowing the -D argument to be used as the stanza name if -n is not also specified in --save-rc-stanza mode. --- client/config_init.c | 17 +++++++++++------ client/fwknop.8.in | 6 +++++- doc/fwknop.man.asciidoc | 4 +++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/config_init.c b/client/config_init.c index b2451014..17af6abf 100644 --- a/client/config_init.c +++ b/client/config_init.c @@ -638,8 +638,7 @@ keys_status(fko_cli_options_t *options) { set_rc_file(rcfile, options); log_msg(LOG_VERBOSITY_NORMAL, - "[+] Wrote Rijndael and HMAC keys to rc file: %s", - options->rc_file); + "[+] Wrote Rijndael and HMAC keys to rc file: %s", rcfile); } else log_msg(LOG_VERBOSITY_NORMAL, @@ -1571,10 +1570,16 @@ validate_options(fko_cli_options_t *options) if ( (options->save_rc_stanza == 1) && (options->use_rc_stanza[0] == 0) ) { - log_msg(LOG_VERBOSITY_ERROR, - "The option --save-rc-stanza must be used with the " - "--named-config option to specify the stanza to update."); - exit(EXIT_FAILURE); + /* Set the stanza name to the -D arg value + */ + if (options->spa_server_str[0] == 0x0) + { + log_msg(LOG_VERBOSITY_ERROR, + "Must use --destination unless --test mode is used"); + exit(EXIT_FAILURE); + } + + strlcpy(options->use_rc_stanza, options->spa_server_str, sizeof(options->use_rc_stanza)); } /* Gotta have a Destination unless we are just testing or getting the diff --git a/client/fwknop.8.in b/client/fwknop.8.in index 1af61a8c..df871d6a 100644 --- a/client/fwknop.8.in +++ b/client/fwknop.8.in @@ -218,7 +218,11 @@ Specify path to the fwknop rc file (default is $HOME/\&.fwknoprc)\&. .RS 4 Save command line arguments to the $HOME/\&.fwknoprc stanza specified with the \fB\-n\fR -option\&. +option\&. If the +\fB\-n\fR +option is omitted, then the stanza name will default to the destination server value (hostname or IP) given with the +\fB\-D\fR +argument\&. .RE .PP \fB\-\-force\-stanza\fR diff --git a/doc/fwknop.man.asciidoc b/doc/fwknop.man.asciidoc index 1d9e9f14..f6f7f059 100644 --- a/doc/fwknop.man.asciidoc +++ b/doc/fwknop.man.asciidoc @@ -233,7 +233,9 @@ GENERAL OPTIONS *--save-rc-stanza*='':: Save command line arguments to the $HOME/.fwknoprc stanza specified with - the *-n* option. + the *-n* option. If the *-n* option is omitted, then the stanza name will + default to the destination server value (hostname or IP) given with the + *-D* argument. *--force-stanza*:: Used with *--save-rc-stanza* to overwrite all of the variables for the