[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] [PATCH] Bug fixes: MODE STREAM, HELP (IHAVE)



This is a patch against 1.9.4, 1.9.4-ma1 and probably 1.9.3 also (not
checked) which makes leafnode respond to MODE STREAM with a 500 error
instead of the improper 200. While MODE STREAM is not officially
documented anywhere, it is part of an IETF draft and may be implemented
in some software already.

Since leafnode does not implement the CHECK and TAKETHIS commands, it
should respond to MODE STREAM properly. 

This patch also does some cleanups and corrects dohelp() which listed 
ihave as supported. 

I plan to extend that nntp_log_and_reply stuff to some more generic
function that might show up in miscutil.c and will probably cut
leafnode's code size a lot, make it easier to overview and maintain,
but that's a longer task. 

Find the patch attached. 

-- 
Matthias Andree

 Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!



--- nntpd.c.orig	Mon Jul 26 02:41:40 1999
+++ nntpd.c	Mon Jul 26 03:09:43 1999
@@ -14,6 +14,8 @@
 Modified by Cornelius Krasel <krasel@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
 and Kazushi (Jam) Marukawa <jam@xxxxxxxxx>.
 Copyright of the modifications 1998, 1999.
+Modified by Matthias Andree <ma@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
+Copyright of the modifications 1999. 
 
 See file COPYING for restrictions on the use of this software.
 */
@@ -36,6 +38,7 @@
 #include <netdb.h>
 #include <setjmp.h>
 #include <signal.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -139,6 +142,32 @@
     printf("%s: %s\r\n", msg, strerror(errno) );
 }
 
+static void nntp_log_and_reply(const char *fmt, ...) {
+  /* like printf, but appends \r\n automatically
+     plus, if debugmode is true, log to
+     syslog using LOG_DEBUG priority and prepending > character
+     (c) 1999 Matthias Andree <ma@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> */
+  char buffer[1024];
+  va_list args;
+
+  va_start(args, fmt);
+  vsnprintf(buffer, sizeof buffer, fmt, args);
+  if (debugmode) {
+    syslog( LOG_DEBUG, ">%s", buffer);
+  }
+  printf( "%s\r\n", buffer);
+  va_end(args);
+}
+
+void domode(const char *arg);
+void domode(const char *arg) {
+  if (!strcasecmp(arg, "reader")) {
+    nntp_log_and_reply("200 Leafnode %s, pleased to meet you!", 
+		       version);
+  } else {
+    nntp_log_and_reply("500 MODE other than READER not supported");
+  }
+}
 
 void parser(void) {
     char *arg;
@@ -148,9 +177,7 @@
 	n = strlen(cmd);
 	if ( ( n == 0 ) || ( n > MAXLINELENGTH ) ) {
 	    /* ignore attempts at buffer overflow */
-	    if ( debugmode )
-		syslog( LOG_DEBUG, ">500 Dazed and confused" );
-	    printf( "500 Dazed and confused\r\n" );
+	    nntp_log_and_reply ("500 Dazed and confused");
 	    continue;
 	}
 
@@ -170,9 +197,7 @@
 	    cmd[n--] = '\0';
 
 	if (!strcasecmp(cmd, "quit")) {
-	    if ( debugmode )
-		syslog( LOG_DEBUG, ">205 Always happy to serve!" );
-	    printf("205 Always happy to serve!\r\n");
+	    nntp_log_and_reply("205 Always happy to serve!");
 	    return;
 	}
 	rereadactive();
@@ -186,10 +211,6 @@
 	    doarticle(arg, 0);
 	} else if (!strcasecmp(cmd, "help")) {
 	    dohelp();
-	} else if (!strcasecmp(cmd, "ihave")) {
-	    if ( debugmode )
-		syslog( LOG_DEBUG, ">500 IHAVE is for big news servers" );
-	    printf("500 IHAVE is for big news servers\r\n");
 	} else if (!strcasecmp(cmd, "last")) {
 	    domove(-1);
 	} else if (!strcasecmp(cmd, "next")) {
@@ -197,23 +218,13 @@
 	} else if (!strcasecmp(cmd, "list")) {
 	    dolist(arg);
 	} else if (!strcasecmp(cmd, "mode")) {
-	    if ( debugmode )
-		syslog( LOG_DEBUG, ">200 Leafnode %s, pleased to meet you!",
-			version);
-	    printf("200 Leafnode %s, pleased to meet you!\r\n", version);
+	    domode(arg);
 	} else if (!strcasecmp(cmd, "newgroups")) {
 	    donewgroups(arg);
-	} else if (!strcasecmp(cmd, "newnews")) {
-	    if ( debugmode )
-		syslog( LOG_DEBUG,
-			">500 NEWNEWS is meaningless for this server" );
-	    printf( "500 NEWNEWS is meaningless for this server\r\n" );
 	} else if (!strcasecmp(cmd, "post")) {
 	    dopost();
 	} else if (!strcasecmp(cmd, "slave")) {
-	    if ( debugmode )
-		syslog( LOG_DEBUG, ">202 Cool - I always wanted a slave" );
-	    printf("202 Cool - I always wanted a slave\r\n");
+	    nntp_log_and_reply("202 Cool - I always wanted a slave");
 	} else if (!strcasecmp(cmd, "xhdr")) {
 	    doxhdr(arg);
 	} else if (!strcasecmp(cmd, "xover")) {
@@ -225,15 +236,11 @@
 	} else if (!strcasecmp(cmd, "group")) {
 	    dogroup(arg);
 	} else {
-	    if ( debugmode )
-		syslog( LOG_DEBUG, ">500 Unknown command" );
-	    printf("500 Unknown command\r\n");
+	    nntp_log_and_reply("500 Unknown command");
 	}
 	fflush(stdout);
     }
-    if ( debugmode )
-	syslog( LOG_DEBUG, ">421 Network error" );
-    error("421 Network error");
+    nntp_log_and_reply("421 Network error: %s", strerror(errno));
 }
 
 /*
@@ -574,7 +581,7 @@
     printf("  group newsgroup\r\n");
     printf("  head [MessageID|Number]\r\n");
     printf("  help\r\n");
-    printf("  ihave\r\n");
+/*  printf("  ihave\r\n"); */
     printf("  last\r\n");
 /*  printf("  list [active|newsgroups|distributions|schema] [group_pattern]\r\n"); */
     printf("  list [active|newsgroups] [group_pattern]\r\n");