mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
improved search directory for native libs
This commit is contained in:
parent
c0eee93dac
commit
c8e31c42f5
Binary file not shown.
BIN
java/ModSecurityTestApp/dist/ModSecurityTestApp.war
vendored
BIN
java/ModSecurityTestApp/dist/ModSecurityTestApp.war
vendored
Binary file not shown.
@ -7,7 +7,6 @@ import java.net.UnknownHostException;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
|
||||
public final class ModSecurity {
|
||||
//From build/classes: >"c:\Program Files\Java\jdk1.7.0_05\bin\javah.exe" -classpath c:\work\apache-tomcat-7.0.39\lib\servlet-api.jar;. org.modsecurity.ModSecurity
|
||||
|
||||
@ -17,9 +16,18 @@ public final class ModSecurity {
|
||||
private FilterConfig filterConfig;
|
||||
private String confFilename;
|
||||
private long confTime;
|
||||
private static boolean libsLoaded = false;
|
||||
|
||||
static {
|
||||
//ModSecurityLoader calls System.load() for every native library needed by ModSecurity.
|
||||
private void loadNativeLibs(String zlibPath,
|
||||
String libxml2Path,
|
||||
String libpcrePath,
|
||||
String libaprPath,
|
||||
String libapriconvPath,
|
||||
String libaprutilPath,
|
||||
String libModSecurityPath) {
|
||||
if (!libsLoaded) {
|
||||
libsLoaded = true;
|
||||
//ModSecurityLoader calls System.load() for every native library needed by ModSecurity.
|
||||
// try {
|
||||
// Class.forName("org.modsecurity.loader.ModSecurityLoader");
|
||||
// } catch (ClassNotFoundException ex) {
|
||||
@ -27,33 +35,55 @@ public final class ModSecurity {
|
||||
// "ModSecurityLoader was not found, please make sure that you have \"ModSecurityLoader.jar\" in your server lib folder.", ex);
|
||||
// }
|
||||
|
||||
//If the ModSecurityLoader is not used, native libraries can be loaded here, however this is bad practice since this will raise UnsatisfiedLinkError if
|
||||
//ModSecurity is used in multiple webapps. This will also will raise problems when the web-app is redeployed and the server is running.
|
||||
try {
|
||||
System.loadLibrary("zlib1"); //needed for libxml2 in Windows
|
||||
} catch(UnsatisfiedLinkError ex) {
|
||||
//If the ModSecurityLoader is not used, native libraries can be loaded here, however this is bad practice since this will raise UnsatisfiedLinkError if
|
||||
//ModSecurity is used in multiple webapps. This will also will raise problems when the web-app is redeployed and the server is running.
|
||||
try {
|
||||
loadLib("zlib1", zlibPath);
|
||||
} catch (UnsatisfiedLinkError ex) {
|
||||
}
|
||||
loadLib("xml2", libxml2Path);
|
||||
loadLib("pcre", libpcrePath);
|
||||
loadLib("apr-1", libaprPath);
|
||||
try {
|
||||
loadLib("apriconv-1", libapriconvPath);
|
||||
} catch (UnsatisfiedLinkError ex) {
|
||||
}
|
||||
loadLib("aprutil-1", libaprutilPath);
|
||||
loadLib("ModSecurityJNI", libModSecurityPath);
|
||||
}
|
||||
System.loadLibrary("libxml2");
|
||||
System.loadLibrary("pcre");
|
||||
System.loadLibrary("libapr-1");
|
||||
}
|
||||
|
||||
private void loadLib(String name, String absolutePath) throws UnsatisfiedLinkError {
|
||||
try {
|
||||
System.loadLibrary("libapriconv-1"); //needed for libaprutil-1 in Windows
|
||||
} catch(UnsatisfiedLinkError ex) {
|
||||
System.load(absolutePath);
|
||||
return;
|
||||
} catch (NullPointerException ex) {
|
||||
} catch (UnsatisfiedLinkError ex) {
|
||||
throw ex;
|
||||
}
|
||||
try {
|
||||
System.loadLibrary(name);
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError ex) {
|
||||
}
|
||||
try {
|
||||
System.loadLibrary("lib" + name);
|
||||
} catch (UnsatisfiedLinkError ex) {
|
||||
throw ex;
|
||||
}
|
||||
System.loadLibrary("libaprutil-1");
|
||||
System.loadLibrary("ModSecurityJNI");
|
||||
//System.loadLibrary tries to resolve native libraries from java.library.path variable. If this fails, absolute path to libraries
|
||||
//can be specified using System.load("/path/lib.so")
|
||||
// try { System.load("c:\\work\\mod_security\\java\\libs\\zlib1.dll"); } catch(UnsatisfiedLinkError ex) {}
|
||||
// System.load("c:\\work\\mod_security\\java\\libs\\libxml2.dll");
|
||||
// System.load("c:\\work\\mod_security\\java\\libs\\pcre.dll");
|
||||
// System.load("c:\\work\\mod_security\\java\\libs\\libapr-1.dll");
|
||||
// try { System.load("c:\\work\\mod_security\\java\\libs\\libapriconv-1.dll"); } catch(UnsatisfiedLinkError ex) {}
|
||||
// System.load("c:\\work\\mod_security\\java\\libs\\libaprutil-1.dll");
|
||||
// System.load("c:\\work\\mod_security\\java\\Debug\\ModSecurityJNI.dll");
|
||||
}
|
||||
|
||||
public ModSecurity(FilterConfig fc, String confFile) throws ServletException {
|
||||
public ModSecurity(FilterConfig fc,
|
||||
String confFile,
|
||||
String zlibPath,
|
||||
String libxml2Path,
|
||||
String libpcrePath,
|
||||
String libaprPath,
|
||||
String libapriconvPath,
|
||||
String libaprutilPath,
|
||||
String libModSecurityPath) throws ServletException {
|
||||
loadNativeLibs(zlibPath, libxml2Path, libpcrePath, libaprPath, libapriconvPath, libaprutilPath, libModSecurityPath);
|
||||
|
||||
this.filterConfig = fc;
|
||||
this.confFilename = confFile;
|
||||
confTime = new File(confFilename).lastModified();
|
||||
|
@ -25,7 +25,15 @@ public class ModSecurityFilter implements Filter {
|
||||
throw new ServletException("ModSecurity: parameter 'conf' not available in web.xml");
|
||||
}
|
||||
|
||||
modsecurity = new ModSecurity(fc, confFilename);
|
||||
modsecurity = new ModSecurity(fc,
|
||||
confFilename,
|
||||
fc.getInitParameter("zlib1"),
|
||||
fc.getInitParameter("libxml2"),
|
||||
fc.getInitParameter("libpcre"),
|
||||
fc.getInitParameter("libapr-1"),
|
||||
fc.getInitParameter("libapriconv-1"),
|
||||
fc.getInitParameter("libaprutil-1"),
|
||||
fc.getInitParameter("libModSecurityJNI"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,6 +16,46 @@
|
||||
Include activated_rules\*.conf
|
||||
-->
|
||||
</init-param>
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
OPTIONAL parameters for loading native libraries from absolute paths. This is an alternitive to specifying
|
||||
-Djava.library.path=/path/to/libs/ variable which is used by the JVM to search libraries.
|
||||
|
||||
zlib1 and libapriconv-1 are Windows only libraries
|
||||
-->
|
||||
|
||||
<!--
|
||||
<init-param>
|
||||
<param-name>zlib1</param-name>
|
||||
<param-value>c:\work\zlib1.dll</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>libxml2</param-name>
|
||||
<param-value>/usr/lib/i386-linux-gnu/libxml2.so</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>libpcre</param-name>
|
||||
<param-value>/usr/lib/i386-linux-gnu/libxml2.so</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>libapr-1</param-name>
|
||||
<param-value>/usr/lib/libapr-1.so</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>libapriconv-1</param-name>
|
||||
<param-value>c:\work\zlib1.dll</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>libaprutil-1</param-name>
|
||||
<param-value>/usr/lib/libaprutil-1.so</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>libModSecurityJNI</param-name>
|
||||
<param-value>/usr/lib/libModSecurityJNI.so</param-value>
|
||||
</init-param>
|
||||
-->
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
|
Loading…
x
Reference in New Issue
Block a user