Skip to content

Commit bc3d3f1

Browse files
author
Felipe Zimmerle
committed
Adds support to setenv action
Issue #1044
1 parent 4dd2812 commit bc3d3f1

File tree

12 files changed

+5120
-5417
lines changed

12 files changed

+5120
-5417
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.3 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Adds support to setenv action.
5+
[Issue #1044 - @zimmerle]
46
- Adds new transaction constructor that accepts the transaction id
57
as parameter.
68
[Issue #1627 - @defanator, @zimmerle]

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ TESTS+=test/test-cases/regression/variable-MATCHED_VAR.json
117117
TESTS+=test/test-cases/regression/variable-REQUEST_URI.json
118118
TESTS+=test/test-cases/regression/variable-ENV.json
119119
TESTS+=test/test-cases/regression/variable-URLENCODED_ERROR.json
120+
TESTS+=test/test-cases/regression/action-setenv.json
120121
TESTS+=test/test-cases/regression/action-setsid.json
121122
TESTS+=test/test-cases/regression/variable-AUTH_TYPE.json
122123
TESTS+=test/test-cases/regression/variable-TIME_DAY.json

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ACTIONS = \
136136
actions/rev.cc \
137137
actions/rule_id.cc \
138138
actions/severity.cc \
139+
actions/set_env.cc \
139140
actions/set_rsc.cc \
140141
actions/set_sid.cc \
141142
actions/set_uid.cc \

src/actions/set_env.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address [email protected].
13+
*
14+
*/
15+
16+
#include "src/actions/set_env.h"
17+
18+
#include <iostream>
19+
#include <string>
20+
21+
#include "modsecurity/transaction.h"
22+
#include "modsecurity/rule.h"
23+
#include "src/utils/string.h"
24+
25+
namespace modsecurity {
26+
namespace actions {
27+
28+
29+
bool SetENV::init(std::string *error) {
30+
return true;
31+
}
32+
33+
34+
bool SetENV::evaluate(Rule *rule, Transaction *t) {
35+
std::string colNameExpanded(m_string->evaluate(t));
36+
37+
#ifndef NO_LOGS
38+
t->debug(8, "Setting envoriment variable: "
39+
+ colNameExpanded + ".");
40+
#endif
41+
42+
putenv((char *)colNameExpanded.c_str());
43+
44+
return true;
45+
}
46+
47+
} // namespace actions
48+
} // namespace modsecurity

src/actions/set_env.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address [email protected].
13+
*
14+
*/
15+
16+
#include <string>
17+
#include <utility>
18+
#include <memory>
19+
20+
#include "modsecurity/actions/action.h"
21+
#include "src/run_time_string.h"
22+
23+
#ifndef SRC_ACTIONS_SET_ENV_H_
24+
#define SRC_ACTIONS_SET_ENV_H_
25+
26+
class Transaction;
27+
28+
namespace modsecurity {
29+
class Transaction;
30+
namespace actions {
31+
32+
33+
class SetENV : public Action {
34+
public:
35+
explicit SetENV(std::string _action)
36+
: Action(_action) { }
37+
38+
explicit SetENV(std::unique_ptr<RunTimeString> z)
39+
: Action("setenv", RunTimeOnlyIfMatchKind),
40+
m_string(std::move(z)) { }
41+
42+
bool evaluate(Rule *rule, Transaction *transaction) override;
43+
bool init(std::string *error) override;
44+
45+
private:
46+
std::unique_ptr<RunTimeString> m_string;
47+
};
48+
49+
50+
} // namespace actions
51+
} // namespace modsecurity
52+
53+
#endif // SRC_ACTIONS_SET_ENV_H_

0 commit comments

Comments
 (0)