Blame SOURCES/mod_security-2.9.2-remote-rules-timeout.patch

5beff5
diff --git a/apache2/apache2_config.c b/apache2/apache2_config.c
5beff5
index ce97950..5d4e9b5 100644
5beff5
--- a/apache2/apache2_config.c
5beff5
+++ b/apache2/apache2_config.c
5beff5
@@ -2345,6 +2345,24 @@ static const char *cmd_remote_rules(cmd_parms *cmd, void *_dcfg, const char *p1,
5beff5
 }
5beff5
 
5beff5
 
5beff5
+static const char *cmd_remote_timeout(cmd_parms *cmd, void *_dcfg, const char *p1)
5beff5
+{
5beff5
+    directory_config *dcfg = (directory_config *)_dcfg;
5beff5
+    long int timeout;
5beff5
+
5beff5
+    if (dcfg == NULL) return NULL;
5beff5
+
5beff5
+    timeout = strtol(p1, NULL, 10);
5beff5
+    if ((timeout == LONG_MAX)||(timeout == LONG_MIN)||(timeout < 0)) {
5beff5
+        return apr_psprintf(cmd->pool, "ModSecurity: Invalid value for SecRemoteTimeout: %s", p1);
5beff5
+    }
5beff5
+
5beff5
+    remote_rules_timeout = timeout;
5beff5
+
5beff5
+    return NULL;
5beff5
+}
5beff5
+
5beff5
+
5beff5
 static const char *cmd_status_engine(cmd_parms *cmd, void *_dcfg, const char *p1)
5beff5
 {
5beff5
     if (strcasecmp(p1, "on") == 0) {
5beff5
@@ -3658,6 +3677,14 @@ const command_rec module_directives[] = {
5beff5
         "Abort or Warn"
5beff5
     ),
5beff5
 
5beff5
+    AP_INIT_TAKE1 (
5beff5
+        "SecRemoteTimeout",
5beff5
+        cmd_remote_timeout,
5beff5
+        NULL,
5beff5
+        CMD_SCOPE_ANY,
5beff5
+        "timeout in seconds"
5beff5
+    ),
5beff5
+
5beff5
 
5beff5
     AP_INIT_TAKE1 (
5beff5
         "SecXmlExternalEntity",
5beff5
diff --git a/apache2/mod_security2.c b/apache2/mod_security2.c
5beff5
index b6e98e9..1410ac7 100644
5beff5
--- a/apache2/mod_security2.c
5beff5
+++ b/apache2/mod_security2.c
5beff5
@@ -79,6 +79,8 @@ msc_remote_rules_server DSOLOCAL *remote_rules_server = NULL;
5beff5
 #endif
5beff5
 int DSOLOCAL remote_rules_fail_action = REMOTE_RULES_ABORT_ON_FAIL;
5beff5
 char DSOLOCAL *remote_rules_fail_message = NULL;
5beff5
+unsigned long int DSOLOCAL remote_rules_timeout = NOT_SET;
5beff5
+
5beff5
 
5beff5
 int DSOLOCAL status_engine_state = STATUS_ENGINE_DISABLED;
5beff5
 
5beff5
diff --git a/apache2/modsecurity.h b/apache2/modsecurity.h
5beff5
index f170034..d9de1f0 100644
5beff5
--- a/apache2/modsecurity.h
5beff5
+++ b/apache2/modsecurity.h
5beff5
@@ -150,6 +150,7 @@ extern DSOLOCAL msc_remote_rules_server *remote_rules_server;
5beff5
 #endif
5beff5
 extern DSOLOCAL int remote_rules_fail_action;
5beff5
 extern DSOLOCAL char *remote_rules_fail_message;
5beff5
+extern DSOLOCAL unsigned long int remote_rules_timeout;
5beff5
 
5beff5
 extern DSOLOCAL int status_engine_state;
5beff5
 
5beff5
diff --git a/apache2/msc_remote_rules.c b/apache2/msc_remote_rules.c
5beff5
index 8a6df9e..af437d1 100644
5beff5
--- a/apache2/msc_remote_rules.c
5beff5
+++ b/apache2/msc_remote_rules.c
5beff5
@@ -353,6 +353,11 @@ int msc_remote_download_content(apr_pool_t *mp, const char *uri, const char *key
5beff5
         /* We want Curl to return error in case there is an HTTP error code */
5beff5
         curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
5beff5
 
5beff5
+        /* In case we want different timeout than a default one */
5beff5
+        if (remote_rules_timeout != NOT_SET){
5beff5
+            curl_easy_setopt(curl, CURLOPT_TIMEOUT, remote_rules_timeout);
5beff5
+        }
5beff5
+
5beff5
         res = curl_easy_perform(curl);
5beff5
 
5beff5
         if (res != CURLE_OK)