NeoMutt  2025-12-11-694-ga89709
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 multipart_validator (const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "show_multipart_alternative" 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 hcache_validator (const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "header_cache" config variable - Implements ConfigDef::validator() -.
 
static int hcache_backend_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() -.
 
int debug_level_validator (const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "debug_level" 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 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)
Free memory and set the pointer to NULL.
Definition memory.h:68
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition charset.c:880
#define _(a)
Definition message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
const char * name
User-visible name.
Definition set.h:66
uint32_t type
Variable type, e.g. DT_STRING.
Definition set.h:67
#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 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:

◆ 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 39 of file config.c.

40{
41 if (value == 0)
42 return CSR_SUCCESS;
43
44 const char *str = (const char *) value;
45
46 if (mutt_str_equal(str, "inline") || mutt_str_equal(str, "info"))
47 return CSR_SUCCESS;
48
49 buf_printf(err, _("Invalid value for option %s: %s"), cdef->name, str);
50 return CSR_ERR_INVALID;
51}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
+ 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 105 of file thread.c.

106{
107 if (((value & SORT_MASK) == EMAIL_SORT_THREADS) && (value & SORT_LAST))
108 {
109 buf_printf(err, _("Cannot use 'last-' prefix with 'threads' for %s"), cdef->name);
110 return CSR_ERR_INVALID;
111 }
112 return CSR_SUCCESS;
113}
#define SORT_MASK
Mask for the sort id.
Definition sort.h:39
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition sort.h:41
@ EMAIL_SORT_THREADS
Sort by email threads.
Definition sort.h:62
+ 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" config variable - Implements ConfigDef::validator() -.

Definition at line 44 of file config.c.

45{
46 if (value == 0)
47 return CSR_SUCCESS;
48
49 const char *const c_header_cache_backend = cs_subset_string(NeoMutt->sub, "header_cache_backend");
50 if (!c_header_cache_backend)
51 {
52 buf_printf(err, _("Set option %s before setting %s"), "header_cache_backend", cdef->name);
53 return CSR_ERR_INVALID;
54 }
55
56 return CSR_SUCCESS;
57}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:

◆ hcache_backend_validator()

static int hcache_backend_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 62 of file config.c.

64{
65 if (value == 0)
66 return CSR_SUCCESS;
67
68 const char *str = (const char *) value;
69
71 return CSR_SUCCESS;
72
73 buf_printf(err, _("Invalid value for %s"), cdef->name);
74 buf_addch(err, '\n');
75 struct Slist *sl = store_backend_list();
76 struct Buffer *list = buf_pool_get();
77 struct ListNode *np = NULL;
78 bool first = true;
79 STAILQ_FOREACH(np, &sl->head, entries)
80 {
81 if (!first)
82 buf_addstr(list, ", ");
83 buf_addstr(list, np->data);
84 first = false;
85 }
86 buf_add_printf(err, _("Choose from: %s"), buf_string(list));
87 buf_pool_release(&list);
88 slist_free(&sl);
90}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
#define CSR_INV_WARNING
Report as a warning, not an error.
Definition set.h:48
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition slist.c:124
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition store.c:110
struct Slist * store_backend_list(void)
Get a list of backend names.
Definition store.c:69
String manipulation buffer.
Definition buffer.h:36
+ 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 96 of file config.c.

98{
99#ifdef USE_HCACHE_COMPRESSION
100 if (value == 0)
101 return CSR_SUCCESS;
102
103 const char *str = (const char *) value;
104
105 if (compress_get_ops(str))
106 return CSR_SUCCESS;
107
108 buf_printf(err, _("Invalid value for %s"), cdef->name);
109 buf_addch(err, '\n');
110 struct Slist *sl = compress_list();
111 struct Buffer *list = buf_pool_get();
112 struct ListNode *np = NULL;
113 bool first = true;
114 STAILQ_FOREACH(np, &sl->head, entries)
115 {
116 if (!first)
117 buf_addstr(list, ", ");
118 buf_addstr(list, np->data);
119 first = false;
120 }
121 buf_add_printf(err, _("Choose from: %s"), buf_string(list));
122 buf_pool_release(&list);
123 slist_free(&sl);
125#else
126 return CSR_SUCCESS;
127#endif
128}
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
Definition compress.c:78
struct Slist * compress_list(void)
Get a list of compression backend names.
Definition compress.c:59
+ 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 133 of file config.c.

135{
136#ifdef USE_HCACHE_COMPRESSION
137 const char *const c_header_cache_compress_method = cs_subset_string(NeoMutt->sub, "header_cache_compress_method");
138 if (!c_header_cache_compress_method)
139 {
140 buf_printf(err, _("Set option %s before setting %s"),
141 "header_cache_compress_method", cdef->name);
142 return CSR_ERR_INVALID;
143 }
144
145 const struct ComprOps *cops = compress_get_ops(c_header_cache_compress_method);
146 if (!cops)
147 {
148 buf_printf(err, _("Invalid value for option %s: %s"),
149 "header_cache_compress_method", c_header_cache_compress_method);
150 return CSR_ERR_INVALID;
151 }
152
153 if ((value < cops->min_level) || (value > cops->max_level))
154 {
155 // L10N: This applies to the "$header_cache_compress_level" config variable.
156 // It shows the minimum and maximum values, e.g. 'between 1 and 22'
157 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
158 cdef->name, cops->min_level, cops->max_level);
159 return CSR_ERR_INVALID;
160 }
161#endif
162 return CSR_SUCCESS;
163}
Definition lib.h:65
short max_level
Maximum compression level.
Definition lib.h:68
short min_level
Minimum compression level.
Definition lib.h:67
+ 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:96
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition sasl.c:131
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 43 of file config.c.

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

◆ debug_level_validator()

int debug_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:52
+ Here is the call graph for this function:
+ Here is the caller 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:

◆ 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:503
+ 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 59 of file config.c.

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