1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-05 16:55:50 +03:00

mod_lua: Expose SSL variables via r:ssl_var_lookup()

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1199056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eric Covener
2011-11-08 01:53:15 +00:00
parent bd5efb04fa
commit 2af550c8c9
5 changed files with 36 additions and 1 deletions

View File

@@ -16,6 +16,8 @@ Changes with Apache 2.3.15
core: Fix integer overflow in ap_pregsub. This can be triggered e.g. core: Fix integer overflow in ap_pregsub. This can be triggered e.g.
with mod_setenvif via a malicious .htaccess. [Stefan Fritsch] with mod_setenvif via a malicious .htaccess. [Stefan Fritsch]
*) mod_lua: Expose SSL variables via r:ssl_var_lookup(). [Eric Covener]
*) mod_lua: LuaHook{AccessChecker,AuthChecker,CheckUserID,TranslateName} *) mod_lua: LuaHook{AccessChecker,AuthChecker,CheckUserID,TranslateName}
can now additionally be run as "early" or "late" relative to other modules. can now additionally be run as "early" or "late" relative to other modules.
[Eric Covener] [Eric Covener]

View File

@@ -364,6 +364,7 @@
* add ap_pregsub_ex() * add ap_pregsub_ex()
* 20111025.1 (2.3.15-dev) Add ap_escape_urlencoded(), ap_escape_urlencoded_buffer() * 20111025.1 (2.3.15-dev) Add ap_escape_urlencoded(), ap_escape_urlencoded_buffer()
* and ap_unescape_urlencoded(). * and ap_unescape_urlencoded().
* 20111025.2 (2.3.15-dev) Add ap_lua_ssl_val to mod_lua
*/ */
#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -371,7 +372,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR #ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20111025 #define MODULE_MAGIC_NUMBER_MAJOR 20111025
#endif #endif
#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ #define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */
/** /**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a * Determine if the server's current MODULE_MAGIC_NUMBER is at least a

View File

@@ -217,6 +217,16 @@ static int req_escape_html(lua_State *L)
lua_pushstring(L, ap_escape_html(r->pool, s)); lua_pushstring(L, ap_escape_html(r->pool, s));
return 1; return 1;
} }
/* wrap optional ssl_var_lookup as r:ssl_var_lookup(String) */
static int req_ssl_var_lookup(lua_State *L)
{
request_rec *r = ap_lua_check_request_rec(L, 1);
const char *s = luaL_checkstring(L, 2);
const char *res = ap_lua_ssl_val(r->pool, r->server, r->connection, r,
(char *)s);
lua_pushstring(L, res);
return 1;
}
/* BEGIN dispatch mathods for request_rec fields */ /* BEGIN dispatch mathods for request_rec fields */
/* not really a field, but we treat it like one */ /* not really a field, but we treat it like one */
@@ -602,6 +612,8 @@ AP_LUA_DECLARE(void) ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p)
makefun(&req_construct_url, APL_REQ_FUNTYPE_LUACFUN, p)); makefun(&req_construct_url, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "escape_html", APR_HASH_KEY_STRING, apr_hash_set(dispatch, "escape_html", APR_HASH_KEY_STRING,
makefun(&req_escape_html, APL_REQ_FUNTYPE_LUACFUN, p)); makefun(&req_escape_html, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "ssl_var_lookup", APR_HASH_KEY_STRING,
makefun(&req_ssl_var_lookup, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING, apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING,
makefun(&req_assbackwards_field, APL_REQ_FUNTYPE_BOOLEAN, p)); makefun(&req_assbackwards_field, APL_REQ_FUNTYPE_BOOLEAN, p));
apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING, apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING,

View File

@@ -22,6 +22,8 @@
#include "lua_apr.h" #include "lua_apr.h"
#include "lua_config.h" #include "lua_config.h"
#include "apr_optional.h"
#include "mod_ssl.h"
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_open, APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_open,
(lua_State *L, apr_pool_t *p), (lua_State *L, apr_pool_t *p),
@@ -30,6 +32,7 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_open,
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_request, APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_request,
(lua_State *L, request_rec *r), (lua_State *L, request_rec *r),
(L, r), OK, DECLINED) (L, r), OK, DECLINED)
static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *lua_ssl_val = NULL;
module AP_MODULE_DECLARE_DATA lua_module; module AP_MODULE_DECLARE_DATA lua_module;
@@ -1006,6 +1009,13 @@ static const char *register_lua_root(cmd_parms *cmd, void *_cfg,
cfg->root_path = root; cfg->root_path = root;
return NULL; return NULL;
} }
AP_LUA_DECLARE(const char *) ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var)
{
if (lua_ssl_val) {
return (const char *)lua_ssl_val(p, s, c, r, (char *)var);
}
return NULL;
}
/*******************************/ /*******************************/
@@ -1149,6 +1159,13 @@ static int lua_request_hook(lua_State *L, request_rec *r)
return OK; return OK;
} }
static int lua_post_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
lua_ssl_val = APR_RETRIEVE_OPTIONAL_FN(ssl_var_lookup);
return OK;
}
static void lua_register_hooks(apr_pool_t *p) static void lua_register_hooks(apr_pool_t *p)
{ {
/* ap_register_output_filter("luahood", luahood, NULL, AP_FTYPE_RESOURCE); */ /* ap_register_output_filter("luahood", luahood, NULL, AP_FTYPE_RESOURCE); */
@@ -1196,6 +1213,7 @@ static void lua_register_hooks(apr_pool_t *p)
ap_hook_quick_handler(lua_quick_harness, NULL, NULL, APR_HOOK_FIRST); ap_hook_quick_handler(lua_quick_harness, NULL, NULL, APR_HOOK_FIRST);
ap_hook_translate_name(lua_alias_munger, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_translate_name(lua_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(lua_post_config, NULL, NULL, APR_HOOK_MIDDLE);
APR_OPTIONAL_HOOK(ap_lua, lua_open, lua_open_hook, NULL, NULL, APR_OPTIONAL_HOOK(ap_lua, lua_open, lua_open_hook, NULL, NULL,
APR_HOOK_REALLY_FIRST); APR_HOOK_REALLY_FIRST);

View File

@@ -148,4 +148,6 @@ APR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_open,
APR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_request, APR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_request,
(lua_State *L, request_rec *r)) (lua_State *L, request_rec *r))
AP_LUA_DECLARE(const char *) ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
#endif /* !_MOD_LUA_H_ */ #endif /* !_MOD_LUA_H_ */