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