Re: Regex in db table

2021-09-01 Thread mimerunner

Maybe if I had sent you the proper diff it would have worked...

Index: table_db.c
===
RCS file: /cvs/src/usr.sbin/smtpd/table_db.c,v
retrieving revision 1.22
diff -u -p -r1.22 table_db.c
--- table_db.c  23 Jan 2021 16:11:11 -  1.22
+++ table_db.c  1 Sep 2021 11:19:02 -
@@ -55,7 +55,9 @@ static char *table_db_get_entry_match(vo

  struct table_backend table_backend_db = {
"db",
-   
K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP,
+   K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|
+   K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP|K_RELAYHOST|
+   K_STRING|K_REGEX,
table_db_config,
NULL,
NULL,
@@ -72,7 +74,8 @@ static struct keycmp {
  } keycmp[] = {
{ K_DOMAIN, table_domain_match },
{ K_NETADDR, table_netaddr_match },
-   { K_MAILADDR, table_mailaddr_match }
+   { K_MAILADDR, table_mailaddr_match },
+   { K_REGEX, table_regex_match },
  };

  struct dbhandle {


Thanks, with this patch it works!




Re: Regex in db table

2021-09-01 Thread gilles
September 1, 2021 1:01 PM, mimerun...@gmx.de wrote:

>> Care to try the following diff ?
>> --- table_db.c.orig.txt 2021-08-28 15:50:28.0 +0200
>> +++ table_db.c 2021-08-28 15:50:10.0 +0200
>> @@ -42,7 +42,9 @@ static char *table_db_get_entry_match(vo
>> 
>> struct table_backend table_backend_db = {
>> "db",
>> - 
>> K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP,
>> + K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|
>> + K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP|K_RELAYHOST|
>> + K_STRING|K_REGEX,
>> table_db_config,
>> NULL,
>> NULL,
> 
> Thank you gilles. I tried the patch but unfortunately the behaviour is
> exactly the same as before.
> 
> $ makemap -U myregex.db
> .*
> 
> The filter with this table should always match, but it only matches the
> literal string ".*" When switching the table to file:/ backend the regex
> works as expected.


Maybe if I had sent you the proper diff it would have worked...


Index: table_db.c
===
RCS file: /cvs/src/usr.sbin/smtpd/table_db.c,v
retrieving revision 1.22
diff -u -p -r1.22 table_db.c
--- table_db.c  23 Jan 2021 16:11:11 -  1.22
+++ table_db.c  1 Sep 2021 11:19:02 -
@@ -55,7 +55,9 @@ static char *table_db_get_entry_match(vo
 
 struct table_backend table_backend_db = {
"db",
-   
K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP,
+   K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|
+   K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP|K_RELAYHOST|
+   K_STRING|K_REGEX,
table_db_config,
NULL,
NULL,
@@ -72,7 +74,8 @@ static struct keycmp {
 } keycmp[] = {
{ K_DOMAIN, table_domain_match },
{ K_NETADDR, table_netaddr_match },
-   { K_MAILADDR, table_mailaddr_match }
+   { K_MAILADDR, table_mailaddr_match },
+   { K_REGEX, table_regex_match },
 };
 
 struct dbhandle {



Re: Regex in db table

2021-08-27 Thread Edgar Pettijohn



On 8/26/21 6:25 AM, Jack wrote:

Could you resend with proper line breaks. This is difficult to read.



Sorry, the line breaks got messed up.

I'm using OpenSTMPD 6.8 portable and want to filter on DNS names or HELO
strings with regular expressions. Therefore I created the following
minified config:


$ cat /etc/opensmtpd/smptd.conf
table helotable db:/etc/opensmtpd/helotable.db
filter block_helo phase helo match helo regex  disconnect
"554 Not welcome"
listen on 0.0.0.0 filter { block_helo }

$ makemaup -U /etc/opensmtpd/helotable.db
myte.t 


However the filter "block_helo" only matches when someone connects with
the verbatim string "HELO myte.t" (with a dot), which is of course not
how regex are supposed to work.
As soon as I replace the database entry with a regular text file (table
helotable file:/etc/opensmtpd/helotable.txt), the regex starts to work,
ie "HELO mytest" or "HELO mytett" are matched.
Question: How can I use regular expressions in db files? Text files
don't seem to be an option, because they are only read on startup so I
cannot update them on the fly.

You can update `file' tables with `smtpctl update table helotable'. If 
it is a bug in the db table I'm willing to bet it won't be fixed. As I 
recall it is on the chopping block. Don't think its built by default on 
portable at least.



Edgar




Re: Regex in db table

2021-08-26 Thread Thomas Bohl

Question: How can I use regular expressions in db files?


Don't know, but



Text files
don't seem to be an option, because they are only read on startup so I
cannot update them on the fly.


# smtpctl update table helotable


File is recommended over db:
https://www.mail-archive.com/misc@opensmtpd.org/msg03302.html



Re: Regex in db table

2021-08-26 Thread Jack

Could you resend with proper line breaks. This is difficult to read.



Sorry, the line breaks got messed up.

I'm using OpenSTMPD 6.8 portable and want to filter on DNS names or HELO
strings with regular expressions. Therefore I created the following
minified config:


$ cat /etc/opensmtpd/smptd.conf
table helotable db:/etc/opensmtpd/helotable.db
filter block_helo phase helo match helo regex  disconnect
"554 Not welcome"
listen on 0.0.0.0 filter { block_helo }

$ makemaup -U /etc/opensmtpd/helotable.db
myte.t 


However the filter "block_helo" only matches when someone connects with
the verbatim string "HELO myte.t" (with a dot), which is of course not
how regex are supposed to work.
As soon as I replace the database entry with a regular text file (table
helotable file:/etc/opensmtpd/helotable.txt), the regex starts to work,
ie "HELO mytest" or "HELO mytett" are matched.
Question: How can I use regular expressions in db files? Text files
don't seem to be an option, because they are only read on startup so I
cannot update them on the fly.



Re: Regex in db table

2021-08-25 Thread Edgar Pettijohn



On 8/25/21 2:43 AM, Jack wrote:

Hello list,

I already posted this on the bug tracker of OpenSMTPD, but maybe I'm
doing something wrong in the config and you can help me:

I'm using OpenSTMPD 6.8 portable and want to filter on DNS names or HELO
strings with regular expressions. Therefore I created the following
minified config:




||$ cat /etc/opensmtpd/smptd.conf |table helotable
db:/etc/opensmtpd/helotable.db filter block_helo phase helo match helo
regex  disconnect "554 Not welcome" listen on 0.0.0.0 filter
{ block_helo } $ cat /etc/opensmtpd/helotable.txt myte.t
| However the filter block_helo only
matches when someone connects with the verbatim string "HELO myte.t"
(with a dot). As soon as I replace the database entry with a regular
text file, the regex starts to work, ie "HELO mytest" or "HELO mytett"
are matched. How can I use regular expressions in db files? Text files
don't seem to be an option, because they are only read on startup so I
cannot update them on the fly. Thanks in advance. ||



Could you resend with proper line breaks. This is difficult to read.


Edgar




Regex in db table

2021-08-25 Thread Jack

Hello list,

I already posted this on the bug tracker of OpenSMTPD, but maybe I'm
doing something wrong in the config and you can help me:

I'm using OpenSTMPD 6.8 portable and want to filter on DNS names or HELO
strings with regular expressions. Therefore I created the following
minified config:




||$ cat /etc/opensmtpd/smptd.conf |table helotable
db:/etc/opensmtpd/helotable.db filter block_helo phase helo match helo
regex  disconnect "554 Not welcome" listen on 0.0.0.0 filter
{ block_helo } $ cat /etc/opensmtpd/helotable.txt myte.t
| However the filter block_helo only
matches when someone connects with the verbatim string "HELO myte.t"
(with a dot). As soon as I replace the database entry with a regular
text file, the regex starts to work, ie "HELO mytest" or "HELO mytett"
are matched. How can I use regular expressions in db files? Text files
don't seem to be an option, because they are only read on startup so I
cannot update them on the fly. Thanks in advance. ||