X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Fmain-postlicyd.c;h=dab0bf0159776549858a8b031ad7453fc3028fe0;hb=8950d42993b7148718f712b8d7e77aaa21ef14ce;hp=50c19d5005fdd0a55c0876bce2519e19be64f1b0;hpb=09cd9ac733c72efbd4f0b7ca90f2e2ccc60d2c07;p=apps%2Fpfixtools.git diff --git a/postlicyd/main-postlicyd.c b/postlicyd/main-postlicyd.c index 50c19d5..dab0bf0 100644 --- a/postlicyd/main-postlicyd.c +++ b/postlicyd/main-postlicyd.c @@ -44,7 +44,7 @@ #include "query.h" #define DAEMON_NAME "postlicyd" -#define DAEMON_VERSION "0.3" +#define DAEMON_VERSION "0.4" #define DEFAULT_PORT 10000 #define RUNAS_USER "nobody" #define RUNAS_GROUP "nogroup" @@ -83,7 +83,10 @@ static bool config_refresh(void *mconfig) if (filter_running > 0) { return true; } + log_state = "refreshing "; + info("reloading configuration"); bool ret = config_reload(mconfig); + log_state = ""; foreach (client_t **server, busy) { client_io_ro(*server); }} @@ -126,53 +129,43 @@ static void policy_answer(client_t *pcy, const char *message) static const filter_t *next_filter(client_t *pcy, const filter_t *filter, const query_t *query, const filter_hook_t *hook, bool *ok) { +#define MESSAGE_FORMAT "request client=%s from=<%s> to=<%s> at %s: " +#define MESSAGE_PARAMS query->client_name, \ + query->sender == NULL ? "undefined" : query->sender, \ + query->recipient == NULL ? "undefined" : query->recipient, \ + smtp_state_names[query->state] + if (hook != NULL) { query_context_t *context = client_data(pcy); if (hook->counter >= 0 && hook->counter < MAX_COUNTERS && hook->cost > 0) { context->context.counters[hook->counter] += hook->cost; - debug("request client=%s, from=<%s>, to=<%s>: added %d to counter %d (now %u)", - query->client_name, - query->sender == NULL ? "undefined" : query->sender, - query->recipient == NULL ? "undefined" : query->recipient, + debug(MESSAGE_FORMAT "added %d to counter %d (now %u)", MESSAGE_PARAMS, hook->cost, hook->counter, context->context.counters[hook->counter]); } } if (hook == NULL) { - warn("request client=%s, from=<%s>, to=<%s>: aborted", - query->client_name, - query->sender == NULL ? "undefined" : query->sender, - query->recipient == NULL ? "undefined" : query->recipient); + warn(MESSAGE_FORMAT "aborted", MESSAGE_PARAMS); *ok = false; return NULL; } else if (hook->async) { - debug("request client=%s, from=<%s>, to=<%s>: " - "asynchronous filter from filter %s", - query->client_name, - query->sender == NULL ? "undefined" : query->sender, - query->recipient == NULL ? "undefined" : query->recipient, - filter->name); + debug(MESSAGE_FORMAT "asynchronous filter from filter %s", + MESSAGE_PARAMS, filter->name); *ok = true; return NULL; } else if (hook->postfix) { - info("request client=%s, from=<%s>, to=<%s>: " - "awswer %s from filter %s: \"%s\"", - query->client_name, - query->sender == NULL ? "undefined" : query->sender, - query->recipient == NULL ? "undefined" : query->recipient, + info(MESSAGE_FORMAT "awswer %s from filter %s: \"%s\"", MESSAGE_PARAMS, htokens[hook->type], filter->name, hook->value); policy_answer(pcy, hook->value); *ok = true; return NULL; } else { - debug("request client=%s, from=<%s>, to=<%s>: " - "awswer %s from filter %s: next filter %s", - query->client_name, - query->sender == NULL ? "undefined" : query->sender, - query->recipient == NULL ? "undefined" : query->recipient, - htokens[hook->type], filter->name, - (array_ptr(config->filters, hook->filter_id))->name); + debug(MESSAGE_FORMAT "awswer %s from filter %s: next filter %s", + MESSAGE_PARAMS, htokens[hook->type], filter->name, + (array_ptr(config->filters, hook->filter_id))->name); return array_ptr(config->filters, hook->filter_id); } +#undef MESSAGE_PARAMS +#undef MESSAGE_FORMAT } static bool policy_process(client_t *pcy, const config_t *mconfig) @@ -181,7 +174,7 @@ static bool policy_process(client_t *pcy, const config_t *mconfig) const query_t* query = &context->query; const filter_t *filter; if (mconfig->entry_points[query->state] == -1) { - warn("no filter defined for current protocol_state (%d)", query->state); + warn("no filter defined for current protocol_state (%s)", smtp_state_names[query->state]); return false; } if (context->context.current_filter != NULL) { @@ -293,6 +286,7 @@ void usage(void) " -f stay in foreground\n" " -d grow logging level\n" " -u unsafe mode (don't drop privileges)\n" + " -c check-conf\n" , stderr); } @@ -305,8 +299,9 @@ int main(int argc, char *argv[]) bool daemonize = true; int port = DEFAULT_PORT; bool port_from_cli = false; + bool check_conf = false; - for (int c = 0; (c = getopt(argc, argv, "ufd" "l:p:")) >= 0; ) { + for (int c = 0; (c = getopt(argc, argv, "ufdc" "l:p:")) >= 0; ) { switch (c) { case 'p': pidfile = optarg; @@ -324,6 +319,11 @@ int main(int argc, char *argv[]) case 'd': ++log_level; break; + case 'c': + check_conf = true; + daemonize = false; + unsafe = true; + break; default: usage(); return EXIT_FAILURE; @@ -339,7 +339,10 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION); + if (check_conf) { + return config_check(argv[optind]) ? EXIT_SUCCESS : EXIT_FAILURE; + } + info("%s v%s...", DAEMON_NAME, DAEMON_VERSION); if (pidfile_open(pidfile) < 0) { crit("unable to write pidfile %s", pidfile);