summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2019-10-12 09:39:28 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2019-10-12 09:39:28 (GMT)
commit6ec886e647516e800febddee3f70491edfb561b0 (patch) (side-by-side diff)
tree27b8b989706f86bcf152b051239327b13614b045
parent5e408fbd531ace6094415762762a82ee40118ecb (diff)
downloadmailutils-6ec886e647516e800febddee3f70491edfb561b0.tar.gz
mailutils-6ec886e647516e800febddee3f70491edfb561b0.tar.bz2
cli: implement a hint that disallows overriding configuration from the command line
* include/mailutils/cfg.h (MU_CFHINT_NO_CONFIG_OVERRIDE): New hint. * libmailutils/cli/cli.c (init_options): Omit configuration override options if MU_CFHINT_NO_CONFIG_OVERRIDE is set.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/mailutils/cfg.h23
-rw-r--r--libmailutils/cli/cli.c46
2 files changed, 38 insertions, 31 deletions
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index 1a35886..fa5183f 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -83,31 +83,34 @@ struct mu_cfg_parse_hints
/* Bit constants for the flags field of struct mu_cfg_parse_hints */
/* Parse site-wide configuration file hints.site_file */
-#define MU_CFHINT_SITE_FILE 0x0001
+#define MU_CFHINT_SITE_FILE 0x0001
/* Parse custom configuration file hints.custom_file */
-#define MU_CFHINT_CUSTOM_FILE 0x0002
+#define MU_CFHINT_CUSTOM_FILE 0x0002
/* The hints.program field is set. The "program PROGNAME" section
will be processed, if PROGNAME is the same as hints.program.
If include statement is used with the directory name DIR as its
argument, the file DIR/PROGNAME will be looked up and read in,
if it exists. */
-#define MU_CFHINT_PROGRAM 0x0004
+#define MU_CFHINT_PROGRAM 0x0004
/* If MU_CFHINT_PROGRAM is set, look for the file ~/.PROGNAME after parsing
site-wide configuration */
-#define MU_CFHINT_PER_USER_FILE 0x0008
-
+#define MU_CFHINT_PER_USER_FILE 0x0008
+
+/* Don't allow to overide configuration settings from the command line. */
+#define MU_CFHINT_NO_CONFIG_OVERRIDE 0x0010
+
/* Verbosely log files being processed */
-#define MU_CF_VERBOSE 0x0010
+#define MU_CF_VERBOSE 0x0100
/* Dump the pare tree on stderr */
-#define MU_CF_DUMP 0x0020
+#define MU_CF_DUMP 0x0200
/* Format location of the statement */
-#define MU_CF_FMT_LOCUS 0x0100
+#define MU_CF_FMT_LOCUS 0x1000
/* Print only value */
-#define MU_CF_FMT_VALUE_ONLY 0x0200
+#define MU_CF_FMT_VALUE_ONLY 0x2000
/* Print full parameter path */
-#define MU_CF_FMT_PARAM_PATH 0x0400
+#define MU_CF_FMT_PARAM_PATH 0x4000
struct mu_cfg_tree
{
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 90f9cab..5b0a189 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -252,23 +252,23 @@ static struct mu_option mu_no_config_option = {
/* These options are always available for utilities that use at least
one of default configuration files */
-static struct mu_option mu_config_options[] = {
- { "config-file", 0, N_("FILE"), MU_OPTION_IMMEDIATE,
- N_("load this configuration file; implies --no-config"),
- mu_c_string, NULL, config_file },
-
+static struct mu_option mu_config_lint_options[] = {
{ "config-verbose", 0, NULL, MU_OPTION_IMMEDIATE,
N_("verbosely log parsing of the configuration files"),
mu_c_string, NULL, config_verbose },
-
{ "config-lint", 0, NULL, MU_OPTION_IMMEDIATE,
N_("check configuration file syntax and exit"),
mu_c_string, NULL, config_lint },
+ MU_OPTION_END
+};
+static struct mu_option mu_config_override_options[] = {
+ { "config-file", 0, N_("FILE"), MU_OPTION_IMMEDIATE,
+ N_("load this configuration file; implies --no-config"),
+ mu_c_string, NULL, config_file },
{ "set", 0, N_("PARAM=VALUE"), MU_OPTION_IMMEDIATE,
N_("set configuration parameter"),
mu_c_string, NULL, param_set },
-
MU_OPTION_END
};
@@ -425,29 +425,33 @@ init_options (mu_opool_t pool,
if (hints->flags & CONFIG_ENABLED)
{
opool_add_option (pool, &mu_config_option_header);
- opool_add_options (pool, mu_config_options);
- if (hints->flags & MU_CFHINT_SITE_FILE)
+ opool_add_options (pool, mu_config_lint_options);
+ if (!(hints->flags & MU_CFHINT_NO_CONFIG_OVERRIDE))
{
- opool_add_options (pool, mu_site_config_options);
- if (hints->flags & MU_CFHINT_PER_USER_FILE)
+ opool_add_options (pool, mu_config_override_options);
+ if (hints->flags & MU_CFHINT_SITE_FILE)
{
- opool_add_options (pool, mu_user_config_options);
- opool_add_option (pool, &mu_no_config_option);
+ opool_add_options (pool, mu_site_config_options);
+ if (hints->flags & MU_CFHINT_PER_USER_FILE)
+ {
+ opool_add_options (pool, mu_user_config_options);
+ opool_add_option (pool, &mu_no_config_option);
+ }
+ else
+ {
+ struct mu_option opt = mu_no_config_option;
+ opt.opt_flags = MU_OPTION_ALIAS;
+ opool_add_option (pool, &opt);
+ }
}
- else
+ else if (hints->flags & MU_CFHINT_PER_USER_FILE)
{
struct mu_option opt = mu_no_config_option;
+ opool_add_options (pool, mu_user_config_options);
opt.opt_flags = MU_OPTION_ALIAS;
opool_add_option (pool, &opt);
}
}
- else if (hints->flags & MU_CFHINT_PER_USER_FILE)
- {
- struct mu_option opt = mu_no_config_option;
- opool_add_options (pool, mu_user_config_options);
- opt.opt_flags = MU_OPTION_ALIAS;
- opool_add_option (pool, &opt);
- }
mu_list_append (oplist, opool_end_option (pool));
}

Return to:

Send suggestions and report system problems to the System administrator.