INN commit: branches/2.5 (include/nntp.h innd/nc.c nnrpd/commands.c)

INN Commit rra at isc.org
Sun Nov 15 09:19:39 UTC 2009


    Date: Sunday, November 15, 2009 @ 01:19:39
  Author: iulius
Revision: 8757

* Return 435/438 instead of 501 to IHAVE/CHECK commands
for compatibility reasons.

* When a CHECK/TAKETHIS command line is too long and no
streaming is allowed, 500 must be returned (these
commands are unknown).

Modified:
  branches/2.5/include/nntp.h
  branches/2.5/innd/nc.c
  branches/2.5/nnrpd/commands.c

------------------+
 include/nntp.h   |   16 --------------
 innd/nc.c        |   60 ++++++++++++++++++++++++++++++++++++++++-------------
 nnrpd/commands.c |    9 +++++--
 3 files changed, 52 insertions(+), 33 deletions(-)

Modified: include/nntp.h
===================================================================
--- include/nntp.h	2009-11-15 09:19:26 UTC (rev 8756)
+++ include/nntp.h	2009-11-15 09:19:39 UTC (rev 8757)
@@ -26,33 +26,17 @@
 
 #define NNTP_BAD_COMMAND		"500 Syntax error or bad command"
 #define NNTP_ACCESS			"502 Permission denied"
-#define NNTP_HAVEIT			"435 Duplicate"
-#define NNTP_HAVEIT_BADID		"435 Bad Message-ID"
 #define NNTP_LIST_FOLLOWS		"215"
 #define NNTP_ARTICLE_FOLLOWS		"220"
 #define NNTP_REJECTIT_EMPTY		"437 Empty article"
-#define NNTP_RESENDIT_LATER             "436 Retry later"
 #define NNTP_POSTEDOK			"240 Article posted"
-#define NNTP_SENDIT			"335"
 #define NNTP_BAD_SUBCMD			"501 Bad subcommand"
 #define NNTP_NOTINGROUP			"412 Not in a newsgroup"
 #define NNTP_NOSUCHGROUP		"411 No such group"
 #define NNTP_NEWNEWSOK			"230 New news follows"
 #define NNTP_NOARTINGRP			"423 Bad article number"
 #define NNTP_NOCURRART			"420 No current article"
-#define NNTP_CANTPOST			"440 Posting not allowed"
 
-/* new entries for the "streaming" protocol */
-/* response to "mode stream" else 500 if stream not supported */
-
-/* response to "check <id>".  Must include ID of article.
-** Example: "431 <1234 at host.domain>"
-*/
-
-/* responses to "takethis <id>.  Must include ID of article */
-
-/* End of new entries for the "streaming" protocol */
-
 /*
 **  The first character of an NNTP reply can be used as a category class.
 */

Modified: innd/nc.c
===================================================================
--- innd/nc.c	2009-11-15 09:19:26 UTC (rev 8756)
+++ innd/nc.c	2009-11-15 09:19:39 UTC (rev 8757)
@@ -520,7 +520,10 @@
     cp->Start = cp->Next;
 
     if (!ARTidok(av[1])) {
-        NCwritereply(cp, NNTP_HAVEIT_BADID);
+        /* Return 435 here instead of 501 for compatibility reasons. */
+        xasprintf(&buff, "%d Syntax error in message-ID", NNTP_FAIL_IHAVE_REFUSE);
+        NCwritereply(cp, buff);
+        free(buff);
         syslog(L_NOTICE, "%s bad_messageid %s", CHANname(cp),
                MaxLength(av[1], av[1]));
 	return;
@@ -540,7 +543,9 @@
     if ((innconf->refusecybercancels) && (strncmp(av[1], "<cancel.", 8) == 0)) {
 	cp->Refused++;
 	cp->Ihave_Cybercan++;
-	NCwritereply(cp, NNTP_HAVEIT);
+        xasprintf(&buff, "%d Cyberspam cancel", NNTP_FAIL_IHAVE_REFUSE);
+        NCwritereply(cp, buff);
+        free(buff);
 	return;
     }
 
@@ -598,24 +603,30 @@
     if (HIScheck(History, av[1]) || cp->Ignore) {
 	cp->Refused++;
 	cp->Ihave_Duplicate++;
-	NCwritereply(cp, NNTP_HAVEIT);
-    }
-    else if (WIPinprogress(av[1], cp, false)) {
+        xasprintf(&buff, "%d Duplicate", NNTP_FAIL_IHAVE_REFUSE);
+        NCwritereply(cp, buff);
+        free(buff);
+    } else if (WIPinprogress(av[1], cp, false)) {
 	cp->Ihave_Deferred++;
 	if (cp->NoResendId) {
 	    cp->Refused++;
-	    NCwritereply(cp, NNTP_HAVEIT);
+            xasprintf(&buff, "%d Do not resend", NNTP_FAIL_IHAVE_REFUSE);
+            NCwritereply(cp, buff);
+            free(buff);
 	} else {
-	    NCwritereply(cp, NNTP_RESENDIT_LATER);
+            xasprintf(&buff, "%d Retry later", NNTP_FAIL_IHAVE_DEFER);
+            NCwritereply(cp, buff);
+            free(buff);
 	}
-    }
-    else {
+    } else {
 	if (cp->Sendid.size > 0) {
             free(cp->Sendid.data);
 	    cp->Sendid.size = 0;
 	}
 	cp->Ihave_SendIt++;
-	NCwritereply(cp, NNTP_SENDIT);
+        xasprintf(&buff, "%d Send it", NNTP_CONT_IHAVE);
+        NCwritereply(cp, buff);
+        free(buff);
 	cp->ArtBeg = Now.tv_sec;
 	cp->State = CSgetheader;
 	ARTprepare(cp);
@@ -845,6 +856,7 @@
   static char   **av;
   char          **v;
   bool          validcommandtoolong;
+  int           syntaxerrorcode = NNTP_ERR_SYNTAX;
 
   readmore = movedata = false;
   if (Tracing || cp->Tracing)
@@ -973,11 +985,22 @@
         for (dp = NCcommands; dp < ARRAY_END(NCcommands); dp++) {
           if ((dp->Function != NC_unimp) &&
               (strcasecmp(av[0], dp->Name) == 0)) {
-              validcommandtoolong = true;
+              if (!StreamingOff || cp->Streaming ||
+                  (dp->Function != NCcheck && dp->Function != NCtakethis)) {
+                  validcommandtoolong = true;
+              }
+              /* Return 435/438 instead of 501 to IHAVE/CHECK commands
+               * for compatibility reasons. */
+              if (strcasecmp(av[0], "IHAVE") == 0) {
+                  syntaxerrorcode = NNTP_FAIL_IHAVE_REFUSE;
+              } else if (strcasecmp(av[0], "CHECK") == 0
+                         && (!StreamingOff || cp->Streaming)) {
+                  syntaxerrorcode = NNTP_FAIL_CHECK_REFUSE;
+              }
           }
         }
         snprintf(buff, sizeof(buff), "%d Line too long",
-                 validcommandtoolong ? NNTP_ERR_SYNTAX : NNTP_ERR_COMMAND);
+                 validcommandtoolong ? syntaxerrorcode : NNTP_ERR_COMMAND);
         NCwritereply(cp, buff);
         cp->Start = cp->Next;
 
@@ -995,6 +1018,14 @@
       /* Loop through the command table. */
       for (dp = NCcommands; dp < ARRAY_END(NCcommands); dp++) {
 	if (strcasecmp(av[0], dp->Name) == 0) {
+          /* Return 435/438 instead of 501 to IHAVE/CHECK commands
+           * for compatibility reasons. */
+          if (strcasecmp(av[0], "IHAVE") == 0) {
+              syntaxerrorcode = NNTP_FAIL_IHAVE_REFUSE;
+          } else if (strcasecmp(av[0], "CHECK") == 0
+                     && (!StreamingOff || cp->Streaming)) {
+              syntaxerrorcode = NNTP_FAIL_CHECK_REFUSE;
+          }
 	  /* Ignore the streaming commands if necessary. */
 	  if (!StreamingOff || cp->Streaming ||
 	    (dp->Function != NCcheck && dp->Function != NCtakethis)) {
@@ -1035,7 +1066,7 @@
               if (strlen(*v) > NNTP_MAXLEN_ARG) {
                   validcommandtoolong = true;
                   snprintf(buff, sizeof(buff), "%d Argument too long",
-                           NNTP_ERR_SYNTAX);
+                           syntaxerrorcode);
                   NCwritereply(cp, buff);
                   break;
               }
@@ -1049,7 +1080,7 @@
       if ((dp->Minac != NC_any && ac < dp->Minac)
           || (dp->Maxac != NC_any && ac > dp->Maxac)) {
           snprintf(buff, sizeof(buff), "%d Syntax is:  %s %s",
-                   NNTP_ERR_SYNTAX, dp->Name, dp->Help ? dp->Help : "(no argument allowed)");
+                   syntaxerrorcode, dp->Name, dp->Help ? dp->Help : "(no argument allowed)");
           NCwritereply(cp, buff);
           cp->Start = cp->Next;
           break;
@@ -1174,6 +1205,7 @@
 	syslog(L_NOTICE, "%s internal rejecting too long command line (%lu > %d)",
 	  CHANname(cp), (unsigned long) i, NNTP_MAXLEN_COMMAND);
 	cp->LargeCmdSize = 0;
+        /* Command eaten; we do not know whether it was valid (500 or 501). */
 	snprintf(buff, sizeof(buff), "%d command exceeds limit of %d bytes",
                  NNTP_ERR_COMMAND, NNTP_MAXLEN_COMMAND);
 	cp->State = CSgetcmd;

Modified: nnrpd/commands.c
===================================================================
--- nnrpd/commands.c	2009-11-15 09:19:26 UTC (rev 8756)
+++ nnrpd/commands.c	2009-11-15 09:19:39 UTC (rev 8757)
@@ -636,20 +636,23 @@
        * invoke the spaghetti factor). 
        */
       if ((path = (char *) PostRecFilename(Client.ip,PERMuser)) == NULL) {
-        Reply("%s\r\n", ihave ? NNTP_RESENDIT_LATER : NNTP_CANTPOST);
+        Reply("%d %s\r\n", ihave ? NNTP_FAIL_IHAVE_DEFER : NNTP_FAIL_POST_AUTH,
+              ihave ? "Retry later" : "Posting not allowed");
         return;
       }
       
       if (LockPostRec(path) == 0) {
         syslog(L_ERROR, "%s error write locking '%s'",
                Client.host, path);
-        Reply("%s\r\n", ihave ? NNTP_RESENDIT_LATER : NNTP_CANTPOST);
+        Reply("%d %s\r\n", ihave ? NNTP_FAIL_IHAVE_DEFER : NNTP_FAIL_POST_AUTH,
+              ihave ? "Retry later" : "Posting not allowed");
         return;
       }
       
       if (!RateLimit(&sleeptime,path)) {
 	syslog(L_ERROR, "%s can't check rate limit info", Client.host);
-	Reply("%s\r\n", ihave ? NNTP_RESENDIT_LATER : NNTP_CANTPOST);
+        Reply("%d %s\r\n", ihave ? NNTP_FAIL_IHAVE_DEFER : NNTP_FAIL_POST_AUTH,
+              ihave ? "Retry later" : "Posting not allowed");
         UnlockPostRec(path);
 	return;
       } else if (sleeptime != 0L) {




More information about the inn-committers mailing list