Skip to content

Commit

Permalink
Look for password in both CVS and CVSNT password files.
Browse files Browse the repository at this point in the history
In conn, if password is not passed on command line, look for a password
entry in both the CVS password file and the CVSNT password file.  If only
one file is found and the requested repository is in that file, or if both
files are found but the requested repository is found in only one file, use
the password from the single file containing the repository entry.  If both
files are found and the requested repository is found in both files, then
produce an error message.

The CVS password file separates tokens with a space character, while
the CVSNT password file separates tokens with an equal (=) character.
Add a sub find_password_entry that accepts the password file name
and a delimiter to eliminate code duplication.

Signed-off-by: Guy Rouillier <guyr@burntmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Guy Rouillier authored and Junio C Hamano committed May 1, 2011
1 parent 7ed863a commit 58fdef0
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions git-cvsimport.perl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,31 @@ sub new {
return $self;
}

sub find_password_entry {
my ($cvspass, @cvsroot) = @_;
my ($file, $delim) = @$cvspass;
my $pass;
local ($_);

if (open(my $fh, $file)) {
# :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
CVSPASSFILE:
while (<$fh>) {
chomp;
s/^\/\d+\s+//;
my ($w, $p) = split($delim,$_,2);
for my $cvsroot (@cvsroot) {
if ($w eq $cvsroot) {
$pass = $p;
last CVSPASSFILE;
}
}
}
close($fh);
}
return $pass;
}

sub conn {
my $self = shift;
my $repo = $self->{'fullrep'};
Expand Down Expand Up @@ -259,19 +284,23 @@ sub conn {
if ($pass) {
$pass = $self->_scramble($pass);
} else {
open(H,$ENV{'HOME'}."/.cvspass") and do {
# :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
while (<H>) {
chomp;
s/^\/\d+\s+//;
my ($w,$p) = split(/\s/,$_,2);
if ($w eq $rr or $w eq $rr2) {
$pass = $p;
last;
}
my @cvspass = ([$ENV{'HOME'}."/.cvspass", qr/\s/],
[$ENV{'HOME'}."/.cvs/cvspass", qr/=/]);
my @loc = ();
foreach my $cvspass (@cvspass) {
my $p = find_password_entry($cvspass, $rr, $rr2);
if ($p) {
push @loc, $cvspass->[0];
$pass = $p;
}
};
$pass = "A" unless $pass;
}

if (1 < @loc) {
die("Multiple cvs password files have ".
"entries for CVSROOT $opt_d: @loc");
} elsif (!$pass) {
$pass = "A";
}
}

my ($s, $rep);
Expand Down

0 comments on commit 58fdef0

Please sign in to comment.