Yahoo Groups archive

Milter-greylist

Index last updated: 2026-04-28 23:32 UTC

Thread

Little issue with conf parser

Little issue with conf parser

2004-06-14 by Cyril Guibourg

According to greyist.conf manpage, comments can be placed after a statement
on the same line

A line like:
addr 213.91.0.0/17	# Teaser / Firstream

is seen by conf_lex as ADDR IPADDR CIDR instead of ADDR IPADDR CIDR COMMENT.
This ends into parser error that prevents processing of the remaining of the
configuration file.

I tried to fix the token definition but I think that it breaks RFC2882
when considering atext lexical definition in dot-atom part of a SMTP addy.

The diff is:

--- conf_lex.l.orig     Tue Jun  1 18:15:49 2004
+++ conf_lex.l  Mon Jun 14 20:09:19 2004
@@ -38,7 +38,7 @@
 all            [Aa][Ll][Ll]
 delay          -?[0-9]{1,}[smhdw]?
 path           "\""[^"\n]{1,}"\""
-regex          "/"[^/\n]{1,}"/"
+regex          "/"[^/#\n]{1,}"/"
 dumpfreq       [Dd][Uu][Mm][Pp][Ff][Rr][Ee][Qq]:?
 timeout                [Tt][Ii][Mm][Ee][Oo][Uu][Tt]:?
 domain         [Dd][Oo][Mm][Aa][Ii][Nn]:?


Given the following configuration file

$ cat /milter/greylist.conf 
quiet
dumpfile "/var/db/milter-greylist/greylist.db"
addr 127.0.0.0/8
addr 192.168.0.0/16     # My private netblock
addr 213.91.0.0/17      # Teaser / Firstream
rcpt    spamtrap@...
rcpt    /.*@.../
rcpt    /[#.]*@.../


Before patch:

$ ./milter-greylist -Dv -f /milter/greylist.conf -p /milter/sock
load exception net 127.0.0.0/255.0.0.0
load exception net 192.168.0.0/255.255.0.0
error at line 5: syntax error
milter-greylist: cannot read dumpfile "/var/db/milter-greylist/greylist.db"
milter-greylist: starting with an empty greylist
^Cmilter-greylist: greylist: mi_stop=2
milter-greylist: Final database dump: no change to dump
milter-greylist: Exitting

After patch:

$ ./milter-greylist -Dv -f /milter/greylist.conf -p /milter/sock
load exception net 127.0.0.0/255.0.0.0
load exception net 192.168.0.0/255.255.0.0
load exception net 213.91.0.0/255.255.128.0
load exception rcpt spamtrap@...
load exception rcpt regex .*@...
unknown token "/" line 8


Any clue ?  What about patching the man page ? :)

Thanks.

Re: [milter-greylist] Little issue with conf parser

2004-06-14 by manu@netbsd.org

Cyril Guibourg <cg+milter-greylist@...> wrote:

> addr 213.91.0.0/17    # Teaser / Firstream

Um, true. I don't see how to fix that yet, but I'm sure it's possible.
Anyone has a suggestion? (remove the lex/yacc parser is a bad suggestion
:)

-- 
Emmanuel Dreyfus
Il y a 10 sortes de personnes dans le monde: ceux qui comprennent 
le binaire et ceux qui ne le comprennent pas.
manu@...

Re: [milter-greylist] Little issue with conf parser

2004-06-14 by Dan Hollis

On Mon, 14 Jun 2004 manu@... wrote:
> Cyril Guibourg <cg+milter-greylist@...> wrote:
> > addr 213.91.0.0/17    # Teaser / Firstream
> Um, true. I don't see how to fix that yet, but I'm sure it's possible.
> Anyone has a suggestion? (remove the lex/yacc parser is a bad suggestion
> :)

Make a better parser and use that instead? You dont have to _remove_ the 
lex/yacc parser, just dont use it :-)

FWIW I still think a lex/yacc parser is suboptimal, IMHO a self written 
parser would be easier to modify / maintain.

-Dan

Re: [milter-greylist] Little issue with conf parser

2004-06-14 by Matthieu Herrb

manu@... wrote:

> Cyril Guibourg <cg+milter-greylist@...> wrote:
> 
> 
>>addr 213.91.0.0/17    # Teaser / Firstream
> 
> 
> Um, true. I don't see how to fix that yet, but I'm sure it's possible.
> Anyone has a suggestion? (remove the lex/yacc parser is a bad suggestion
> :)

You can eat comments to the end of line in the lexer using C code 
instead of using an expression. Iirc the usual idiom for that is 
something like:

"#" { 	while (input() != '\n')
		;
	conf_line++;
     }

-- 
					Matthieu

Re: [milter-greylist] Little issue with conf parser

2004-06-14 by manu@netbsd.org

Dan Hollis <goemon@...> wrote:

> FWIW I still think a lex/yacc parser is suboptimal, IMHO a self written
> parser would be easier to modify / maintain.

Yes, I know your point of view. My point of view is that I'm not as
comfortable as you are with writing parsers, so I prefer to work with
lex & yacc.

-- 
Emmanuel Dreyfus
Il y a 10 sortes de personnes dans le monde: ceux qui comprennent 
le binaire et ceux qui ne le comprennent pas.
manu@...

Re: [milter-greylist] Little issue with conf parser

2004-06-14 by manu@netbsd.org

Matthieu Herrb <matthieu.herrb@...> wrote:

> You can eat comments to the end of line in the lexer using C code 
> instead of using an expression. Iirc the usual idiom for that is 
> something like:
> 
> "#" {         while (input() != '\n')
>               ;
>       conf_line++;
>      }

It does not sems to work as expected, or this does not fix the problem
we currently have. This will still trigger an error with this patch:
addr 213.91.0.0/17      # Teaser / Firstream

-- 
Emmanuel Dreyfus
Il y a 10 sortes de personnes dans le monde: ceux qui comprennent 
le binaire et ceux qui ne le comprennent pas.
manu@...

Re: [milter-greylist] Little issue with conf parser

2004-06-15 by Matthias Scheler

On Tue, Jun 15, 2004 at 01:24:34AM +0200, Emmanuel Dreyfus wrote:
> It does not sems to work as expected, or this does not fix the problem
> we currently have. This will still trigger an error with this patch:
> addr 213.91.0.0/17      # Teaser / Firstream

Can't you rewrite the input function to ignore anything after a '#' until
a newline is found?

	Kind regards

-- 
Matthias Scheler                                  http://scheler.de/~matthias/

Re: [milter-greylist] Little issue with conf parser

2004-06-15 by Cyril Guibourg

Matthias Scheler <tron@...> writes:

> Can't you rewrite the input function to ignore anything after a '#' until
> a newline is found?

My understanding of dot-atom definition in RFC2882 is that '#' is a
valid character for smtp address.

Re: [milter-greylist] Little issue with conf parser

2004-06-15 by Emmanuel Dreyfus

On Tue, Jun 15, 2004 at 10:43:41AM +0200, Cyril Guibourg wrote:
> My understanding of dot-atom definition in RFC2882 is that '#' is a
> valid character for smtp address.

Easy fix: document that comments are only lines starting by a #

-- 
Emmanuel Dreyfus
manu@...

Re: [milter-greylist] Little issue with conf parser

2004-06-15 by Cyril Guibourg

Emmanuel Dreyfus <manu@...> writes:

> Easy fix: document that comments are only lines starting by a #

This exactly what I meant when asking about patching the man page in my
initial message !

So, here is the fix:

--- greylist.conf.5.orig        Wed May 26 23:50:13 2004
+++ greylist.conf.5     Tue Jun 15 11:02:28 2004
@@ -40,8 +40,8 @@
 configures 
 .Xr milter-greylist 8
 operation. The format is simple: each line contains a keyword and an 
-optionnal argument. Anything between a # and the end of a line is 
-considered as a comment and is ignored. Blank lines are ignored as well.
+optionnal argument. Any line starting with a # is considered as a comment
+and is ignored. Blank lines are ignored as well.
 .Sh WHITELIST
 The primary use of 
 .Nm


:-)

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.