Project

General

Profile

mod_evasive.patch

crypt, 2010-07-15 09:05

View differences:

lighttpd-1.4.23___/src/mod_evasive.c 2010-05-24 02:10:58.000000000 +0200
28 28
typedef struct {
29 29
	unsigned short max_conns;
30 30
	unsigned short silent;
31
	buffer *location;
31 32
} plugin_config;
32 33

  
33 34
typedef struct {
......
58 59
		for (i = 0; i < srv->config_context->used; i++) {
59 60
			plugin_config *s = p->config_storage[i];
60 61

  
62
			buffer_free(s->location);
63

  
61 64
			free(s);
62 65
		}
63 66
		free(p->config_storage);
......
75 78
	config_values_t cv[] = {
76 79
		{ "evasive.max-conns-per-ip",    NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 0 */
77 80
		{ "evasive.silent",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
81
		{ "evasive.location",            NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 2 */
78 82
		{ NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
79 83
	};
80 84

  
......
86 90
		s = calloc(1, sizeof(plugin_config));
87 91
		s->max_conns       = 0;
88 92
		s->silent          = 0;
93
		s->location        = buffer_init();
89 94

  
90 95
		cv[0].destination = &(s->max_conns);
91 96
		cv[1].destination = &(s->silent);
97
		cv[2].destination = s->location;
92 98

  
93 99
		p->config_storage[i] = s;
94 100

  
......
108 114

  
109 115
	PATCH(max_conns);
110 116
	PATCH(silent);
117
	PATCH(location);
111 118

  
112 119
	/* skip the first, the global context */
113 120
	for (i = 1; i < srv->config_context->used; i++) {
......
125 132
				PATCH(max_conns);
126 133
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.silent"))) {
127 134
				PATCH(silent);
135
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.location"))) {
136
				PATCH(location);
128 137
			}
129 138
		}
130 139
	}
......
185 194
					"turned away. Too many connections.");
186 195
			}
187 196

  
188
			con->http_status = 403;
197
			if (2 < p->conf.location->used) {
198
				response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.location));
199

  
200
				con->http_status = 302;
201
				con->file_finished = 1;
202
			} else {
203
				con->http_status = 403;
204
			}
189 205
			con->mode = DIRECT;
190 206
			return HANDLER_FINISHED;
191 207
		}