NeoMutt  2023-11-03-107-g582dc1
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

Validate a config variable. More...

+ Collaboration diagram for validator():

Functions

int charset_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variables - Implements ConfigDef::validator() -.
 
int charset_slist_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the multiple "charset" config variables - Implements ConfigDef::validator() -.
 
static int hcache_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() -.
 
static int compress_method_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "header_cache_compress_method" config variable - Implements ConfigDef::validator() -.
 
static int compress_level_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "header_cache_compress_level" config variable - Implements ConfigDef::validator() -.
 
static int imap_auth_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "imap_authenticators" config variable - Implements ConfigDef::validator() -.
 
static int maildir_field_delimiter_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "maildir_field_delimiter" config variable - Implements ConfigDef::validator() -.
 
static int multipart_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "show_multipart_alternative" config variable - Implements ConfigDef::validator() -.
 
int level_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "debug_level" config variable - Implements ConfigDef::validator() -.
 
int sort_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "sort" config variable - Implements ConfigDef::validator() -.
 
static int nm_default_url_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "nm_default_url" config variable - Implements ConfigDef::validator() -.
 
static int nm_query_window_timebase_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "nm_query_window_timebase" config variable - Implements ConfigDef::validator() -.
 
static int pop_auth_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "pop_authenticators" config variable - Implements ConfigDef::validator() -.
 
static int wrapheaders_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "wrap_headers" config variable - Implements ConfigDef::validator() -.
 
static int smtp_auth_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -.
 
static int simple_command_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "sendmail" and "inews" config variables - Implements ConfigDef::validator() -.
 

Detailed Description

Validate a config variable.

Parameters
csConfig items
cdefConfig definition
valueNative value
errMessage for the user
Return values
CSR_SUCCESSSuccess
CSR_ERR_INVALIDFailure

Function Documentation

◆ charset_validator()

int charset_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "charset" config variables - Implements ConfigDef::validator() -.

Validate the config variables that contain a single charset.

Definition at line 42 of file charset.c.

44{
45 if (value == 0)
46 return CSR_SUCCESS;
47
48 const char *str = (const char *) value;
49
50 if ((cdef->type & DT_CHARSET_SINGLE) && strchr(str, ':'))
51 {
52 buf_printf(err, _("'charset' must contain exactly one character set name"));
53 return CSR_ERR_INVALID;
54 }
55
56 int rc = CSR_SUCCESS;
57 bool strict = (cdef->type & DT_CHARSET_STRICT);
58 char *q = NULL;
59 char *s = mutt_str_dup(str);
60
61 for (char *p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q))
62 {
63 if (*p == '\0')
64 continue; // LCOV_EXCL_LINE
65 if (!mutt_ch_check_charset(p, strict))
66 {
67 rc = CSR_ERR_INVALID;
68 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, p);
69 break;
70 }
71 }
72
73 FREE(&s);
74 return rc;
75}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
#define DT_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition: charset.h:28
#define DT_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition: charset.h:29
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define FREE(x)
Definition: memory.h:45
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:889
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
+ Here is the call graph for this function:

◆ charset_slist_validator()

int charset_slist_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the multiple "charset" config variables - Implements ConfigDef::validator() -.

Validate the config variables that can contain a multiple charsets.

Definition at line 82 of file charset.c.

84{
85 if (value == 0)
86 return CSR_SUCCESS;
87
88 const struct Slist *list = (const struct Slist *) value;
89
90 int rc = CSR_SUCCESS;
91 bool strict = (cdef->type & DT_CHARSET_STRICT);
92
93 const struct ListNode *np = NULL;
94 STAILQ_FOREACH(np, &list->head, entries)
95 {
96 char const *charset = np->data;
97 if (!mutt_ch_check_charset(charset, strict))
98 {
99 rc = CSR_ERR_INVALID;
100 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, charset);
101 break;
102 }
103 }
104
105 return rc;
106}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
String list.
Definition: slist.h:47
struct ListHead head
List containing values.
Definition: slist.h:48
+ Here is the call graph for this function:

◆ hcache_validator()

static int hcache_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "header_cache_backend" config variable - Implements ConfigDef::validator() -.

Definition at line 42 of file config.c.

44{
45#ifdef USE_HCACHE
46 if (value == 0)
47 return CSR_SUCCESS;
48
49 const char *str = (const char *) value;
50
52 return CSR_SUCCESS;
53
54 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
55 return CSR_ERR_INVALID;
56#else
57 return CSR_SUCCESS;
58#endif
59}
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:128
+ Here is the call graph for this function:

◆ compress_method_validator()

static int compress_method_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "header_cache_compress_method" config variable - Implements ConfigDef::validator() -.

Definition at line 65 of file config.c.

68{
69#ifdef USE_HCACHE_COMPRESSION
70 if (value == 0)
71 return CSR_SUCCESS;
72
73 const char *str = (const char *) value;
74
75 if (compress_get_ops(str))
76 return CSR_SUCCESS;
77
78 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
79 return CSR_ERR_INVALID;
80#else
81 return CSR_SUCCESS;
82#endif
83}
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:79
+ Here is the call graph for this function:

◆ compress_level_validator()

static int compress_level_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "header_cache_compress_level" config variable - Implements ConfigDef::validator() -.

Definition at line 88 of file config.c.

90{
91#ifdef USE_HCACHE_COMPRESSION
92 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
93 if (!c_header_cache_compress_method)
94 {
95 buf_printf(err, _("Set option %s before setting %s"),
96 "header_cache_compress_method", cdef->name);
97 return CSR_ERR_INVALID;
98 }
99
100 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
101 if (!cops)
102 {
103 buf_printf(err, _("Invalid value for option %s: %s"),
104 "header_cache_compress_method", c_header_cache_compress_method);
105 return CSR_ERR_INVALID;
106 }
107
108 if ((value < cops->min_level) || (value > cops->max_level))
109 {
110 // L10N: This applies to the "$header_cache_compress_level" config variable.
111 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
112 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
113 cdef->name, cops->min_level, cops->max_level);
114 return CSR_ERR_INVALID;
115 }
116#endif
117 return CSR_SUCCESS;
118}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
Definition: lib.h:63
short max_level
Maximum compression level.
Definition: lib.h:66
short min_level
Minimum compression level.
Definition: lib.h:65
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:

◆ imap_auth_validator()

static int imap_auth_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "imap_authenticators" config variable - Implements ConfigDef::validator() -.

Definition at line 43 of file config.c.

45{
46 const struct Slist *imap_auth_methods = (const struct Slist *) value;
47 if (!imap_auth_methods || (imap_auth_methods->count == 0))
48 return CSR_SUCCESS;
49
50 struct ListNode *np = NULL;
51 STAILQ_FOREACH(np, &imap_auth_methods->head, entries)
52 {
53 if (imap_auth_is_valid(np->data))
54 continue;
55#ifdef USE_SASL_CYRUS
57 continue;
58#endif
59 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
60 return CSR_ERR_INVALID;
61 }
62
63 return CSR_SUCCESS;
64}
bool imap_auth_is_valid(const char *authenticator)
Check if string is a valid imap authentication method.
Definition: auth.c:92
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:135
size_t count
Number of values in list.
Definition: slist.h:49
+ Here is the call graph for this function:

◆ maildir_field_delimiter_validator()

static int maildir_field_delimiter_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "maildir_field_delimiter" config variable - Implements ConfigDef::validator() -.

Ensure maildir_field_delimiter is a single non-alphanumeric non-(-.\/) character.

Definition at line 43 of file config.c.

46{
47 const char *delim = (const char *) value;
48
49 if (strlen(delim) != 1)
50 {
51 // L10N: maildir_field_delimiter is a config variable and shouldn't be translated
52 buf_printf(err, _("maildir_field_delimiter must be exactly one character long"));
53 return CSR_ERR_INVALID;
54 }
55
56 if (isalnum(*delim) || strchr("-.\\/", *delim))
57 {
58 // L10N: maildir_field_delimiter is a config variable and shouldn't be translated
59 buf_printf(err, _("maildir_field_delimiter cannot be alphanumeric or '-.\\/'"));
60 return CSR_ERR_INVALID;
61 }
62
63 return CSR_SUCCESS;
64}
+ Here is the call graph for this function:

◆ multipart_validator()

static int multipart_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "show_multipart_alternative" config variable - Implements ConfigDef::validator() -.

Definition at line 97 of file mutt_config.c.

99{
100 if (value == 0)
101 return CSR_SUCCESS;
102
103 const char *str = (const char *) value;
104
105 if (mutt_str_equal(str, "inline") || mutt_str_equal(str, "info"))
106 return CSR_SUCCESS;
107
108 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
109 return CSR_ERR_INVALID;
110}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:763
+ Here is the call graph for this function:

◆ level_validator()

int level_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "debug_level" config variable - Implements ConfigDef::validator() -.

Definition at line 269 of file mutt_logging.c.

271{
272 if ((value < 0) || (value >= LL_MAX))
273 {
274 buf_printf(err, _("Invalid value for option %s: %ld"), cdef->name, (long) value);
275 return CSR_ERR_INVALID;
276 }
277
278 return CSR_SUCCESS;
279}
@ LL_MAX
Definition: logging2.h:50
+ Here is the call graph for this function:

◆ sort_validator()

int sort_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "sort" config variable - Implements ConfigDef::validator() -.

Definition at line 105 of file mutt_thread.c.

107{
108 if (((value & SORT_MASK) == SORT_THREADS) && (value & SORT_LAST))
109 {
110 buf_printf(err, _("Cannot use 'last-' prefix with 'threads' for %s"), cdef->name);
111 return CSR_ERR_INVALID;
112 }
113 return CSR_SUCCESS;
114}
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:76
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:45
+ Here is the call graph for this function:

◆ nm_default_url_validator()

static int nm_default_url_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "nm_default_url" config variable - Implements ConfigDef::validator() -.

Ensure nm_default_url is of the form notmuch://[absolute path]

Definition at line 56 of file config.c.

58{
59#ifdef USE_NOTMUCH
60 const char *url = (const char *) value;
61 if (!is_valid_notmuch_url(url))
62 {
63 buf_printf(err, _("nm_default_url must be: notmuch://<absolute path> . Current: %s"), url);
64 return CSR_ERR_INVALID;
65 }
66#endif
67 return CSR_SUCCESS;
68}
static bool is_valid_notmuch_url(const char *url)
Checks that a URL is in required form.
Definition: config.c:45
+ Here is the call graph for this function:

◆ nm_query_window_timebase_validator()

static int nm_query_window_timebase_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "nm_query_window_timebase" config variable - Implements ConfigDef::validator() -.

Ensure $nm_query_window_timebase matches allowed values.

Allowed values:

  • hour
  • day
  • week
  • month
  • year

Definition at line 82 of file config.c.

85{
86#ifdef USE_NOTMUCH
87 const char *timebase = (const char *) value;
88 if (!nm_query_window_check_timebase(timebase))
89 {
91 // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
92 // They should not be translated.
93 err, _("Invalid nm_query_window_timebase value (valid values are: "
94 "hour, day, week, month, year)"));
95 return CSR_ERR_INVALID;
96 }
97#endif
98 return CSR_SUCCESS;
99}
bool nm_query_window_check_timebase(const char *timebase)
Checks if a given timebase string is valid.
Definition: query.c:148
+ Here is the call graph for this function:

◆ pop_auth_validator()

static int pop_auth_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "pop_authenticators" config variable - Implements ConfigDef::validator() -.

Definition at line 41 of file config.c.

43{
44 const struct Slist *pop_auth_methods = (const struct Slist *) value;
45 if (!pop_auth_methods || (pop_auth_methods->count == 0))
46 return CSR_SUCCESS;
47
48 struct ListNode *np = NULL;
49 STAILQ_FOREACH(np, &pop_auth_methods->head, entries)
50 {
51 if (pop_auth_is_valid(np->data))
52 continue;
53#ifdef USE_SASL_CYRUS
55 continue;
56#endif
57 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
58 return CSR_ERR_INVALID;
59 }
60
61 return CSR_SUCCESS;
62}
bool pop_auth_is_valid(const char *authenticator)
Check if string is a valid pop authentication method.
Definition: auth.c:500
+ Here is the call graph for this function:

◆ wrapheaders_validator()

static int wrapheaders_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "wrap_headers" config variable - Implements ConfigDef::validator() -.

Definition at line 44 of file config.c.

46{
47 const int min_length = 78; // Recommendations from RFC5233
48 const int max_length = 998;
49
50 if ((value >= min_length) && (value <= max_length))
51 return CSR_SUCCESS;
52
53 // L10N: This applies to the "$wrap_headers" config variable.
54 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
55 cdef->name, min_length, max_length);
56 return CSR_ERR_INVALID;
57}
+ Here is the call graph for this function:

◆ smtp_auth_validator()

static int smtp_auth_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -.

Definition at line 62 of file config.c.

64{
65 const struct Slist *smtp_auth_methods = (const struct Slist *) value;
66 if (!smtp_auth_methods || (smtp_auth_methods->count == 0))
67 return CSR_SUCCESS;
68
69 struct ListNode *np = NULL;
70 STAILQ_FOREACH(np, &smtp_auth_methods->head, entries)
71 {
72 if (smtp_auth_is_valid(np->data))
73 continue;
74#ifdef USE_SASL_CYRUS
76 continue;
77#endif
78 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
79 return CSR_ERR_INVALID;
80 }
81
82 return CSR_SUCCESS;
83}
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition: smtp.c:931
+ Here is the call graph for this function:

◆ simple_command_validator()

static int simple_command_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

Validate the "sendmail" and "inews" config variables - Implements ConfigDef::validator() -.

Definition at line 88 of file config.c.

90{
91 // Check for shell metacharacters that won't do what the user expects
92 const char *valstr = (const char *) value;
93 if (!valstr)
94 return CSR_SUCCESS;
95
96 const char c = valstr[strcspn(valstr, "|&;()<>[]{}$`'~\"\\*?")];
97 if (c == '\0')
98 return CSR_SUCCESS;
99
100 // L10N: This applies to the "$sendmail" and "$inews" config variables.
101 buf_printf(err, _("Option %s must not contain shell metacharacters: %c"), cdef->name, c);
102 return CSR_ERR_INVALID;
103}
+ Here is the call graph for this function: