projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add event to interrupt the server_loop.
[apps/pfixtools.git]
/
postlicyd
/
match.c
diff --git
a/postlicyd/match.c
b/postlicyd/match.c
index
91edd17
..
d50b12a
100644
(file)
--- a/
postlicyd/match.c
+++ b/
postlicyd/match.c
@@
-54,6
+54,15
@@
typedef struct match_condition_t {
} match_condition_t;
ARRAY(match_condition_t)
} match_condition_t;
ARRAY(match_condition_t)
+static const char *condition_names[] = {
+ "unknown",
+ "equals to",
+ "differs from",
+ "contains",
+ "is contained",
+ "is empty"
+};
+
#define CONDITION_INIT { PTK_UNKNOWN, false, MATCH_UNKNOWN, NULL, 0 }
typedef struct match_config_t {
#define CONDITION_INIT { PTK_UNKNOWN, false, MATCH_UNKNOWN, NULL, 0 }
typedef struct match_config_t {
@@
-86,8
+95,8
@@
static bool match_filter_constructor(filter_t *filter)
#define PARSE_CHECK(Expr, Str, ...) \
if (!(Expr)) { \
#define PARSE_CHECK(Expr, Str, ...) \
if (!(Expr)) { \
-
syslog(LOG_ERR, Str, ##__VA_ARGS__);
\
- match_config_delete(&config); \
+
err(Str, ##__VA_ARGS__);
\
+ match_config_delete(&config);
\
return false; \
}
return false; \
}
@@
-115,18
+124,17
@@
static bool match_filter_constructor(filter_t *filter)
#define IS_OP_END(N) \
((N) == '=' || (N) == 'i')
match_condition_t condition = CONDITION_INIT;
#define IS_OP_END(N) \
((N) == '=' || (N) == 'i')
match_condition_t condition = CONDITION_INIT;
- const char *p =
m_strnextsp
(param->value);
+ const char *p =
skipspaces
(param->value);
const char *n = p + 1;
PARSE_CHECK(isalnum(*p), "invalid field name");
for (n = p + 1 ; *n && (isalnum(*n) || *n == '_') ; ++n);
const char *n = p + 1;
PARSE_CHECK(isalnum(*p), "invalid field name");
for (n = p + 1 ; *n && (isalnum(*n) || *n == '_') ; ++n);
- PARSE_CHECK(*n &&
- (isspace(*n) || IS_OP_START(*n)),
+ PARSE_CHECK(*n && (isspace(*n) || IS_OP_START(*n)),
"invalid condition, expected operator after field name");
condition.field = policy_tokenize(p, n - p);
PARSE_CHECK(condition.field >= PTK_HELO_NAME
&& condition.field < PTK_SMTPD_ACCESS_POLICY,
"invalid condition, expected operator after field name");
condition.field = policy_tokenize(p, n - p);
PARSE_CHECK(condition.field >= PTK_HELO_NAME
&& condition.field < PTK_SMTPD_ACCESS_POLICY,
- "invalid field name %.*s",
n - p
, p);
- p =
m_strnextsp
(n);
+ "invalid field name %.*s",
(int)(n - p)
, p);
+ p =
skipspaces
(n);
n = p + 1;
PARSE_CHECK(IS_OP_START(*p) && IS_OP_END(*n),
"invalid operator %2s", p);
n = p + 1;
PARSE_CHECK(IS_OP_START(*p) && IS_OP_END(*n),
"invalid operator %2s", p);
@@
-147,7
+155,7
@@
static bool match_filter_constructor(filter_t *filter)
PARSE_CHECK(condition.condition != MATCH_UNKNOWN,
"invalid operator");
if (condition.condition != MATCH_EMPTY) {
PARSE_CHECK(condition.condition != MATCH_UNKNOWN,
"invalid operator");
if (condition.condition != MATCH_EMPTY) {
- p =
m_strnextsp
(n + 1);
+ p =
skipspaces
(n + 1);
PARSE_CHECK(*p, "no value defined to check the condition");
condition.value_len = param->value_len - (p - param->value);
condition.value = p_dupstr(p, condition.value_len);
PARSE_CHECK(*p, "no value defined to check the condition");
condition.value_len = param->value_len - (p - param->value);
condition.value = p_dupstr(p, condition.value_len);
@@
-181,7
+189,9
@@
static inline bool match_condition(const match_condition_t *cond, const query_t
CASE(HELO_NAME, helo_name)
CASE(QUEUE_ID, queue_id)
CASE(SENDER, sender)
CASE(HELO_NAME, helo_name)
CASE(QUEUE_ID, queue_id)
CASE(SENDER, sender)
+ CASE(SENDER_DOMAIN, sender_domain)
CASE(RECIPIENT, recipient)
CASE(RECIPIENT, recipient)
+ CASE(RECIPIENT_DOMAIN, recipient_domain)
CASE(RECIPIENT_COUNT, recipient_count)
CASE(CLIENT_ADDRESS, client_address)
CASE(CLIENT_NAME, client_name)
CASE(RECIPIENT_COUNT, recipient_count)
CASE(CLIENT_ADDRESS, client_address)
CASE(CLIENT_NAME, client_name)
@@
-202,6
+212,10
@@
static inline bool match_condition(const match_condition_t *cond, const query_t
#undef CASE
default: return false;
}
#undef CASE
default: return false;
}
+ debug("running condition: \"%s\" %s %s\"%s\"",
+ field, condition_names[cond->condition],
+ cond->case_sensitive ? "" : "(alternative) ",
+ cond->value ? cond->value : "(none)");
switch (cond->condition) {
case MATCH_EQUAL:
case MATCH_DIFFER:
switch (cond->condition) {
case MATCH_EQUAL:
case MATCH_DIFFER:
@@
-212,7
+226,7
@@
static inline bool match_condition(const match_condition_t *cond, const query_t
return !!((strcmp(field, cond->value) == 0)
^ (cond->condition == MATCH_DIFFER));
} else {
return !!((strcmp(field, cond->value) == 0)
^ (cond->condition == MATCH_DIFFER));
} else {
- return !!((strcasecmp(field, cond->value) == 0)
+ return !!((
ascii_
strcasecmp(field, cond->value) == 0)
^ (cond->condition == MATCH_DIFFER));
}
break;
^ (cond->condition == MATCH_DIFFER));
}
break;
@@
-224,8
+238,7
@@
static inline bool match_condition(const match_condition_t *cond, const query_t
if (cond->case_sensitive) {
return strstr(field, cond->value);
} else {
if (cond->case_sensitive) {
return strstr(field, cond->value);
} else {
- /* XXX: GNU Sources */
- return strcasestr(field, cond->value);
+ return m_stristrn(field, cond->value, cond->value_len);
}
break;
}
break;
@@
-236,13
+249,12
@@
static inline bool match_condition(const match_condition_t *cond, const query_t
if (cond->case_sensitive) {
return strstr(cond->value, field);
} else {
if (cond->case_sensitive) {
return strstr(cond->value, field);
} else {
- /* XXX: GNU Sources */
- return strcasestr(cond->value, field);
+ return m_stristr(cond->value, field);
}
break;
case MATCH_EMPTY:
}
break;
case MATCH_EMPTY:
- return !!(
!!(field == NULL || *field == '\0')) ^ (!!cond->case_sensitive
);
+ return !!(
(field == NULL || *field == '\0') ^ (!cond->case_sensitive)
);
default:
assert(false && "invalid condition type");
default:
assert(false && "invalid condition type");
@@
-256,15
+268,19
@@
static filter_result_t match_filter(const filter_t *filter, const query_t *query
foreach (const match_condition_t *condition, config->conditions) {
bool r = match_condition(condition, query);
if (!r && config->match_all) {
foreach (const match_condition_t *condition, config->conditions) {
bool r = match_condition(condition, query);
if (!r && config->match_all) {
- return HTK_FALSE;
+ debug("condition failed, match_all failed");
+ return HTK_FAIL;
} else if (r && !(config->match_all)) {
} else if (r && !(config->match_all)) {
- return HTK_TRUE;
+ debug("condition succeed, not-match_all succeed");
+ return HTK_MATCH;
}
}}
if (config->match_all) {
}
}}
if (config->match_all) {
- return HTK_TRUE;
+ debug("all conditions matched, match_all succeed");
+ return HTK_MATCH;
} else {
} else {
- return HTK_FALSE;
+ debug("no condition matched, not-match_all failed");
+ return HTK_FAIL;
}
}
}
}
@@
-276,8
+292,8
@@
static int match_init(void)
*/
(void)filter_hook_register(type, "abort");
(void)filter_hook_register(type, "error");
*/
(void)filter_hook_register(type, "abort");
(void)filter_hook_register(type, "error");
- (void)filter_hook_register(type, "
true
");
- (void)filter_hook_register(type, "fa
lse
");
+ (void)filter_hook_register(type, "
match
");
+ (void)filter_hook_register(type, "fa
il
");
/* Parameters.
*/
/* Parameters.
*/