INN commit: trunk (6 files)

INN Commit rra at isc.org
Sun Feb 7 18:18:16 UTC 2010


    Date: Sunday, February 7, 2010 @ 10:18:16
  Author: iulius
Revision: 8949

Use Perl and Python filters on message-ID when articles
are given to innd via TAKETHIS.  The new RFC-3977 structure
of the TAKETHIS command easily allows such a check.

Modified:
  trunk/doc/pod/hook-perl.pod
  trunk/doc/pod/hook-python.pod
  trunk/doc/pod/news.pod
  trunk/innd/nc.c
  trunk/innd/perl.c
  trunk/innd/python.c

-------------------------+
 doc/pod/hook-perl.pod   |   37 ++++++++++++++++---------------------
 doc/pod/hook-python.pod |    6 ++----
 doc/pod/news.pod        |    6 ++++++
 innd/nc.c               |   26 ++++++++++++++++++++++++--
 innd/perl.c             |    3 ++-
 innd/python.c           |    3 ++-
 6 files changed, 52 insertions(+), 29 deletions(-)

Modified: doc/pod/hook-perl.pod
===================================================================
--- doc/pod/hook-perl.pod	2010-02-06 11:29:33 UTC (rev 8948)
+++ doc/pod/hook-perl.pod	2010-02-07 18:18:16 UTC (rev 8949)
@@ -150,28 +150,23 @@
 by the Perl filter and include a count of how many articles were rejected
 with each reason string.)
 
-One other type of filtering is also supported.  If Perl filtering is
-turned on and the Perl function filter_messageid() is defined, that
-function will be called for each message ID received from a peer (via
-either CHECK or IHAVE).  The function receives a single argument, the
-message ID, and like filter_art() should return an empty string to accept
-the article or an error string to refuse the article (make sure that
-such a message is properly encoded in UTF-8 so as to comply with the
-NNTP protocol).  This function is called before any history lookups and
-for every article offered to innd with CHECK or IHAVE (before the actual
-article is sent).  Accordingly, the message ID is the only information
-it has about the article (the %hdr hash will be empty).  This code would
-sit in a performance-critical hot path in a typical server, and therefore
-should be as fast as possible, but it can do things like refuse articles
-from certain hosts or cancels for already rejected articles (if they
-follow the $alz convention) without having to take the network bandwidth
-hit of accepting the entire article first.
+One other type of filtering is also supported.  If Perl filtering is turned
+on and the Perl function filter_messageid() is defined, that function will
+be called for each message-ID received from a peer (via either CHECK, IHAVE
+or TAKETHIS).  The function receives a single argument, the message-ID,
+and like filter_art() should return an empty string to accept the article
+or an error string to refuse the article (make sure that such a message
+is properly encoded in UTF-8 so as to comply with the NNTP protocol).
+This function is called before any history lookups and for every article
+offered to B<innd> with CHECK or IHAVE (before the actual article is sent),
+or with TAKETHIS (after the actual article is sent).  Accordingly, the
+message-ID is the only information it has about the article (the %hdr hash
+will be empty).  This code would sit in a performance-critical hot path in
+a typical server, and therefore should be as fast as possible, but it can
+do things like refuse articles from certain hosts or cancels for already
+rejected articles (if they follow the $alz convention) without having to
+take the network bandwidth hit of accepting the entire article first.
 
-Note that you cannot rely on filter_messageid() being called for every
-incoming article; articles sent via TAKETHIS without an earlier CHECK will
-never pass through filter_messageid() and will only go through
-filter_art().
-
 Finally, whenever ctlinnd throttle, ctlinnd pause, or ctlinnd go is run,
 the Perl function filter_mode() is called if it exists.  It receives no
 arguments and returns no value, but it has access to a global hash %mode

Modified: doc/pod/hook-python.pod
===================================================================
--- doc/pod/hook-python.pod	2010-02-06 11:29:33 UTC (rev 8948)
+++ doc/pod/hook-python.pod	2010-02-07 18:18:16 UTC (rev 8949)
@@ -126,11 +126,9 @@
 =item filter_messageid(I<self>, I<msgid>)
 
 I<msgid> is a buffer object containing the ID of an article being offered by
-IHAVE or CHECK.  Like with C<filter_art>, the message will be refused if
+CHECK, IHAVE or TAKETHIS.  Like with C<filter_art>, the message will be refused if
 you return a non-empty string.  If you use this feature, keep it light
-because it is called at a rather busy place in B<innd>'s main loop.  Also, do
-not rely on this function alone to reject by ID; you should repeat the
-tests in C<filter_art> to catch articles sent with TAKETHIS but no CHECK.
+because it is called at a rather busy place in B<innd>'s main loop.
 
 =item filter_mode(I<self>, I<oldmode>, I<newmode>, I<reason>)
 

Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod	2010-02-06 11:29:33 UTC (rev 8948)
+++ doc/pod/news.pod	2010-02-07 18:18:16 UTC (rev 8949)
@@ -155,6 +155,12 @@
 
 =item *
 
+The Perl and Python filters for B<innd> now check the message-ID of articles
+arriving through TAKETHIS.  Only CHECK and IHAVE commands previously
+used them.
+
+=item *
+
 Case-insensitive matches are now used for distributions, path identities,
 IMAP commands, header names, and control commands.  (Newsgroups are still
 matched case-sensitively.)  Message-IDs are case-sensitively matched,

Modified: innd/nc.c
===================================================================
--- innd/nc.c	2010-02-06 11:29:33 UTC (rev 8948)
+++ innd/nc.c	2010-02-07 18:18:16 UTC (rev 8949)
@@ -1846,8 +1846,11 @@
     static char empty[] = "";
     int     returncode; /* Will *not* be changed in NCpostit()
                            if it does *not* start with '2'. */
-    size_t  msglen;
+    size_t  idlen, msglen;
     WIP     *wp;
+#if defined(DO_PERL) || defined(DO_PYTHON)
+    char    *filterrc;
+#endif /* DO_PERL || DO_PYTHON */
 
     cp->Takethis++;
     cp->Start = cp->Next;
@@ -1862,10 +1865,30 @@
         mid = cp->av[1];
         returncode = NNTP_OK_TAKETHIS; /* Default code. */
     }
+
+    idlen = strlen(mid);
+    msglen = idlen + 5; /* 3 digits + space + id + null. */
+
     if (!IsValidMessageID(mid, false)) {
         syslog(L_NOTICE, "%s bad_messageid %s", CHANname(cp),
                MaxLength(mid, mid));
         returncode = NNTP_FAIL_TAKETHIS_REJECT;
+    } else {
+#if defined(DO_PERL)
+        /* Invoke a Perl message filter on the message-ID. */
+        filterrc = PLmidfilter(mid);
+        if (filterrc) {
+            returncode = NNTP_FAIL_TAKETHIS_REJECT;
+        }
+#endif /* defined(DO_PERL) */
+
+#if defined(DO_PYTHON)
+        /* Invoke a Python message filter on the message-ID. */
+        filterrc = PYmidfilter(mid, idlen);
+        if (filterrc) {
+            returncode = NNTP_FAIL_TAKETHIS_REJECT;
+        }
+#endif /* defined(DO_PYTHON) */
     }
 
     /* Check authentication after everything else. */
@@ -1874,7 +1897,6 @@
             NNTP_FAIL_AUTH_NEEDED : NNTP_ERR_ACCESS;
     }
 
-    msglen = strlen(mid) + 5; /* 3 digits + space + id + null. */
     if (cp->Sendid.size < msglen) {
         if (cp->Sendid.size > 0)
             free(cp->Sendid.data);

Modified: innd/perl.c
===================================================================
--- innd/perl.c	2010-02-06 11:29:33 UTC (rev 8948)
+++ innd/perl.c	2010-02-07 18:18:16 UTC (rev 8949)
@@ -132,7 +132,8 @@
 
 
 /*
-**  Run an incoming message ID from CHECK or IHAVE through the Perl filter.
+**  Run an incoming message-ID from CHECK, IHAVE or TAKETHIS through
+**  the Perl filter.
 **  Returns NULL to accept the article or a rejection message to reject it.
 */
 char *

Modified: innd/python.c
===================================================================
--- innd/python.c	2010-02-06 11:29:33 UTC (rev 8948)
+++ innd/python.c	2010-02-07 18:18:16 UTC (rev 8949)
@@ -154,7 +154,8 @@
 
 
 /*
-**  Refuse Message-IDs offered through CHECK or IHAVE that we don't like.
+**  Refuse message-IDs offered through CHECK, IHAVE or TAKETHIS that
+**  we don't like.
 */
 char *
 PYmidfilter(char *messageID, int msglen)




More information about the inn-committers mailing list