MINOR: acl: report errors encountered when loading patterns from files
This happens in acl_read_patterns_from_file(). Errors are still incomplete, parsing functions must be improved to report parsing errors.
This commit is contained in:
parent
4e6336fdfd
commit
08ad0b38c4
28
src/acl.c
28
src/acl.c
|
@ -1144,9 +1144,14 @@ static struct acl_expr *prune_acl_expr(struct acl_expr *expr)
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Reads patterns from a file. If <err_msg> is non-NULL, an error message will
|
||||||
|
* be returned there on errors and the caller will have to free it.
|
||||||
|
*/
|
||||||
static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
||||||
struct acl_expr *expr,
|
struct acl_expr *expr,
|
||||||
const char *filename, int patflags)
|
const char *filename, int patflags,
|
||||||
|
char **err)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *c;
|
char *c;
|
||||||
|
@ -1154,10 +1159,13 @@ static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
||||||
struct acl_pattern *pattern;
|
struct acl_pattern *pattern;
|
||||||
int opaque;
|
int opaque;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int line = 0;
|
||||||
|
|
||||||
file = fopen(filename, "r");
|
file = fopen(filename, "r");
|
||||||
if (!file)
|
if (!file) {
|
||||||
|
memprintf(err, "failed to open pattern file <%s>", filename);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* now parse all patterns. The file may contain only one pattern per
|
/* now parse all patterns. The file may contain only one pattern per
|
||||||
* line. If the line contains spaces, they will be part of the pattern.
|
* line. If the line contains spaces, they will be part of the pattern.
|
||||||
|
@ -1167,7 +1175,7 @@ static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
||||||
pattern = NULL;
|
pattern = NULL;
|
||||||
args[1] = "";
|
args[1] = "";
|
||||||
while (fgets(trash, sizeof(trash), file) != NULL) {
|
while (fgets(trash, sizeof(trash), file) != NULL) {
|
||||||
|
line++;
|
||||||
c = trash;
|
c = trash;
|
||||||
|
|
||||||
/* ignore lines beginning with a dash */
|
/* ignore lines beginning with a dash */
|
||||||
|
@ -1191,8 +1199,10 @@ static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
||||||
/* we keep the previous pattern along iterations as long as it's not used */
|
/* we keep the previous pattern along iterations as long as it's not used */
|
||||||
if (!pattern)
|
if (!pattern)
|
||||||
pattern = (struct acl_pattern *)malloc(sizeof(*pattern));
|
pattern = (struct acl_pattern *)malloc(sizeof(*pattern));
|
||||||
if (!pattern)
|
if (!pattern) {
|
||||||
|
memprintf(err, "out of memory when loading patterns from file <%s>", filename);
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
}
|
||||||
|
|
||||||
memset(pattern, 0, sizeof(*pattern));
|
memset(pattern, 0, sizeof(*pattern));
|
||||||
pattern->flags = patflags;
|
pattern->flags = patflags;
|
||||||
|
@ -1205,8 +1215,11 @@ static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
||||||
pattern->val.tree = &expr->pattern_tree;
|
pattern->val.tree = &expr->pattern_tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aclkw->parse(args, pattern, &opaque))
|
if (!aclkw->parse(args, pattern, &opaque)) {
|
||||||
|
memprintf(err, "failed to parse pattern '%s' at line %d of file <%s>",
|
||||||
|
*args, line, filename);
|
||||||
goto out_free_pattern;
|
goto out_free_pattern;
|
||||||
|
}
|
||||||
|
|
||||||
/* if the parser did not feed the tree, let's chain the pattern to the list */
|
/* if the parser did not feed the tree, let's chain the pattern to the list */
|
||||||
if (!(pattern->flags & ACL_PAT_F_TREE)) {
|
if (!(pattern->flags & ACL_PAT_F_TREE)) {
|
||||||
|
@ -1348,11 +1361,8 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
|
||||||
if ((*args)[1] == 'i')
|
if ((*args)[1] == 'i')
|
||||||
patflags |= ACL_PAT_F_IGNORE_CASE;
|
patflags |= ACL_PAT_F_IGNORE_CASE;
|
||||||
else if ((*args)[1] == 'f') {
|
else if ((*args)[1] == 'f') {
|
||||||
if (!acl_read_patterns_from_file(aclkw, expr, args[1], patflags | ACL_PAT_F_FROM_FILE)) {
|
if (!acl_read_patterns_from_file(aclkw, expr, args[1], patflags | ACL_PAT_F_FROM_FILE, err))
|
||||||
if (err)
|
|
||||||
memprintf(err, "failed to load some ACL patterns from file '%s'", args[1]);
|
|
||||||
goto out_free_expr;
|
goto out_free_expr;
|
||||||
}
|
|
||||||
args++;
|
args++;
|
||||||
}
|
}
|
||||||
else if ((*args)[1] == '-') {
|
else if ((*args)[1] == '-') {
|
||||||
|
|
Loading…
Reference in New Issue