From 8642c01344246675d7b8ffe6fd71504c9113745b Mon Sep 17 00:00:00 2001 From: brenosilva Date: Wed, 30 Mar 2011 17:58:54 +0000 Subject: [PATCH] gsb now saves the base url in tx.1 when match a full url --- apache2/msc_util.c | 22 ++++++++++++---------- apache2/msc_util.h | 2 +- apache2/re_operators.c | 20 +++++++++++++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/apache2/msc_util.c b/apache2/msc_util.c index 4b5f66f6..e9f9d9a4 100644 --- a/apache2/msc_util.c +++ b/apache2/msc_util.c @@ -192,15 +192,16 @@ int convert_to_int(const char c) return n; } -/* \brief Set a match to tx.0 +/* \brief Set a match to tx.N * -* \param msr -* \param capture -* \param match +* \param msr Pointer to modsec resource +* \param capture If ON match will be saved +* \param match Pointer to captured string + *\parm tx_n The tx number to save the data * * \retval 0 On Sucess|Fail */ -int set_match_to_tx(modsec_rec *msr, int capture, const char *match) { +int set_match_to_tx(modsec_rec *msr, int capture, const char *match, int tx_n) { if (capture) { int i; @@ -208,7 +209,7 @@ int set_match_to_tx(modsec_rec *msr, int capture, const char *match) { if (s == NULL) return -1; - s->name = "0"; + s->name = apr_psprintf(msr->mp,"%d", tx_n); s->name_len = strlen(s->name); s->value = apr_pstrdup(msr->mp, match); if (s->value == NULL) return -1; @@ -216,16 +217,17 @@ int set_match_to_tx(modsec_rec *msr, int capture, const char *match) { apr_table_setn(msr->tx_vars, s->name, (void *)s); if (msr->txcfg->debuglog_level >= 9) { - msr_log(msr, 9, "Added phrase match to TX.0: %s", - log_escape_nq_ex(msr->mp, s->value, s->value_len)); + msr_log(msr, 9, "Added phrase match to TX.%d: %s", + tx_n, log_escape_nq_ex(msr->mp, s->value, s->value_len)); } - /* Unset the remaining ones (from previous invocations). */ - for(i = 1; i <= 9; i++) { + /* + for(i = 0; i <= 9; i++) { char buf[2]; apr_snprintf(buf, sizeof(buf), "%d", i); apr_table_unset(msr->tx_vars, buf); } + */ } return 0; diff --git a/apache2/msc_util.h b/apache2/msc_util.h index 0f7841e1..f648570a 100644 --- a/apache2/msc_util.h +++ b/apache2/msc_util.h @@ -92,7 +92,7 @@ int DSOLOCAL decode_base64_ext(char *plain_text, const char *input, int input_le int DSOLOCAL convert_to_int(const char c); -int DSOLOCAL set_match_to_tx(modsec_rec *msr, int capture, const char *match); +int DSOLOCAL set_match_to_tx(modsec_rec *msr, int capture, const char *match, int tx_n); int DSOLOCAL js_decode_nonstrict_inplace(unsigned char *input, long int input_len); diff --git a/apache2/re_operators.c b/apache2/re_operators.c index 3408ec0b..2d448f65 100644 --- a/apache2/re_operators.c +++ b/apache2/re_operators.c @@ -1429,11 +1429,18 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var ret = verify_gsb(gsb, rule, match, match_length); if(ret > 0) { - set_match_to_tx(msr, capture, match); + set_match_to_tx(msr, capture, match, 0); if (! *error_msg) { *error_msg = apr_psprintf(msr->mp, "Gsb lookup for \"%s\" succeeded.", log_escape_nq(msr->mp, match)); } + + str = apr_pstrdup(rule->ruleset->mp,match); + + base = apr_strtok(str,"/",&savedptr); + if(base != NULL) + set_match_to_tx(msr, capture, base, 1); + return 1; } @@ -1451,11 +1458,18 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var ret = verify_gsb(gsb, rule, canon, canon_length); if(ret > 0) { - set_match_to_tx(msr, capture, match); + set_match_to_tx(msr, capture, match, 0); if (! *error_msg) { *error_msg = apr_psprintf(msr->mp, "Gsb lookup for \"%s\" succeeded.", log_escape_nq(msr->mp, canon)); } + + str = apr_pstrdup(rule->ruleset->mp,match); + + base = apr_strtok(str,"/",&savedptr); + if(base != NULL) + set_match_to_tx(msr, capture, base, 1); + return 1; } } @@ -1482,7 +1496,7 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var ret = verify_gsb(gsb, rule, canon, canon_length); if(ret > 0) { - set_match_to_tx(msr, capture, canon); + set_match_to_tx(msr, capture, canon, 0); if (! *error_msg) { *error_msg = apr_psprintf(msr->mp, "Gsb lookup for \"%s\" succeeded.", log_escape_nq(msr->mp, canon));