mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-16 07:56:12 +03:00
Lua: Add ability to retrieve values from persistent collections.
This commit is contained in:
parent
fa4738e865
commit
235fd2c077
@ -83,12 +83,6 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) {
|
|||||||
filename, lua_tostring(L, -1));
|
filename, lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compile script. */
|
|
||||||
// lua_pcall(L, 0, 0, 0);
|
|
||||||
|
|
||||||
/* Find the execution entry point. */
|
|
||||||
// lua_getglobal(L, "main");
|
|
||||||
|
|
||||||
/* Dump the script into binary form. */
|
/* Dump the script into binary form. */
|
||||||
dump.pool = pool;
|
dump.pool = pool;
|
||||||
dump.parts = apr_array_make(pool, 128, sizeof(msc_script_part *));
|
dump.parts = apr_array_make(pool, 128, sizeof(msc_script_part *));
|
||||||
@ -136,6 +130,7 @@ static int l_getvar(lua_State *L) {
|
|||||||
char *varname = NULL;
|
char *varname = NULL;
|
||||||
char *param = NULL;
|
char *param = NULL;
|
||||||
modsec_rec *msr = NULL;
|
modsec_rec *msr = NULL;
|
||||||
|
msre_rule *rule = NULL;
|
||||||
char *my_error_msg = NULL;
|
char *my_error_msg = NULL;
|
||||||
|
|
||||||
/* Retrieve parameters. */
|
/* Retrieve parameters. */
|
||||||
@ -145,21 +140,27 @@ static int l_getvar(lua_State *L) {
|
|||||||
lua_getglobal(L, "__msr");
|
lua_getglobal(L, "__msr");
|
||||||
msr = (modsec_rec *)lua_topointer(L, -1);
|
msr = (modsec_rec *)lua_topointer(L, -1);
|
||||||
|
|
||||||
|
/* Retrieve rule. */
|
||||||
|
lua_getglobal(L, "__rule");
|
||||||
|
rule = (msre_rule *)lua_topointer(L, -1);
|
||||||
|
|
||||||
/* Resolve variable $varname. */
|
/* Resolve variable $varname. */
|
||||||
param = strchr(varname, ':');
|
param = strchr(varname, '.');
|
||||||
if (param != NULL) {
|
if (param != NULL) {
|
||||||
*param = '\0';
|
*param = '\0';
|
||||||
param++;
|
param++;
|
||||||
}
|
}
|
||||||
|
|
||||||
msre_var *var = msre_create_var_ex(msr->msc_rule_mptmp, msr->modsecurity->msre,
|
msre_var *var = msre_create_var_ex(msr->msc_rule_mptmp, msr->modsecurity->msre,
|
||||||
varname, NULL, msr, &my_error_msg);
|
varname, param, msr, &my_error_msg);
|
||||||
|
|
||||||
if (var == NULL) {
|
if (var == NULL) {
|
||||||
msr_log(msr, 1, "SecRuleScript: Failed to resolve variable: %s", varname);
|
msr_log(msr, 1, "SecRuleScript: Failed to resolve variable: %s", varname);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
msre_var *vx = generate_single_var(msr, var, param, msr->msc_rule_mptmp);
|
msre_var *vx = NULL;
|
||||||
|
|
||||||
|
vx = generate_single_var(msr, var, rule, msr->msc_rule_mptmp);
|
||||||
if (vx != NULL) {
|
if (vx != NULL) {
|
||||||
/* Transform the variable if a list of transformation
|
/* Transform the variable if a list of transformation
|
||||||
* functions has been supplied.
|
* functions has been supplied.
|
||||||
@ -190,8 +191,8 @@ static int l_getvar(lua_State *L) {
|
|||||||
log_escape_nq_ex(msr->msc_rule_mptmp, vx->value, vx->value_len));
|
log_escape_nq_ex(msr->msc_rule_mptmp, vx->value, vx->value_len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
if (lua_isstring(L, 2)) { /* The second parameter may be a simple string? */
|
else if (lua_isstring(L, 2)) { /* The second parameter may be a simple string? */
|
||||||
msre_tfn_metadata *tfn = NULL;
|
msre_tfn_metadata *tfn = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -255,6 +256,10 @@ int lua_execute(msre_rule *rule, modsec_rec *msr, char **error_msg) {
|
|||||||
lua_pushlightuserdata(L, (void *)msr);
|
lua_pushlightuserdata(L, (void *)msr);
|
||||||
lua_setglobal(L, "__msr");
|
lua_setglobal(L, "__msr");
|
||||||
|
|
||||||
|
/* Associate rule with the state. */
|
||||||
|
lua_pushlightuserdata(L, (void *)rule);
|
||||||
|
lua_setglobal(L, "__rule");
|
||||||
|
|
||||||
/* Register functions. */
|
/* Register functions. */
|
||||||
luaL_register(L, "m", mylib);
|
luaL_register(L, "m", mylib);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user