From 848fbcda3f97777a60501cc9ade3ff665eefc159 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Oct 2025 19:29:39 +0000 Subject: [PATCH] imapd|nntpd|pop3d: output IP + port on new connections 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 | 4 +++- lib/PublicInbox/Daemon.pm | 3 ++- lib/PublicInbox/IMAP.pm | 5 +++-- lib/PublicInbox/NNTP.pm | 4 ++-- lib/PublicInbox/POP3.pm | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 0da84b250..70c6c844f 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -333,7 +333,7 @@ retry: # 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()); @@ -341,6 +341,8 @@ sub greet { } 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; } diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 66a25879e..5b43375b3 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -139,7 +139,8 @@ sub load_mod ($;$$) { $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}) { diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 020a205ae..c85804922 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -98,8 +98,9 @@ sub do_greet { } 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 } diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 5acaea0f6..49ba1bddb 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -49,8 +49,8 @@ COMPRESS DEFLATE\r 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 ($$) { diff --git a/lib/PublicInbox/POP3.pm b/lib/PublicInbox/POP3.pm index 6d24b17c6..fae02df88 100644 --- a/lib/PublicInbox/POP3.pm +++ b/lib/PublicInbox/POP3.pm @@ -58,8 +58,8 @@ sub do_greet { } 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] -- 2.47.3