MAJOR: acl: make all ACLs reference the fetch function via a sample.
ACL fetch functions used to directly reference a fetch function. Now
that all ACL fetches have their sample fetches equivalent, we can make
ACLs reference a sample fetch keyword instead.
In order to simplify the code, a sample keyword name may be NULL if it
is the same as the ACL's, which is the most common case.
A minor change appeared, http_auth always expects one argument though
the ACL allowed it to be missing and reported as such afterwards, so
fix the ACL to match this. This is not really a bug.
diff --git a/src/acl.c b/src/acl.c
index fe5c869..8e6f97a 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -27,6 +27,7 @@
#include <proto/channel.h>
#include <proto/log.h>
#include <proto/proxy.h>
+#include <proto/sample.h>
#include <proto/stick_table.h>
#include <ebsttree.h>
@@ -1583,7 +1584,7 @@
/* we need to reset context and flags */
memset(&smp, 0, sizeof(smp));
fetch_next:
- if (!expr->kw->fetch(px, l4, l7, opt, expr->args, &smp)) {
+ if (!expr->kw->smp->process(px, l4, l7, opt, expr->args, &smp)) {
/* maybe we could not fetch because of missing data */
if (smp.flags & SMP_F_MAY_CHANGE && !(opt & SMP_OPT_FINAL))
acl_res |= ACL_PAT_MISS;
@@ -1901,6 +1902,35 @@
return cfgerr;
}
+/* initializes ACLs by resolving the sample fetch names they rely upon.
+ * Returns 0 on success, otherwise an error.
+ */
+int init_acl()
+{
+ int err = 0;
+ int index;
+ const char *name;
+ struct acl_kw_list *kwl;
+ struct sample_fetch *smp;
+
+ list_for_each_entry(kwl, &acl_keywords.list, list) {
+ for (index = 0; kwl->kw[index].kw != NULL; index++) {
+ name = kwl->kw[index].fetch_kw;
+ if (!name)
+ name = kwl->kw[index].kw;
+
+ smp = find_sample_fetch(name, strlen(name));
+ if (!smp) {
+ Alert("Critical internal error: ACL keyword '%s' relies on sample fetch '%s' which was not registered!\n",
+ kwl->kw[index].kw, name);
+ err++;
+ continue;
+ }
+ kwl->kw[index].smp = smp;
+ }
+ }
+ return err;
+}
/************************************************************************/
/* All supported sample fetch functions must be declared here */
@@ -1947,8 +1977,8 @@
* Please take care of keeping this list alphabetically sorted.
*/
static struct acl_kw_list acl_kws = {{ },{
- { "always_false", acl_parse_nothing, smp_fetch_false, acl_match_nothing, ACL_USE_NOTHING, 0 },
- { "always_true", acl_parse_nothing, smp_fetch_true, acl_match_nothing, ACL_USE_NOTHING, 0 },
+ { "always_false", NULL, acl_parse_nothing, acl_match_nothing, ACL_USE_NOTHING, 0 },
+ { "always_true", NULL, acl_parse_nothing, acl_match_nothing, ACL_USE_NOTHING, 0 },
{ /* END */ },
}};