Skip to content

Commit e8b8f2c

Browse files
author
Felipe Zimmerle
committed
Adds msc_utils.c
1 parent b05adb5 commit e8b8f2c

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

build/apxs-wrapper.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ for opt in "$@"; do
1212
esac
1313
done
1414

15-
exec @APXS@ -Wc,-fPIC -Wc,-O0 -a -c -I @V3INCLUDE@ -L @V3LIB@ -lmodsecurity src/mod_security3.c src/msc_config.c src/msc_filters.c
15+
exec @APXS@ -Wc,-fPIC -Wc,-O0 -a -c -I @V3INCLUDE@ -L @V3LIB@ -lmodsecurity src/mod_security3.c src/msc_config.c src/msc_filters.c src/msc_utils.c

src/msc_utils.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
#include "msc_utils.h"
3+
4+
5+
int id(const char *fn, const char *format, ...)
6+
{
7+
va_list args;
8+
va_start(args, format);
9+
FILE *f = fopen(fn, "a");
10+
vfprintf(f, format, args);
11+
fclose(f);
12+
va_end(args);
13+
}
14+
15+
16+
/**
17+
* Sends a brigade with an error bucket down the filter chain.
18+
*/
19+
apr_status_t send_error_bucket(msc_t *msr, ap_filter_t *f, int status)
20+
{
21+
apr_bucket_brigade *brigade = NULL;
22+
apr_bucket *bucket = NULL;
23+
24+
/* Set the status line explicitly for the error document */
25+
f->r->status_line = ap_get_status_line(status);
26+
27+
brigade = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc);
28+
if (brigade == NULL)
29+
{
30+
return APR_EGENERAL;
31+
}
32+
33+
bucket = ap_bucket_error_create(status, NULL, f->r->pool,
34+
f->r->connection->bucket_alloc);
35+
if (bucket == NULL)
36+
{
37+
return APR_EGENERAL;
38+
}
39+
40+
APR_BRIGADE_INSERT_TAIL(brigade, bucket);
41+
42+
bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc);
43+
if (bucket == NULL)
44+
{
45+
return APR_EGENERAL;
46+
}
47+
48+
APR_BRIGADE_INSERT_TAIL(brigade, bucket);
49+
50+
ap_pass_brigade(f->next, brigade);
51+
52+
/* NOTE:
53+
* It may not matter what we do from the filter as it may be too
54+
* late to even generate an error (already sent to client). Nick Kew
55+
* recommends to return APR_EGENERAL in hopes that the handler in control
56+
* will notice and do The Right Thing. So, that is what we do now.
57+
*/
58+
return APR_EGENERAL;
59+
}
60+

src/msc_utils.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
#include <modsecurity/modsecurity.h>
3+
#include <modsecurity/rules.h>
4+
#include <modsecurity/intervention.h>
5+
6+
#include "http_core.h"
7+
#include "http_request.h"
8+
#include "httpd.h"
9+
#include "ap_release.h"
10+
11+
#include <apr_general.h>
12+
#include <apr_optional.h>
13+
14+
#ifndef _SRC_MSC_UTILS__
15+
#define _SRC_MSC_UTILS__
16+
17+
#include "mod_security3.h"
18+
19+
20+
int id(const char *fn, const char *format, ...);
21+
22+
23+
apr_status_t send_error_bucket(msc_t *msr, ap_filter_t *f, int status);
24+
25+
26+
#endif /* _SRC_MSC_UTILS__ */

0 commit comments

Comments
 (0)