@@ -286,13 +286,19 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
286
286
}
287
287
288
288
289
- char * ngx_conf_set_rules (ngx_conf_t * cf , ngx_command_t * cmd , void * conf ) {
290
- ngx_str_t * value = cf -> args -> elts ;
291
- int res ;
292
- const char * error = NULL ;
293
- char * rules = ngx_str_to_char (value [1 ], cf -> pool );
294
- ngx_pool_t * old_pool ;
295
- ngx_http_modsecurity_conf_t * mcf = conf ;
289
+ char *
290
+ ngx_conf_set_rules (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
291
+ {
292
+ int res ;
293
+ char * rules ;
294
+ ngx_str_t * value ;
295
+ const char * error ;
296
+ ngx_pool_t * old_pool ;
297
+ ngx_http_modsecurity_conf_t * mcf = conf ;
298
+ ngx_http_modsecurity_main_conf_t * mmcf ;
299
+
300
+ value = cf -> args -> elts ;
301
+ rules = ngx_str_to_char (value [1 ], cf -> pool );
296
302
297
303
if (rules == (char * )-1 ) {
298
304
return NGX_CONF_ERROR ;
@@ -301,22 +307,32 @@ char *ngx_conf_set_rules(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
301
307
old_pool = ngx_http_modsecurity_pcre_malloc_init (cf -> pool );
302
308
res = msc_rules_add (mcf -> rules_set , rules , & error );
303
309
ngx_http_modsecurity_pcre_malloc_done (old_pool );
310
+
304
311
if (res < 0 ) {
305
312
dd ("Failed to load the rules: '%s' - reason: '%s'" , rules , error );
306
313
return strdup (error );
307
314
}
308
315
316
+ mmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_modsecurity_module );
317
+ mmcf -> rules_inline += res ;
318
+
309
319
return NGX_CONF_OK ;
310
320
}
311
321
312
322
313
- char * ngx_conf_set_rules_file (ngx_conf_t * cf , ngx_command_t * cmd , void * conf ) {
314
- ngx_str_t * value = cf -> args -> elts ;
315
- int res ;
316
- const char * error = NULL ;
317
- ngx_pool_t * old_pool ;
318
- ngx_http_modsecurity_conf_t * mcf = conf ;
319
- char * rules_set = ngx_str_to_char (value [1 ], cf -> pool );
323
+ char *
324
+ ngx_conf_set_rules_file (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
325
+ {
326
+ int res ;
327
+ char * rules_set ;
328
+ ngx_str_t * value ;
329
+ const char * error ;
330
+ ngx_pool_t * old_pool ;
331
+ ngx_http_modsecurity_conf_t * mcf = conf ;
332
+ ngx_http_modsecurity_main_conf_t * mmcf ;
333
+
334
+ value = cf -> args -> elts ;
335
+ rules_set = ngx_str_to_char (value [1 ], cf -> pool );
320
336
321
337
if (rules_set == (char * )-1 ) {
322
338
return NGX_CONF_ERROR ;
@@ -325,39 +341,54 @@ char *ngx_conf_set_rules_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
325
341
old_pool = ngx_http_modsecurity_pcre_malloc_init (cf -> pool );
326
342
res = msc_rules_add_file (mcf -> rules_set , rules_set , & error );
327
343
ngx_http_modsecurity_pcre_malloc_done (old_pool );
344
+
328
345
if (res < 0 ) {
329
346
dd ("Failed to load the rules from: '%s' - reason: '%s'" , rules_set , error );
330
347
return strdup (error );
331
348
}
332
349
350
+ mmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_modsecurity_module );
351
+ mmcf -> rules_file += res ;
352
+
333
353
return NGX_CONF_OK ;
334
354
}
335
355
336
356
337
- char * ngx_conf_set_rules_remote (ngx_conf_t * cf , ngx_command_t * cmd , void * conf ) {
338
- ngx_str_t * value = cf -> args -> elts ;
339
- int res ;
340
- const char * error = NULL ;
341
- const char * rules_remote_key = ngx_str_to_char (value [1 ], cf -> pool );
342
- const char * rules_remote_server = ngx_str_to_char (value [2 ], cf -> pool );
343
- ngx_pool_t * old_pool ;
344
- ngx_http_modsecurity_conf_t * mcf = conf ;
357
+ char *
358
+ ngx_conf_set_rules_remote (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
359
+ {
360
+ int res ;
361
+ ngx_str_t * value ;
362
+ const char * error ;
363
+ const char * rules_remote_key , * rules_remote_server ;
364
+ ngx_pool_t * old_pool ;
365
+ ngx_http_modsecurity_conf_t * mcf = conf ;
366
+ ngx_http_modsecurity_main_conf_t * mmcf ;
367
+
368
+ value = cf -> args -> elts ;
369
+ rules_remote_key = ngx_str_to_char (value [1 ], cf -> pool );
370
+ rules_remote_server = ngx_str_to_char (value [2 ], cf -> pool );
345
371
346
372
if (rules_remote_server == (char * )-1 ) {
347
373
return NGX_CONF_ERROR ;
348
374
}
375
+
349
376
if (rules_remote_key == (char * )-1 ) {
350
377
return NGX_CONF_ERROR ;
351
378
}
352
379
353
380
old_pool = ngx_http_modsecurity_pcre_malloc_init (cf -> pool );
354
381
res = msc_rules_add_remote (mcf -> rules_set , rules_remote_key , rules_remote_server , & error );
355
382
ngx_http_modsecurity_pcre_malloc_done (old_pool );
383
+
356
384
if (res < 0 ) {
357
385
dd ("Failed to load the rules from: '%s' - reason: '%s'" , rules_remote_server , error );
358
386
return strdup (error );
359
387
}
360
388
389
+ mmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_modsecurity_module );
390
+ mmcf -> rules_remote += res ;
391
+
361
392
return NGX_CONF_OK ;
362
393
}
363
394
@@ -564,6 +595,9 @@ ngx_http_modsecurity_create_main_conf(ngx_conf_t *cf)
564
595
*
565
596
* conf->modsec = NULL;
566
597
* conf->pool = NULL;
598
+ * conf->rules_inline = 0;
599
+ * conf->rules_file = 0;
600
+ * conf->rules_remote = 0;
567
601
*/
568
602
569
603
cln = ngx_pool_cleanup_add (cf -> pool , 0 );
@@ -597,7 +631,13 @@ ngx_http_modsecurity_create_main_conf(ngx_conf_t *cf)
597
631
static char *
598
632
ngx_http_modsecurity_init_main_conf (ngx_conf_t * cf , void * conf )
599
633
{
600
- ngx_log_error (NGX_LOG_NOTICE , cf -> log , 0 , MODSECURITY_NGINX_WHOAMI );
634
+ ngx_http_modsecurity_main_conf_t * mmcf ;
635
+ mmcf = (ngx_http_modsecurity_main_conf_t * ) conf ;
636
+
637
+ ngx_log_error (NGX_LOG_NOTICE , cf -> log , 0 ,
638
+ "%s (rules loaded inline/local/remote: %ui/%ui/%ui)" ,
639
+ MODSECURITY_NGINX_WHOAMI , mmcf -> rules_inline ,
640
+ mmcf -> rules_file , mmcf -> rules_remote );
601
641
602
642
return NGX_CONF_OK ;
603
643
}
0 commit comments