Write a postlicyd(8) man page.
[apps/pfixtools.git] / postlicyd / main-postlicyd.c
index a4543ec..888a393 100644 (file)
 /*     products derived from this software without specific prior written     */
 /*     permission.                                                            */
 /*                                                                            */
-/*  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND   */
-/*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE     */
-/*  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR        */
-/*  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS    */
-/*  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR    */
-/*  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF      */
-/*  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  */
-/*  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN   */
-/*  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)   */
-/*  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF    */
-/*  THE POSSIBILITY OF SUCH DAMAGE.                                           */
+/*  THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS   */
+/*  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED         */
+/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE    */
+/*  DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY         */
+/*  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL        */
+/*  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS   */
+/*  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)     */
+/*  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,       */
+/*  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN  */
+/*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
+/*  POSSIBILITY OF SUCH DAMAGE.                                               */
+/*                                                                            */
+/*   Copyright (c) 2006-2008 the Authors                                      */
+/*   see AUTHORS and source files for details                                 */
 /******************************************************************************/
 
 /*
@@ -44,7 +47,7 @@
 #include "query.h"
 
 #define DAEMON_NAME             "postlicyd"
-#define DAEMON_VERSION          "0.4"
+#define DAEMON_VERSION          "0.5"
 #define DEFAULT_PORT            10000
 #define RUNAS_USER              "nobody"
 #define RUNAS_GROUP             "nogroup"
@@ -147,13 +150,13 @@ static const filter_t *next_filter(client_t *pcy, const filter_t *filter,
         *ok = true;
         return NULL;
     } else if (hook->postfix) {
-        log_reply(INFO, "awswer %s from filter %s: \"%s\"",
+        log_reply(INFO, "answer %s from filter %s: \"%s\"",
                   htokens[hook->type], filter->name, hook->value);
         policy_answer(pcy, hook->value);
         *ok = true;
         return NULL;
     } else {
-        log_reply(DEBUG,  "awswer %s from filter %s: next filter %s",
+        log_reply(DEBUG, "answer %s from filter %s: next filter %s",
                   htokens[hook->type], filter->name,
                   (array_ptr(config->filters, hook->filter_id))->name);
         return array_ptr(config->filters, hook->filter_id);
@@ -167,7 +170,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 (%s)", smtp_state_names[query->state]);
+        warn("no filter defined for current protocol_state (%s)", smtp_state_names[query->state].str);
         return false;
     }
     if (context->context.current_filter != NULL) {
@@ -225,9 +228,10 @@ static int policy_run(client_t *pcy, void* vconfig)
     query->eoq = eoq + strlen("\n\n");
 
     /* The instance changed => reset the static context */
-    if (query->instance == NULL || strcmp(context->context.instance, query->instance) != 0) {
+    if (query->instance.str == NULL || query->instance.len == 0
+        || strcmp(context->context.instance, query->instance.str) != 0) {
         filter_context_clean(&context->context);
-        m_strcat(context->context.instance, 64, query->instance);
+        m_strcat(context->context.instance, 64, query->instance.str);
     }
     client_io_none(pcy);
     return policy_process(pcy, mconfig) ? 0 : -1;
@@ -294,7 +298,7 @@ int main(int argc, char *argv[])
     bool port_from_cli = false;
     bool check_conf = false;
 
-    for (int c = 0; (c = getopt(argc, argv, "ufdc" "l:p:")) >= 0; ) {
+    for (int c = 0; (c = getopt(argc, argv, "hufdc" "l:p:")) >= 0; ) {
         switch (c) {
           case 'p':
             pidfile = optarg;