Apache HTTPD
mod_lua.c
Go to the documentation of this file.
1
18#include "mod_lua.h"
19#include <string.h>
20#include <stdlib.h>
21#include <ctype.h>
22#include <apr_thread_mutex.h>
23#include <apr_pools.h>
24#include "lua_apr.h"
25#include "lua_config.h"
26#include "apr_optional.h"
27#include "mod_auth.h"
28#include "util_mutex.h"
29
30
31#ifdef APR_HAS_THREADS
32#include "apr_thread_proc.h"
33#endif
34
35/* getpid for *NIX */
36#if APR_HAVE_SYS_TYPES_H
37#include <sys/types.h>
38#endif
39#if APR_HAVE_UNISTD_H
40#include <unistd.h>
41#endif
42
43/* getpid for Windows */
44#if APR_HAVE_PROCESS_H
45#include <process.h>
46#endif
47
49 (lua_State *L, apr_pool_t *p),
50 (L, p), OK, DECLINED)
51
53 (lua_State *L, request_rec *r),
54 (L, r), OK, DECLINED)
55
56module AP_MODULE_DECLARE_DATA lua_module;
57
58#define AP_LUA_HOOK_FIRST (APR_HOOK_FIRST - 1)
59#define AP_LUA_HOOK_LAST (APR_HOOK_LAST + 1)
60
61typedef struct {
62 const char *name;
63 const char *file_name;
64 const char *function_name;
67
72
74
82
83#define DEFAULT_LUA_SHMFILE "lua_ivm_shm"
84
88
90{
91 if (lua_ivm_shm) {
93 }
94 return OK;
95}
96
102{
103 const char *lua_response;
105 r->content_type = "text/html";
106 ap_rputs("<h3>Error!</h3>\n", r);
107 ap_rputs("<pre>", r);
108 lua_response = lua_tostring(L, -1);
110 ap_rputs("</pre>\n", r);
111
112 ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, r->pool, APLOGNO(01471) "Lua error: %s",
114}
115
123
125{
127 return OK;
128}
129
130static const char *scope_to_string(unsigned int scope)
131{
132 switch (scope) {
135 return "once";
137 return "request";
139 return "conn";
140#if APR_HAS_THREADS
142 return "thread";
144 return "server";
145#endif
146 default:
147 ap_assert(0);
148 return 0;
149 }
150}
151
153{
154 char *hash;
156
157 if (spec->scope == AP_LUA_SCOPE_SERVER) {
159 lua_settop(L, 0);
160 lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Lua.server_spec");
162 hash = apr_psprintf(r->pool, "reslist:%s", spec->file);
163 if (apr_pool_userdata_get((void **)&reslist, hash,
166 if (reslist != NULL) {
168 }
169 }
170 }
171}
172
174 request_rec *r,
175 const ap_lua_dir_cfg *cfg,
177 const char *filename,
178 const char *bytecode,
179 apr_size_t bytecode_len,
180 const char *function,
181 const char *what)
182{
185
186 spec->scope = cfg->vm_scope;
187 spec->pool = r->pool;
188 spec->package_paths = cfg->package_paths;
189 spec->package_cpaths = cfg->package_cpaths;
190 spec->cb = &lua_open_callback;
191 spec->cb_arg = NULL;
192 spec->bytecode = bytecode;
193 spec->bytecode_len = bytecode_len;
195 spec->vm_min = cfg->vm_min ? cfg->vm_min : 1;
196 spec->vm_max = cfg->vm_max ? cfg->vm_max : 1;
197
198 if (filename) {
199 char *file;
202 spec->file = file;
203 }
204 else {
205 spec->file = r->filename;
206 }
208 "%s details: scope: %s, file: %s, func: %s",
209 what, scope_to_string(spec->scope), spec->file,
210 function ? function : "-");
211
212 switch (spec->scope) {
216 apr_pool_tag(pool, "mod_lua-vm");
217 break;
219 pool = r->pool;
220 break;
222 pool = r->connection->pool;
223 break;
224#if APR_HAS_THREADS
226 pool = apr_thread_pool_get(r->connection->current_thread);
227 break;
229 pool = r->server->process->pool;
230 break;
231#endif
232 default:
233 ap_assert(0);
234 }
235
237 return spec;
238}
239
240static const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* string, const char** values)
241{
242 char *stringBetween;
243 const char* ret;
244 int srclen,x,y;
245 srclen = strlen(string);
246 ret = "";
247 y = 0;
248 for (x=0; x < srclen; x++) {
249 if (string[x] == '$' && x != srclen-1 && string[x+1] >= '0' && string[x+1] <= '9') {
250 int v = *(string+x+1) - '0';
251 if (x-y > 0) {
252 stringBetween = apr_pstrndup(pool, string+y, x-y);
253 }
254 else {
255 stringBetween = "";
256 }
258 y = ++x+1;
259 }
260 }
261
262 if (x-y > 0 && y > 0) {
263 stringBetween = apr_pstrndup(pool, string+y, x-y);
265 }
266 /* If no replacement was made, just return the original string */
267 else if (y == 0) {
268 return string;
269 }
270 return ret;
271}
272
273
274
279{
280 int rc = OK;
281 if (strcmp(r->handler, "lua-script")) {
282 return DECLINED;
283 }
284 /* Decline the request if the script does not exist (or is a directory),
285 * rather than just returning internal server error */
286 if (
288 || (r->finfo.filetype & APR_DIR)
289 ) {
290 return DECLINED;
291 }
293 "handling [%s] in mod_lua", r->filename);
294
295 /* XXX: This seems wrong because it may generate wrong headers for HEAD requests */
296 if (!r->header_only) {
297 lua_State *L;
300 &lua_module);
301 ap_lua_vm_spec *spec = create_vm_spec(&pool, r, cfg, NULL, NULL, NULL,
302 0, "handle", "request handler");
303
304 L = ap_lua_get_lua_state(pool, spec, r);
305 if (!L) {
306 /* TODO annotate spec with failure reason */
308 ap_rputs("Unable to compile VM, see logs", r);
309 ap_lua_release_state(L, spec, r);
311 }
312 ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r, APLOGNO(01474) "got a vm!");
313 lua_getglobal(L, "handle");
314 if (!lua_isfunction(L, -1)) {
316 "lua: Unable to find entry function '%s' in %s (not a valid function)",
317 "handle",
318 spec->file);
319 ap_lua_release_state(L, spec, r);
321 }
323 if (lua_pcall(L, 1, 1, 0)) {
325 }
326 if (lua_isnumber(L, -1)) {
327 rc = lua_tointeger(L, -1);
328 }
329 ap_lua_release_state(L, spec, r);
330 }
331 return rc;
332}
333
334
335/* ------------------- Input/output content filters ------------------- */
336
337
339{
341 ap_lua_vm_spec *spec;
342 int n, rc, nres;
343 lua_State *L;
346 &lua_module);
348 &lua_module);
349
350 ctx = apr_pcalloc(r->pool, sizeof(lua_filter_ctx));
351 ctx->broken = 0;
352 *c = ctx;
353 /* Find the filter that was called.
354 * XXX: If we were wired with mod_filter, the filter (mod_filters name)
355 * and the provider (our underlying filters name) need to have matched.
356 */
357 for (n = 0; n < cfg->mapped_filters->nelts; n++) {
360
361 if (hook_spec == NULL) {
362 continue;
363 }
364 if (!strcasecmp(hook_spec->filter_name, f->frec->name)) {
365 spec = create_vm_spec(&pool, r, cfg, server_cfg,
366 hook_spec->file_name,
367 NULL,
368 0,
369 hook_spec->function_name,
370 "filter");
371 L = ap_lua_get_lua_state(pool, spec, r);
372 if (L) {
373 L = lua_newthread(L);
374 }
375
376 if (!L) {
378 "lua: Failed to obtain lua interpreter for %s %s",
379 hook_spec->function_name, hook_spec->file_name);
380 ap_lua_release_state(L, spec, r);
381 return APR_EGENERAL;
382 }
383 if (hook_spec->function_name != NULL) {
384 lua_getglobal(L, hook_spec->function_name);
385 if (!lua_isfunction(L, -1)) {
387 "lua: Unable to find entry function '%s' in %s (not a valid function)",
388 hook_spec->function_name,
389 hook_spec->file_name);
390 ap_lua_release_state(L, spec, r);
391 return APR_EGENERAL;
392 }
393
395 }
396 else {
397 int t;
399
400 t = lua_gettop(L);
401 lua_setglobal(L, "r");
402 lua_settop(L, t);
403 }
404 ctx->L = L;
405 ctx->spec = spec;
406
407 /* If a Lua filter is interested in filtering a request, it must first do a yield,
408 * otherwise we'll assume that it's not interested and pretend we didn't find it.
409 */
410 rc = lua_resume(L, 1, &nres);
411 if (rc == LUA_YIELD) {
412 if (f->frec->providers == NULL) {
413 /* Not wired by mod_filter */
414 apr_table_unset(r->headers_out, "Content-Length");
415 apr_table_unset(r->headers_out, "Content-MD5");
416 apr_table_unset(r->headers_out, "ETAG");
417 }
418 return OK;
419 }
420 else {
421 ap_lua_release_state(L, spec, r);
422 return APR_ENOENT;
423 }
424 }
425 }
426 return APR_ENOENT;
427}
428
430{
431 request_rec *r = f->r;
432 int rc, nres;
433 lua_State *L;
437 apr_status_t rv;
438
439 /* Set up the initial filter context and acquire the function.
440 * The corresponding Lua function should yield here.
441 */
442 if (!f->ctx) {
444 if (rc == APR_EGENERAL) {
446 }
447 if (rc == APR_ENOENT) {
448 /* No filter entry found (or the script declined to filter), just pass on the buckets */
450 return ap_pass_brigade(f->next,pbbIn);
451 }
452 else {
453 /* We've got a willing lua filter, setup and check for a prefix */
454 size_t olen;
456 const char* output = lua_tolstring(ctx->L, 1, &olen);
457
458 f->ctx = ctx;
459 ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
460
461 if (olen > 0) {
462 pbktOut = apr_bucket_heap_create(output, olen, NULL, c->bucket_alloc);
464 rv = ap_pass_brigade(f->next, ctx->tmpBucket);
465 apr_brigade_cleanup(ctx->tmpBucket);
466 if (rv != APR_SUCCESS) {
467 return rv;
468 }
469 }
470 }
471 }
472 ctx = (lua_filter_ctx*) f->ctx;
473 L = ctx->L;
474 /* While the Lua function is still yielding, pass in buckets to the coroutine */
475 if (!ctx->broken) {
479 {
480 const char *data;
483
484 /* read the bucket */
486
487 /* Push the bucket onto the Lua stack as a global var */
489 lua_setglobal(L, "bucket");
490
491 /* If Lua yielded, it means we have something to pass on */
492 if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
493 size_t olen;
494 const char* output = lua_tolstring(L, 1, &olen);
495 if (olen > 0) {
497 c->bucket_alloc);
499 rv = ap_pass_brigade(f->next, ctx->tmpBucket);
500 apr_brigade_cleanup(ctx->tmpBucket);
501 if (rv != APR_SUCCESS) {
502 return rv;
503 }
504 }
505 }
506 else {
507 ctx->broken = 1;
508 ap_lua_release_state(L, ctx->spec, r);
511 apr_brigade_cleanup(ctx->tmpBucket);
513 "lua: Error while executing filter: %s",
514 lua_tostring(L, -1));
516 }
517 }
518 /* If we've safely reached the end, do a final call to Lua to allow for any
519 finishing moves by the script, such as appending a tail. */
522 lua_pushnil(L);
523 lua_setglobal(L, "bucket");
524 if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
526 size_t olen;
527 const char* output = lua_tolstring(L, 1, &olen);
528 if (olen > 0) {
530 c->bucket_alloc);
532 }
533 }
534 pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
536 ap_lua_release_state(L, ctx->spec, r);
537 rv = ap_pass_brigade(f->next, ctx->tmpBucket);
538 apr_brigade_cleanup(ctx->tmpBucket);
539 if (rv != APR_SUCCESS) {
540 return rv;
541 }
542 }
543 }
544 /* Clean up */
546 return APR_SUCCESS;
547}
548
549
550
555 apr_off_t nBytes)
556{
557 request_rec *r = f->r;
558 int rc, lastCall = 0, nres;
559 lua_State *L;
563
564 /* Set up the initial filter context and acquire the function.
565 * The corresponding Lua function should yield here.
566 */
567 if (!f->ctx) {
569 f->ctx = ctx;
570 if (rc == APR_EGENERAL) {
571 ctx->broken = 1;
574 }
575 if (rc == APR_ENOENT ) {
577 ctx->broken = 1;
578 }
579 if (rc == APR_SUCCESS) {
580 ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
581 }
582 }
583 ctx = (lua_filter_ctx*) f->ctx;
584 L = ctx->L;
585 /* If the Lua script broke or denied serving the request, just pass the buckets through */
586 if (ctx->broken) {
587 return ap_get_brigade(f->next, pbbOut, eMode, eBlock, nBytes);
588 }
589
590 if (APR_BRIGADE_EMPTY(ctx->tmpBucket)) {
591 ret = ap_get_brigade(f->next, ctx->tmpBucket, eMode, eBlock, nBytes);
593 return ret;
594 }
595
596 /* While the Lua function is still yielding, pass buckets to the coroutine */
597 if (!ctx->broken) {
598 lastCall = 0;
599 while (!APR_BRIGADE_EMPTY(ctx->tmpBucket)) {
600 apr_bucket *pbktIn = APR_BRIGADE_FIRST(ctx->tmpBucket);
602 const char *data;
604
607 break;
608 }
609
610 /* read the bucket */
612 if (ret != APR_SUCCESS)
613 return ret;
614
615 /* Push the bucket onto the Lua stack as a global var */
616 lastCall++;
618 lua_setglobal(L, "bucket");
619
620 /* If Lua yielded, it means we have something to pass on */
621 if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
622 size_t olen;
623 const char* output = lua_tolstring(L, 1, &olen);
624 pbktOut = apr_bucket_heap_create(output, olen, 0, c->bucket_alloc);
627 return APR_SUCCESS;
628 }
629 else {
630 ctx->broken = 1;
631 ap_lua_release_state(L, ctx->spec, r);
635 }
636 }
637 /* If we've safely reached the end, do a final call to Lua to allow for any
638 finishing moves by the script, such as appending a tail. */
639 if (lastCall == 0) {
640 apr_bucket *pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
641 lua_pushnil(L);
642 lua_setglobal(L, "bucket");
643 if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
645 size_t olen;
646 const char* output = lua_tolstring(L, 1, &olen);
647 pbktOut = apr_bucket_heap_create(output, olen, 0, c->bucket_alloc);
649 }
651 ap_lua_release_state(L, ctx->spec, r);
652 }
653 }
654 return APR_SUCCESS;
655}
656
657
658/* ---------------- Configury stuff --------------- */
659
662static int lua_request_rec_hook_harness(request_rec *r, const char *name, int apr_hook_when)
663{
664 int rc;
666 lua_State *L;
667 ap_lua_vm_spec *spec;
669 &lua_module);
671 &lua_module);
672 const char *key = apr_psprintf(r->pool, "%s_%d", name, apr_hook_when);
675 if (hook_specs) {
676 int i;
677 for (i = 0; i < hook_specs->nelts; i++) {
680
681 if (hook_spec == NULL) {
682 continue;
683 }
684 spec = create_vm_spec(&pool, r, cfg, server_cfg,
685 hook_spec->file_name,
686 hook_spec->bytecode,
687 hook_spec->bytecode_len,
688 hook_spec->function_name,
689 "request hook");
690
691 L = ap_lua_get_lua_state(pool, spec, r);
692
693 if (!L) {
695 "lua: Failed to obtain lua interpreter for entry function '%s' in %s",
696 hook_spec->function_name, hook_spec->file_name);
698 }
699
700 if (hook_spec->function_name != NULL) {
701 lua_getglobal(L, hook_spec->function_name);
702 if (!lua_isfunction(L, -1)) {
704 "lua: Unable to find entry function '%s' in %s (not a valid function)",
705 hook_spec->function_name,
706 hook_spec->file_name);
707 ap_lua_release_state(L, spec, r);
709 }
710
712 }
713 else {
714 int t;
716
717 t = lua_gettop(L);
718 lua_setglobal(L, "r");
719 lua_settop(L, t);
720 }
721
722 if (lua_pcall(L, 1, 1, 0)) {
724 ap_lua_release_state(L, spec, r);
726 }
727 rc = DECLINED;
728 if (lua_isnumber(L, -1)) {
729 rc = lua_tointeger(L, -1);
730 ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r, "Lua hook %s:%s for phase %s returned %d",
731 hook_spec->file_name, hook_spec->function_name, name, rc);
732 }
733 else {
735 "Lua hook %s:%s for phase %s did not return a numeric value",
736 hook_spec->file_name, hook_spec->function_name, name);
738 }
739 if (rc != DECLINED) {
740 ap_lua_release_state(L, spec, r);
741 return rc;
742 }
743 ap_lua_release_state(L, spec, r);
744 }
745 }
746 return DECLINED;
747}
748
749
750/* Fix for making sure that LuaMapHandler works when FallbackResource is set */
752{
753 /* If there is no handler set yet, this might be a LuaMapHandler request */
754 if (r->handler == NULL) {
755 int n = 0;
758 &lua_module);
759 for (n = 0; n < cfg->mapped_handlers->nelts; n++) {
762
763 if (hook_spec == NULL) {
764 continue;
765 }
766 if (!ap_regexec(hook_spec->uri_pattern, r->uri, 10, match, 0)) {
767 r->handler = apr_pstrdup(r->pool, "lua-map-handler");
768 return OK;
769 }
770 }
771 }
772 return DECLINED;
773}
774
775
777{
778 int rc, n = 0;
780 lua_State *L;
781 const char *filename, *function_name;
782 const char *values[10];
783 ap_lua_vm_spec *spec;
786 &lua_module);
788 &lua_module);
789 for (n = 0; n < cfg->mapped_handlers->nelts; n++) {
792
793 if (hook_spec == NULL) {
794 continue;
795 }
796 if (!ap_regexec(hook_spec->uri_pattern, r->uri, 10, match, 0)) {
797 int i;
798 for (i=0 ; i < 10; i++) {
799 if (match[i].rm_eo >= 0) {
800 values[i] = apr_pstrndup(r->pool, r->uri+match[i].rm_so, match[i].rm_eo - match[i].rm_so);
801 }
802 else values[i] = "";
803 }
805 function_name = ap_lua_interpolate_string(r->pool, hook_spec->function_name, values);
806 spec = create_vm_spec(&pool, r, cfg, server_cfg,
807 filename,
808 hook_spec->bytecode,
809 hook_spec->bytecode_len,
810 function_name,
811 "mapped handler");
812 L = ap_lua_get_lua_state(pool, spec, r);
813
814 if (!L) {
816 "lua: Failed to obtain Lua interpreter for entry function '%s' in %s",
817 function_name, filename);
818 ap_lua_release_state(L, spec, r);
820 }
821
822 if (function_name != NULL) {
823 lua_getglobal(L, function_name);
824 if (!lua_isfunction(L, -1)) {
826 "lua: Unable to find entry function '%s' in %s (not a valid function)",
827 function_name,
828 filename);
829 ap_lua_release_state(L, spec, r);
831 }
832
834 }
835 else {
836 int t;
838
839 t = lua_gettop(L);
840 lua_setglobal(L, "r");
841 lua_settop(L, t);
842 }
843
844 if (lua_pcall(L, 1, 1, 0)) {
846 ap_lua_release_state(L, spec, r);
848 }
849 rc = DECLINED;
850 if (lua_isnumber(L, -1)) {
851 rc = lua_tointeger(L, -1);
852 }
853 else {
855 "lua: Lua handler %s in %s did not return a value, assuming apache2.OK",
856 function_name,
857 filename);
858 rc = OK;
859 }
860 ap_lua_release_state(L, spec, r);
861 if (rc != DECLINED) {
862 return rc;
863 }
864 }
865 }
866 return DECLINED;
867}
868
869
871 size_t bufsiz)
872{
873 apr_size_t i = 0;
874
875 if (cfg->getstr) {
876 apr_status_t rc = (cfg->getstr) (buf, bufsiz, cfg->param);
877 if (rc == APR_SUCCESS) {
878 i = strlen(buf);
879 if (i && buf[i - 1] == '\n')
880 ++cfg->line_number;
881 }
882 else {
883 buf[0] = '\0';
884 i = 0;
885 }
886 }
887 else {
888 while (i < bufsiz) {
889 char ch;
890 apr_status_t rc = (cfg->getch) (&ch, cfg->param);
891 if (rc != APR_SUCCESS)
892 break;
893 buf[i++] = ch;
894 if (ch == '\n') {
895 ++cfg->line_number;
896 break;
897 }
898 }
899 }
900 return i;
901}
902
911
912
913/* Okay, this deserves a little explanation -- in order for the errors that lua
914 * generates to be 'accuarate', including line numbers, we basically inject
915 * N line number new lines into the 'top' of the chunk reader.....
916 *
917 * be happy. this is cool.
918 *
919 */
920static const char *lf =
921 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
922#define N_LF 32
923
924static const char *direct_chunkreader(lua_State *lvm, void *udata,
925 size_t *plen)
926{
927 const char *p;
928 struct cr_ctx *ctx = udata;
929
930 if (ctx->startline) {
931 *plen = ctx->startline > N_LF ? N_LF : ctx->startline;
932 ctx->startline -= *plen;
933 return lf;
934 }
935 *plen = config_getstr(ctx->cfp, ctx->buf, HUGE_STRING_LEN);
936
937 for (p = ctx->buf; isspace(*p); ++p);
938 if (p[0] == '<' && p[1] == '/') {
939 apr_size_t i = 0;
940 while (i < strlen(ctx->endstr)) {
941 if (tolower(p[i + 2]) != ctx->endstr[i])
942 return ctx->buf;
943 ++i;
944 }
945 *plen = 0;
946 return NULL;
947 }
948 /*fprintf(stderr, "buf read: %s\n", ctx->buf); */
949 return ctx->buf;
950}
951
952static int ldump_writer(lua_State *L, const void *b, size_t size, void *B)
953{
954 (void) L;
955 luaL_addlstring((luaL_Buffer *) B, (const char *) b, size);
956 return 0;
957}
958
965
966/* You can be unhappy now.
967 *
968 * This is uncool.
969 *
970 * When you create a <Section handler in httpd, the only 'easy' way to create
971 * a directory context is to parse the section, and convert it into a 'normal'
972 * Configureation option, and then collapse the entire section, in memory,
973 * back into the parent section -- from which you can then get the new directive
974 * invoked.... anyways. evil. Rici taught me how to do this hack :-)
975 */
976static const char *hack_section_handler(cmd_parms *cmd, void *_cfg,
977 const char *arg)
978{
980 ap_directive_t *directive = cmd->directive;
981 hack_section_baton *baton = directive->data;
982 const char *key = apr_psprintf(cmd->pool, "%s_%d", baton->name, baton->apr_hook_when);
983
986 if (!hook_specs) {
987 hook_specs = apr_array_make(cmd->pool, 2,
989 apr_hash_set(cfg->hooks, key,
991 }
992
993 baton->spec->scope = cfg->vm_scope;
994
996
997 return NULL;
998}
999
1000static const char *register_named_block_function_hook(const char *name,
1001 cmd_parms *cmd,
1002 void *mconfig,
1003 const char *line)
1004{
1005 const char *function = NULL;
1007 int when = APR_HOOK_MIDDLE;
1008 const char *endp = ap_strrchr_c(line, '>');
1009
1010 if (endp == NULL) {
1011 return apr_pstrcat(cmd->pool, cmd->cmd->name,
1012 "> directive missing closing '>'", NULL);
1013 }
1014
1015 line = apr_pstrndup(cmd->temp_pool, line, endp - line);
1016
1017 if (line[0]) {
1018 const char *word;
1019 word = ap_getword_conf(cmd->temp_pool, &line);
1020 if (*word) {
1021 function = apr_pstrdup(cmd->pool, word);
1022 }
1023 word = ap_getword_conf(cmd->temp_pool, &line);
1024 if (*word) {
1025 if (!strcasecmp("early", word)) {
1027 }
1028 else if (!strcasecmp("late", word)) {
1030 }
1031 else {
1032 return apr_pstrcat(cmd->pool, cmd->cmd->name,
1033 "> 2nd argument must be 'early' or 'late'", NULL);
1034 }
1035 }
1036 }
1037
1038 spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_mapped_handler_spec));
1039
1040 {
1041 cr_ctx ctx;
1042 lua_State *lvm;
1043 char *tmp;
1044 int rv;
1045 ap_directive_t **current;
1047
1048 spec->file_name = apr_psprintf(cmd->pool, "%s:%u",
1049 cmd->config_file->name,
1050 cmd->config_file->line_number);
1051 if (function) {
1052 spec->function_name = (char *) function;
1053 }
1054 else {
1055 function = NULL;
1056 }
1057
1058 ctx.cmd = cmd;
1059 tmp = apr_pstrdup(cmd->pool, cmd->err_directive->directive + 1);
1060 ap_str_tolower(tmp);
1061 ctx.endstr = tmp;
1062 ctx.cfp = cmd->config_file;
1063 ctx.startline = cmd->config_file->line_number;
1064
1065 /* This lua State is used only to compile the input strings -> bytecode, so we don't need anything extra. */
1066 lvm = luaL_newstate();
1067
1068 lua_settop(lvm, 0);
1069
1071
1072 if (rv != 0) {
1073 const char *errstr = apr_pstrcat(cmd->pool, "Lua Error:",
1074 lua_tostring(lvm, -1), NULL);
1075 lua_close(lvm);
1076 return errstr;
1077 }
1078 else {
1079 luaL_Buffer b;
1080 luaL_buffinit(lvm, &b);
1083 spec->bytecode_len = lua_rawlen(lvm, -1);
1084 spec->bytecode = apr_pstrmemdup(cmd->pool, lua_tostring(lvm, -1),
1085 spec->bytecode_len);
1086 lua_close(lvm);
1087 }
1088
1089 current = mconfig;
1090
1091 /* Here, we have to replace our current config node for the next pass */
1092 if (!*current) {
1093 *current = apr_pcalloc(cmd->pool, sizeof(**current));
1094 }
1095
1096 baton = apr_pcalloc(cmd->pool, sizeof(hack_section_baton));
1097 baton->name = name;
1098 baton->spec = spec;
1099 baton->apr_hook_when = when;
1100
1101 (*current)->filename = cmd->config_file->name;
1102 (*current)->line_num = cmd->config_file->line_number;
1103 (*current)->directive = apr_pstrdup(cmd->pool, "Lua_____ByteCodeHack");
1104 (*current)->args = NULL;
1105 (*current)->data = baton;
1106 }
1107
1108 return NULL;
1109}
1110
1111static const char *register_named_file_function_hook(const char *name,
1112 cmd_parms *cmd,
1113 void *_cfg,
1114 const char *file,
1115 const char *function,
1116 int apr_hook_when)
1117{
1120 const char *key = apr_psprintf(cmd->pool, "%s_%d", name, apr_hook_when);
1123
1124 if (!hook_specs) {
1125 hook_specs = apr_array_make(cmd->pool, 2,
1126 sizeof(ap_lua_mapped_handler_spec *));
1128 }
1129
1130 spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_mapped_handler_spec));
1131 spec->file_name = apr_pstrdup(cmd->pool, file);
1132 spec->function_name = apr_pstrdup(cmd->pool, function);
1133 spec->scope = cfg->vm_scope;
1134
1136 return NULL;
1137}
1138static const char *register_mapped_file_function_hook(const char *pattern,
1139 cmd_parms *cmd,
1140 void *_cfg,
1141 const char *file,
1142 const char *function)
1143{
1146 ap_regex_t *regex = apr_pcalloc(cmd->pool, sizeof(ap_regex_t));
1147 if (ap_regcomp(regex, pattern,0)) {
1148 return "Invalid regex pattern!";
1149 }
1150
1151 spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_mapped_handler_spec));
1152 spec->file_name = apr_pstrdup(cmd->pool, file);
1153 spec->function_name = apr_pstrdup(cmd->pool, function);
1154 spec->scope = cfg->vm_scope;
1155 spec->uri_pattern = regex;
1156
1158 return NULL;
1159}
1160static const char *register_filter_function_hook(const char *filter,
1161 cmd_parms *cmd,
1162 void *_cfg,
1163 const char *file,
1164 const char *function,
1165 int direction)
1166{
1169
1170 spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_filter_handler_spec));
1171 spec->file_name = apr_pstrdup(cmd->pool, file);
1172 spec->function_name = apr_pstrdup(cmd->pool, function);
1173 spec->filter_name = filter;
1174
1176 /* TODO: Make it work on other types than just AP_FTYPE_RESOURCE? */
1177 if (direction == AP_LUA_FILTER_OUTPUT) {
1181 }
1182 else {
1185 }
1186 return NULL;
1187}
1188/* disabled (see reference below)
1189static int lua_check_user_id_harness_first(request_rec *r)
1190{
1191 return lua_request_rec_hook_harness(r, "check_user_id", AP_LUA_HOOK_FIRST);
1192}
1193*/
1195{
1196 return lua_request_rec_hook_harness(r, "check_user_id", APR_HOOK_MIDDLE);
1197}
1198/* disabled (see reference below)
1199static int lua_check_user_id_harness_last(request_rec *r)
1200{
1201 return lua_request_rec_hook_harness(r, "check_user_id", AP_LUA_HOOK_LAST);
1202}
1203*/
1204
1206{
1207 return lua_request_rec_hook_harness(r, "pre_translate_name", APR_HOOK_MIDDLE);
1208}
1209
1211{
1212 return lua_request_rec_hook_harness(r, "translate_name", AP_LUA_HOOK_FIRST);
1213}
1215{
1216 return lua_request_rec_hook_harness(r, "translate_name", APR_HOOK_MIDDLE);
1217}
1219{
1220 return lua_request_rec_hook_harness(r, "translate_name", AP_LUA_HOOK_LAST);
1221}
1222
1224{
1226}
1227
1229{
1230 return lua_request_rec_hook_harness(r, "map_to_storage", APR_HOOK_MIDDLE);
1231}
1232
1234{
1235 return lua_request_rec_hook_harness(r, "type_checker", APR_HOOK_MIDDLE);
1236}
1237
1239{
1240 return lua_request_rec_hook_harness(r, "access_checker", AP_LUA_HOOK_FIRST);
1241}
1243{
1244 return lua_request_rec_hook_harness(r, "access_checker", APR_HOOK_MIDDLE);
1245}
1247{
1248 return lua_request_rec_hook_harness(r, "access_checker", AP_LUA_HOOK_LAST);
1249}
1250
1252{
1253 return lua_request_rec_hook_harness(r, "auth_checker", AP_LUA_HOOK_FIRST);
1254}
1256{
1257 return lua_request_rec_hook_harness(r, "auth_checker", APR_HOOK_MIDDLE);
1258}
1260{
1261 return lua_request_rec_hook_harness(r, "auth_checker", AP_LUA_HOOK_LAST);
1262}
1264{
1265 /* ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(03223)
1266 * "LuaHookInsertFilter not yet implemented"); */
1267}
1268
1270{
1271 return lua_request_rec_hook_harness(r, "log_transaction", APR_HOOK_FIRST);
1272}
1273
1275{
1276 if (lookup) {
1277 return DECLINED;
1278 }
1280}
1281
1283 const char *file,
1284 const char *function)
1285{
1286 return register_named_file_function_hook("pre_translate_name", cmd, _cfg, file,
1287 function, APR_HOOK_MIDDLE);
1288}
1289
1291 const char *line)
1292{
1293 return register_named_block_function_hook("pre_translate_name", cmd, _cfg,
1294 line);
1295}
1296
1298 const char *file,
1299 const char *function,
1300 const char *when)
1301{
1304 int apr_hook_when = APR_HOOK_MIDDLE;
1305 if (err) {
1306 return err;
1307 }
1308
1309 if (when) {
1310 if (!strcasecmp(when, "early")) {
1311 apr_hook_when = AP_LUA_HOOK_FIRST;
1312 }
1313 else if (!strcasecmp(when, "late")) {
1314 apr_hook_when = AP_LUA_HOOK_LAST;
1315 }
1316 else {
1317 return "Third argument must be 'early' or 'late'";
1318 }
1319 }
1320
1321 return register_named_file_function_hook("translate_name", cmd, _cfg,
1322 file, function, apr_hook_when);
1323}
1324
1326 const char *line)
1327{
1328 return register_named_block_function_hook("translate_name", cmd, _cfg,
1329 line);
1330}
1331
1332
1333static const char *register_fixups_hook(cmd_parms *cmd, void *_cfg,
1334 const char *file,
1335 const char *function)
1336{
1338 function, APR_HOOK_MIDDLE);
1339}
1340static const char *register_fixups_block(cmd_parms *cmd, void *_cfg,
1341 const char *line)
1342{
1343 return register_named_block_function_hook("fixups", cmd, _cfg, line);
1344}
1345
1347 const char *file,
1348 const char *function)
1349{
1350 return register_named_file_function_hook("map_to_storage", cmd, _cfg,
1351 file, function, APR_HOOK_MIDDLE);
1352}
1353
1355 const char *file,
1356 const char *function)
1357{
1358 return register_named_file_function_hook("log_transaction", cmd, _cfg,
1359 file, function, APR_HOOK_FIRST);
1360}
1361
1363 const char *line)
1364{
1365 return register_named_block_function_hook("map_to_storage", cmd, _cfg,
1366 line);
1367}
1368
1369
1371 const char *file,
1372 const char *function,
1373 const char *when)
1374{
1375 int apr_hook_when = APR_HOOK_MIDDLE;
1376/* XXX: This does not currently work!!
1377 if (when) {
1378 if (!strcasecmp(when, "early")) {
1379 apr_hook_when = AP_LUA_HOOK_FIRST;
1380 }
1381 else if (!strcasecmp(when, "late")) {
1382 apr_hook_when = AP_LUA_HOOK_LAST;
1383 }
1384 else {
1385 return "Third argument must be 'early' or 'late'";
1386 }
1387 }
1388*/
1389 return register_named_file_function_hook("check_user_id", cmd, _cfg, file,
1390 function, apr_hook_when);
1391}
1393 const char *line)
1394{
1395 return register_named_block_function_hook("check_user_id", cmd, _cfg,
1396 line);
1397}
1398
1400 const char *file,
1401 const char *function)
1402{
1403 return register_named_file_function_hook("type_checker", cmd, _cfg, file,
1404 function, APR_HOOK_MIDDLE);
1405}
1407 const char *line)
1408{
1409 return register_named_block_function_hook("type_checker", cmd, _cfg,
1410 line);
1411}
1412
1414 const char *file,
1415 const char *function,
1416 const char *when)
1417{
1418 int apr_hook_when = APR_HOOK_MIDDLE;
1419
1420 if (when) {
1421 if (!strcasecmp(when, "early")) {
1422 apr_hook_when = AP_LUA_HOOK_FIRST;
1423 }
1424 else if (!strcasecmp(when, "late")) {
1425 apr_hook_when = AP_LUA_HOOK_LAST;
1426 }
1427 else {
1428 return "Third argument must be 'early' or 'late'";
1429 }
1430 }
1431
1432 return register_named_file_function_hook("access_checker", cmd, _cfg,
1433 file, function, apr_hook_when);
1434}
1436 const char *line)
1437{
1438
1439 return register_named_block_function_hook("access_checker", cmd, _cfg,
1440 line);
1441}
1442
1444 const char *file,
1445 const char *function,
1446 const char *when)
1447{
1448 int apr_hook_when = APR_HOOK_MIDDLE;
1449
1450 if (when) {
1451 if (!strcasecmp(when, "early")) {
1452 apr_hook_when = AP_LUA_HOOK_FIRST;
1453 }
1454 else if (!strcasecmp(when, "late")) {
1455 apr_hook_when = AP_LUA_HOOK_LAST;
1456 }
1457 else {
1458 return "Third argument must be 'early' or 'late'";
1459 }
1460 }
1461
1462 return register_named_file_function_hook("auth_checker", cmd, _cfg, file,
1463 function, apr_hook_when);
1464}
1466 const char *line)
1467{
1468 return register_named_block_function_hook("auth_checker", cmd, _cfg,
1469 line);
1470}
1471
1473 const char *file,
1474 const char *function)
1475{
1476 return "LuaHookInsertFilter not yet implemented";
1477}
1478
1479static const char *register_quick_hook(cmd_parms *cmd, void *_cfg,
1480 const char *file, const char *function)
1481{
1484 if (err) {
1485 return err;
1486 }
1488 function, APR_HOOK_MIDDLE);
1489}
1490static const char *register_map_handler(cmd_parms *cmd, void *_cfg,
1491 const char* match, const char *file, const char *function)
1492{
1495 if (err) {
1496 return err;
1497 }
1498 if (!function) function = "handle";
1500 function);
1501}
1502static const char *register_output_filter(cmd_parms *cmd, void *_cfg,
1503 const char* filter, const char *file, const char *function)
1504{
1507 if (err) {
1508 return err;
1509 }
1510 if (!function) function = "handle";
1511 return register_filter_function_hook(filter, cmd, _cfg, file,
1512 function, AP_LUA_FILTER_OUTPUT);
1513}
1514static const char *register_input_filter(cmd_parms *cmd, void *_cfg,
1515 const char* filter, const char *file, const char *function)
1516{
1519 if (err) {
1520 return err;
1521 }
1522 if (!function) function = "handle";
1523 return register_filter_function_hook(filter, cmd, _cfg, file,
1524 function, AP_LUA_FILTER_INPUT);
1525}
1526static const char *register_quick_block(cmd_parms *cmd, void *_cfg,
1527 const char *line)
1528{
1530 line);
1531}
1532
1533
1534
1536 const char *arg,
1538{
1539 apr_status_t rv;
1540
1542 ap_get_module_config(cmd->server->module_config, &lua_module);
1543
1544 char *fixed_filename;
1546 server_cfg->root_path,
1547 arg,
1549 cmd->pool);
1550
1551 if (rv != APR_SUCCESS) {
1552 return apr_psprintf(cmd->pool,
1553 "Unable to build full path to file, %s", arg);
1554 }
1555
1556 *(const char **) apr_array_push(dir_array) = fixed_filename;
1557 return NULL;
1558}
1559
1560
1565static const char *register_package_dir(cmd_parms *cmd, void *_cfg,
1566 const char *arg)
1567{
1569
1571}
1572
1578 void *_cfg,
1579 const char *arg)
1580{
1582
1584}
1585
1587 void *_cfg,
1588 const char *arg)
1589{
1591
1592 if (strcasecmp("none", arg) == 0) {
1594 }
1595 else if (strcasecmp("parent-first", arg) == 0) {
1597 }
1598 else if (strcasecmp("parent-last", arg) == 0) {
1600 }
1601 else {
1602 return apr_psprintf(cmd->pool,
1603 "LuaInherit type of '%s' not recognized, valid "
1604 "options are 'none', 'parent-first', and 'parent-last'",
1605 arg);
1606 }
1607 return NULL;
1608}
1610 void *_cfg,
1611 const char *arg)
1612{
1614
1615 if (strcasecmp("never", arg) == 0) {
1617 }
1618 else if (strcasecmp("stat", arg) == 0) {
1620 }
1621 else if (strcasecmp("forever", arg) == 0) {
1623 }
1624 else {
1625 return apr_psprintf(cmd->pool,
1626 "LuaCodeCache type of '%s' not recognized, valid "
1627 "options are 'never', 'stat', and 'forever'",
1628 arg);
1629 }
1630 return NULL;
1631}
1632static const char *register_lua_scope(cmd_parms *cmd,
1633 void *_cfg,
1634 const char *scope,
1635 const char *min,
1636 const char *max)
1637{
1639 if (strcmp("once", scope) == 0) {
1641 }
1642 else if (strcmp("request", scope) == 0) {
1644 }
1645 else if (strcmp("conn", scope) == 0) {
1647 }
1648 else if (strcmp("thread", scope) == 0) {
1649#if !APR_HAS_THREADS
1650 return apr_psprintf(cmd->pool,
1651 "Scope type of '%s' cannot be used because this "
1652 "server does not have threading support "
1653 "(APR_HAS_THREADS)",
1654 scope);
1655#endif
1657 }
1658 else if (strcmp("server", scope) == 0) {
1659 unsigned int vmin, vmax;
1660#if !APR_HAS_THREADS
1661 return apr_psprintf(cmd->pool,
1662 "Scope type of '%s' cannot be used because this "
1663 "server does not have threading support "
1664 "(APR_HAS_THREADS)",
1665 scope);
1666#endif
1668 vmin = min ? atoi(min) : 1;
1669 vmax = max ? atoi(max) : 1;
1670 if (vmin == 0) {
1671 vmin = 1;
1672 }
1673 if (vmax < vmin) {
1674 vmax = vmin;
1675 }
1676 cfg->vm_min = vmin;
1677 cfg->vm_max = vmax;
1678 }
1679 else {
1680 return apr_psprintf(cmd->pool,
1681 "Invalid value for LuaScope, '%s', acceptable "
1682 "values are: 'once', 'request', 'conn'"
1684 ", 'thread', 'server'"
1685#endif
1686 ,scope);
1687 }
1688
1689 return NULL;
1690}
1691
1692
1693
1694static const char *register_lua_root(cmd_parms *cmd, void *_cfg,
1695 const char *root)
1696{
1697 /* ap_lua_dir_cfg* cfg = (ap_lua_dir_cfg*)_cfg; */
1698 ap_lua_server_cfg *cfg = ap_get_module_config(cmd->server->module_config,
1699 &lua_module);
1700
1701 cfg->root_path = root;
1702 return NULL;
1703}
1704
1706 request_rec *r, const char *var)
1707{
1708 return ap_ssl_var_lookup(p, s, c, r, var);
1709}
1710
1712{
1713 return ap_ssl_conn_is_ssl(c);
1714}
1715
1716/*******************************/
1717
1718static const char *lua_authz_parse(cmd_parms *cmd, const char *require_line,
1719 const void **parsed_require_line)
1720{
1721 const char *provider_name;
1724
1725 apr_pool_userdata_get((void**)&provider_name, AUTHZ_PROVIDER_NAME_NOTE,
1726 cmd->temp_pool);
1727 ap_assert(provider_name != NULL);
1728
1730 ap_assert(spec != NULL);
1731 func->spec = spec;
1732
1733 if (require_line && *require_line) {
1734 const char *arg;
1735 func->args = apr_array_make(cmd->pool, 2, sizeof(const char *));
1736 while ((arg = ap_getword_conf(cmd->pool, &require_line)) && *arg) {
1737 APR_ARRAY_PUSH(func->args, const char *) = arg;
1738 }
1739 }
1740
1742 return NULL;
1743}
1744
1746 const void *parsed_require_line)
1747{
1749 ap_lua_vm_spec *spec;
1750 lua_State *L;
1752 &lua_module);
1754 &lua_module);
1757 int result;
1758 int nargs = 0;
1759
1760 spec = create_vm_spec(&pool, r, cfg, server_cfg, prov_spec->file_name,
1761 NULL, 0, prov_spec->function_name, "authz provider");
1762
1763 L = ap_lua_get_lua_state(pool, spec, r);
1764 if (L == NULL) {
1766 "Unable to compile VM for authz provider %s", prov_spec->name);
1767 return AUTHZ_GENERAL_ERROR;
1768 }
1769 lua_getglobal(L, prov_spec->function_name);
1770 if (!lua_isfunction(L, -1)) {
1772 "Unable to find entry function '%s' in %s (not a valid function)",
1773 prov_spec->function_name, prov_spec->file_name);
1774 ap_lua_release_state(L, spec, r);
1775 return AUTHZ_GENERAL_ERROR;
1776 }
1778 if (prov_func->args) {
1779 int i;
1780 if (!lua_checkstack(L, prov_func->args->nelts)) {
1782 "Error: authz provider %s: too many arguments", prov_spec->name);
1783 ap_lua_release_state(L, spec, r);
1784 return AUTHZ_GENERAL_ERROR;
1785 }
1786 for (i = 0; i < prov_func->args->nelts; i++) {
1787 const char *arg = APR_ARRAY_IDX(prov_func->args, i, const char *);
1788 lua_pushstring(L, arg);
1789 }
1790 nargs = prov_func->args->nelts;
1791 }
1792 if (lua_pcall(L, 1 + nargs, 1, 0)) {
1793 const char *err = lua_tostring(L, -1);
1795 "Error executing authz provider %s: %s", prov_spec->name, err);
1796 ap_lua_release_state(L, spec, r);
1797 return AUTHZ_GENERAL_ERROR;
1798 }
1799 if (!lua_isnumber(L, -1)) {
1801 "Error: authz provider %s did not return integer", prov_spec->name);
1802 ap_lua_release_state(L, spec, r);
1803 return AUTHZ_GENERAL_ERROR;
1804 }
1805 result = lua_tointeger(L, -1);
1806 ap_lua_release_state(L, spec, r);
1807 switch (result) {
1808 case AUTHZ_DENIED:
1809 case AUTHZ_GRANTED:
1810 case AUTHZ_NEUTRAL:
1813 return result;
1814 default:
1816 "Error: authz provider %s: invalid return value %d",
1817 prov_spec->name, result);
1818 }
1819 return AUTHZ_GENERAL_ERROR;
1820}
1821
1823{
1826};
1827
1828static const char *register_authz_provider(cmd_parms *cmd, void *_cfg,
1829 const char *name, const char *file,
1830 const char *function)
1831{
1833 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1834 if (err)
1835 return err;
1836
1837 spec = apr_pcalloc(cmd->pool, sizeof(*spec));
1838 spec->name = name;
1839 spec->file_name = file;
1840 spec->function_name = function;
1841
1847 return NULL;
1848}
1849
1850
1851static const command_rec lua_commands[] = {
1852
1854 "Specify the base path for resolving relative paths for mod_lua directives"),
1855
1856 AP_INIT_TAKE1("LuaPackagePath", register_package_dir, NULL, OR_ALL,
1857 "Add a directory to lua's package.path"),
1858
1859 AP_INIT_TAKE1("LuaPackageCPath", register_package_cdir, NULL, OR_ALL,
1860 "Add a directory to lua's package.cpath"),
1861
1863 "Provide an authorization provider"),
1864
1865 AP_INIT_TAKE2("LuaHookPreTranslateName", register_pre_trans_name_hook, NULL,
1866 OR_ALL,
1867 "Provide a hook for the pre_translate name phase of request processing"),
1868
1869 AP_INIT_RAW_ARGS("<LuaHookPreTranslateName", register_pre_trans_name_block, NULL,
1871 "Provide a hook for the pre_translate name phase of request processing"),
1872
1873 AP_INIT_TAKE23("LuaHookTranslateName", register_translate_name_hook, NULL,
1874 OR_ALL,
1875 "Provide a hook for the translate name phase of request processing"),
1876
1877 AP_INIT_RAW_ARGS("<LuaHookTranslateName", register_translate_name_block,
1878 NULL,
1880 "Provide a hook for the translate name phase of request processing"),
1881
1882 AP_INIT_TAKE2("LuaHookFixups", register_fixups_hook, NULL, OR_ALL,
1883 "Provide a hook for the fixups phase of request processing"),
1884 AP_INIT_RAW_ARGS("<LuaHookFixups", register_fixups_block, NULL,
1886 "Provide a inline hook for the fixups phase of request processing"),
1887
1888 /* todo: test */
1889 AP_INIT_TAKE2("LuaHookMapToStorage", register_map_to_storage_hook, NULL,
1890 OR_ALL,
1891 "Provide a hook for the map_to_storage phase of request processing"),
1892 AP_INIT_RAW_ARGS("<LuaHookMapToStorage", register_map_to_storage_block,
1893 NULL,
1895 "Provide a hook for the map_to_storage phase of request processing"),
1896
1897 /* todo: test */
1898 AP_INIT_TAKE23("LuaHookCheckUserID", register_check_user_id_hook, NULL,
1899 OR_ALL,
1900 "Provide a hook for the check_user_id phase of request processing"),
1901 AP_INIT_RAW_ARGS("<LuaHookCheckUserID", register_check_user_id_block,
1902 NULL,
1904 "Provide a hook for the check_user_id phase of request processing"),
1905
1906 /* todo: test */
1907 AP_INIT_TAKE2("LuaHookTypeChecker", register_type_checker_hook, NULL,
1908 OR_ALL,
1909 "Provide a hook for the type_checker phase of request processing"),
1910 AP_INIT_RAW_ARGS("<LuaHookTypeChecker", register_type_checker_block, NULL,
1912 "Provide a hook for the type_checker phase of request processing"),
1913
1914 /* todo: test */
1915 AP_INIT_TAKE23("LuaHookAccessChecker", register_access_checker_hook, NULL,
1916 OR_ALL,
1917 "Provide a hook for the access_checker phase of request processing"),
1918 AP_INIT_RAW_ARGS("<LuaHookAccessChecker", register_access_checker_block,
1919 NULL,
1921 "Provide a hook for the access_checker phase of request processing"),
1922
1923 /* todo: test */
1924 AP_INIT_TAKE23("LuaHookAuthChecker", register_auth_checker_hook, NULL,
1925 OR_ALL,
1926 "Provide a hook for the auth_checker phase of request processing"),
1927 AP_INIT_RAW_ARGS("<LuaHookAuthChecker", register_auth_checker_block, NULL,
1929 "Provide a hook for the auth_checker phase of request processing"),
1930
1931 /* todo: test */
1932 AP_INIT_TAKE2("LuaHookInsertFilter", register_insert_filter_hook, NULL,
1933 OR_ALL,
1934 "Provide a hook for the insert_filter phase of request processing"),
1935
1937 OR_ALL,
1938 "Provide a hook for the logging phase of request processing"),
1939
1941 "One of once, request, conn, server -- default is once"),
1942
1944 "Controls how Lua scripts in parent contexts are merged with the current "
1945 " context: none|parent-last|parent-first (default: parent-first) "),
1946
1948 "Controls the behavior of the in-memory code cache "
1949 " context: stat|forever|never (default: stat) "),
1950
1951 AP_INIT_TAKE2("LuaQuickHandler", register_quick_hook, NULL, OR_ALL,
1952 "Provide a hook for the quick handler of request processing"),
1953 AP_INIT_RAW_ARGS("<LuaQuickHandler", register_quick_block, NULL,
1955 "Provide a hook for the quick handler of request processing"),
1956 AP_INIT_RAW_ARGS("Lua_____ByteCodeHack", hack_section_handler, NULL,
1957 OR_ALL,
1958 "(internal) Byte code handler"),
1960 "Maps a path to a lua handler"),
1961 AP_INIT_TAKE3("LuaOutputFilter", register_output_filter, NULL, OR_ALL,
1962 "Registers a Lua function as an output filter"),
1963 AP_INIT_TAKE3("LuaInputFilter", register_input_filter, NULL, OR_ALL,
1964 "Registers a Lua function as an input filter"),
1965 {NULL}
1966};
1967
1968
1969static void *create_dir_config(apr_pool_t *p, char *dir)
1970{
1971 ap_lua_dir_cfg *cfg = apr_pcalloc(p, sizeof(ap_lua_dir_cfg));
1972 cfg->package_paths = apr_array_make(p, 2, sizeof(char *));
1973 cfg->package_cpaths = apr_array_make(p, 2, sizeof(char *));
1974 cfg->mapped_handlers =
1976 cfg->mapped_filters =
1978 cfg->pool = p;
1979 cfg->hooks = apr_hash_make(p);
1980 cfg->dir = apr_pstrdup(p, dir);
1983 cfg->vm_min = 0;
1984 cfg->vm_max = 0;
1986
1987 return cfg;
1988}
1989
1991{
1995 ap_set_module_config(r->request_config, &lua_module, cfg);
1996 return OK;
1997}
1998
2000{
2001
2003 cfg->root_path = NULL;
2004
2005 return cfg;
2006}
2007
2009{
2011 return OK;
2012}
2013
2015 apr_pool_t *ptemp)
2016{
2017 ap_mutex_register(pconf, "lua-ivm-shm", NULL, APR_LOCK_DEFAULT, 0);
2018 return OK;
2019}
2020
2022 apr_pool_t *ptemp, server_rec *s)
2023{
2024 apr_pool_t **pool;
2026
2028 return OK;
2029
2030 /* Create ivm mutex */
2031 rs = ap_global_mutex_create(&lua_ivm_mutex, NULL, "lua-ivm-shm", NULL,
2032 s, pconf, 0);
2033 if (APR_SUCCESS != rs) {
2035 }
2036
2037 /* Create shared memory space, anonymous first if possible. */
2040 /* Fall back to filename-based; nuke any left-over first. */
2042
2044
2046 }
2047 if (rs != APR_SUCCESS) {
2049 "mod_lua: Failed to create shared memory segment on file %s",
2050 lua_ivm_shmfile ? lua_ivm_shmfile : "(anonymous)");
2052 }
2055 apr_pool_tag(*pool, "mod_lua-shared");
2058 return OK;
2059}
2061 const void *key,
2063 const void *overlay_val,
2064 const void *base_val,
2065 const void *data)
2066{
2070}
2071
2072static void *merge_dir_config(apr_pool_t *p, void *basev, void *overridesv)
2073{
2075
2079
2080 a->pool = overrides->pool;
2081 a->dir = apr_pstrdup(p, overrides->dir);
2082
2083 a->vm_scope = (overrides->vm_scope == AP_LUA_SCOPE_UNSET) ? base->vm_scope: overrides->vm_scope;
2084 a->inherit = (overrides->inherit == AP_LUA_INHERIT_UNSET) ? base->inherit : overrides->inherit;
2085 a->codecache = (overrides->codecache == AP_LUA_CACHE_UNSET) ? base->codecache : overrides->codecache;
2086
2087 a->vm_min = (overrides->vm_min == 0) ? base->vm_min : overrides->vm_min;
2088 a->vm_max = (overrides->vm_max == 0) ? base->vm_max : overrides->vm_max;
2089
2090 if (a->inherit == AP_LUA_INHERIT_UNSET || a->inherit == AP_LUA_INHERIT_PARENT_FIRST) {
2091 a->package_paths = apr_array_append(p, base->package_paths, overrides->package_paths);
2092 a->package_cpaths = apr_array_append(p, base->package_cpaths, overrides->package_cpaths);
2093 a->mapped_handlers = apr_array_append(p, base->mapped_handlers, overrides->mapped_handlers);
2094 a->mapped_filters = apr_array_append(p, base->mapped_filters, overrides->mapped_filters);
2095 a->hooks = apr_hash_merge(p, overrides->hooks, base->hooks, overlay_hook_specs, NULL);
2096 }
2097 else if (a->inherit == AP_LUA_INHERIT_PARENT_LAST) {
2098 a->package_paths = apr_array_append(p, overrides->package_paths, base->package_paths);
2099 a->package_cpaths = apr_array_append(p, overrides->package_cpaths, base->package_cpaths);
2100 a->mapped_handlers = apr_array_append(p, overrides->mapped_handlers, base->mapped_handlers);
2101 a->mapped_filters = apr_array_append(p, overrides->mapped_filters, base->mapped_filters);
2102 a->hooks = apr_hash_merge(p, base->hooks, overrides->hooks, overlay_hook_specs, NULL);
2103 }
2104 else {
2105 a->package_paths = overrides->package_paths;
2106 a->package_cpaths = overrides->package_cpaths;
2107 a->mapped_handlers= overrides->mapped_handlers;
2108 a->mapped_filters= overrides->mapped_filters;
2109 a->hooks= overrides->hooks;
2110 }
2111
2112 return a;
2113}
2114
2116{
2117 /* ap_register_output_filter("luahood", luahood, NULL, AP_FTYPE_RESOURCE); */
2121
2122 /* http_request.h hooks */
2125
2132
2136
2137/* XXX: Does not work :(
2138 * ap_hook_check_user_id(lua_check_user_id_harness_first, NULL, NULL,
2139 AP_LUA_HOOK_FIRST);
2140 */
2143/* XXX: Does not work :(
2144 * ap_hook_check_user_id(lua_check_user_id_harness_last, NULL, NULL,
2145 AP_LUA_HOOK_LAST);
2146*/
2149
2162
2166
2169
2172
2176
2177 /* Hook this right before FallbackResource kicks in */
2180
2181 /* providers */
2183
2184 /* Logging catcher */
2187}
2188
2191 create_dir_config, /* create per-dir config structures */
2192 merge_dir_config, /* merge per-dir config structures */
2193 create_server_config, /* create per-server config structures */
2194 NULL, /* merge per-server config structures */
2195 lua_commands, /* table of config file commands */
2196 lua_register_hooks /* register hooks */
2197};
int n
Definition ap_regex.h:278
int int const char ** match
Definition ap_regex.h:279
const char * pattern
Definition ap_regex.h:243
const char apr_size_t len
Definition ap_regex.h:187
const char * string
Definition ap_regex.h:171
APR-UTIL registration of functions exported by modules.
APR memory allocation.
#define hash(h, r, b, n)
Definition apr_random.c:51
#define min(a, b)
Definition apr_random.c:32
apr_array_append(apr_pool_t *p, const apr_array_header_t *first, const apr_array_header_t *second)
Definition apr_tables.c:213
APR Thread Mutex Routines.
APR Thread and Process Library.
static apr_pool_t * pconf
Definition event.c:441
#define AP_INIT_TAKE123(directive, func, mconfig, where, help)
#define AP_INIT_TAKE1(directive, func, mconfig, where, help)
char * ap_runtime_dir_relative(apr_pool_t *p, const char *fname)
Definition config.c:1610
#define ap_get_module_config(v, m)
void ap_hook_post_config(ap_HOOK_post_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:105
#define AP_DECLARE_MODULE(foo)
void ap_hook_quick_handler(ap_HOOK_quick_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:173
ap_conf_vector_t * base
#define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help)
void ap_hook_handler(ap_HOOK_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:170
#define ap_set_module_config(v, m, val)
void ap_hook_pre_config(ap_HOOK_pre_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:91
request_rec * r
#define AP_INIT_TAKE3(directive, func, mconfig, where, help)
void ap_hook_child_init(ap_HOOK_child_init_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:167
#define AP_INIT_TAKE23(directive, func, mconfig, where, help)
#define AP_INIT_TAKE2(directive, func, mconfig, where, help)
#define HUGE_STRING_LEN
Definition httpd.h:303
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
#define AP_FILTER_PROTO_CHANGE
void ap_remove_input_filter(ap_filter_t *f)
ap_filter_rec_t * ap_register_output_filter_protocol(const char *name, ap_out_filter_func filter_func, ap_init_filter_func filter_init, ap_filter_type ftype, unsigned int proto_flags)
#define AP_FILTER_PROTO_CHANGE_LENGTH
apr_status_t ap_pass_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket)
apr_status_t ap_filter_rec_t * ap_register_input_filter(const char *name, ap_in_filter_func filter_func, ap_init_filter_func filter_init, ap_filter_type ftype)
apr_status_t ap_get_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket, ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
void ap_remove_output_filter(ap_filter_t *f)
@ AP_FTYPE_RESOURCE
#define AP_SQ_MS_CREATE_PRE_CONFIG
Definition http_core.h:1047
int ap_state_query(int query_code)
Definition core.c:5378
#define AP_SQ_MAIN_STATE
Definition http_core.h:1030
#define APLOGNO(n)
Definition http_log.h:117
#define APLOG_TRACE4
Definition http_log.h:75
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_TRACE3
Definition http_log.h:74
#define ap_log_error
Definition http_log.h:370
#define APLOG_MARK
Definition http_log.h:283
#define ap_log_perror
Definition http_log.h:412
#define APLOG_WARNING
Definition http_log.h:68
#define APLOG_CRIT
Definition http_log.h:66
#define APLOG_TRACE2
Definition http_log.h:73
#define APLOG_TRACE1
Definition http_log.h:72
const unsigned char * buf
Definition util_md5.h:50
apr_status_t ap_global_mutex_create(apr_global_mutex_t **mutex, const char **name, const char *type, const char *instance_id, server_rec *server, apr_pool_t *pool, apr_int32_t options)
Definition util_mutex.c:407
apr_status_t ap_mutex_register(apr_pool_t *pconf, const char *type, const char *default_dir, apr_lockmech_e default_mech, apr_int32_t options)
Definition util_mutex.c:254
void ap_hook_log_transaction(ap_HOOK_log_transaction_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition protocol.c:2587
static APR_INLINE int ap_rputs(const char *str, request_rec *r)
const char * ap_ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *name)
Definition ssl.c:186
int ap_ssl_conn_is_ssl(conn_rec *c)
Definition ssl.c:90
apr_status_t ap_register_auth_provider(apr_pool_t *pool, const char *provider_group, const char *provider_name, const char *provider_version, const void *provider, int type)
Definition request.c:2179
#define AP_AUTH_INTERNAL_PER_CONF
void ap_hook_pre_translate_name(ap_HOOK_pre_translate_name_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:79
void ap_hook_auth_checker(ap_HOOK_auth_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:95
void ap_hook_translate_name(ap_HOOK_translate_name_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:81
void ap_hook_check_user_id(ap_HOOK_check_user_id_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:85
void ap_hook_map_to_storage(ap_HOOK_map_to_storage_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:83
void ap_hook_fixups(ap_HOOK_fixups_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:87
void ap_hook_access_checker(ap_HOOK_access_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:91
void ap_hook_create_request(ap_HOOK_create_request_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:98
void ap_hook_type_checker(ap_HOOK_type_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:89
void ap_hook_insert_filter(ap_HOOK_insert_filter_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:96
ap_vhost_iterate_conn_cb void * baton
Definition http_vhost.h:87
void const char * arg
Definition http_vhost.h:63
#define APR_EGENERAL
Definition apr_errno.h:313
#define APR_ENOENT
Definition apr_errno.h:662
#define APR_STATUS_IS_ENOTIMPL(s)
Definition apr_errno.h:615
apr_file_t * f
#define APR_BUCKET_REMOVE(e)
#define APR_BRIGADE_LAST(b)
#define APR_BRIGADE_INSERT_TAIL(b, e)
#define APR_BUCKET_NEXT(e)
apr_read_type_e
Definition apr_buckets.h:57
#define APR_BRIGADE_EMPTY(b)
#define APR_BRIGADE_SENTINEL(b)
#define apr_bucket_delete(e)
#define APR_BUCKET_IS_EOS(e)
apr_brigade_flush void * ctx
apr_bucket apr_bucket_brigade * a
#define APR_BRIGADE_FIRST(b)
#define apr_bucket_read(e, str, len, block)
@ APR_BLOCK_READ
Definition apr_buckets.h:58
apr_pool_t apr_dbd_t int apr_dbd_prepared_t int nargs
Definition apr_dbd.h:414
const void apr_size_t srclen
Definition apr_escape.h:355
#define APR_HOOK_FIRST
Definition apr_hooks.h:301
#define APR_HOOK_REALLY_FIRST
Definition apr_hooks.h:299
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
const char apr_hash_t ** values
#define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns, link, ret, name, args_decl, args_use, ok, decline)
#define APR_OPTIONAL_HOOK(ns, name, pfn, aszPre, aszSucc, nOrder)
apr_redis_t * rc
Definition apr_redis.h:173
apr_redis_server_t * rs
Definition apr_redis.h:205
#define OR_ALL
#define RSRC_CONF
#define EXEC_ON_READ
#define HTTP_INTERNAL_SERVER_ERROR
Definition httpd.h:535
#define STANDARD20_MODULE_STUFF
#define ap_strrchr_c(s, c)
Definition httpd.h:2357
#define AP_DEBUG_ASSERT(exp)
Definition httpd.h:2283
#define ap_escape_html(p, s)
Definition httpd.h:1860
void ap_str_tolower(char *s)
Definition util.c:2410
#define ap_assert(exp)
Definition httpd.h:2271
char * ap_getword_conf(apr_pool_t *p, const char **line)
Definition util.c:833
#define NOT_IN_FILES
#define NOT_IN_HTACCESS
#define NOT_IN_DIRECTORY
#define GLOBAL_ONLY
const char * ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden)
Definition core.c:1301
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
@ APR_DIR
@ APR_NOFILE
const char * key
void * data
const char apr_file_t * file
#define APR_FILEPATH_NOTRELATIVE
apr_array_header_t ** result
int strcasecmp(const char *a, const char *b)
apr_ssize_t * klen
Definition apr_hash.h:71
#define APR_HASH_KEY_STRING
Definition apr_hash.h:47
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_interval_time_t t
apr_interval_time_t apr_pollcb_cb_t func
Definition apr_poll.h:422
apr_pool_t * b
Definition apr_pools.h:529
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
apr_dir_t * dir
@ APR_LOCK_DEFAULT
apr_size_t const char * filename
Definition apr_shm.h:72
const char * s
Definition apr_strings.h:95
#define APR_ARRAY_PUSH(ary, type)
Definition apr_tables.h:150
#define APR_ARRAY_IDX(ary, i, type)
Definition apr_tables.h:141
apr_int32_t apr_int32_t apr_int32_t err
apr_cmdtype_e cmd
apr_size_t apr_size_t max
Definition apr_time.h:220
int ap_lua_init(lua_State *L, apr_pool_t *p)
Definition lua_apr.c:88
void ap_lua_load_config_lmodule(lua_State *L)
Definition lua_config.c:262
void ap_lua_push_request(lua_State *L, request_rec *r)
void ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p)
lua_State * ap_lua_get_lua_state(apr_pool_t *lifecycle_pool, ap_lua_vm_spec *spec, request_rec *r)
Definition lua_vmprep.c:436
void ap_lua_init_mutex(apr_pool_t *pool, server_rec *s)
Definition lua_vmprep.c:43
void ap_lua_load_apache2_lmodule(lua_State *L)
Definition lua_vmprep.c:145
#define AP_LUA_SCOPE_SERVER
Definition lua_vmprep.h:43
#define AP_LUA_SCOPE_UNSET
Definition lua_vmprep.h:38
#define AP_LUA_SCOPE_THREAD
Definition lua_vmprep.h:42
#define AP_LUA_CACHE_UNSET
Definition lua_vmprep.h:45
#define AP_LUA_CACHE_FOREVER
Definition lua_vmprep.h:48
#define AP_LUA_FILTER_OUTPUT
Definition lua_vmprep.h:51
#define AP_LUA_SCOPE_CONN
Definition lua_vmprep.h:41
#define AP_LUA_SCOPE_REQUEST
Definition lua_vmprep.h:40
#define AP_LUA_SCOPE_ONCE
Definition lua_vmprep.h:39
#define AP_LUA_CACHE_NEVER
Definition lua_vmprep.h:46
#define AP_LUA_FILTER_INPUT
Definition lua_vmprep.h:50
#define AP_LUA_CACHE_STAT
Definition lua_vmprep.h:47
apr_pool_t * p
Definition md_event.c:32
Authentication and Authorization Extension for Apache.
authz_status
Definition mod_auth.h:72
@ AUTHZ_DENIED
Definition mod_auth.h:73
@ AUTHZ_GENERAL_ERROR
Definition mod_auth.h:76
@ AUTHZ_DENIED_NO_USER
Definition mod_auth.h:77
@ AUTHZ_NEUTRAL
Definition mod_auth.h:75
@ AUTHZ_GRANTED
Definition mod_auth.h:74
#define AUTHZ_PROVIDER_NAME_NOTE
Definition mod_auth.h:46
#define AUTHZ_PROVIDER_VERSION
Definition mod_auth.h:42
#define AUTHZ_PROVIDER_GROUP
Definition mod_auth.h:40
static int lua_auth_checker_harness_first(request_rec *r)
Definition mod_lua.c:1251
const char * ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var)
Definition mod_lua.c:1705
static const char * ap_lua_interpolate_string(apr_pool_t *pool, const char *string, const char **values)
Definition mod_lua.c:240
static int ldump_writer(lua_State *L, const void *b, size_t size, void *B)
Definition mod_lua.c:952
static const char * hack_section_handler(cmd_parms *cmd, void *_cfg, const char *arg)
Definition mod_lua.c:976
static const char * lua_authz_parse(cmd_parms *cmd, const char *require_line, const void **parsed_require_line)
Definition mod_lua.c:1718
static const char * scope_to_string(unsigned int scope)
Definition mod_lua.c:130
static const char * register_authz_provider(cmd_parms *cmd, void *_cfg, const char *name, const char *file, const char *function)
Definition mod_lua.c:1828
static const char * register_auth_checker_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1465
static const char * register_auth_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function, const char *when)
Definition mod_lua.c:1443
static const char * register_pre_trans_name_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1290
apr_global_mutex_t * lua_ivm_mutex
Definition mod_lua.c:85
static int lua_check_user_id_harness(request_rec *r)
Definition mod_lua.c:1194
int ap_lua_ssl_is_https(conn_rec *c)
Definition mod_lua.c:1711
static void * create_server_config(apr_pool_t *p, server_rec *s)
Definition mod_lua.c:1999
static void report_lua_error(lua_State *L, request_rec *r)
Definition mod_lua.c:101
static const command_rec lua_commands[]
Definition mod_lua.c:1851
static const char * register_lua_codecache(cmd_parms *cmd, void *_cfg, const char *arg)
Definition mod_lua.c:1609
static int lua_access_checker_harness(request_rec *r)
Definition mod_lua.c:1242
#define N_LF
Definition mod_lua.c:922
static int lua_pre_trans_name_harness(request_rec *r)
Definition mod_lua.c:1205
static int lua_request_rec_hook_harness(request_rec *r, const char *name, int apr_hook_when)
Definition mod_lua.c:662
static void lua_insert_filter_harness(request_rec *r)
Definition mod_lua.c:1263
static const char * register_input_filter(cmd_parms *cmd, void *_cfg, const char *filter, const char *file, const char *function)
Definition mod_lua.c:1514
static int lua_map_handler_fixups(request_rec *r)
Definition mod_lua.c:751
int ap_lua_run_lua_request(lua_State *L, request_rec *r)
Definition mod_lua.c:54
static void lua_open_callback(lua_State *L, apr_pool_t *p, void *ctx)
Definition mod_lua.c:116
static int lua_auth_checker_harness_last(request_rec *r)
Definition mod_lua.c:1259
static const char * register_named_file_function_hook(const char *name, cmd_parms *cmd, void *_cfg, const char *file, const char *function, int apr_hook_when)
Definition mod_lua.c:1111
static const char * register_map_to_storage_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1346
static int lua_auth_checker_harness(request_rec *r)
Definition mod_lua.c:1255
static const char * register_access_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function, const char *when)
Definition mod_lua.c:1413
static int lua_translate_name_harness(request_rec *r)
Definition mod_lua.c:1214
static void lua_register_hooks(apr_pool_t *p)
Definition mod_lua.c:2115
static const char * register_type_checker_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1406
static const char * register_fixups_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1333
static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade *pbbIn)
Definition mod_lua.c:429
static const char * register_access_checker_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1435
static void * create_dir_config(apr_pool_t *p, char *dir)
Definition mod_lua.c:1969
static const char * register_log_transaction_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1354
static const char * register_type_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1399
static const char * register_mapped_file_function_hook(const char *pattern, cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1138
static void * overlay_hook_specs(apr_pool_t *p, const void *key, apr_ssize_t klen, const void *overlay_val, const void *base_val, const void *data)
Definition mod_lua.c:2060
static const char * register_map_handler(cmd_parms *cmd, void *_cfg, const char *match, const char *file, const char *function)
Definition mod_lua.c:1490
static int lua_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
Definition mod_lua.c:2021
#define AP_LUA_HOOK_FIRST
Definition mod_lua.c:58
static int lua_map_to_storage_harness(request_rec *r)
Definition mod_lua.c:1228
static const char * register_check_user_id_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1392
static const char * register_lua_scope(cmd_parms *cmd, void *_cfg, const char *scope, const char *min, const char *max)
Definition mod_lua.c:1632
static void ap_lua_release_state(lua_State *L, ap_lua_vm_spec *spec, request_rec *r)
Definition mod_lua.c:152
static const char * register_translate_name_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1325
static const char * register_insert_filter_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1472
static ap_lua_vm_spec * create_vm_spec(apr_pool_t **lifecycle_pool, request_rec *r, const ap_lua_dir_cfg *cfg, const ap_lua_server_cfg *server_cfg, const char *filename, const char *bytecode, apr_size_t bytecode_len, const char *function, const char *what)
Definition mod_lua.c:173
static int lua_log_transaction_harness(request_rec *r)
Definition mod_lua.c:1269
#define AP_LUA_HOOK_LAST
Definition mod_lua.c:59
static apr_status_t lua_input_filter_handle(ap_filter_t *f, apr_bucket_brigade *pbbOut, ap_input_mode_t eMode, apr_read_type_e eBlock, apr_off_t nBytes)
Definition mod_lua.c:551
static int lua_open_hook(lua_State *L, apr_pool_t *p)
Definition mod_lua.c:124
static const char * register_quick_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1479
static apr_size_t config_getstr(ap_configfile_t *cfg, char *buf, size_t bufsiz)
Definition mod_lua.c:870
static const char * register_check_user_id_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function, const char *when)
Definition mod_lua.c:1370
static void * merge_dir_config(apr_pool_t *p, void *basev, void *overridesv)
Definition mod_lua.c:2072
static const char * register_pre_trans_name_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function)
Definition mod_lua.c:1282
static const char * register_package_cdir(cmd_parms *cmd, void *_cfg, const char *arg)
Definition mod_lua.c:1577
static const char * register_package_helper(cmd_parms *cmd, const char *arg, apr_array_header_t *dir_array)
Definition mod_lua.c:1535
static int lua_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
Definition mod_lua.c:2014
static const char * register_translate_name_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function, const char *when)
Definition mod_lua.c:1297
static int lua_handler(request_rec *r)
Definition mod_lua.c:278
static const char * direct_chunkreader(lua_State *lvm, void *udata, size_t *plen)
Definition mod_lua.c:924
static int lua_access_checker_harness_last(request_rec *r)
Definition mod_lua.c:1246
static int lua_quick_harness(request_rec *r, int lookup)
Definition mod_lua.c:1274
static apr_status_t lua_setup_filter_ctx(ap_filter_t *f, request_rec *r, lua_filter_ctx **c)
Definition mod_lua.c:338
static int lua_fixup_harness(request_rec *r)
Definition mod_lua.c:1223
static const char * register_map_to_storage_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1362
static int lua_translate_name_harness_first(request_rec *r)
Definition mod_lua.c:1210
static const authz_provider lua_authz_provider
Definition mod_lua.c:1822
apr_hash_t * lua_authz_providers
Definition mod_lua.c:73
static const char * register_filter_function_hook(const char *filter, cmd_parms *cmd, void *_cfg, const char *file, const char *function, int direction)
Definition mod_lua.c:1160
static int lua_map_handler(request_rec *r)
Definition mod_lua.c:776
static const char * register_lua_root(cmd_parms *cmd, void *_cfg, const char *root)
Definition mod_lua.c:1694
static authz_status lua_authz_check(request_rec *r, const char *require_line, const void *parsed_require_line)
Definition mod_lua.c:1745
static int lua_type_checker_harness(request_rec *r)
Definition mod_lua.c:1233
static apr_status_t shm_cleanup_wrapper(void *unused)
Definition mod_lua.c:89
static const char * register_quick_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1526
static int lua_translate_name_harness_last(request_rec *r)
Definition mod_lua.c:1218
apr_shm_t * lua_ivm_shm
Definition mod_lua.c:86
static const char * register_output_filter(cmd_parms *cmd, void *_cfg, const char *filter, const char *file, const char *function)
Definition mod_lua.c:1502
#define DEFAULT_LUA_SHMFILE
Definition mod_lua.c:83
static const char * register_lua_inherit(cmd_parms *cmd, void *_cfg, const char *arg)
Definition mod_lua.c:1586
static const char * lf
Definition mod_lua.c:920
static const char * register_package_dir(cmd_parms *cmd, void *_cfg, const char *arg)
Definition mod_lua.c:1565
static const char * register_named_block_function_hook(const char *name, cmd_parms *cmd, void *mconfig, const char *line)
Definition mod_lua.c:1000
static int lua_request_hook(lua_State *L, request_rec *r)
Definition mod_lua.c:2008
static const char * register_fixups_block(cmd_parms *cmd, void *_cfg, const char *line)
Definition mod_lua.c:1340
static int create_request_config(request_rec *r)
Definition mod_lua.c:1990
static int lua_access_checker_harness_first(request_rec *r)
Definition mod_lua.c:1238
char * lua_ivm_shmfile
Definition mod_lua.c:87
#define lua_rawlen(L, i)
Definition mod_lua.h:63
@ AP_LUA_INHERIT_PARENT_LAST
Definition mod_lua.h:100
@ AP_LUA_INHERIT_PARENT_FIRST
Definition mod_lua.h:99
@ AP_LUA_INHERIT_UNSET
Definition mod_lua.h:97
@ AP_LUA_INHERIT_NONE
Definition mod_lua.h:98
#define lua_resume(a, b, c)
Definition mod_lua.h:65
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
char * name
apr_status_t(* getch)(char *ch, void *param)
unsigned line_number
apr_status_t(* getstr)(void *buf, apr_size_t bufsiz, void *param)
Structure used to build the config tree.
const char * directive
The representation of a filter chain.
apr_hash_t * hooks
Definition mod_lua.h:135
apr_array_header_t * package_paths
Definition mod_lua.h:116
unsigned int vm_min
Definition mod_lua.h:131
unsigned int codecache
Definition mod_lua.h:146
apr_array_header_t * package_cpaths
Definition mod_lua.h:117
unsigned int vm_max
Definition mod_lua.h:132
ap_lua_inherit_t inherit
Definition mod_lua.h:141
apr_array_header_t * mapped_handlers
Definition mod_lua.h:122
apr_pool_t * pool
Definition mod_lua.h:125
const char * dir
Definition mod_lua.h:138
apr_array_header_t * mapped_filters
Definition mod_lua.h:123
unsigned int vm_scope
Definition mod_lua.h:130
apr_hash_t * request_scoped_vms
Definition mod_lua.h:165
mapped_request_details * mapped_request_details
Definition mod_lua.h:164
const char * root_path
Definition mod_lua.h:153
apr_array_header_t * package_paths
Definition lua_vmprep.h:61
unsigned int vm_max
Definition lua_vmprep.h:70
const char * bytecode
Definition lua_vmprep.h:82
apr_pool_t * pool
Definition lua_vmprep.h:76
apr_array_header_t * package_cpaths
Definition lua_vmprep.h:62
unsigned int vm_min
Definition lua_vmprep.h:69
apr_size_t bytecode_len
Definition lua_vmprep.h:83
ap_lua_state_open_callback cb
Definition lua_vmprep.h:72
const char * file
Definition lua_vmprep.h:65
apr_filetype_e filetype
Structure to store things which are per connection.
Definition httpd.h:1152
apr_pool_t * pool
Definition httpd.h:1154
const char * endstr
Definition mod_lua.c:908
ap_configfile_t * cfp
Definition mod_lua.c:906
char buf[8192]
Definition mod_lua.c:909
size_t startline
Definition mod_lua.c:907
cmd_parms * cmd
Definition mod_lua.c:905
const char * name
Definition mod_lua.c:961
ap_lua_mapped_handler_spec * spec
Definition mod_lua.c:962
apr_array_header_t * args
Definition mod_lua.c:70
lua_authz_provider_spec * spec
Definition mod_lua.c:69
const char * function_name
Definition mod_lua.c:64
const char * name
Definition mod_lua.c:62
ap_lua_vm_spec * spec
Definition mod_lua.c:65
const char * file_name
Definition mod_lua.c:63
apr_bucket_brigade * tmpBucket
Definition mod_lua.c:77
ap_lua_vm_spec * spec
Definition mod_lua.c:79
lua_State * L
Definition mod_lua.c:78
apr_pool_t * pool
Definition httpd.h:831
A structure that represents the current request.
Definition httpd.h:845
int status
Definition httpd.h:891
char * uri
Definition httpd.h:1016
const char * content_type
Definition httpd.h:992
int header_only
Definition httpd.h:875
const char * handler
Definition httpd.h:994
apr_pool_t * pool
Definition httpd.h:847
char * filename
Definition httpd.h:1018
conn_rec * connection
Definition httpd.h:849
apr_finfo_t finfo
Definition httpd.h:1094
struct ap_conf_vector_t * request_config
Definition httpd.h:1049
server_rec * server
Definition httpd.h:851
struct ap_conf_vector_t * per_dir_config
Definition httpd.h:1047
apr_table_t * headers_out
Definition httpd.h:978
A structure to keep track of authorization requirements.
Definition http_core.h:316
A structure to store information for each virtual server.
Definition httpd.h:1322
process_rec * process
Definition httpd.h:1324
struct ap_conf_vector_t * module_config
Definition httpd.h:1341
#define var
#define regex
ap_input_mode_t
input filtering modes
Definition util_filter.h:41
@ AP_MODE_EATCRLF
Definition util_filter.h:50
Apache Mutex support library.
static NAMED * lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize)
Definition xmlparse.c:7191