NeoMutt  2024-12-12-14-g7b49f7
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" config variable - 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 45 of file charset.c.

47{
48 if (value == 0)
49 return CSR_SUCCESS;
50
51 const char *str = (const char *) value;
52
53 if ((cdef->type & D_CHARSET_SINGLE) && strchr(str, ':'))
54 {
55 buf_printf(err, _("'charset' must contain exactly one character set name"));
56 return CSR_ERR_INVALID;
57 }
58
59 int rc = CSR_SUCCESS;
60 bool strict = (cdef->type & D_CHARSET_STRICT);
61 char *q = NULL;
62 char *s = mutt_str_dup(str);
63
64 for (char *p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q))
65 {
66 if (*p == '\0')
67 continue; // LCOV_EXCL_LINE
68 if (!mutt_ch_check_charset(p, strict))
69 {
70 rc = CSR_ERR_INVALID;
71 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, p);
72 break;
73 }
74 }
75
76 FREE(&s);
77 return rc;
78}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
#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:55
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:894
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define D_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition: types.h:84
#define D_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition: types.h:85
+ 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 85 of file charset.c.

87{
88 if (value == 0)
89 return CSR_SUCCESS;
90
91 const struct Slist *list = (const struct Slist *) value;
92
93 int rc = CSR_SUCCESS;
94 bool strict = (cdef->type & D_CHARSET_STRICT);
95
96 const struct ListNode *np = NULL;
97 STAILQ_FOREACH(np, &list->head, entries)
98 {
99 char const *charset = np->data;
100 if (!mutt_ch_check_charset(charset, strict))
101 {
102 rc = CSR_ERR_INVALID;
103 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, charset);
104 break;
105 }
106 }
107
108 return rc;
109}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A List node for strings.
Definition: list.h:37
char * data
String.
Definition: list.h:38
String list.
Definition: slist.h:37
struct ListHead head
List containing values.
Definition: slist.h:38
+ 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 44 of file config.c.

46{
47#ifdef USE_HCACHE
48 if (value == 0)
49 return CSR_SUCCESS;
50
51 const char *str = (const char *) value;
52
54 return CSR_SUCCESS;
55
56 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
57 return CSR_ERR_INVALID;
58#else
59 return CSR_SUCCESS;
60#endif
61}
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:129
+ 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 67 of file config.c.

70{
71#ifdef USE_HCACHE_COMPRESSION
72 if (value == 0)
73 return CSR_SUCCESS;
74
75 const char *str = (const char *) value;
76
77 if (compress_get_ops(str))
78 return CSR_SUCCESS;
79
80 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
81 return CSR_ERR_INVALID;
82#else
83 return CSR_SUCCESS;
84#endif
85}
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition: compress.c:81
+ 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 90 of file config.c.

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

47{
48 const struct Slist *imap_auth_methods = (const struct Slist *) value;
49 if (!imap_auth_methods || (imap_auth_methods->count == 0))
50 return CSR_SUCCESS;
51
52 struct ListNode *np = NULL;
53 STAILQ_FOREACH(np, &imap_auth_methods->head, entries)
54 {
55 if (imap_auth_is_valid(np->data))
56 continue;
57#ifdef USE_SASL_CYRUS
59 continue;
60#endif
61 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
62 return CSR_ERR_INVALID;
63 }
64
65 return CSR_SUCCESS;
66}
bool imap_auth_is_valid(const char *authenticator)
Check if string is a valid imap authentication method.
Definition: auth.c:95
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:136
size_t count
Number of values in list.
Definition: slist.h:39
+ 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 44 of file config.c.

47{
48 const char *delim = (const char *) value;
49
50 if (strlen(delim) != 1)
51 {
52 // L10N: maildir_field_delimiter is a config variable and shouldn't be translated
53 buf_printf(err, _("maildir_field_delimiter must be exactly one character long"));
54 return CSR_ERR_INVALID;
55 }
56
57 if (isalnum(*delim) || strchr("-.\\/", *delim))
58 {
59 // L10N: maildir_field_delimiter is a config variable and shouldn't be translated
60 buf_printf(err, _("maildir_field_delimiter cannot be alphanumeric or '-.\\/'"));
61 return CSR_ERR_INVALID;
62 }
63
64 return CSR_SUCCESS;
65}
+ 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 112 of file mutt_config.c.

114{
115 if (value == 0)
116 return CSR_SUCCESS;
117
118 const char *str = (const char *) value;
119
120 if (mutt_str_equal(str, "inline") || mutt_str_equal(str, "info"))
121 return CSR_SUCCESS;
122
123 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
124 return CSR_ERR_INVALID;
125}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
+ 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 270 of file mutt_logging.c.

272{
273 if ((value < 0) || (value >= LL_MAX))
274 {
275 buf_printf(err, _("Invalid value for option %s: %ld"), cdef->name, (long) value);
276 return CSR_ERR_INVALID;
277 }
278
279 return CSR_SUCCESS;
280}
@ 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 107 of file mutt_thread.c.

109{
110 if (((value & SORT_MASK) == EMAIL_SORT_THREADS) && (value & SORT_LAST))
111 {
112 buf_printf(err, _("Cannot use 'last-' prefix with 'threads' for %s"), cdef->name);
113 return CSR_ERR_INVALID;
114 }
115 return CSR_SUCCESS;
116}
#define SORT_MASK
Mask for the sort id.
Definition: sort.h:38
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort.h:40
@ EMAIL_SORT_THREADS
Sort by email threads.
Definition: sort.h:62
+ 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 58 of file config.c.

60{
61#ifdef USE_NOTMUCH
62 const char *url = (const char *) value;
63 if (!is_valid_notmuch_url(url))
64 {
65 buf_printf(err, _("nm_default_url must be: notmuch://<absolute path> . Current: %s"), url);
66 return CSR_ERR_INVALID;
67 }
68#endif
69 return CSR_SUCCESS;
70}
static bool is_valid_notmuch_url(const char *url)
Checks that a URL is in required form.
Definition: config.c:47
+ 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 84 of file config.c.

87{
88#ifdef USE_NOTMUCH
89 const char *timebase = (const char *) value;
90 if (!nm_query_window_check_timebase(timebase))
91 {
93 // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
94 // They should not be translated.
95 err, _("Invalid nm_query_window_timebase value (valid values are: "
96 "hour, day, week, month, year)"));
97 return CSR_ERR_INVALID;
98 }
99#endif
100 return CSR_SUCCESS;
101}
bool nm_query_window_check_timebase(const char *timebase)
Checks if a given timebase string is valid.
Definition: query.c:149
+ 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 45 of file config.c.

47{
48 const struct Slist *pop_auth_methods = (const struct Slist *) value;
49 if (!pop_auth_methods || (pop_auth_methods->count == 0))
50 return CSR_SUCCESS;
51
52 struct ListNode *np = NULL;
53 STAILQ_FOREACH(np, &pop_auth_methods->head, entries)
54 {
55 if (pop_auth_is_valid(np->data))
56 continue;
57#ifdef USE_SASL_CYRUS
59 continue;
60#endif
61 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
62 return CSR_ERR_INVALID;
63 }
64
65 return CSR_SUCCESS;
66}
bool pop_auth_is_valid(const char *authenticator)
Check if string is a valid pop authentication method.
Definition: auth.c:502
+ 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 58 of file config.c.

60{
61 const int min_length = 78; // Recommendations from RFC5233
62 const int max_length = 998;
63
64 if ((value >= min_length) && (value <= max_length))
65 return CSR_SUCCESS;
66
67 // L10N: This applies to the "$wrap_headers" config variable.
68 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
69 cdef->name, min_length, max_length);
70 return CSR_ERR_INVALID;
71}
+ 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 76 of file config.c.

78{
79 const struct Slist *smtp_auth_methods = (const struct Slist *) value;
80 if (!smtp_auth_methods || (smtp_auth_methods->count == 0))
81 return CSR_SUCCESS;
82
83 struct ListNode *np = NULL;
84 STAILQ_FOREACH(np, &smtp_auth_methods->head, entries)
85 {
86 if (smtp_auth_is_valid(np->data))
87 continue;
88#ifdef USE_SASL_CYRUS
90 continue;
91#endif
92 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
93 return CSR_ERR_INVALID;
94 }
95
96 return CSR_SUCCESS;
97}
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition: smtp.c:926
+ 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" config variable - Implements ConfigDef::validator() -.

Definition at line 102 of file config.c.

104{
105 // Check for shell metacharacters that won't do what the user expects
106 const char *valstr = (const char *) value;
107 if (!valstr)
108 return CSR_SUCCESS;
109
110 const char c = valstr[strcspn(valstr, "|&;()<>[]{}$`'~\"\\*?")];
111 if (c == '\0')
112 return CSR_SUCCESS;
113
114 // L10N: This applies to the "$sendmail" and "$inews" config variables.
115 buf_printf(err, _("Option %s must not contain shell metacharacters: %c"), cdef->name, c);
116 return CSR_ERR_INVALID;
117}
+ Here is the call graph for this function: