Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webhome validator #2276

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ static void initConfig(struct config *conf)
conf->webserver.paths.webhome.t = CONF_STRING;
conf->webserver.paths.webhome.f = FLAG_RESTART_FTL;
conf->webserver.paths.webhome.d.s = (char*)"/admin/";
conf->webserver.paths.webhome.c = validate_filepath;
conf->webserver.paths.webhome.c = validate_filepath_two_slash;

// sub-struct interface
conf->webserver.interface.boxed.k = "webserver.interface.boxed";
Expand Down
15 changes: 15 additions & 0 deletions src/config/validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ bool validate_filepath(union conf_value *val, const char *key, char err[VALIDATO
return true;
}

// Validate a file path that needs to have both a slash at the beginning and at
// the end
bool validate_filepath_two_slash(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN])
{
// Check if the path starts and ends with a slash
if(strlen(val->s) < 1 || val->s[0] != '/' || val->s[strlen(val->s) - 1] != '/')
{
snprintf(err, VALIDATOR_ERRBUF_LEN, "%s: file path does not start and end with a slash (\"%s\")", key, val->s);
return false;
}

// Check if the path contains only valid characters
return validate_filepath(val, key, err);
}

// Validate file path (empty allowed)
bool validate_filepath_empty(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN])
{
Expand Down
1 change: 1 addition & 0 deletions src/config/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bool validate_dns_domain(union conf_value *val, const char *key, char err[VALIDA
bool validate_cidr(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
bool validate_domain(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
bool validate_filepath(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
bool validate_filepath_two_slash(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
bool validate_filepath_empty(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
bool validate_filepath_dash(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
bool validate_regex_array(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);
Expand Down
Loading