X-Git-Url: http://git.madism.org/?a=blobdiff_plain;ds=sidebyside;f=main-postlicyd.c;h=e31999df84f6a40d86ddec24f7735ad989a8eabe;hb=ab8bc5aee397b411abd0358171e990e8bc4647d6;hp=ff5097fae14fb785db1961063529ece6a63df9e5;hpb=e19b9956a229a2197ec33175f1da59629192c3aa;p=apps%2Fpfixtools.git diff --git a/main-postlicyd.c b/main-postlicyd.c index ff5097f..e31999d 100644 --- a/main-postlicyd.c +++ b/main-postlicyd.c @@ -70,7 +70,7 @@ typedef struct query_t { const char *recipient_count; const char *client_address; const char *client_name; - const char *rclient_name; + const char *reverse_client_name; const char *instance; /* postfix 2.2+ */ @@ -99,8 +99,8 @@ static int postfix_parsejob(query_t *query, char *p) } \ } while (0) - p_clear(&query, 1); - while (p[0] != '\r' || p[1] != '\n') { + p_clear(query, 1); + while (*p != '\n') { char *k, *v; int klen, vlen, vtk; @@ -113,10 +113,10 @@ static int postfix_parsejob(query_t *query, char *p) while (isblank(*p)) p++; - p = strstr(v = p, "\r\n"); - PARSE_CHECK(p, "could not find final \\r\\n in line"); + p = strchr(v = p, '\n'); + PARSE_CHECK(p, "could not find final \\n in line"); for (vlen = p - v; vlen && isblank(v[vlen]); vlen--); - p += 2; /* skip \r\n */ + p += 1; /* skip \n */ vtk = tokenize(v, vlen); switch (tokenize(k, klen)) { @@ -128,7 +128,7 @@ static int postfix_parsejob(query_t *query, char *p) CASE(RECIPIENT_COUNT, recipient_count); CASE(CLIENT_ADDRESS, client_address); CASE(CLIENT_NAME, client_name); - CASE(RCLIENT_NAME, rclient_name); + CASE(REVERSE_CLIENT_NAME, reverse_client_name); CASE(INSTANCE, instance); CASE(SASL_METHOD, sasl_method); CASE(SASL_USERNAME, sasl_username); @@ -189,6 +189,7 @@ static void *policy_run(int fd, void *data) buffer_init(&buf); for (;;) { + ssize_t search_offs = MAX(0, buf.len - 1); int nb = buffer_read(&buf, fd, -1); const char *eoq; query_t q; @@ -205,15 +206,15 @@ static void *policy_run(int fd, void *data) break; } - eoq = strstr(buf.data + MAX(0, buf.len - 3), "\r\n\r\n"); + eoq = strstr(buf.data + search_offs, "\n\n"); if (!eoq) continue; if (postfix_parsejob(&q, buf.data) < 0) break; - buffer_consume(&buf, eoq + strlen("\r\n\r\n") - buf.data); - if (xwrite(fd, "DUNNO\r\n", strlen("DUNNO\r\n"))) { + buffer_consume(&buf, eoq + strlen("\n\n") - buf.data); + if (xwrite(fd, "DUNNO\n\n", strlen("DUNNO\n\n"))) { UNIXERR("write"); break; } @@ -310,18 +311,35 @@ int main(int argc, char *argv[]) pidfile_refresh(); addr.sin_port = htons(port); - sock = tcp_listen((struct sockaddr *)&addr, sizeof(addr)); + sock = tcp_listen_nonblock((struct sockaddr *)&addr, sizeof(addr)); if (sock < 0) return EXIT_FAILURE; while (!sigint) { - int fd = accept(sock, NULL, 0); - if (fd < 0) { - if (errno != EINTR && errno != EAGAIN) - UNIXERR("accept"); - continue; + fd_set rfd; + struct timeval tv = { 1, 0 }; + int res; + + FD_SET(sock, &rfd); + res = select(sock + 1, &rfd, NULL, NULL, &tv); + + if (res < 0) { + if (errno != EINTR && errno != EAGAIN) { + UNIXERR("select"); + return EXIT_FAILURE; + } + } + if (res > 0) { + int fd = accept(sock, NULL, 0); + if (fd < 0) { + if (errno != EINTR && errno != EAGAIN) { + UNIXERR("accept"); + return EXIT_FAILURE; + } + continue; + } + thread_launch(policy_run, fd, NULL); } - thread_launch(policy_run, fd, NULL); threads_join(); }