|
Packit Service |
384592 |
/*
|
|
Packit Service |
384592 |
* ModSecurity for Apache 2.x, http://www.modsecurity.org/
|
|
Packit Service |
384592 |
* Copyright (c) 2004-2013 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
|
Packit Service |
384592 |
*
|
|
Packit Service |
384592 |
* You may not use this file except in compliance with
|
|
Packit Service |
384592 |
* the License. You may obtain a copy of the License at
|
|
Packit Service |
384592 |
*
|
|
Packit Service |
384592 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit Service |
384592 |
*
|
|
Packit Service |
384592 |
* If any of the files related to licensing are missing or if you have any
|
|
Packit Service |
384592 |
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
|
Packit Service |
384592 |
* directly using the email address security@modsecurity.org.
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
#include "httpd.h"
|
|
Packit Service |
384592 |
#include "http_core.h"
|
|
Packit Service |
384592 |
#include "http_config.h"
|
|
Packit Service |
384592 |
#include "http_log.h"
|
|
Packit Service |
384592 |
#include "http_protocol.h"
|
|
Packit Service |
384592 |
#include "ap_config.h"
|
|
Packit Service |
384592 |
#include "apr_optional.h"
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
#include "modsecurity.h"
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
/**
|
|
Packit Service |
384592 |
* This function will be invoked by
|
|
Packit Service |
384592 |
* ModSecurity to transform input.
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
static int reverse(apr_pool_t *mptmp, unsigned char *input,
|
|
Packit Service |
384592 |
long int input_len, char **rval, long int *rval_len)
|
|
Packit Service |
384592 |
{
|
|
Packit Service |
384592 |
/* Transformation functions can choose to do their
|
|
Packit Service |
384592 |
* thing in-place, overwriting the existing content. This
|
|
Packit Service |
384592 |
* is normally possible only if the transformed content
|
|
Packit Service |
384592 |
* is of equal length or shorter.
|
|
Packit Service |
384592 |
*
|
|
Packit Service |
384592 |
* If you need to expand the content use the temporary
|
|
Packit Service |
384592 |
* memory pool mptmp to allocate the space.
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
/* Reverse the string in place, but only if it's long enough. */
|
|
Packit Service |
384592 |
if (input_len > 1) {
|
|
Packit Service |
384592 |
long int i = 0;
|
|
Packit Service |
384592 |
long int j = input_len - 1;
|
|
Packit Service |
384592 |
while(i < j) {
|
|
Packit Service |
384592 |
char c = input[i];
|
|
Packit Service |
384592 |
input[i] = input[j];
|
|
Packit Service |
384592 |
input[j] = c;
|
|
Packit Service |
384592 |
i++;
|
|
Packit Service |
384592 |
j--;
|
|
Packit Service |
384592 |
}
|
|
Packit Service |
384592 |
}
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
/* Tell ModSecurity about the content
|
|
Packit Service |
384592 |
* we have generated. In this case we
|
|
Packit Service |
384592 |
* merely point back to the input buffer.
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
*rval = (char *)input;
|
|
Packit Service |
384592 |
*rval_len = input_len;
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
/* Must return 1 if the content was
|
|
Packit Service |
384592 |
* changed, or 0 otherwise.
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
return 1;
|
|
Packit Service |
384592 |
}
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
static int hook_pre_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_temp) {
|
|
Packit Service |
384592 |
void (*fn)(const char *name, void *fn);
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
/* Look for the registration function
|
|
Packit Service |
384592 |
* exported by ModSecurity.
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
fn = APR_RETRIEVE_OPTIONAL_FN(modsec_register_tfn);
|
|
Packit Service |
384592 |
if (fn) {
|
|
Packit Service |
384592 |
/* Use it to register our new
|
|
Packit Service |
384592 |
* transformation function under the
|
|
Packit Service |
384592 |
* name "reverse".
|
|
Packit Service |
384592 |
*/
|
|
Packit Service |
384592 |
fn("reverse", (void *)reverse);
|
|
Packit Service |
384592 |
} else {
|
|
Packit Service |
384592 |
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
|
|
Packit Service |
384592 |
"mod_tfn_reverse: Unable to find modsec_register_tfn.");
|
|
Packit Service |
384592 |
}
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
return OK;
|
|
Packit Service |
384592 |
}
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
static void register_hooks(apr_pool_t *p) {
|
|
Packit Service |
384592 |
ap_hook_pre_config(hook_pre_config, NULL, NULL, APR_HOOK_LAST);
|
|
Packit Service |
384592 |
}
|
|
Packit Service |
384592 |
|
|
Packit Service |
384592 |
/* Dispatch list for API hooks */
|
|
Packit Service |
384592 |
module AP_MODULE_DECLARE_DATA tfn_reverse_module = {
|
|
Packit Service |
384592 |
STANDARD20_MODULE_STUFF,
|
|
Packit Service |
384592 |
NULL, /* create per-dir config structures */
|
|
Packit Service |
384592 |
NULL, /* merge per-dir config structures */
|
|
Packit Service |
384592 |
NULL, /* create per-server config structures */
|
|
Packit Service |
384592 |
NULL, /* merge per-server config structures */
|
|
Packit Service |
384592 |
NULL, /* table of config file commands */
|
|
Packit Service |
384592 |
register_hooks /* register hooks */
|
|
Packit Service |
384592 |
};
|
|
Packit Service |
384592 |
|