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

[leafnode-list] test patch for "illegal headers" or "illegal article"



Cory, Mike,

please apply this patch on top of 1.9.52.rc9, compile and install the
patched version and see how the "illegal headers" or "illegal article"
works out. The interesting question is if this makes too much logging in
your cron mails.

Index: leafnode.h
===================================================================
RCS file: /var/CVS/leafnode-1/leafnode.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- leafnode.h	22 Mar 2004 12:57:08 -0000	1.77
+++ leafnode.h	25 Mar 2004 13:57:58 -0000	1.78
@@ -3,7 +3,7 @@
  * conditions.
  */
 
-/* $Id: leafnode.h,v 1.77 2004/03/22 12:57:08 emma Exp $ */
+/* $Id: leafnode.h,v 1.78 2004/03/25 13:57:58 emma Exp $ */
 
 #ifndef LEAFNODE_H
 #define LEAFNODE_H
@@ -368,7 +368,7 @@
 int getxover(void);		/* set xoverinfo, return 0 on error, nonzero else */
 
 int agetcwd(char **buf, size_t *capa);
-int legalxoverline(char *xover, unsigned long artno);
+int legalxoverline(char *xover, const char **errmsg /* out */);
 void freexover(void);
 
 #ifdef CHECKGROUPORDER
Index: texpire.c
===================================================================
RCS file: /var/CVS/leafnode-1/texpire.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- texpire.c	7 Mar 2004 16:51:18 -0000	1.45
+++ texpire.c	25 Mar 2004 13:57:58 -0000	1.46
@@ -215,8 +215,10 @@
 
     /* check the syntax of the .overview info, and delete all illegal stuff */
     for (art = first; art <= last; art++) {
+	const char *x;
+
 	if (articles[art - first].xover &&
-	    !legalxoverline(articles[art - first].xover, art)) {
+	    !legalxoverline(articles[art - first].xover, &x)) {
 	    articles[art - first].xover = NULL;
 	}
     }
Index: xoverutil.c
===================================================================
RCS file: /var/CVS/leafnode-1/xoverutil.c,v
retrieving revision 1.39
diff -u -r1.39 xoverutil.c
--- xoverutil.c	25 Mar 2004 03:49:30 -0000	1.39
+++ xoverutil.c	25 Mar 2004 14:26:20 -0000
@@ -77,14 +77,15 @@
 }
 
 static /*@null@*/ /*@only@*/
-char *getxoverline(const char *filename)
+char *getxoverline(const char *filename, const char **e /** error message is stored here */)
 {
     char *l;
+    const char *em;
     char *result;
     FILE *f;
-    unsigned long art = strtoul(filename, NULL, 10);
 
     result = NULL;
+    *e = NULL;
     debug = 0;
     if ((f = fopen(filename, "r"))) {
 	char *from, *subject, *date, *msgid, *references, *lines, *xref;
@@ -182,11 +183,16 @@
 		strcat(result, xref);	/* RATS: ignore */
 	    }
 	} else {
-	    if (from == NULL) syslog(LOG_DEBUG, "getxoverline: %s lacks From:", filename);
-	    else if (date == NULL) syslog(LOG_DEBUG, "getxoverline: %s lacks Date:", filename);
-	    else if (subject == NULL) syslog(LOG_DEBUG, "getxoverline: %s lacks Subject:", filename);
-	    else if (msgid == NULL) syslog(LOG_DEBUG, "getxoverline: %s lacks Message-ID:", filename);
-	    else if (bytes == 0) syslog(LOG_DEBUG, "getxoverline: %s 0 bytes", filename);
+	    if (from == NULL)
+		*e = "missing From: header";
+	    else if (date == NULL)
+		*e = "missing Date: header";
+	    else if (subject == NULL)
+		*e = "missing Subject: header";
+	    else if (msgid == NULL)
+		*e = "missing Message-ID: header";
+	    else if (bytes == 0)
+		*e = "article has 0 bytes";
 	}
 	(void)fclose(f);
 	if (from)
@@ -204,10 +210,12 @@
 	if (xref)
 	    free(xref);
     } else {
-	syslog(LOG_ERR, "error: getxoverline: cannot open %s: %m", filename);
+	ln_log(LNLOG_SERR, LNLOG_CARTICLE,
+		"error: getxoverline: cannot open %s: %m", filename);
     }
     debug = debugmode;
-    if (result && !legalxoverline(result, art)) {
+    if (result && !legalxoverline(result, &em)) {
+	*e = em;
 	free(result);
 	result = NULL;
     }
@@ -218,7 +226,7 @@
  * return 1 if xover is a legal overview line, 0 else
  */
 int
-legalxoverline(char *xover, unsigned long artno)
+legalxoverline(char *xover, const char **e)
 {
     char *p;
     char *q;
@@ -233,9 +241,7 @@
 	int c = (unsigned char)*p++;
 
 	if ((c != '\t' && c < ' ') || (c > 126 && c < 160)) {
-	    if (debugmode)
-		syslog(LOG_DEBUG,
-		       "%lu xover error: non-printable chars.", artno);
+	    *e = "non-printable characters in headers (relaxed check allows for iso-8859*)";
 	    return 0;
 	}
     }
@@ -243,8 +249,7 @@
     p = xover;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG, "%lu xover error: no Subject: header.", artno);
+	*e = "missing Subject: header";
 	return 0;
     }
 
@@ -252,9 +257,7 @@
 
     while (p != q) {
 	if (!isdigit((unsigned char)*p)) {
-	    if (debugmode)
-		syslog(LOG_DEBUG, "%lu xover error: article "
-		       "number must consists of digits.", artno);
+	    *e = "article number contains non-digit characters";
 	    return 0;
 	}
 	p++;
@@ -263,8 +266,7 @@
     p = q + 1;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG, "%lu xover error: no From: header.", artno);
+	*e = "missing From: header";
 	return 0;
     }
 
@@ -273,8 +275,7 @@
     p = q + 1;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG, "%lu xover error: no Date: header.", artno);
+	*e = "missing Date: header";
 	return 0;
     }
 
@@ -283,8 +284,7 @@
     p = q + 1;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG, "%lu xover error: no Message-ID: header.", artno);
+	*e = "missing Message-ID: header";
 	return 0;
     }
 
@@ -293,48 +293,37 @@
     p = q + 1;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG,
-		   "%lu xover error: no References: or Bytes: header.", artno);
+	*e = "missing References: or Bytes: header";
 	return 0;
     }
 
     /* message-id: <*@*> */
 
     if (*p != '<') {
-	if (debugmode)
-	    syslog(LOG_DEBUG,
-		   "%lu xover error: Message-ID does not start with <.", artno);
+	*e = "Message-ID: does not start with \"<\"";
 	return 0;
     }
     while (p != q && *p != '@' && *p != '>' && *p != ' ')
 	p++;
     if (*p != '@') {
-	if (debugmode)
-	    syslog(LOG_DEBUG,
-		   "%lu xover error: Message-ID does not contain @.", artno);
+	*e = "Message-ID: does not contain @";
 	return 0;
     }
     while (p != q && *p != '>' && *p != ' ')
 	p++;
     if (*p != '>') {
-	if (debugmode)
-	    syslog(LOG_DEBUG,
-		   "%lu xover error: Message-ID does not end with >.", artno);
+	*e = "Message-ID: does not end with \">\"";
 	return 0;
     }
     if (++p != q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG,
-		   "%lu xover error: Message-ID does not end with >.", artno);
+	*e = "Message-ID: does not end with \">\"";
 	return 0;
     }
 
     p = q + 1;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG, "%lu xover error: no Bytes: header.", artno);
+	*e = "missing Bytes: header";
 	return 0;
     }
 
@@ -342,26 +331,19 @@
 
     while (p != q) {
 	if (*p != '<') {
-	    if (debugmode)
-		syslog(LOG_DEBUG, "%lu xover error: "
-		       "Reference does not start with <.", artno);
+	    *e = "References: does not start with \"<\"";
 	    return 0;
 	}
 	while (p != q && *p != '@' && *p != '>' && *p != ' ')
 	    p++;
 	if (*p != '@') {
-	    if (debugmode)
-		syslog(LOG_DEBUG,
-		       "%lu xover error: Reference does not contain @.", artno);
+	    *e = "References: does not contain @";
 	    return 0;
 	}
 	while (p != q && *p != '>' && *p != ' ')
 	    p++;
 	if (*p++ != '>') {
-	    if (debugmode)
-		syslog(LOG_DEBUG,
-		       "%lu xover error: Reference does not end with >.",
-		       artno);
+	    *e = "References: does not end with \">\"";
 	    return 0;
 	}
 	while (p != q && *p == ' ')
@@ -371,8 +353,7 @@
     p = q + 1;
     q = strchr(p, '\t');
     if (!q) {
-	if (debugmode)
-	    syslog(LOG_DEBUG, "%lu xover error: no Lines: header.", artno);
+	*e = "missing Lines: header";
 	return 0;
     }
 
@@ -380,9 +361,7 @@
 
     while (p != q) {
 	if (!isdigit((unsigned char)*p)) {
-	    if (debugmode)
-		syslog(LOG_DEBUG, "%lu xover error: illegal digit "
-		       "in Bytes: header.", artno);
+	    *e = "non-digit character in Bytes: header";
 	    return 0;
 	}
 	p++;
@@ -397,9 +376,7 @@
 
     while (p && *p && p != q) {
 	if (!isdigit((unsigned char)*p)) {
-	    if (debugmode)
-		syslog(LOG_DEBUG, "%lu xover error: illegal digit "
-		       "in Lines: header.", artno);
+	    *e = "non-digit character in Lines: header";
 	    return 0;
 	}
 	p++;
@@ -414,10 +391,10 @@
 
     if (agetcwd(&t, &s_t)) {
 	if (chdir(spooldir)) {
-	    syslog(LOG_ERR, "error: cannot chdir(%s): %m", spooldir);
+	    ln_log(LNLOG_SERR, LNLOG_CTOP, "error: cannot chdir(%s): %m", spooldir);
 	}
 	if (rmdir(t) && errno != ENOTEMPTY) {
-	    syslog(LOG_ERR, "error: cannot rmdir(%s): %m", t);
+	    ln_log(LNLOG_SERR, LNLOG_CTOP, "error: cannot rmdir(%s): %m", t);
 	}
 	free(t);
     }
@@ -462,7 +439,7 @@
     /* find article range */
     d = opendir(".");
     if (!d) {
-	syslog(LOG_ERR, "error: opendir: %m");
+	ln_log(LNLOG_SERR, LNLOG_CTOP, "error: opendir: %m");
 	return 0;
     }
 
@@ -487,7 +464,7 @@
 	closedir(d);
 	(void)unlink(".overview");
 	if (debugmode) {
-	    char *t; size_t s_t;
+	    char *t = NULL; size_t s_t;
 	    if (!agetcwd(&t, &s_t)) {
 		ln_log(LNLOG_SERR, LNLOG_CGROUP, "error: getcwd: %m");
 	    } else {
@@ -513,7 +490,7 @@
 	overview = (char *)critmalloc(st.st_size + 1, "getxover");
 	if ((off_t) read(fd, overview, st.st_size) != st.st_size) {
 	    int e = errno;
-	    char *t; size_t s_t;
+	    char *t = NULL; size_t s_t;
 	    /* short read */
 	    close(fd);
 
@@ -533,7 +510,7 @@
 	    /* iterate line-wise */
 	    p = overview;
 	    while (p && *p) {
-		char *t;
+		const char *t;
 
 		while (p && isspace((unsigned char)*p))
 		    p++;
@@ -542,17 +519,17 @@
 		    *q++ = '\0';
 
 		
-		art = strtoul(p, &t, 10);
-		if (legalxoverline(p, art)) {
+		art = strtoul(p, NULL, 10);
+		if (legalxoverline(p, &t)) {
 		    if (art > xlast || art < xfirst) {
 			error++;
 		    } else if (xoverinfo[art - xfirst].text) {
-			char *tt; size_t s_tt;
+			char *tt = NULL; size_t s_tt;
 			error++;
 			if (!agetcwd(&tt, &s_tt)) {
-			    syslog(LOG_ERR, "error: getcwd: %m");
+			    ln_log(LNLOG_SERR, LNLOG_CARTICLE, "error: getcwd: %m");
 			} else {
-			    syslog(LOG_ERR, "error: multiple lines for article %lu "
+			    ln_log(LNLOG_SERR, LNLOG_CARTICLE, "error: multiple lines for article %lu "
 				    "in .overview for %s", art, tt);
 			    free(tt);
 			}
@@ -562,7 +539,15 @@
 		    } else if (xoverinfo[art - xfirst].exists == 0) {
 			xoverinfo[art - xfirst].text = critstrdup(p, "getxover");
 		    }
-		} /* if (t && *t == '\t') */
+		} else {
+		    char *tt = NULL; size_t s_tt;
+		    if (!agetcwd(&tt, &s_tt)) {
+			ln_log(LNLOG_SERR, LNLOG_CTOP, "error: getcwd: %m");
+		    } else {
+			ln_log(LNLOG_SERR, LNLOG_CTOP, "error: illegal line for article %lu in .overview for %s: %s", art, tt, t);
+			free(tt);
+		    }
+		}
 
 		p = q;
 	    } /* while p && *p */
@@ -570,7 +555,7 @@
     } /* if open && fstat */
 
     if (!agetcwd(&tt, &s_tt)) {
-	syslog(LOG_ERR, "error: getcwd: %m");
+	ln_log(LNLOG_SERR, LNLOG_CTOP, "error: getcwd: %m");
 	closedir(d);
 	return 0;
     }
@@ -582,6 +567,7 @@
 	art = strtoul(de->d_name, &p, 10);
 	if (p && !*p && art >= xfirst && art <= xlast) {
 	    if (!xoverinfo[art - xfirst].text) {
+		const char *e;
 
 		xoverinfo[art - xfirst].exists = 0;
 		if (debugmode) {
@@ -590,16 +576,17 @@
 		}
 		error++;
 		if ((xoverinfo[art - xfirst].text =
-		     getxoverline(de->d_name)) == NULL) {
-		    syslog(LOG_NOTICE, "illegal article: %s/%s",
-			   tt, de->d_name);
+		     getxoverline(de->d_name, &e)) == NULL) {
+		    ln_log(LNLOG_SINFO, LNLOG_CARTICLE,
+			   "article %s/%s contained illegal headers: %s\n",
+			   tt, de->d_name, e);
 		    if ((lstat(de->d_name, &st) == 0) && S_ISREG(st.st_mode)) {
 			if (unlink(de->d_name))
-			    syslog(LOG_WARNING, "warning: failed to remove %s/%s: %m",
-				   tt, de->d_name);
+			    ln_log(LNLOG_SWARNING, LNLOG_CARTICLE,
+				    "warning: failed to remove %s/%s: %m", tt, de->d_name);
 		    } else {
-			syslog(LOG_WARNING, "warning: %s/%s is not a regular file",
-			       tt, de->d_name);
+			ln_log(LNLOG_SWARNING, LNLOG_CARTICLE, 
+				"warning: %s/%s is not a regular file", tt, de->d_name);
 		    }
 		}
 	    }
@@ -609,10 +596,7 @@
 	    xoverinfo[art - xfirst].exists = 1;
 	} else {
 	    /* kill non-article files, like "core" */
-	    if (art == 0
-		&& strcmp(de->d_name, ".overview")
-		&& strcmp(de->d_name, ".")
-		&& strcmp(de->d_name, ".."))
+	    if (art == 0)
 	    {
 		if (unlink(de->d_name)
 		    && errno != EISDIR
@@ -622,15 +606,9 @@
 			    "error: attempted to delete %s/%s in case it's junk: %s\n",
 			   tt, de->d_name, strerror(errno));
 		}
-	    } else if (p && !*p) {
-		if (art >= xfirst && art <= xlast) {
-		    ln_log(LNLOG_SERR, LNLOG_CTOP,
-			   "error: article %s/%lu contained illegal headers\n",
-			   tt, art);
-		}
 	    }
 	}
-    }
+    } /* while (de = readdir(d)) */
 
     /* count removed articles */
     for (art = xfirst; art <= xlast; art++) {
@@ -663,7 +641,7 @@
 		    if (writes(wfd, xoverinfo[art - xfirst].text) == - 1
 			|| writes(wfd, "\n") == -1) 
 		    {
-			syslog(LOG_ERR,
+			ln_log(LNLOG_SERR, LNLOG_CGROUP,
 			       "error: write() for .overview failed: %m");
 			va = 0;
 			break;
@@ -676,10 +654,10 @@
 	    if (va) {
 		if (rename(newfile, ".overview")) {
 		    if (unlink(newfile))
-			syslog(LOG_ERR,
-			       "error: rename() and unlink() both failed: %m");
+			ln_log(LNLOG_SERR, LNLOG_CGROUP,
+			       "error: unlink(%s) failed: %m", newfile);
 		    else
-			syslog(LOG_ERR,
+			ln_log(LNLOG_SERR, LNLOG_CGROUP,
 			       "error: rename(%s/%s, .overview) failed: %m",
 			       tt, newfile);
 		} else {
@@ -692,7 +670,8 @@
 		   .overview file I think */
 	    }
 	} else {
-	    syslog(LOG_ERR, "error: mkstemp of new .overview failed: %m");
+	    ln_log(LNLOG_SERR, LNLOG_CGROUP,
+		    "error: mkstemp of new .overview failed: %m");
 	}
     }
 
@@ -714,7 +693,7 @@
     xsnprintf(s, SIZE_s, "%s/interesting.groups", spooldir);
     d = opendir(s);
     if (!d) {
-	syslog(LOG_ERR, "error: opendir %s: %m", s);
+	ln_log(LNLOG_SERR, LNLOG_CGROUP, "error: opendir %s: %m", s);
 	return;
     }
 

-- 
Matthias Andree

Encrypt your mail: my GnuPG key ID is 0x052E7D95
-- 
_______________________________________________
leafnode-list mailing list
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
http://www.dt.e-technik.uni-dortmund.de/mailman/listinfo/leafnode-list
http://leafnode.sourceforge.net/