?revision_form?Rev ?revision_input??revision_submit??revision_endform?
Rev 87 |
Rev 90 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
--- /dev/null
+++ b/shared/dlopen_templates.c
@@ -0,0 +1,40 @@
+#include <dlfcn.h>
+#include "shared.h"
+
+struct template_map_index template_map_index[] = {
+ {NIL, NIL, NIL},
+ {NIL, NIL, NIL}
+};
+
+struct template_map_index *
+dlopen_templates(const char *set, const char *suffix)
+{
+ struct template_map_index *tmi = &template_map_index[0];
+ static void *handle = 0;
+
+ if (!handle || strcmp(tmi->name, set)) {
+ char *filename = pool_printf(NIL, "/usr/lib/prayer/templates/%s%s.so",
+ set, suffix);
+ char *map_symbol = pool_printf(NIL, "template_map_%s",
+ set);
+ char *count_symbol = pool_printf(NIL, "template_map_%s_count",
+ set);
+
+ if (handle) {
+ dlclose(handle);
+ free(tmi->name);
+ }
+ tmi->name = pool_strdup(NIL, set);
+ if (!(handle = dlopen(filename, RTLD_NOW))
+ || !(tmi->template_map = dlsym(handle, map_symbol))
+ || !(tmi->count = dlsym(handle, count_symbol))) {
+ log_fatal("Failed to load template library: \"%s\": %s",
+ filename, dlerror());
+ }
+ log_debug("Loaded library %s with %d templates", filename, *tmi->count);
+ free(filename);
+ free(map_symbol);
+ free(count_symbol);
+ }
+ return tmi;
+}
--- /dev/null
+++ b/shared/dlopen_templates.h
@@ -0,0 +1 @@
+struct template_map_index *dlopen_templates(const char *set, const char *suffix);
--- a/templates/cam/Makefile
+++ b/templates/cam/Makefile
@@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS)
TYPE=cam
-TARGETS=templates.a templates_frontend.a
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
T_FILES_FRONTEND=login.t login_hermes.t \
frontend_login_error.t frontend_security.t frontend_session.t \
@@ -111,6 +111,12 @@ templates.a: $(O_FILES)
rm -f templates.a
ar q templates.a $(O_FILES)
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND)
+
+$(TYPE).so: $(O_FILES)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES)
+
%.o: %.c Makefile
$(CC) $(CFLAGS) -I../../lib -c $<
@@ -129,8 +135,12 @@ install:
cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
+ $(BROOT)$(LIB_PREFIX)/templates
+ cp *.so $(BROOT)$(LIB_PREFIX)/templates/
+
clean:
- rm -f $(TARGETS) *.html *.o *.c \#*\# *~
+ rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~
include Makefile.deps
--- a/templates/old/Makefile
+++ b/templates/old/Makefile
@@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS)
TYPE=old
-TARGETS=templates.a templates_frontend.a
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
T_FILES_FRONTEND=login.t \
frontend_login_error.t frontend_security.t frontend_session.t \
@@ -110,6 +110,12 @@ templates.a: $(O_FILES)
rm -f templates.a
ar q templates.a $(O_FILES)
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND)
+
+$(TYPE).so: $(O_FILES)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES)
+
%.o: %.c Makefile
$(CC) $(CFLAGS) -I../../lib -c $<
@@ -128,8 +134,12 @@ install:
cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
+ $(BROOT)$(LIB_PREFIX)/templates
+ cp *.so $(BROOT)$(LIB_PREFIX)/templates/
+
clean:
- rm -f $(TARGETS) *.html *.o *.c \#*\# *~
+ rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~
include Makefile.deps
--- a/servers/prayer_chroot.c
+++ b/servers/prayer_chroot.c
@@ -327,6 +327,8 @@ int main(int argc, char *argv[])
config_extract_ssl(config, &ssl_config);
iostream_init(&ssl_config);
+ dlopen_templates(config->template_set, "_frontend");
+
prayer_main_write_pid(config);
if (want_prefork && !want_foreground)
--- a/shared/Makefile
+++ b/shared/Makefile
@@ -33,7 +33,7 @@ MYCFLAGS = $(BASECFLAGS)
SHARED_OBJS = \
config.o gzip.o html_common.o log.o \
- request.o response.o user_agent.o
+ request.o response.o user_agent.o dlopen_templates.o
all: $(SHARED_OBJS)
--- a/servers/prayer_main.c
+++ b/servers/prayer_main.c
@@ -350,6 +350,8 @@ int main(int argc, char *argv[])
open("/dev/null", O_WRONLY); /* Reopen stderr */
}
+ dlopen_templates(config->template_set, "_frontend");
+
prayer_main_write_pid(config);
if (want_prefork && !want_foreground)
--- a/shared/shared.h
+++ b/shared/shared.h
@@ -40,3 +40,4 @@ extern int errno; /* just
#include "setproctitle.h"
#include "mymutex.h"
#include "log.h"
+#include "dlopen_templates.h"
--- a/servers/Makefile
+++ b/servers/Makefile
@@ -73,7 +73,7 @@ ifeq ($(strip $(CCLIENT_KERB_ENABLE)), t
endif
MYCFLAGS = $(BASECFLAGS) $(SERVER_SSL_INCLUDE) $(CCLIENT_INCLUDE)
-MYLDFLAGS = $(BASELDFLAGS)
+MYLDFLAGS = $(BASELDFLAGS) -ldl
TEMPLATES= ../templates/index.o \
../templates/old/templates.a \
@@ -84,15 +84,13 @@ TEMPLATES_FRONTEND= ../templates/index.o
../templates/cam/templates_frontend.a
PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \
- ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND)
+ ../shared/shared.a $(LIB)
SESSION_OBJS= \
session_config.o session_exchange.o session_unix.o session_server.o \
session_main.o portlist.o ../cmd/cmd.a ../session/session.a \
../shared/shared.a ../lib/lib_nossl.a
-SESSION_OBJS += $(TEMPLATES)
-
#########################################################################
all: $(BIN)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ install-cert:
install:
$(MAKE) -C files install
$(MAKE) -C man install
-# $(MAKE) -C templates install
+ $(MAKE) -C templates install
$(MAKE) -C servers install
$(MAKE) -C utils install
ifeq ($(strip $(ACCOUNTD_ENABLE)), true)
--- a/servers/session_exchange.c
+++ b/servers/session_exchange.c
@@ -212,6 +212,8 @@ BOOL session_exchange(struct session * s
else
template_set = config->template_set; /* Safe default */
+ dlopen_templates(template_set, "");
+
/* Set up template_vars ready for dispatch */
session->template_vals = tvals
= template_vals_create(request->pool,