INN commit: trunk (6 files)

INN Commit Russ_Allbery at isc.org
Thu Aug 28 19:32:24 UTC 2008


    Date: Thursday, August 28, 2008 @ 12:32:23
  Author: iulius
Revision: 7983

Add a new function IsValidMessageID(char *string) which returns
whether a string is a valid message-ID according to RFC 3977.

Added:
  trunk/lib/messageid.c
    (from rev 7957, trunk/lib/genid.c)
Modified:
  trunk/MANIFEST
  trunk/include/inn/libinn.h
  trunk/lib/Makefile
  trunk/nnrpd/article.c
Deleted:
  trunk/lib/genid.c

----------------------+
 MANIFEST             |   10 ++---
 include/inn/libinn.h |    1 
 lib/Makefile         |   12 +++---
 lib/genid.c          |   39 ---------------------
 lib/messageid.c      |   90 +++++++++++++++++++++++++++++++++++++++++++++++++
 nnrpd/article.c      |   10 ++++-
 6 files changed, 111 insertions(+), 51 deletions(-)

Modified: MANIFEST
===================================================================
--- MANIFEST	2008-08-28 06:36:03 UTC (rev 7982)
+++ MANIFEST	2008-08-28 19:32:23 UTC (rev 7983)
@@ -493,13 +493,12 @@
 lib/fdlimit.c                         File descriptor limits
 lib/fseeko.c                          fseeko replacement
 lib/ftello.c                          ftello replacement
-lib/genid.c                           Generate a message ID
 lib/getaddrinfo.c                     getaddrinfo replacement
 lib/getfqdn.c                         Get FQDN of local host
 lib/getmodaddr.c                      Get a moderator's address
 lib/getnameinfo.c                     getnameinfo replacement
 lib/getpagesize.c                     getpagesize replacement
-lib/hash.c                            Create hash from message ID
+lib/hash.c                            Create hash from a message-ID
 lib/hashtab.c                         Generic hash table
 lib/hex.c                             Convert to and from hex strings
 lib/hstrerror.c                       Error reporting for resolver
@@ -514,6 +513,7 @@
 lib/makedir.c                         Make directory recursively
 lib/md5.c                             MD5 checksum calculation
 lib/memcmp.c                          memcmp replacement
+lib/messageid.c                       Functions for message-IDs
 lib/messages.c                        Error reporting and debug output
 lib/mkstemp.c                         mkstemp replacement
 lib/mmap.c                            mmap manipulation routines
@@ -588,8 +588,8 @@
 nnrpd/Makefile                        Makefile for nnrpd
 nnrpd/article.c                       Article-related routines
 nnrpd/auth-ext.c                      External authentication handling
-nnrpd/cache.c                         MessageID cache routines
-nnrpd/cache.h                         MessageID cache interfaces
+nnrpd/cache.c                         Message-ID cache routines
+nnrpd/cache.h                         Message-ID cache interfaces
 nnrpd/commands.c                      Assorted server commands
 nnrpd/group.c                         Group-related routines
 nnrpd/line.c                          Long line-by-line reading routines
@@ -784,7 +784,7 @@
 tests/data/articles/bad-hdr-trunc     News article with colon then newline
 tests/data/articles/bad-long-cont     News article with long continuation line
 tests/data/articles/bad-long-hdr      News article with long header
-tests/data/articles/bad-msgid         News article without a message ID
+tests/data/articles/bad-msgid         News article without a message-ID
 tests/data/articles/bad-no-body       News article without a body
 tests/data/articles/bad-no-header     News article without a header
 tests/data/articles/bad-nul-body      News article with a nul in the body

Modified: include/inn/libinn.h
===================================================================
--- include/inn/libinn.h	2008-08-28 06:36:03 UTC (rev 7982)
+++ include/inn/libinn.h	2008-08-28 19:32:23 UTC (rev 7983)
@@ -145,6 +145,7 @@
 
 /* Headers. */
 extern char *           GenerateMessageID(char *domain);
+extern bool             IsValidMessageID(const char *string);
 extern void             HeaderCleanFrom(char *from);
 extern struct _DDHANDLE * DDstart(FILE *FromServer, FILE *ToServer);
 extern void               DDcheck(struct _DDHANDLE *h, char *group);

Modified: lib/Makefile
===================================================================
--- lib/Makefile	2008-08-28 06:36:03 UTC (rev 7982)
+++ lib/Makefile	2008-08-28 19:32:23 UTC (rev 7983)
@@ -8,9 +8,9 @@
 # The base library files that are always compiled and included.
 SOURCES       = buffer.c cleanfrom.c clientactive.c clientlib.c concat.c \
 		conffile.c confparse.c daemonize.c date.c dbz.c defdist.c \
-		dispatch.c fdflags.c fdlimit.c genid.c getfqdn.c \
+		dispatch.c fdflags.c fdlimit.c getfqdn.c \
 		getmodaddr.c hash.c hashtab.c hex.c innconf.c inndcomm.c \
-		list.c localopen.c lockfile.c makedir.c md5.c messages.c \
+		list.c localopen.c lockfile.c makedir.c md5.c messageid.c messages.c \
 		mmap.c network.c newsuser.c nntp.c qio.c radix32.c \
 		readin.c remopen.c \
 		reservedfd.c resource.c sendarticle.c sendpass.c sequence.c \
@@ -144,10 +144,6 @@
 fdlimit.o: fdlimit.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/libinn.h ../include/inn/defines.h
-genid.o: genid.c ../include/config.h ../include/inn/defines.h \
-  ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
-  ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
-  ../include/inn/libinn.h
 getfqdn.o: getfqdn.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/libinn.h ../include/inn/defines.h \
@@ -197,6 +193,10 @@
 md5.o: md5.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/md5.h ../include/inn/defines.h
+messageid.o: messageid.c ../include/config.h ../include/inn/defines.h \
+  ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
+  ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
+  ../include/inn/libinn.h
 messages.o: messages.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/messages.h ../include/inn/defines.h \

Deleted: lib/genid.c
===================================================================
--- lib/genid.c	2008-08-28 06:36:03 UTC (rev 7982)
+++ lib/genid.c	2008-08-28 19:32:23 UTC (rev 7983)
@@ -1,39 +0,0 @@
-/*  $Id$
-**
-**  Generate a message ID.
-*/
-
-#include "config.h"
-#include "clibrary.h"
-#include <time.h>
-
-#include "inn/innconf.h"
-#include "inn/libinn.h"
-
-/* Scale time back a bit, for shorter Message-ID's. */
-#define OFFSET	673416000L
-
-char *
-GenerateMessageID(char *domain)
-{
-    static char		buff[SMBUF];
-    static int		count;
-    char		*p;
-    char		sec32[10];
-    char		pid32[10];
-    time_t		now;
-
-    now = time(NULL);
-    Radix32(now - OFFSET, sec32);
-    Radix32(getpid(), pid32);
-    if ((domain != NULL && innconf->domain == NULL) ||
-	(domain != NULL && innconf->domain != NULL
-         && strcmp(domain, innconf->domain) != 0)) {
-	p = domain;
-    } else {
-	if ((p = GetFQDN(domain)) == NULL)
-	    return NULL;
-    }
-    snprintf(buff, sizeof(buff), "<%s$%s$%d@%s>", sec32, pid32, ++count, p);
-    return buff;
-}

Copied: trunk/lib/messageid.c (from rev 7957, trunk/lib/genid.c)
===================================================================
--- lib/messageid.c	                        (rev 0)
+++ lib/messageid.c	2008-08-28 19:32:23 UTC (rev 7983)
@@ -0,0 +1,90 @@
+/*  $Id$
+**
+**  Routines for message-IDs:  generation and checks.
+*/
+
+#include "config.h"
+#include "clibrary.h"
+#include <time.h>
+
+#include "inn/innconf.h"
+#include "inn/libinn.h"
+
+/* Scale time back a bit, for shorter message-ID's. */
+#define OFFSET	673416000L
+
+char *
+GenerateMessageID(char *domain)
+{
+    static char		buff[SMBUF];
+    static int		count;
+    char		*p;
+    char		sec32[10];
+    char		pid32[10];
+    time_t		now;
+
+    now = time(NULL);
+    Radix32(now - OFFSET, sec32);
+    Radix32(getpid(), pid32);
+    if ((domain != NULL && innconf->domain == NULL) ||
+	(domain != NULL && innconf->domain != NULL
+         && strcmp(domain, innconf->domain) != 0)) {
+	p = domain;
+    } else {
+	if ((p = GetFQDN(domain)) == NULL)
+	    return NULL;
+    }
+    snprintf(buff, sizeof(buff), "<%s$%s$%d@%s>", sec32, pid32, ++count, p);
+    return buff;
+}
+
+
+/*
+** We currently only check the requirements for RFC 3977:
+**
+**   o  A message-ID MUST begin with "<", end with ">", and MUST NOT
+**      contain the latter except at the end.
+**
+**   o  A message-ID MUST be between 3 and 250 octets in length.
+**
+**   o  A message-ID MUST NOT contain octets other than printable US-ASCII
+**      characters.
+*/
+bool
+IsValidMessageID(const char *string)
+{
+    int len = 0;
+    const unsigned char *p;
+
+    /* Not NULL. */
+    if (string == NULL)
+        return false;
+
+    p = (const unsigned char *) string;
+
+    /* Begins with "<". */
+    if (p[0] != '<')
+        return false;
+
+    for (; *p != '\0'; p++) {
+        len++;
+        /* Contains ">" *only* at the end. */
+        if (*p == '>') {
+            p++;
+            if (*p != '\0')
+                return false;
+            else
+                break;
+        }
+        /* Contains only US-ASCII characters. */
+        if (*p < 33 || *p == 127)
+            return false;
+    } 
+
+    /* Between 3 and 250 octets in length.
+     * Ends with ">". */
+    if (len < 3 || len > 250 || p[-1] != '>')
+        return false;
+    else
+        return true;
+}

Modified: nnrpd/article.c
===================================================================
--- nnrpd/article.c	2008-08-28 06:36:03 UTC (rev 7982)
+++ nnrpd/article.c	2008-08-28 19:32:23 UTC (rev 7983)
@@ -614,7 +614,7 @@
 	break;
     case 'h': case 'H':
 	what = &SENDhead;
-	/* Poster might do a "head" command to verify the article. */
+	/* Poster might do a HEAD command to verify the article. */
 	ok = PERMcanread || PERMcanpost;
 	break;
     }
@@ -626,6 +626,10 @@
 
     /* Requesting by Message-ID? */
     if (ac == 2 && av[1][0] == '<') {
+        if (!IsValidMessageID(av[1])) {
+            Reply("%d Syntax error in Message-ID\r\n", NNTP_ERR_SYNTAX);
+            return;
+        }
 	if (!ARTopenbyid(av[1], &art, final)) {
 	    Reply("%d No such article\r\n", NNTP_FAIL_NOTFOUND);
 	    return;
@@ -1023,6 +1027,10 @@
     do {
 	/* Message-ID specified? */
 	if (ac > 2 && av[2][0] == '<') {
+            if (!IsValidMessageID(av[2])) {
+                Reply("%d Syntax error in Message-ID\r\n", NNTP_ERR_SYNTAX);
+                return;
+            }
 	    p = av[2];
 	    if (!ARTopenbyid(p, &artnum, false)) {
 		Printf("%d No such article.\r\n", NNTP_FAIL_NOTFOUND);



More information about the inn-committers mailing list