From: Eric Wong Date: Mon, 8 Aug 2022 23:16:47 +0000 (+0000) Subject: imap: prioritize AUTH=ANONYMOUS clients X-Git-Tag: v1.9.0~42 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=6bfbb1d477d1adf40fa15a9f6e326f01cf966fc9 imap: prioritize AUTH=ANONYMOUS clients ...by deprioritizing clients using a username + password. As IMAP provides AUTH=ANONYMOUS for designating anonymous access, we'll rely on it as a heuristic for favoring "good" clients. Clients using a username + password seem to (more often than not) be malicious and looking for info which doesn't belong in public inboxes. This copies the technique used by WWW + -httpd to deprioritize expensive mbox.gz downloads. --- diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 77e2e5e9..5e8a6a66 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -688,7 +688,7 @@ sub requeue_once { # but only after all pending writes are done. # autovivify wbuf. wbuf may be populated by $cb, # no need to rearm if so: (push returns new size of array) - requeue($self) if push(@{$self->{wbuf}}, \&long_step) == 1; + $self->requeue if push(@{$self->{wbuf}}, \&long_step) == 1; } sub long_response ($$;@) { diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 4ef5252b..605c5e51 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -575,6 +575,16 @@ sub fetch_run_ops { $self->msg_more(")\r\n"); } +sub requeue { # overrides PublicInbox::DS::requeue + my ($self) = @_; + if ($self->{anon}) { # AUTH=ANONYMOUS gets high priority + $self->SUPER::requeue; + } else { # low priority + push(@{$self->{imapd}->{-authed_q}}, $self) == 1 and + PublicInbox::DS::requeue($self->{imapd}); + } +} + sub fetch_blob_cb { # called by git->cat_async via ibx_async_cat my ($bref, $oid, $type, $size, $fetch_arg) = @_; my ($self, undef, $msgs, $range_info, $ops, $partial) = @$fetch_arg; diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm index 5368ff04..dd0d2c53 100644 --- a/lib/PublicInbox/IMAPD.pm +++ b/lib/PublicInbox/IMAPD.pm @@ -87,4 +87,11 @@ sub idler_start { $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_cfg}); } +sub event_step { # called vai requeue for low-priority IMAP clients + my ($self) = @_; + my $imap = shift(@{$self->{-authed_q}}) // return; + PublicInbox::DS::requeue($self) if scalar(@{$self->{-authed_q}}); + $imap->event_step; # PublicInbox::IMAP::event_step +} + 1;