Re: allow comments and empty lines in spamd.alloweddomains

Previous thread: pfsync and byte/packet counters by Alexander Sabourenkov on Tuesday, February 17, 2009 - 5:19 am. (5 messages)

Next thread: improve sdmmc/sdhc performance by Miod Vallat on Wednesday, February 18, 2009 - 12:58 am. (1 message)
From: Stephan A. Rickauer
Date: Tuesday, February 17, 2009 - 1:13 pm

I wonder whether something along those lines could be done:

--- grey.c	2009-02-17 20:39:54.000000000 +0100
+++ grey.c-mine	2009-02-17 21:08:27.000000000 +0100
@@ -321,6 +321,8 @@
 		while ((buf = fgetln(fp, &len))) {
 			if (buf[len-1] == '\n')
 				len--;
+		        if (!strlen(buf) || buf[0] == '#')
+			       continue;
 			if ((m = malloc(sizeof(struct mail_addr))) == NULL)
 				goto bad;
 			if ((len + 1) > sizeof(m->addr)) {


I regularely feel surprised not being able to comment my entries ;)

Cheers,
Stephan

-- 
-----------------------------------------------------------
StarTek - secure by design           Tel  ++41 44 500 111-0
Postfach 19                          Fax  ++41 44 500 111-2
CH-8118 Pfaffhausen/ZH               Web  http://startek.ch

RSA public key for email: http://startek.ch/people/star.key
-----------------------------------------------------------

From: Otto Moerbeek
Date: Tuesday, February 17, 2009 - 2:24 pm

This diff is very wrong. To know why, read the fgetln(3) manpage.

	-Otto

From: Stephan A. Rickauer
Date: Tuesday, February 17, 2009 - 3:02 pm

Ups, the man page is _very_ clear indeed ;)

From: d-ra
Date: Tuesday, February 17, 2009 - 3:39 pm

OK, but it would be handy to allow comments. The attached patch honors
fgetln(3) habit not to return C style strings. But it does not detect
empty lines, i.e. lines with len==0.
--- grey.c.orig	Tue Feb 17 23:27:39 2009
+++ grey.c	Tue Feb 17 23:30:57 2009
@@ -321,6 +321,8 @@
 		while ((buf = fgetln(fp, &len))) {
 			if (buf[len-1] == '\n')
 				len--;
+			if ( len && (buf[0]=='#') )
+				continue;
 			if ((m = malloc(sizeof(struct mail_addr))) == NULL)
 				goto bad;
 			if ((len + 1) > sizeof(m->addr)) {

From: Pawel Veselov
Date: Tuesday, February 17, 2009 - 4:45 pm

Umm, may be ---   if (!len || (buf[0] == '#'))  --- ?

From: d-ra
Date: Wednesday, February 18, 2009 - 1:23 am

This would skip also empty lines. This would be another handy feature.

But I didn't want to chance too many things at once to minimize the
risk that nothing is merged into the tree. This is not the first time
we see patches for comments in spamd.alloweddomains on the
mailinglist, but none of them were accepted.

From: Olli Hauer
Date: Tuesday, February 17, 2009 - 11:03 pm

no, this is what I use, it also prevents a failure if someone has a trailing space after the mailaddress (allow entry)

Index: grey.c
===================================================================
RCS file: /cvs/src/libexec/spamd/grey.c,v
retrieving revision 1.45
diff -u -r1.45 grey.c
--- grey.c  7 Dec 2008 21:12:52 -0000   1.45
+++ grey.c  18 Feb 2009 06:02:00 -0000
@@ -319,6 +319,18 @@
        SLIST_REMOVE_HEAD(&match_suffix, entry);
    if ((fp = fopen(alloweddomains_file, "r")) != NULL) {
        while ((buf = fgetln(fp, &len))) {
+           /* strip white space-characters */
+           while (len > 0 && isspace(buf[len-1]))
+               len--;
+           while (len > 0 && isspace(*buf)) {
+               buf++;
+               len--;
+           }
+           /* jump over comments and blank lines */
+           if (*buf == '#' || *buf == '\n')
+               continue;
+           if (len == 0)
+               continue;
            if (buf[len-1] == '\n')
                len--;
            if ((m = malloc(sizeof(struct mail_addr))) == NULL)


-- 
Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
f|r nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

From: patrick keshishian
Date: Tuesday, February 17, 2009 - 11:14 pm

You should do your len check before the check for '#' and '\n'.

--patrick

From: Olli Hauer
Date: Tuesday, February 17, 2009 - 11:20 pm

you are right.


Index: grey.c
===================================================================
RCS file: /cvs/src/libexec/spamd/grey.c,v
retrieving revision 1.45
diff -u -r1.45 grey.c
--- grey.c  7 Dec 2008 21:12:52 -0000   1.45
+++ grey.c  18 Feb 2009 06:02:00 -0000
@@ -319,6 +319,18 @@
        SLIST_REMOVE_HEAD(&match_suffix, entry);
    if ((fp = fopen(alloweddomains_file, "r")) != NULL) {
        while ((buf = fgetln(fp, &len))) {
+           /* strip white space-characters */
+           while (len > 0 && isspace(buf[len-1]))
+               len--;
+           while (len > 0 && isspace(*buf)) {
+               buf++;
+               len--;
+           }
+           /* jump over comments and blank lines */
+           if (len == 0)
+               continue;
+           if (*buf == '#' || *buf == '\n')
+               continue;
            if (buf[len-1] == '\n')
                len--;
            if ((m = malloc(sizeof(struct mail_addr))) == NULL)

-- 
Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
f|r nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

From: Stephan A. Rickauer
Date: Wednesday, February 18, 2009 - 1:44 am

Works for me. Thanks a lot!


From: Bob Beck
Date: Tuesday, February 17, 2009 - 2:32 pm

ahh.. why are you doing it there?  I don't think that does what you think it
does :)  I suggest you not mess with the fgetln/malloc dance.   

	-Bob

Previous thread: pfsync and byte/packet counters by Alexander Sabourenkov on Tuesday, February 17, 2009 - 5:19 am. (5 messages)

Next thread: improve sdmmc/sdhc performance by Miod Vallat on Wednesday, February 18, 2009 - 12:58 am. (1 message)