Re: [PATCHv5] Add contrib/credentials/netrc with GPG support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

> Otherwise, looks almost ready to me.

For now, I've queued this as a minimum fix-up on top of your patch
and pushed the result out.  It is an equivalent of the previous
review comments in a patch form.  Please review and incorporate in
your reroll as appropriate.

I haven't looked at the part that interacts with the credential
subsystem itself, though.

 contrib/credential/netrc/git-credential-netrc | 35 ++++++++++++---------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/contrib/credential/netrc/git-credential-netrc b/contrib/credential/netrc/git-credential-netrc
index 8298564..30e05fb 100755
--- a/contrib/credential/netrc/git-credential-netrc
+++ b/contrib/credential/netrc/git-credential-netrc
@@ -74,6 +74,10 @@ Options:
                        first matching entry found is returned via the credential
                        helper protocol (see below).
 
+                       When no -f option is given, .authinfo.gpg, .netrc.gpg,
+		       .authinfo, and .netrc files in your home directory are used
+		       in this order.
+
   -k|--insecure      : ignore bad file ownership or permissions
 
   -d|--debug         : turn on debugging (developer info)
@@ -206,8 +210,7 @@ foreach my $file (@$files) {
 	unless (scalar @entries) {
 		if ($!) {
 			log_verbose("Unable to open $file: $!");
-		}
-		else {
+		} else {
 			log_verbose("No netrc entries found in $file");
 		}
 
@@ -230,15 +233,10 @@ sub load_netrc {
 
 	my $io;
 	if ($gpgmode) {
-		# typical shell character escapes from http://www.slac.stanford.edu/slac/www/resource/how-to-use/cgi-rexx/cgi-esc.html
-		my $f = $file;
-		$f =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g;
-		# GPG doesn't work well with 2- or 3-argument open
-		my $cmd = "gpg --decrypt $f";
-		log_verbose("Using GPG to open $file: [$cmd]");
-		open $io, "$cmd|";
-	}
-	else {
+		my @cmd = (qw(gpg --decrypt), $file)
+		log_verbose("Using GPG to open $file: [@cmd]");
+		open $io, "-|", @cmd;
+	} else {
 		log_verbose("Opening $file...");
 		open $io, '<', $file;
 	}
@@ -257,6 +255,9 @@ sub load_netrc {
 		my %entry;
 		my $num_port;
 
+		if (!defined $nentry->{machine}) {
+			next;
+		}
 		if (defined $nentry->{port} && $nentry->{port} =~ m/^\d+$/) {
 			$num_port = $nentry->{port};
 			delete $nentry->{port};
@@ -302,8 +303,7 @@ sub net_netrc_loader {
 		while (@tok) {
 			if ($tok[0] eq "default") {
 				shift(@tok);
-				undef $mach; # ignore 'default' lines
-
+				$mach = { machine => undef }
 				next TOKEN;
 			}
 
@@ -313,8 +313,7 @@ sub net_netrc_loader {
 				my $host = shift @tok;
 				$mach = { machine => $host };
 				push @entries, $mach;
-			}
-			elsif (exists $options{tmap}->{$tok}) {
+			} elsif (exists $options{tmap}->{$tok}) {
 				unless ($mach) {
 					log_debug("Skipping token $tok because no machine was given");
 					next TOKEN;
@@ -329,8 +328,7 @@ sub net_netrc_loader {
 				# Following line added by rmerrell to remove '/' escape char in .netrc
 				$value =~ s/\/\\/\\/g;
 				$mach->{$tok} = $value;
-			}
-			elsif ($tok eq "macdef") { # we ignore macros
+			} elsif ($tok eq "macdef") { # we ignore macros
 				next TOKEN unless $mach;
 				my $value = shift @tok;
 				$macdef = 1;
@@ -380,8 +378,7 @@ sub find_netrc_entry {
 				unless ($query->{$check} eq $entry->{$check}) {
 					next ENTRY;
 				}
-			}
-			else {
+			} else {
 				log_debug("OK: any value satisfies check $check");
 			}
 		}
-- 
1.8.1.2.641.g0b90ac4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]