From: Eric Covener Date: Tue, 8 Nov 2011 01:53:15 +0000 (+0000) Subject: mod_lua: Expose SSL variables via r:ssl_var_lookup() X-Git-Tag: 2.3.15~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2af550c8c9f5610bc6c894a3ec2111ab0870b35d;p=apache 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 --- diff --git a/CHANGES b/CHANGES index 2fff85e88a..c90cb75bdf 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Changes with Apache 2.3.15 core: Fix integer overflow in ap_pregsub. This can be triggered e.g. 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} can now additionally be run as "early" or "late" relative to other modules. [Eric Covener] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index a9443888ac..dac9c1f511 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -364,6 +364,7 @@ * add ap_pregsub_ex() * 20111025.1 (2.3.15-dev) Add ap_escape_urlencoded(), ap_escape_urlencoded_buffer() * and ap_unescape_urlencoded(). + * 20111025.2 (2.3.15-dev) Add ap_lua_ssl_val to mod_lua */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -371,7 +372,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20111025 #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 diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 63b6b699bd..b66de1760e 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -217,6 +217,16 @@ static int req_escape_html(lua_State *L) lua_pushstring(L, ap_escape_html(r->pool, s)); 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 */ /* 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)); apr_hash_set(dispatch, "escape_html", APR_HASH_KEY_STRING, 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, makefun(&req_assbackwards_field, APL_REQ_FUNTYPE_BOOLEAN, p)); apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING, diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index 1771e2e12c..55e5d1ad6d 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -22,6 +22,8 @@ #include "lua_apr.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, (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, (lua_State *L, request_rec *r), (L, r), OK, DECLINED) +static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *lua_ssl_val = NULL; 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; 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; } +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) { /* 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_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_HOOK_REALLY_FIRST); diff --git a/modules/lua/mod_lua.h b/modules/lua/mod_lua.h index 395d204d1a..a152e00ee7 100644 --- a/modules/lua/mod_lua.h +++ b/modules/lua/mod_lua.h @@ -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, (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_ */