You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2012/07/23 14:17:19 UTC

svn commit: r1364603 - in /httpd/httpd/branches/2.4.x: CHANGES STATUS modules/core/mod_so.c

Author: jim
Date: Mon Jul 23 12:17:18 2012
New Revision: 1364603

URL: http://svn.apache.org/viewvc?rev=1364603&view=rev
Log:
Merge r1332378 from trunk:

If a filename without slashes is specified for LoadFile or
LoadModule and the file cannot be found in the server root directory,
try to use the standard dlopen() search path. 

Submitted by: sf
Reviewed/backported by: jim

Modified:
    httpd/httpd/branches/2.4.x/CHANGES
    httpd/httpd/branches/2.4.x/STATUS
    httpd/httpd/branches/2.4.x/modules/core/mod_so.c

Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1364603&r1=1364602&r2=1364603&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Mon Jul 23 12:17:18 2012
@@ -8,6 +8,10 @@ Changes with Apache 2.4.3
      possible XSS for a site where untrusted users can upload files to
      a location with MultiViews enabled. [Niels Heinen <heinenn google.com>]
 
+  *) mod_so: If a filename without slashes is specified for LoadFile or
+     LoadModule and the file cannot be found in the server root directory,
+     try to use the standard dlopen() search path. [Stefan Fritsch]
+
   *) core: Log value of Status header line in script responses rather
      than the fixed header name.  [Chris Darroch]
 

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1364603&r1=1364602&r2=1364603&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Mon Jul 23 12:17:18 2012
@@ -88,11 +88,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-   * mod_so: Optionally allow LoadModule+LoadFile to use the normal search path.
-     trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1332378
-     2.4.x patch: trunk patch works (ex. CHANGES)
-     +1: sf, rjung, jim
-
    * mpm_event: Fix slots staying in "L" state in the scoreboard
      trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1294349
      2.4.x patch: trunk patch works (needs CHANGES entry)

Modified: httpd/httpd/branches/2.4.x/modules/core/mod_so.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/core/mod_so.c?rev=1364603&r1=1364602&r2=1364603&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/core/mod_so.c (original)
+++ httpd/httpd/branches/2.4.x/modules/core/mod_so.c Mon Jul 23 12:17:18 2012
@@ -143,6 +143,37 @@ static apr_status_t unload_module(void *
     return APR_SUCCESS;
 }
 
+static const char *dso_load(cmd_parms *cmd, apr_dso_handle_t **modhandlep,
+                            const char *filename, const char **used_filename)
+{
+    int retry = 0;
+    const char *fullname = ap_server_root_relative(cmd->temp_pool, filename);
+    char my_error[256];
+    if (filename != NULL && ap_strchr_c(filename, '/') == NULL) {
+        /* retry on error without path to use dlopen()'s search path */
+        retry = 1;
+    }
+
+    if (fullname == NULL && !retry) {
+        return apr_psprintf(cmd->temp_pool, "Invalid %s path %s",
+                            cmd->cmd->name, filename);
+    }
+    *used_filename = fullname;
+    if (apr_dso_load(modhandlep, fullname, cmd->pool) == APR_SUCCESS) {
+        return NULL;
+    }
+    if (retry) {
+        *used_filename = filename;
+        if (apr_dso_load(modhandlep, filename, cmd->pool) == APR_SUCCESS)
+            return NULL;
+    }
+
+    return apr_pstrcat(cmd->temp_pool, "Cannot load ", filename,
+                        " into server: ",
+                        apr_dso_error(*modhandlep, my_error, sizeof(my_error)),
+                        NULL);
+}
+
 /*
  * This is called for the directive LoadModule and actually loads
  * a shared object file into the address space of the server process.
@@ -154,7 +185,7 @@ static const char *load_module(cmd_parms
     apr_dso_handle_t *modhandle;
     apr_dso_handle_sym_t modsym;
     module *modp;
-    const char *szModuleFile = ap_server_root_relative(cmd->pool, filename);
+    const char *module_file;
     so_server_conf *sconf;
     ap_module_symbol_t *modi;
     ap_module_symbol_t *modie;
@@ -167,11 +198,6 @@ static const char *load_module(cmd_parms
      */
     *(ap_directive_t **)dummy = NULL;
 
-    if (!szModuleFile) {
-        return apr_pstrcat(cmd->pool, "Invalid LoadModule path ",
-                           filename, NULL);
-    }
-
     /*
      * check for already existing module
      * If it already exists, we have nothing to do
@@ -234,16 +260,11 @@ static const char *load_module(cmd_parms
     /*
      * Load the file into the Apache address space
      */
-    if (apr_dso_load(&modhandle, szModuleFile, cmd->pool) != APR_SUCCESS) {
-        char my_error[256];
-
-        return apr_pstrcat(cmd->pool, "Cannot load ", szModuleFile,
-                          " into server: ",
-                          apr_dso_error(modhandle, my_error, sizeof(my_error)),
-                          NULL);
-    }
+    error = dso_load(cmd, &modhandle, filename, &module_file);
+    if (error)
+        return error;
     ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, cmd->pool, APLOGNO(01575)
-                 "loaded module %s", modname);
+                 "loaded module %s from %s", modname, module_file);
 
     /*
      * Retrieve the pointer to the module structure through the module name:
@@ -254,7 +275,7 @@ static const char *load_module(cmd_parms
         char my_error[256];
 
         return apr_pstrcat(cmd->pool, "Can't locate API module structure `",
-                          modname, "' in file ", szModuleFile, ": ",
+                          modname, "' in file ", module_file, ": ",
                           apr_dso_error(modhandle, my_error, sizeof(my_error)),
                           NULL);
     }
@@ -271,7 +292,7 @@ static const char *load_module(cmd_parms
                             "is garbled - expected signature %08lx but saw "
                             "%08lx - perhaps this is not an Apache module DSO, "
                             "or was compiled for a different Apache version?",
-                            modname, szModuleFile,
+                            modname, module_file,
                             MODULE_MAGIC_COOKIE, modp->magic);
     }
 
@@ -306,26 +327,14 @@ static const char *load_module(cmd_parms
 static const char *load_file(cmd_parms *cmd, void *dummy, const char *filename)
 {
     apr_dso_handle_t *handle;
-    const char *file;
-
-    file = ap_server_root_relative(cmd->pool, filename);
-
-    if (!file) {
-        return apr_pstrcat(cmd->pool, "Invalid LoadFile path ",
-                           filename, NULL);
-    }
+    const char *used_file, *error;
 
-    if (apr_dso_load(&handle, file, cmd->pool) != APR_SUCCESS) {
-        char my_error[256];
-
-        return apr_pstrcat(cmd->pool, "Cannot load ", filename,
-                          " into server: ",
-                          apr_dso_error(handle, my_error, sizeof(my_error)),
-                          NULL);
-    }
+    error = dso_load(cmd, &handle, filename, &used_file);
+    if (error)
+        return error;
 
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, APLOGNO(01576)
-                 "loaded file %s", filename);
+                 "loaded file %s", used_file);
 
     return NULL;
 }