add a verbose option that overrides all others

This commit is contained in:
Yves Rutschle 2024-07-10 15:31:55 +02:00
parent 06b7d7ed14
commit b619f5bf36
7 changed files with 76 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Sat Apr 30 09:55:03 2022.
* on Wed Jul 10 15:27:23 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2021 Yves Rutschle
@ -365,7 +365,7 @@ static int clcpy(config_type type, void* target, const void* cl_arg)
return 0;
}
/* Copy the value of a string argument to arbitrary memory
/* Copy the value of a string argument to arbitary memory
* location that must be large enough, converting on the way
* (i.e. CFG_INT gets atoi() and so on) */
/* 0: success
@ -862,7 +862,7 @@ static int set_target_fields(void* target_addr, struct compound_cl_arg* arg, con
if (pmatch[pmatch_cnt].rm_so == -1) {
/* This should not happen as regexec() did
* match before, unless there is a
* discrepancy between the regex and the
* discrepency between the regex and the
* number of backreferences */
return 0;
}
@ -1155,7 +1155,7 @@ static void scalar_to_string(char** strp, config_setting_t* s)
/* Typesets all the settings in a configuration as a
* newly-allocated string. The string management is caller's
* responsibility.
* responsability.
* Returns the number of scalars in the configuration */
static int cfg_as_string(config_setting_t* parent, const char* path, char** strp)
{

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Sat Apr 30 09:55:03 2022.
* on Wed Jul 10 15:27:23 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2021 Yves Rutschle

View File

@ -16,6 +16,7 @@ chroot: "/var/empty";
# Value: 1: stdout; 2: syslog; 3: stdout+syslog; 4: logfile; ...; 7: all
# Defaults are indicated here, and should be sensible. Generally, you want *-error
# to be always enabled, to know if something is going wrong.
# Each option relates to a different set of messages.
verbose-config: 0; # print configuration at startup
verbose-config-error: 3; # print configuration errors
verbose-connections: 3; # trace established incoming address to forward address
@ -28,6 +29,9 @@ verbose-probe-error: 3; # failures and problems during probing
verbose-system-error: 3; # system call problem, i.e. malloc, fork, failing
verbose-int-error: 3; # internal errors, the kind that should never happen
# This one is special and overrides all previous options if
# set, as a quick way to get "as much as possible"
#verbose: 3;
# Specify a path to the logfile.
#logfile: "/var/log/sslh.log"

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Tue Jan 2 21:25:47 2024.
* on Wed Jul 10 15:27:23 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2021 Yves Rutschle
@ -443,6 +443,7 @@ struct compound_cl_arg {
struct arg_file* sslhcfg_conffile;
struct arg_int* sslhcfg_verbose;
struct arg_int* sslhcfg_verbose_config;
struct arg_int* sslhcfg_verbose_config_error;
struct arg_int* sslhcfg_verbose_connections;
@ -814,10 +815,26 @@ static struct config_desc table_sslhcfg_listen[] = {
},
{ 0 }
};
static struct config_desc table_sslhcfg[] = {
{
/* name */ "verbose",
/* type */ CFG_INT,
/* sub_group*/ NULL,
/* arg_cl */ & sslhcfg_verbose,
/* base_addr */ NULL,
/* offset */ offsetof(struct sslhcfg_item, verbose),
/* offset_len */ 0,
/* offset_present */ 0,
/* size */ sizeof(int),
/* array_type */ -1,
/* mandatory */ 0,
/* optional */ 0,
/* default_val*/ .default_val.def_int = 0
},
{
/* name */ "verbose_config",
/* type */ CFG_INT,
@ -1372,7 +1389,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: listen */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_listen,
.base_entry = & table_sslhcfg [25],
.base_entry = & table_sslhcfg [26],
.targets = sslhcfg_listen_targets,
@ -1384,7 +1401,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: ssh */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_ssh,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_ssh_targets,
@ -1396,7 +1413,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: tls */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_tls,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_tls_targets,
@ -1408,7 +1425,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: ssl */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_ssl,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_ssl_targets,
@ -1420,7 +1437,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: openvpn */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_openvpn,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_openvpn_targets,
@ -1432,7 +1449,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: tinc */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_tinc,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_tinc_targets,
@ -1444,7 +1461,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: wireguard */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_wireguard,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_wireguard_targets,
@ -1456,7 +1473,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: xmpp */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_xmpp,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_xmpp_targets,
@ -1468,7 +1485,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: http */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_http,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_http_targets,
@ -1480,7 +1497,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: adb */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_adb,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_adb_targets,
@ -1492,7 +1509,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: socks5 */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_socks5,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_socks5_targets,
@ -1504,7 +1521,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: syslog */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_syslog,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_syslog_targets,
@ -1516,7 +1533,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: msrdp */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_msrdp,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_msrdp_targets,
@ -1528,7 +1545,7 @@ static struct compound_cl_arg compound_cl_args[] = {
{ /* arg: anyprot */
.regex = "(.+):(\\w+)",
.arg_cl = & sslhcfg_anyprot,
.base_entry = & table_sslhcfg [26],
.base_entry = & table_sslhcfg [27],
.targets = sslhcfg_anyprot_targets,
@ -2193,6 +2210,7 @@ int sslhcfg_cl_parse(int argc, char* argv[], struct sslhcfg_item* cfg)
#ifdef LIBCONFIG
sslhcfg_conffile = arg_filen("F", "config", "<file>", 0, 1, "Specify configuration file"),
#endif
sslhcfg_verbose = arg_intn(NULL, "verbose", "<n>", 0, 1, "Override all verbosness options"),
sslhcfg_verbose_config = arg_intn(NULL, "verbose-config", "<n>", 0, 1, "Print configuration at startup"),
sslhcfg_verbose_config_error = arg_intn(NULL, "verbose-config-error", "<n>", 0, 1, "Print configuration errors"),
sslhcfg_verbose_connections = arg_intn(NULL, "verbose-connections", "<n>", 0, 1, "Trace established incoming address to forward address"),
@ -2239,13 +2257,10 @@ int sslhcfg_cl_parse(int argc, char* argv[], struct sslhcfg_item* cfg)
/* Parse command line */
nerrors = arg_parse(argc, argv, argtable);
if (nerrors) {
// print bad args
arg_print_errors(stdout, sslhcfg_end, "sslhcfg");
// print usage
arg_print_errors(stdout, sslhcfg_end, "sslhcfg");
arg_print_syntax(stdout, argtable, "\n");
// print options
arg_print_glossary(stdout, argtable, " %-25s\t%s\n");
fprintf(stderr, "Invalid args are ignored, please fix them\n");
return -1;
}
@ -2382,6 +2397,9 @@ void sslhcfg_fprint(
int depth)
{
int i;
indent(out, depth);
fprintf(out, "verbose: %d", sslhcfg->verbose);
fprintf(out, "\n");
indent(out, depth);
fprintf(out, "verbose_config: %d", sslhcfg->verbose_config);
fprintf(out, "\n");

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Tue Jan 2 21:25:47 2024.
* on Wed Jul 10 15:27:23 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2021 Yves Rutschle
@ -76,6 +76,7 @@ struct sslhcfg_protocols_item {
};
struct sslhcfg_item {
int verbose;
int verbose_config;
int verbose_config_error;
int verbose_connections;

View File

@ -129,6 +129,27 @@ static void setup_regex_probe(struct sslhcfg_protocols_item *p)
}
#endif
/* Perform some fixups on configuration after reading it.
* if verbose is present, override all other verbose options
*/
void config_finish(struct sslhcfg_item* cfg)
{
if (cfg->verbose) {
cfg->verbose_config = cfg->verbose;
cfg->verbose_config_error = cfg->verbose;
cfg->verbose_connections = cfg->verbose;
cfg->verbose_connections_try = cfg->verbose;
cfg->verbose_connections_error = cfg->verbose;
cfg->verbose_fd = cfg->verbose;
cfg->verbose_packets = cfg->verbose;
cfg->verbose_probe_info = cfg->verbose;
cfg->verbose_probe_error = cfg->verbose;
cfg->verbose_system_error = cfg->verbose;
cfg->verbose_int_error = cfg->verbose;
}
}
/* For each protocol in the configuration, resolve address and set up protocol
* options if required
*/
@ -235,6 +256,9 @@ int main(int argc, char *argv[], char* envp[])
memset(&cfg, 0, sizeof(cfg));
res = sslhcfg_cl_parse(argc, argv, &cfg);
if (res) exit(6);
config_finish(&cfg);
sslhcfg_fprint(stdout, &cfg, 0);
if (cfg.version) {
printf("%s %s\n", server_type, VERSION);

View File

@ -25,6 +25,8 @@ config: {
name : "sslhcfg",
type: "list",
items: (
{ name: "verbose"; type: "int" default: 0;
description: "Override all verbosness options" },
{ name: "verbose-config"; type: "int"; default: 0;
description: "Print configuration at startup" },
{ name: "verbose-config-error"; type: "int"; default: 3;