unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] net_reader: don't approve/reject credentials w/o "fill"
@ 2021-09-06  7:11 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-09-06  7:11 UTC (permalink / raw)
  To: meta

Credentials sourced via ~/.netrc should not be written to
git-credential.
---
 lib/PublicInbox/GitCredential.pm |  1 +
 lib/PublicInbox/NetReader.pm     | 12 ++++++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/GitCredential.pm b/lib/PublicInbox/GitCredential.pm
index b29780d6..c83fed43 100644
--- a/lib/PublicInbox/GitCredential.pm
+++ b/lib/PublicInbox/GitCredential.pm
@@ -56,6 +56,7 @@ sub fill {
 		$self->{$1} = $2;
 	}
 	close $out_r or die "git credential fill failed: \$!=$! \$?=$?\n";
+	$self->{filled} = 1;
 }
 
 1;
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index c050c60f..08166415 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -96,8 +96,8 @@ sub mic_for ($$$$) { # mic = Mail::IMAPClient
 		$cred = undef;
 	}
 	if ($cred) {
-		$cred->check_netrc unless defined $cred->{password};
-		$cred->fill($lei); # may prompt user here
+		my $p = $cred->{password} // $cred->check_netrc;
+		$cred->fill($lei) unless defined($p); # may prompt user here
 		$mic->User($mic_arg->{User} = $cred->{username});
 		$mic->Password($mic_arg->{Password} = $cred->{password});
 	} else { # AUTH=ANONYMOUS
@@ -121,7 +121,7 @@ sub mic_for ($$$$) { # mic = Mail::IMAPClient
 		}
 		$mic = undef;
 	}
-	$cred->run($mic ? 'approve' : 'reject') if $cred;
+	$cred->run($mic ? 'approve' : 'reject') if $cred && $cred->{filled};
 	if ($err) {
 		$lei ? $lei->fail($err) : warn($err);
 	}
@@ -191,7 +191,7 @@ sub nn_for ($$$$) { # nn = Net::NNTP
 		}, 'PublicInbox::GitCredential';
 		($u, $p) = split(/:/, $ui, 2);
 		($cred->{username}, $cred->{password}) = ($u, $p);
-		$cred->check_netrc unless defined $p;
+		$p //= $cred->check_netrc;
 	}
 	my $common = $nn_args->{$sec} // {};
 	my $nn_arg = {
@@ -204,7 +204,7 @@ sub nn_for ($$$$) { # nn = Net::NNTP
 	%$nn_arg = (%$nn_arg, %$sa) if $sa;
 	my $nn = nn_new($nn_arg, $nntp_opt, $uri);
 	if ($cred) {
-		$cred->fill($lei); # may prompt user here
+		$cred->fill($lei) unless defined($p); # may prompt user here
 		if ($nn->authinfo($u, $p)) {
 			push @{$nntp_opt->{-postconn}}, [ 'authinfo', $u, $p ];
 		} else {
@@ -231,7 +231,7 @@ W: see https://rt.cpan.org/Ticket/Display.html?id=129967 for updates
 	}
 
 	$self->{nn_arg}->{$sec} = $nn_arg;
-	$cred->run($nn ? 'approve' : 'reject') if $cred;
+	$cred->run($nn ? 'approve' : 'reject') if $cred && $cred->{filled};
 	$nn;
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-06  7:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  7:11 [PATCH] net_reader: don't approve/reject credentials w/o "fill" Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).