*/
#include "file.h"
-#include "filter.h"
#include "config.h"
#include "str.h"
#define config_param_register(Param)
-config_param_register("first_filter");
+/* Filter to execute on "CONNECT"
+ */
+config_param_register("client_filter");
+
+/* Filter to execute on "MAIL FROM"
+ */
+config_param_register("sender_filter");
+
+/* Filter to execute on "RCPT TO"
+ */
+config_param_register("recipient_filter");
+
+/* Filter to execute on "DATA"
+ */
+config_param_register("data_filter");
+
+/* Filter to execute on "END-OF-DATA"
+ */
+config_param_register("end_of_data_filter");
+
+/* Filter to execute on "ETRN"
+ */
+config_param_register("etrn_filter");
+
+/* Filter to execute on "HELO"
+ */
+config_param_register("helo_filter");
+config_param_register("ehlo_filter");
-struct config_t {
- A(filter_t) filters;
- A(filter_params_t) params;
- int entry_point;
-};
+/* Filter to execute on "VRFY"
+ */
+config_param_register("verify_filter");
static inline config_t *config_new(void)
{
config_t *config = p_new(config_t, 1);
- config->entry_point = -1;
+ for (int i = 0 ; i < SMTP_count ; ++i) {
+ config->entry_points[i] = -1;
+ }
return config;
}
break;
}
}}
+ if (!ok) {
+ return false;
+ }
+
+ ok = false;
+ foreach (filter_param_t *param, config->params) {
+ switch (param->type) {
+#define CASE(Param, State) \
+ case ATK_ ## Param ## _FILTER: \
+ ok = true; \
+ config->entry_points[SMTP_ ## State] \
+ = filter_find_with_name(&config->filters, param->value); \
+ break;
+ CASE(CLIENT, CONNECT)
+ CASE(EHLO, EHLO)
+ CASE(HELO, HELO)
+ CASE(SENDER, MAIL)
+ CASE(RECIPIENT, RCPT)
+ CASE(DATA, DATA)
+ CASE(END_OF_DATA, END_OF_MESSAGE)
+ CASE(VERIFY, VRFY)
+ CASE(ETRN, ETRN)
+#undef CASE
+ default: break;
+ }
+ }}
+ array_deep_wipe(config->params, filter_params_wipe);
+
+ if (!ok) {
+ syslog(LOG_ERR, "no entry point defined");
+ }
return ok;
}
if (escaped) { \
ADD_IN_BUFFER(Buffer, Len, '\\'); \
} \
+ while ((Len) > 0 && isspace((Buffer)[(Len) - 1])) { \
+ (Buffer)[--(Len)] = '\0'; \
+ } \
} \
READ_NEXT(OnEOF); \
} while(0)
READ_BLANK(goto badeof);
READ_STRING("parameter value", value, value_len, ;);
{
- filter_params_t param;
+ filter_param_t param;
param.type = param_tokenize(key, key_len);
if (param.type != ATK_UNKNOWN) {
param.value = m_strdup(value);
syslog(LOG_ERR, "Unexpected end of file");
error:
- filter_wipe(&filter);
+ if (filter.name) {
+ filter_wipe(&filter);
+ }
config_delete(&config);
file_map_close(&map);
return NULL;