]> andersk Git - mod-vhost-ldap.git/blobdiff - mod_vhost_ldap.c
Add more debug info
[mod-vhost-ldap.git] / mod_vhost_ldap.c
index 5553ed8b9d199088f4056eae7b92380b4eaaa4b3..97671af4d90001cfe92116cbcde5a6f2169199fc 100644 (file)
@@ -116,6 +116,43 @@ static void ImportULDAPOptFn(void)
 }
 #endif 
 
+/* Taken from server/core.c */
+static int set_document_root(request_rec *r, const char *arg)
+{
+    void *sconf = r->server->module_config;
+    core_server_config *conf = ap_get_module_config(sconf, &core_module);
+
+    /* Make it absolute, relative to ServerRoot */
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, 
+                 "[mod_vhost_ldap.c] set_document_root: translating DocumentRoot [%s]",
+                 arg);
+    arg = ap_server_root_relative(r->pool, arg);
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, 
+                 "[mod_vhost_ldap.c] set_document_root: relative DocumentRoot [%s]",
+                 arg);
+    if (arg == NULL) {
+        ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, 
+                      "[mod_vhost_ldap.c] set_document_root: DocumentRoot [%s] must be a directory",
+                     arg);
+
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    /* TODO: ap_configtestonly && ap_docrootcheck && */
+    if (apr_filepath_merge((char**)&conf->ap_document_root, NULL, arg,
+                           APR_FILEPATH_TRUENAME, r->pool) != APR_SUCCESS
+        || !ap_is_directory(r->pool, arg)) {
+
+        ap_log_rerror(APLOG_MARK, APLOG_STARTUP, 0,
+                     r,
+                     "[mod_vhost_ldap.c] set_document_root: Warning: DocumentRoot [%s] does not exist",
+                     arg);
+        conf->ap_document_root = arg;
+    }
+    return OK;
+}
+
+
 static int mod_vhost_ldap_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 {
     /* make sure that mod_ldap (util_ldap) is loaded */
@@ -433,7 +470,7 @@ static int mod_vhost_ldap_translate_name(request_rec *r)
     util_ldap_connection_t *ldc = NULL;
     int result = 0;
     const char *dn = NULL;
-    char *cgi;
+    char *cgi, *real;
     const char *hostname = NULL;
     int is_fallback = 0;
 
@@ -567,9 +604,14 @@ fallback:
        }
     }
     if (cgi) {
-       r->filename = apr_pstrcat (r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL);
-       r->handler = "cgi-script";
-       apr_table_setn(r->notes, "alias-forced-type", r->handler);
+        cgi = apr_pstrcat (r->pool, reqc->cgiroot, cgi + strlen("cgi-bin"), NULL);
+        if ((cgi = ap_server_root_relative(r->pool, cgi))) {
+         ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
+                       "[mod_vhost_ldap.c]: ap_document_root is: %s", ap_document_root(r));
+         r->filename = cgi;
+         r->handler = "cgi-script";
+         apr_table_setn(r->notes, "alias-forced-type", r->handler);
+       }
     } else if (r->uri[0] == '/') {
         /*      r->filename = apr_pstrdup(r->pool, r->uri); */
        /*      r->filename = apr_pstrcat (r->pool, reqc->docroot, r->uri, NULL); */
@@ -583,15 +625,23 @@ fallback:
        top->server->server_admin = apr_pstrdup (top->pool, reqc->admin);
     }
 
+    real = apr_pstrcat(r->pool, reqc->docroot, r->uri);
+
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
+                 "[mod_vhost_ldap.c]: ap_server_root_relative(%s) is: %s", real, ap_server_root_relative(r->pool, real));
+
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
                  "[mod_vhost_ldap.c]: ap_document_root is: %s", ap_document_root(r));
 
     reqc->saved_docroot = apr_pstrdup(top->pool, ap_document_root(r));
 
-    set_document_root(r, NULL, reqc->docroot);
+    if (set_document_root(r, reqc->docroot) != OK)
+        return HTTP_INTERNAL_SERVER_ERROR;
 
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
-                 "[mod_vhost_ldap.c]: ap_document_root set to: %s", ap_document_root(r));
+                 "[mod_vhost_ldap.c]: ap_document_root set to: [%s], relative [%s]",
+                 ap_document_root(r),
+                 ap_server_root_relative(r->pool, real));
 
     // set environment variables
     e = top->subprocess_env;
@@ -608,7 +658,8 @@ static int mod_vhost_ldap_cleanup(request_rec * r)
       (mod_vhost_ldap_request_t *)ap_get_module_config(r->request_config,
                                                       &vhost_ldap_module);
 
-    set_document_root(r, NULL, reqc->saved_docroot);
+    if (set_document_root(r, reqc->saved_docroot) != OK)
+        return HTTP_INTERNAL_SERVER_ERROR;
 
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
                  "[mod_vhost_ldap.c]: ap_document_root restored to: %s", ap_document_root(r));
This page took 0.060549 seconds and 4 git commands to generate.