]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
imapd|nntpd|pop3d: output IP + port on new connections master
authorEric Wong <e@80x24.org>
Thu, 2 Oct 2025 19:29:39 +0000 (19:29 +0000)
committerEric Wong <e@80x24.org>
Mon, 6 Oct 2025 23:57:55 +0000 (23:57 +0000)
Dumping the IP address will help admins use the (standard)
output of these servers to track abusive IMAP and POP3 scanners
looking for private mail.  NNTP doesn't seem affected at
the moment, but it's easier to keep the common code
across all three of these stateful protocols.

lib/PublicInbox/DS.pm
lib/PublicInbox/Daemon.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/POP3.pm

index 0da84b250897dc3591864fe7add5e0da9fa48597..70c6c844f0b3f2d3d34fbcffc87bb3d639901b6d 100644 (file)
@@ -333,7 +333,7 @@ retry:
 
 # for IMAP, NNTP, and POP3 which greet clients upon connect
 sub greet {
 
 # for IMAP, NNTP, and POP3 which greet clients upon connect
 sub greet {
-       my ($self, $sock) = @_;
+       my ($self, $sock, $addr) = @_;
        my $ev = EPOLLOUT;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return if $! != EAGAIN || !($ev = PublicInbox::TLS::epollbit());
        my $ev = EPOLLOUT;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return if $! != EAGAIN || !($ev = PublicInbox::TLS::epollbit());
@@ -341,6 +341,8 @@ sub greet {
        }
        push @{$self->{wbuf}}, $self->can('do_greet');
        new($self, $sock, $ev | EPOLLONESHOT);
        }
        push @{$self->{wbuf}}, $self->can('do_greet');
        new($self, $sock, $ev | EPOLLONESHOT);
+       ($addr, my $port) = PublicInbox::Daemon::host_with_port($addr);
+       $self->out('['.fileno($sock)."] accept $addr:$port");
        $self;
 }
 
        $self;
 }
 
index 66a25879e011af4f19db1821ed46aba5a50f6b5d..5b43375b3f76866aabfcb26d35ecf546f6eb1762 100644 (file)
@@ -139,7 +139,8 @@ sub load_mod ($;$$) {
                $tlsd->refresh_groups($sig);
        };
        $xn{post_accept} = $tlsd->can('post_accept_cb') ?
                $tlsd->refresh_groups($sig);
        };
        $xn{post_accept} = $tlsd->can('post_accept_cb') ?
-                       $tlsd->post_accept_cb : sub { $modc->new($_[0], $tlsd) };
+                       $tlsd->post_accept_cb :
+                       sub { $modc->new(@_[0, 1], $tlsd) };
        if ($modc eq 'PublicInbox::HTTP') {
                $xn{af_default} = 'httpready';
                if (my $p = $opt->{psgi}) {
        if ($modc eq 'PublicInbox::HTTP') {
                $xn{af_default} = 'httpready';
                if (my $p = $opt->{psgi}) {
index 020a205aeff271ea0bfbe915630ba1f52a0c13f5..c858049226807837d3d2fabb87e63816351b58b3 100644 (file)
@@ -98,8 +98,9 @@ sub do_greet {
 }
 
 sub new {
 }
 
 sub new {
-       my (undef, $sock, $imapd) = @_;
-       (bless { imapd => $imapd }, 'PublicInbox::IMAP_preauth')->greet($sock)
+       my (undef, $sock, $addr, $imapd) = @_;
+       (bless { imapd => $imapd }, 'PublicInbox::IMAP_preauth')
+               ->greet($sock, $addr)
 }
 
 sub logged_in { 1 }
 }
 
 sub logged_in { 1 }
index 5acaea0f6a2ff5ebb949f7a1bf64b9b96924d1d8..49ba1bddba5988ede60513c3455e08e0c7f26bc3 100644 (file)
@@ -49,8 +49,8 @@ COMPRESS DEFLATE\r
 sub do_greet ($) { $_[0]->write($_[0]->{nntpd}->{greet}) };
 
 sub new {
 sub do_greet ($) { $_[0]->write($_[0]->{nntpd}->{greet}) };
 
 sub new {
-       my ($cls, $sock, $nntpd) = @_;
-       (bless { nntpd => $nntpd }, $cls)->greet($sock)
+       my ($cls, $sock, $addr, $nntpd) = @_;
+       (bless { nntpd => $nntpd }, $cls)->greet($sock, $addr)
 }
 
 sub args_ok ($$) {
 }
 
 sub args_ok ($$) {
index 6d24b17c6c00aec1e581e533cc6d1fdfab618229..fae02df88f4ca87e497df2317e43e3e095bf688e 100644 (file)
@@ -58,8 +58,8 @@ sub do_greet {
 }
 
 sub new {
 }
 
 sub new {
-       my ($cls, $sock, $pop3d) = @_;
-       (bless { pop3d => $pop3d }, $cls)->greet($sock)
+       my ($cls, $sock, $addr, $pop3d) = @_;
+       (bless { pop3d => $pop3d }, $cls)->greet($sock, $addr)
 }
 
 # POP user is $UUID1@$NEWSGROUP[.$SLICE][?QUERY_ARGS]
 }
 
 # POP user is $UUID1@$NEWSGROUP[.$SLICE][?QUERY_ARGS]