NeoMutt  2025-01-09-117-gace867
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 ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variables - Implements ConfigDef::validator() -.
 
int charset_slist_validator (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 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 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 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 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 ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "maildir_field_delimiter" config variable - Implements ConfigDef::validator() -.
 
static int multipart_validator (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 ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "debug_level" config variable - Implements ConfigDef::validator() -.
 
int sort_validator (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 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 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 ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "pop_authenticators" config variable - Implements ConfigDef::validator() -.
 
static int wrapheaders_validator (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 ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -.
 
static int simple_command_validator (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
cdefConfig definition
valueNative value
errMessage for the user
Return values
CSR_SUCCESSSuccess
CSR_ERR_INVALIDFailure

Function Documentation

◆ charset_validator()

int charset_validator ( 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.

46{
47 if (value == 0)
48 return CSR_SUCCESS;
49
50 const char *str = (const char *) value;
51
52 if ((cdef->type & D_CHARSET_SINGLE) && strchr(str, ':'))
53 {
54 buf_printf(err, _("'charset' must contain exactly one character set name"));
55 return CSR_ERR_INVALID;
56 }
57
58 int rc = CSR_SUCCESS;
59 bool strict = (cdef->type & D_CHARSET_STRICT);
60 char *q = NULL;
61 char *s = mutt_str_dup(str);
62
63 for (char *p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q))
64 {
65 if (*p == '\0')
66 continue; // LCOV_EXCL_LINE
67 if (!mutt_ch_check_charset(p, strict))
68 {
69 rc = CSR_ERR_INVALID;
70 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, p);
71 break;
72 }
73 }
74
75 FREE(&s);
76 return rc;
77}
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:36
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:33
#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:254
const char * name
User-visible name.
Definition: set.h:63
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:64
#define D_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition: types.h:83
#define D_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition: types.h:84
+ Here is the call graph for this function:

◆ charset_slist_validator()

int charset_slist_validator ( 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 84 of file charset.c.

85{
86 if (value == 0)
87 return CSR_SUCCESS;
88
89 const struct Slist *list = (const struct Slist *) value;
90
91 int rc = CSR_SUCCESS;
92 bool strict = (cdef->type & D_CHARSET_STRICT);
93
94 const struct ListNode *np = NULL;
95 STAILQ_FOREACH(np, &list->head, entries)
96 {
97 char const *charset = np->data;
98 if (!mutt_ch_check_charset(charset, strict))
99 {
100 rc = CSR_ERR_INVALID;
101 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, charset);
102 break;
103 }
104 }
105
106 return rc;
107}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:390
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 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.

45{
46#ifdef USE_HCACHE
47 if (value == 0)
48 return CSR_SUCCESS;
49
50 const char *str = (const char *) value;
51
53 return CSR_SUCCESS;
54
55 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
56 return CSR_ERR_INVALID;
57#else
58 return CSR_SUCCESS;
59#endif
60}
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 ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

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

Definition at line 66 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:81
+ Here is the call graph for this function:

◆ compress_level_validator()

static int compress_level_validator ( 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: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:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
+ Here is the call graph for this function:

◆ imap_auth_validator()

static int imap_auth_validator ( 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.

46{
47 const struct Slist *imap_auth_methods = (const struct Slist *) value;
48 if (!imap_auth_methods || (imap_auth_methods->count == 0))
49 return CSR_SUCCESS;
50
51 struct ListNode *np = NULL;
52 STAILQ_FOREACH(np, &imap_auth_methods->head, entries)
53 {
54 if (imap_auth_is_valid(np->data))
55 continue;
56#ifdef USE_SASL_CYRUS
58 continue;
59#endif
60 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
61 return CSR_ERR_INVALID;
62 }
63
64 return CSR_SUCCESS;
65}
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 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.

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 ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

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

Definition at line 111 of file mutt_config.c.

112{
113 if (value == 0)
114 return CSR_SUCCESS;
115
116 const char *str = (const char *) value;
117
118 if (mutt_str_equal(str, "inline") || mutt_str_equal(str, "info"))
119 return CSR_SUCCESS;
120
121 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
122 return CSR_ERR_INVALID;
123}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
+ Here is the call graph for this function:

◆ level_validator()

int level_validator ( 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.

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:51
+ Here is the call graph for this function:

◆ sort_validator()

int sort_validator ( 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.

108{
109 if (((value & SORT_MASK) == EMAIL_SORT_THREADS) && (value & SORT_LAST))
110 {
111 buf_printf(err, _("Cannot use 'last-' prefix with 'threads' for %s"), cdef->name);
112 return CSR_ERR_INVALID;
113 }
114 return CSR_SUCCESS;
115}
#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 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 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.

86{
87#ifdef USE_NOTMUCH
88 const char *timebase = (const char *) value;
89 if (!nm_query_window_check_timebase(timebase))
90 {
92 // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
93 // They should not be translated.
94 err, _("Invalid nm_query_window_timebase value (valid values are: "
95 "hour, day, week, month, year)"));
96 return CSR_ERR_INVALID;
97 }
98#endif
99 return CSR_SUCCESS;
100}
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 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.

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

77{
78 const struct Slist *smtp_auth_methods = (const struct Slist *) value;
79 if (!smtp_auth_methods || (smtp_auth_methods->count == 0))
80 return CSR_SUCCESS;
81
82 struct ListNode *np = NULL;
83 STAILQ_FOREACH(np, &smtp_auth_methods->head, entries)
84 {
85 if (smtp_auth_is_valid(np->data))
86 continue;
87#ifdef USE_SASL_CYRUS
89 continue;
90#endif
91 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
92 return CSR_ERR_INVALID;
93 }
94
95 return CSR_SUCCESS;
96}
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 ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)
static

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

Definition at line 101 of file config.c.

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