Skip to content

Commit c54bb74

Browse files
author
Felipe Zimmerle
committed
Adds SecRemoteRules as an build option
SecRemoteRules adds a new dependency to libcurl. Before only mlogc was depending on libcurl. SecRemoteRules also depends on the apr-tools with crypto support, which (as reported by our buildbots) is not default in some environments such as: MacOS X. This commit disable SecRemoteRules support if apr-tools was not compiled with crypto support.
1 parent 38b9924 commit c54bb74

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

apache2/apache2_config.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ static const char *cmd_remote_rules_fail(cmd_parms *cmd, void *_dcfg, const char
22172217
{
22182218
directory_config *dcfg = (directory_config *)_dcfg;
22192219
if (dcfg == NULL) return NULL;
2220-
2220+
#ifdef WITH_REMOTE_RULES_SUPPORT
22212221
if (strncasecmp(p1, "warn", 4) == 0)
22222222
{
22232223
remote_rules_fail_action = REMOTE_RULES_WARN_ON_FAIL;
@@ -2231,6 +2231,10 @@ static const char *cmd_remote_rules_fail(cmd_parms *cmd, void *_dcfg, const char
22312231
return apr_psprintf(cmd->pool, "ModSecurity: Invalid value for " \
22322232
"SecRemoteRulesFailAction, expected: Abort or Warn.");
22332233
}
2234+
#else
2235+
return apr_psprintf(cmd->pool, "ModSecurity: " \
2236+
"SecRemoteRules: ModSecurity was not compiled with such functionality.");
2237+
#endif
22342238

22352239
return NULL;
22362240
}
@@ -2242,6 +2246,7 @@ static const char *cmd_remote_rules(cmd_parms *cmd, void *_dcfg, const char *p1,
22422246
directory_config *dcfg = (directory_config *)_dcfg;
22432247
if (dcfg == NULL) return NULL;
22442248

2249+
#ifdef WITH_REMOTE_RULES_SUPPORT
22452250
// FIXME: make it https only.
22462251
// if (strncasecmp(p1, "https", 5) != 0) {
22472252
if (strncasecmp(p2, "http", 4) != 0) {
@@ -2274,6 +2279,10 @@ static const char *cmd_remote_rules(cmd_parms *cmd, void *_dcfg, const char *p1,
22742279
{
22752280
return error_msg;
22762281
}
2282+
#else
2283+
return apr_psprintf(cmd->pool, "ModSecurity: " \
2284+
"SecRemoteRules: ModSecurity was not compiled with such functionality.");
2285+
#endif
22772286

22782287
return NULL;
22792288
}

apache2/mod_security2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ unsigned long int DSOLOCAL msc_pcre_match_limit = 0;
6868

6969
unsigned long int DSOLOCAL msc_pcre_match_limit_recursion = 0;
7070

71+
#ifdef WITH_REMOTE_RULES_SUPPORT
7172
msc_remote_rules_server DSOLOCAL *remote_rules_server = NULL;
7273
int DSOLOCAL remote_rules_fail_action = REMOTE_RULES_ABORT_ON_FAIL;
74+
#endif
7375

7476
int DSOLOCAL status_engine_state = STATUS_ENGINE_DISABLED;
7577

@@ -759,6 +761,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
759761
}
760762
#endif
761763

764+
#ifdef WITH_REMOTE_RULES_SUPPORT
762765
if (remote_rules_server != NULL)
763766
{
764767
if (remote_rules_server->amount_of_rules == 1)
@@ -776,6 +779,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
776779
remote_rules_server->uri);
777780
}
778781
}
782+
#endif
779783
}
780784

781785
srand((unsigned int)(time(NULL) * getpid()));

apache2/modsecurity.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ typedef struct msc_arg msc_arg;
3333
typedef struct msc_string msc_string;
3434
typedef struct msc_parm msc_parm;
3535

36-
#include "msc_remote_rules.h"
3736
#include "msc_release.h"
3837
#include "msc_logging.h"
3938
#include "msc_multipart.h"
@@ -47,11 +46,13 @@ typedef struct msc_parm msc_parm;
4746
#include "msc_unicode.h"
4847
#include "re.h"
4948
#include "msc_crypt.h"
49+
#include "msc_remote_rules.h"
5050

5151
#include "ap_config.h"
5252
#include "apr_md5.h"
5353
#include "apr_strings.h"
5454
#include "apr_hash.h"
55+
#include "apr_crypto.h"
5556
#include "httpd.h"
5657
#include "http_config.h"
5758
#include "http_log.h"
@@ -145,8 +146,10 @@ extern DSOLOCAL unsigned long int msc_pcre_match_limit;
145146

146147
extern DSOLOCAL unsigned long int msc_pcre_match_limit_recursion;
147148

149+
#ifdef WITH_REMOTE_RULES_SUPPORT
148150
extern DSOLOCAL msc_remote_rules_server *remote_rules_server;
149151
extern DSOLOCAL int remote_rules_fail_action;
152+
#endif
150153

151154
extern DSOLOCAL int status_engine_state;
152155

apache2/msc_remote_rules.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
#define AP_MAX_ARGC 64
2727
#endif
2828

29-
#ifndef APU_HAVE_CRYPTO
30-
#error Missing apu crypto module
31-
#endif
29+
#ifdef WITH_REMOTE_RULES_SUPPORT
3230

3331
/**
3432
* @brief Insert a new SecRule to be processed by ModSecurity
@@ -716,3 +714,4 @@ int msc_remote_clean_chunk(struct msc_curl_memory_buffer_t *chunk)
716714
return 0;
717715
}
718716

717+
#endif

apache2/msc_remote_rules.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,32 @@
1212
* directly using the email address security@modsecurity.org.
1313
*/
1414

15+
#if APU_HAVE_CRYPTO
16+
#define WITH_REMOTE_RULES_SUPPORT
17+
#endif
18+
19+
#ifdef WITH_REMOTE_RULES_SUPPORT
20+
1521
#ifndef MSC_REMOTE_RULES_H
1622
#define MSC_REMOTE_RULES_H
1723

24+
/* forward declarations */
25+
typedef struct msc_remote_rules_server msc_remote_rules_server;
26+
struct msc_curl_memory_buffer_t;
27+
28+
#include "modsecurity.h"
29+
1830
#include <apr_general.h>
1931
#include <apr_optional.h>
2032
#include <apr_thread_pool.h>
21-
#include <curl/curl.h>
22-
2333
#include <apr_sha1.h>
24-
#include <apr_crypto.h>
34+
2535
#include "http_core.h"
36+
#include "http_config.h"
2637

27-
typedef struct msc_remote_rules_server msc_remote_rules_server;
28-
struct msc_curl_memory_buffer_t;
38+
#include <curl/curl.h>
2939

30-
#include "modsecurity.h"
40+
#include <apr_crypto.h>
3141

3242
struct msc_remote_rules_server {
3343
directory_config *context;
@@ -38,7 +48,7 @@ struct msc_remote_rules_server {
3848
};
3949

4050
const char *msc_remote_invoke_cmd(const command_rec *cmd, cmd_parms *parms,
41-
void *mconfig, const char *args);
51+
void *mconfig, const char *args);
4252

4353
int msc_remote_grab_content(apr_pool_t *mp, const char *uri, const char *key,
4454
struct msc_curl_memory_buffer_t *chunk, char **error_msg);
@@ -64,4 +74,5 @@ int msc_remote_add_rules_from_uri(cmd_parms *orig_parms,
6474
int msc_remote_clean_chunk(struct msc_curl_memory_buffer_t *chunk);
6575

6676
#endif
77+
#endif
6778

0 commit comments

Comments
 (0)