[client] merged --stanza-list changes from Franck, closes #94
This commit is contained in:
@@ -209,6 +209,7 @@ EXTRA_DIST = \
|
||||
test/conf/fwknoprc_gpg_args_no_pw_hmac_key \
|
||||
test/conf/fwknoprc_gpg_signing_pw \
|
||||
test/conf/fwknoprc_named_gpg_signing_pw \
|
||||
test/conf/fwknoprc_stanza_list \
|
||||
test/conf/icmp_pcap_filter_fwknopd.conf \
|
||||
test/conf/invalid_expire_access.conf \
|
||||
test/conf/invalid_source_access.conf \
|
||||
|
||||
@@ -43,6 +43,7 @@ enum {
|
||||
TIME_OFFSET_PLUS,
|
||||
SAVE_RC_STANZA,
|
||||
FORCE_SAVE_RC_STANZA,
|
||||
STANZA_LIST,
|
||||
NO_SAVE_ARGS,
|
||||
SHOW_LAST_ARGS,
|
||||
RC_FILE_PATH,
|
||||
@@ -85,6 +86,7 @@ static struct option cmd_opts[] =
|
||||
{"save-packet", 1, NULL, 'B'},
|
||||
{"save-rc-stanza", 0, NULL, SAVE_RC_STANZA},
|
||||
{"force-stanza", 0, NULL, FORCE_SAVE_RC_STANZA},
|
||||
{"stanza-list", 0, NULL, STANZA_LIST},
|
||||
{"no-save-args", 0, NULL, NO_SAVE_ARGS},
|
||||
{"server-cmd", 1, NULL, 'C'},
|
||||
{"digest-type", 1, NULL, FKO_DIGEST_NAME},
|
||||
|
||||
@@ -563,6 +563,58 @@ is_rc_param(const char *line, rc_file_param_t *param)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump available stanzas from a fwknoprc file
|
||||
*
|
||||
* This function parses a rcfile and looks for configured stanzas.
|
||||
* They are all displayed except the default stanza.
|
||||
*
|
||||
* @param rcfile full path to the rcfile to parse
|
||||
*/
|
||||
static void
|
||||
dump_configured_stanzas_from_rcfile(const char* rcfile)
|
||||
{
|
||||
FILE *rc;
|
||||
char line[MAX_LINE_LEN] = {0};
|
||||
char curr_stanza[MAX_LINE_LEN] = {0};
|
||||
|
||||
/* Open the rcfile in read mode */
|
||||
if ((rc = fopen(rcfile, "r")) == NULL)
|
||||
{
|
||||
log_msg(LOG_VERBOSITY_WARNING, "Unable to open rc file: %s: %s",
|
||||
rcfile, strerror(errno));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
log_msg(LOG_VERBOSITY_NORMAL, "The following stanzas are configured in %s :", rcfile);
|
||||
|
||||
/* Parse the rcfile line by line to find stanza */
|
||||
while ((fgets(line, MAX_LINE_LEN, rc)) != NULL)
|
||||
{
|
||||
line[MAX_LINE_LEN-1] = '\0';
|
||||
|
||||
/* Get past comments and empty lines (note: we only look at the first
|
||||
* character. */
|
||||
if(IS_EMPTY_LINE(line[0]))
|
||||
continue;
|
||||
|
||||
/* Check which section we are working on */
|
||||
else if (is_rc_section(line, strlen(line), curr_stanza, sizeof(curr_stanza)))
|
||||
{
|
||||
/* Print the stanza and continue - we exclude the default stanza */
|
||||
if (strcasecmp(curr_stanza, RC_SECTION_DEFAULT) != 0)
|
||||
log_msg(LOG_VERBOSITY_NORMAL, " - %s", curr_stanza);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Nothing we care about */
|
||||
else;
|
||||
}
|
||||
|
||||
fclose(rc);
|
||||
}
|
||||
|
||||
/* Assign path to fwknop rc file
|
||||
*/
|
||||
static void
|
||||
@@ -1752,6 +1804,7 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
|
||||
{
|
||||
int cmd_arg, index, is_err;
|
||||
fko_var_bitmask_t var_bitmask;
|
||||
char rcfile[MAX_PATH_LEN] = {0};
|
||||
|
||||
/* Zero out options, opts_track and bitmask.
|
||||
*/
|
||||
@@ -1780,6 +1833,9 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
|
||||
case SAVE_RC_STANZA:
|
||||
options->save_rc_stanza = 1;
|
||||
break;
|
||||
case STANZA_LIST:
|
||||
options->stanza_list = 1;
|
||||
break;
|
||||
case 'E':
|
||||
strlcpy(options->args_save_file, optarg, sizeof(options->args_save_file));
|
||||
break;
|
||||
@@ -1796,6 +1852,14 @@ config_init(fko_cli_options_t *options, int argc, char **argv)
|
||||
/* Update the verbosity level for the log module */
|
||||
log_set_verbosity(LOG_DEFAULT_VERBOSITY + options->verbose);
|
||||
|
||||
/* Dump the configured stanzas from an rcfile */
|
||||
if (options->stanza_list == 1)
|
||||
{
|
||||
set_rc_file(rcfile, options);
|
||||
dump_configured_stanzas_from_rcfile(rcfile);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* First process the .fwknoprc file.
|
||||
*/
|
||||
process_rc_section(RC_SECTION_DEFAULT, options);
|
||||
@@ -2305,6 +2369,8 @@ usage(void)
|
||||
" -n option.\n"
|
||||
" --force-stanza Used with --save-rc-stanza to overwrite all of\n"
|
||||
" the variables for the specified stanza\n"
|
||||
" --stanza-list Dump a list of the stanzas found in\n"
|
||||
" $HOME/.fwknoprc\n"
|
||||
" --nat-local Access a local service via a forwarded port\n"
|
||||
" on the fwknopd server system.\n"
|
||||
" --nat-port Specify the port to forward to access a\n"
|
||||
|
||||
@@ -161,6 +161,7 @@ typedef struct fko_cli_options
|
||||
unsigned char got_named_stanza;
|
||||
unsigned char save_rc_stanza;
|
||||
unsigned char force_save_rc_stanza;
|
||||
unsigned char stanza_list;
|
||||
|
||||
int input_fd;
|
||||
|
||||
|
||||
@@ -256,6 +256,9 @@ GENERAL OPTIONS
|
||||
Used with *--save-rc-stanza* to overwrite all of the variables for the
|
||||
specified stanza
|
||||
|
||||
*--stanza-list*::
|
||||
Dump a list of the stanzas found in $HOME/.fwknoprc.
|
||||
|
||||
*--show-last*::
|
||||
Display the last command-line arguments used by *fwknop*.
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[default]
|
||||
KEY testkey
|
||||
|
||||
[stanza_1]
|
||||
KEY testkey_1
|
||||
|
||||
[stanza_2]
|
||||
KEY testkey_2
|
||||
@@ -147,6 +147,7 @@ our %cf = (
|
||||
'rc_hmac_sha512_key' => "$conf_dir/fwknoprc_hmac_sha512_key",
|
||||
'rc_hmac_sha512_short_key' => "$conf_dir/fwknoprc_hmac_sha512_short_key",
|
||||
'rc_hmac_sha512_long_key' => "$conf_dir/fwknoprc_hmac_sha512_long_key",
|
||||
'rc_stanza_list' => "$conf_dir/fwknoprc_stanza_list",
|
||||
'base64_key_access' => "$conf_dir/base64_key_access.conf",
|
||||
'custom_input_chain' => "$conf_dir/custom_input_chain_fwknopd.conf",
|
||||
'custom_nat_chain' => "$conf_dir/custom_nat_chain_fwknopd.conf",
|
||||
|
||||
@@ -860,4 +860,14 @@
|
||||
'positive_output_matches' => [qr/Value\s.*out\sof\srange/],
|
||||
'fatal' => $NO
|
||||
},
|
||||
{
|
||||
'category' => 'basic operations',
|
||||
'subcategory' => 'client',
|
||||
'detail' => '--stanza-list',
|
||||
'function' => \&generic_exec,
|
||||
'cmdline' => $default_client_args . " --stanza-list --rc-file $cf{'rc_stanza_list'}",
|
||||
'positive_output_matches' => [qr/The\sfollowing\sstanzas\sare\sconfigured/i, qr/stanza_1/, qr/stanza_2/],
|
||||
'negative_output_matches' => [qr/default/],
|
||||
'fatal' => $NO
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user