projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add server port in the example.
[apps/pfixtools.git]
/
postlicyd
/
main-postlicyd.c
diff --git
a/postlicyd/main-postlicyd.c
b/postlicyd/main-postlicyd.c
index
e75965f
..
5f46e76
100644
(file)
--- a/
postlicyd/main-postlicyd.c
+++ b/
postlicyd/main-postlicyd.c
@@
-56,6
+56,11
@@
static void *query_starter(server_t* server)
return query_new();
}
return query_new();
}
+static bool config_refresh(void *config)
+{
+ return config_reload(config);
+}
+
static int postfix_parsejob(query_t *query, char *p)
{
#define PARSE_CHECK(expr, error, ...) \
static int postfix_parsejob(query_t *query, char *p)
{
#define PARSE_CHECK(expr, error, ...) \
@@
-167,24
+172,23
@@
static void policy_answer(server_t *pcy, const char *fmt, ...)
epoll_modify(pcy->fd, EPOLLIN | EPOLLOUT, pcy);
}
epoll_modify(pcy->fd, EPOLLIN | EPOLLOUT, pcy);
}
-static
void policy_process(server_t *pcy,
config_t *config)
+static
bool policy_process(server_t *pcy, const
config_t *config)
{
const query_t* query = pcy->data;
{
const query_t* query = pcy->data;
- filter_t *filter;
+
const
filter_t *filter;
if (config->entry_points[query->state] == -1) {
syslog(LOG_WARNING, "no filter defined for current protocol_state (%d)", query->state);
if (config->entry_points[query->state] == -1) {
syslog(LOG_WARNING, "no filter defined for current protocol_state (%d)", query->state);
- policy_answer(pcy, "DUNNO");
- return;
+ return false;
}
filter = array_ptr(config->filters, config->entry_points[query->state]);
while (true) {
}
filter = array_ptr(config->filters, config->entry_points[query->state]);
while (true) {
- filter_hook_t *hook = filter_run(filter, query);
+
const
filter_hook_t *hook = filter_run(filter, query);
if (hook == NULL) {
if (hook == NULL) {
-
policy_answer(pcy, "DUNNO
");
- return;
+
syslog(LOG_WARNING, "request aborted
");
+ return
false
;
} else if (hook->postfix) {
policy_answer(pcy, "%s", hook->value);
} else if (hook->postfix) {
policy_answer(pcy, "%s", hook->value);
- return;
+ return
true
;
} else {
filter = array_ptr(config->filters, hook->filter_id);
}
} else {
filter = array_ptr(config->filters, hook->filter_id);
}
@@
-193,11
+197,11
@@
static void policy_process(server_t *pcy, config_t *config)
static int policy_run(server_t *pcy, void* vconfig)
{
static int policy_run(server_t *pcy, void* vconfig)
{
- ssize_t search_offs = MAX(0,
pcy->ibuf.len - 1
);
+ ssize_t search_offs = MAX(0,
(ssize_t)(pcy->ibuf.len - 1)
);
int nb = buffer_read(&pcy->ibuf, pcy->fd, -1);
const char *eoq;
query_t *query = pcy->data;
int nb = buffer_read(&pcy->ibuf, pcy->fd, -1);
const char *eoq;
query_t *query = pcy->data;
- config_t *config = vconfig;
+ con
st con
fig_t *config = vconfig;
if (nb < 0) {
if (errno == EAGAIN || errno == EINTR)
if (nb < 0) {
if (errno == EAGAIN || errno == EINTR)
@@
-218,8
+222,7
@@
static int policy_run(server_t *pcy, void* vconfig)
return -1;
query->eoq = eoq + strlen("\n\n");
epoll_modify(pcy->fd, 0, pcy);
return -1;
query->eoq = eoq + strlen("\n\n");
epoll_modify(pcy->fd, 0, pcy);
- policy_process(pcy, config);
- return 0;
+ return policy_process(pcy, config) ? 0 : -1;
}
int start_listener(int port)
}
int start_listener(int port)
@@
-248,6
+251,7
@@
int main(int argc, char *argv[])
const char *pidfile = NULL;
bool daemonize = true;
int port = DEFAULT_PORT;
const char *pidfile = NULL;
bool daemonize = true;
int port = DEFAULT_PORT;
+ bool port_from_cli = false;
for (int c = 0; (c = getopt(argc, argv, "hf" "l:p:")) >= 0; ) {
switch (c) {
for (int c = 0; (c = getopt(argc, argv, "hf" "l:p:")) >= 0; ) {
switch (c) {
@@
-259,6
+263,7
@@
int main(int argc, char *argv[])
break;
case 'l':
port = atoi(optarg);
break;
case 'l':
port = atoi(optarg);
+ port_from_cli = true;
break;
case 'f':
daemonize = false;
break;
case 'f':
daemonize = false;
@@
-278,15
+283,19
@@
int main(int argc, char *argv[])
if (config == NULL) {
return EXIT_FAILURE;
}
if (config == NULL) {
return EXIT_FAILURE;
}
+ if (port_from_cli || config->port == 0) {
+ config->port = port;
+ }
if (common_setup(pidfile, false, RUNAS_USER, RUNAS_GROUP,
daemonize) != EXIT_SUCCESS
if (common_setup(pidfile, false, RUNAS_USER, RUNAS_GROUP,
daemonize) != EXIT_SUCCESS
- || start_listener(port) < 0) {
+ || start_listener(config->port) < 0) {
+ config_delete(&config);
return EXIT_FAILURE;
}
{
int res = server_loop(query_starter, (delete_client_t)query_delete,
return EXIT_FAILURE;
}
{
int res = server_loop(query_starter, (delete_client_t)query_delete,
- policy_run, config);
+ policy_run, config
_refresh, config
);
config_delete(&config);
return res;
}
config_delete(&config);
return res;
}