* @param eval_func Option evaluation function (e.g. -A filename)
* @return the value the expression parsed to
*/
-AP_DECLARE(int) ap_expr_eval(request_rec *r, ap_parse_node_t *root,
+AP_DECLARE(int) ap_expr_eval(request_rec *r, const ap_parse_node_t *root,
int *was_error, backref_t **reptr,
string_func_t string_func, opt_func_t eval_func);
/**
#include "http_request.h"
#include "http_protocol.h"
#include "ap_provider.h"
+#include "ap_expr.h"
#include "mod_auth.h"
&method_parse_config,
};
+static authz_status expr_check_authorization(request_rec *r,
+ const char *require_line,
+ const void *parsed_require_line)
+{
+ int err = 0;
+ const ap_parse_node_t *expr = parsed_require_line;
+
+ if (ap_expr_eval(r, expr, &err, NULL, ap_expr_string, NULL))
+ return AUTHZ_GRANTED;
+ else
+ return AUTHZ_DENIED;
+}
+
+static const char *expr_parse_config(cmd_parms *cmd, const char *require_line,
+ const void **parsed_require_line)
+{
+ int expr_err = 0;
+ ap_parse_node_t *expr = ap_expr_parse(cmd->pool, require_line, &expr_err);
+
+ if (expr_err)
+ return "Cannot parse expression in require line";
+
+ *parsed_require_line = expr;
+
+ return NULL;
+}
+
+static const authz_provider authz_expr_provider =
+{
+ &expr_check_authorization,
+ &expr_parse_config,
+};
+
static void register_hooks(apr_pool_t *p)
{
ap_register_auth_provider(p, AUTHZ_PROVIDER_GROUP, "method",
AUTHZ_PROVIDER_VERSION,
&authz_method_provider, AP_AUTH_INTERNAL_PER_CONF);
+ ap_register_auth_provider(p, AUTHZ_PROVIDER_GROUP, "expr",
+ AUTHZ_PROVIDER_VERSION,
+ &authz_expr_provider, AP_AUTH_INTERNAL_PER_CONF);
}
AP_DECLARE_MODULE(authz_core) =
}
static ap_parse_node_t *ap_expr_clone_tree(apr_pool_t *pool,
- ap_parse_node_t *pnode,
+ const ap_parse_node_t *pnode,
ap_parse_node_t *parent)
{
ap_parse_node_t *ret;
return (root ? root->value : 0);
}
-AP_DECLARE(int) ap_expr_eval(request_rec *r, ap_parse_node_t *root,
+AP_DECLARE(int) ap_expr_eval(request_rec *r, const ap_parse_node_t *root,
int *was_error, backref_t **reptr,
string_func_t string_func, opt_func_t eval_func)
{