On 01/25/20 14:48, Edgar Pettijohn wrote:


On 01/25/20 14:24, gil...@poolp.org wrote:
January 25, 2020 9:21 PM, "Edgar Pettijohn" <ed...@pettijohn-web.com> wrote:

On 01/25/20 14:20, gil...@poolp.org wrote:

January 25, 2020 8:50 PM, "Edgar Pettijohn" <ed...@pettijohn-web.com> wrote:

I haven't seen any mention of this, but for some reason in my limited "testing" of filters I have to use \r\n in my responses to smtpd. Is this normal? Doesn't seem to be documented and what
filters I've looked at don't appear to be using \r\n.
Indeed, you must certainly NOT use "\r\n" in filters.

For example without ORS = "\r\n" the following script will cause smtpd to basically just hang. There is no errors reported, but when I attempt to telnet localhost 25 the daemon doesn't greet me.
After adding ORS = "\r\n" everything works as expected.
I'm not familiar with awk beyond very basic uses, could this be due to some flushing not happening by default and which gets triggere with "\r\n" ?

This is another awk filter which doesn't use ORS:

https://github.com/jirutka/opensmtpd-filter-rewrite-from/blob/master/filter-rewrite-from

so I'm not sure why yours block but the solution is not with "\r\n" for sure
I get the same with filter-rewrite-from.
Can you run filter traces while you reproduce ?

Doesn't seem to do much.

laptop$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.

laptop$ sudo smtpd -dv -T filters
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
info: OpenSMTPD 6.6.1-portable starting
debug: init ssl-tree
debug: init ssl-tree
debug: init ssl-tree
debug: init ca-tree
debug: init ca-tree
debug: init ssl-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
debug: using "ram" stat backend
setup_peer: control -> klondike[6603] fd=5
setup_peer: lookup -> control[18573] fd=5
setup_peer: control -> lookup[27107] fd=6
setup_peer: lookup -> pony express[16452] fd=6
setup_peer: control -> pony express[16452] fd=7
setup_peer: lookup -> queue[4582] fd=7
setup_peer: control -> queue[4582] fd=8
setup_peer: control -> scheduler[28554] fd=9
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: klondike -> control[18573] fd=5
setup_peer: klondike -> pony express[16452] fd=6
debug: init ca-tree
setup_done: ca[6603] done
setup_proc: klondike done
setup_proc: control done
setup_done: control[18573] done
debug: init ssl-tree
setup_proc: lookup done
setup_done: lka[27107] done
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: pony express -> control[18573] fd=5
filters init type=proc, name=filter-perl, proc=filter-perl
setup_peer: pony express -> klondike[6603] fd=6
setup_peer: pony express -> lookup[27107] fd=7
setup_peer: pony express -> queue[4582] fd=8
setup_done: pony[16452] done
setup_proc: pony express done
debug: rsa_engine_init: using RSA privsep engine
debug: ecdsa_engine_init: using ECDSA privsep engine
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: scheduler -> control[18573] fd=5
setup_peer: queue -> control[18573] fd=5
setup_peer: scheduler -> queue[4582] fd=6
setup_peer: queue -> pony express[16452] fd=6
setup_peer: queue -> lookup[27107] fd=7
setup_peer: queue -> scheduler[28554] fd=8
setup_proc: queue done
setup_done: queue[4582] done
setup_proc: scheduler done
debug: bounce warning after 4h
setup_done: scheduler[28554] done
smtpd: setup done
debug: parent_send_config_ruleset: reloading
debug: parent_send_config: configuring pony process
debug: parent_send_config: configuring ca process
debug: init private ssl-tree
debug: smtp: listen on 127.0.0.1 port 25 flags 0x2400 pki "" ca ""
debug: smtp: listen on [::1] port 25 flags 0x2400 pki "" ca ""
debug: smtp: listen on [fe80::1%lo0] port 25 flags 0x2400 pki "" ca ""
debug: smtp: will accept at most 1697 clients
debug: queue: done loading queue into scheduler
debug: smtpd: scanning offline queue...
debug: smtpd: offline scanning done

I also have the same problem with perl:

#!/usr/pkg/bin/perl
#

open(my $fh, ">>", "/tmp/report.txt");

select($fh);
$|++;
select(stdout);
$|++;

while (my $line = <>) {
        if ($line =~ /config|ready/) {
                print "register|report|smtp-in|*\r\n";
                print "register|ready\r\n";
                #print "register|report|smtp-in|*";
                #print "register|ready";
        }

        chomp $line;

        print $fh $line . "\n";
}

Following with the \r\n lines uncommented and the others commented out.

laptop$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 netbsd ESMTP OpenSMTPD

laptop$ sudo smtpd -dv -T filters
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
info: OpenSMTPD 6.6.1-portable starting
debug: init ssl-tree
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: init ssl-tree
debug: using "ram" stat backend
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: init ca-tree
debug: using "fs" queue backend
debug: init ssl-tree
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: control -> klondike[6520] fd=5
setup_peer: klondike -> control[18812] fd=5
setup_peer: lookup -> control[18812] fd=5
setup_peer: control -> lookup[8702] fd=6
setup_peer: lookup -> pony express[29130] fd=6
setup_peer: klondike -> pony express[29130] fd=6
setup_peer: control -> pony express[29130] fd=7
setup_peer: lookup -> queue[27683] fd=7
setup_peer: control -> queue[27683] fd=8
setup_done: ca[6520] done
setup_proc: klondike done
setup_peer: control ->debug: init ca-tree
 scheduler[20214] fd=9
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: queue -> control[18812] fd=5
setup_done: control[18812] done
setup_proc: lookup done
setup_done: lka[8702] done
setup_peer: queue -> pony express[29130] fd=6
setup_proc: control done
setup_peer: queue -> lookup[8702] fd=7
setup_peer: queue -> scheduler[20214] fd=8
filters init type=proc, name=filter-perl, proc=filter-perl
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: scheduler -> control[18812] fd=5
setup_peer: scheduler -> queue[27683] fd=6
debug: init ssl-tree
debug: init ca-tree
debug: init ssl-tree
debug: using "fs" queue backend
debug: using "ramqueue" scheduler backend
debug: using "ram" stat backend
setup_peer: pony express -> control[18812] fd=5
setup_peer: pony express -> klondike[6520] fd=6
setup_peer: pony express -> lookup[8702] fd=7
setup_peer: pony express -> queue[27683] fd=8
setup_proc: pony express done
setup_done: pony[29130] done
setup_proc: queue done
setup_done: queue[27683] done
setup_proc: scheduler done
debug: bounce warning after 4h
setup_done: scheduler[20214] done
smtpd: setup done
debug: rsa_engine_init: using RSA privsep engine
debug: ecdsa_engine_init: using ECDSA privsep engine
debug: parent_send_config_ruleset: reloading
debug: parent_send_config: configuring pony process
debug: parent_send_config: configuring ca process
debug: init private ssl-tree
debug: smtp: listen on 127.0.0.1 port 25 flags 0x2400 pki "" ca ""
debug: smtp: listen on [::1] port 25 flags 0x2400 pki "" ca ""
debug: smtp: listen on [fe80::1%lo0] port 25 flags 0x2400 pki "" ca ""
debug: smtp: will accept at most 1697 clients
debug: queue: done loading queue into scheduler
debug: smtpd: scanning offline queue...
debug: smtpd: offline scanning done
9817e269b7d12cd1 smtp connected address=[::1] host=localhost
9817e269b7d12cd1 filters session-begin
9817e269b7d12cd1 filters protocol phase=connect, resume=n, action=proceed

laptop$ tail /tmp/report.txt
report|0.5|1579985176.668641|smtp-in|filter-response|3ab5dd0ec0f58629|quit|proceed report|0.5|1579985176.668641|smtp-in|filter-response|3ab5dd0ec0f58629|quit|proceed report|0.5|1579985176.668647|smtp-in|protocol-server|3ab5dd0ec0f58629|221 2.0.0 Bye report|0.5|1579985176.668647|smtp-in|protocol-server|3ab5dd0ec0f58629|221 2.0.0 Bye report|0.5|1579985176.668647|smtp-in|protocol-server|3ab5dd0ec0f58629|221 2.0.0 Bye report|0.5|1579985176.668647|smtp-in|protocol-server|3ab5dd0ec0f58629|221 2.0.0 Bye
report|0.5|1579985176.668697|smtp-in|link-disconnect|3ab5dd0ec0f58629
report|0.5|1579985176.668697|smtp-in|link-disconnect|3ab5dd0ec0f58629
report|0.5|1579985176.668697|smtp-in|link-disconnect|3ab5dd0ec0f58629
report|0.5|1579985176.668697|smtp-in|link-disconnect|3ab5dd0ec0f58629



The following c filter behaves correctly without \r\n.

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int
main(int argc, char *argv[])
{
        char *line = NULL;
        size_t linesize = 0;
        ssize_t linelen;
        FILE *fp;

        fp = fopen("/tmp/report.txt", "a");
        if (fp == NULL)
                err(1, "fopen");

        while ((linelen = getline(&line, &linesize, stdin)) != -1) {
                if (strncasecmp(line, "config|ready", 12) == 0) {
                        fprintf(stdout, "register|report|smtp-in|*\n");
                        fprintf(stdout, "register|ready\n");
                        fflush(stdout);
                }

                fprintf(fp, "%s", line);
                fflush(fp);
        }

        free(line);

        if (ferror(stdin))
                err(1, "getline");

        return 0;
}


Reply via email to