Skip to content

Commit 58fdef0

Browse files
Guy Rouilliergitster
authored andcommitted
Look for password in both CVS and CVSNT password files.
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ed863a commit 58fdef0

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

git-cvsimport.perl

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,31 @@ sub new {
227227
return $self;
228228
}
229229

230+
sub find_password_entry {
231+
my ($cvspass, @cvsroot) = @_;
232+
my ($file, $delim) = @$cvspass;
233+
my $pass;
234+
local ($_);
235+
236+
if (open(my $fh, $file)) {
237+
# :pserver:[email protected]:/cvsroot/zmailer Ah<Z
238+
CVSPASSFILE:
239+
while (<$fh>) {
240+
chomp;
241+
s/^\/\d+\s+//;
242+
my ($w, $p) = split($delim,$_,2);
243+
for my $cvsroot (@cvsroot) {
244+
if ($w eq $cvsroot) {
245+
$pass = $p;
246+
last CVSPASSFILE;
247+
}
248+
}
249+
}
250+
close($fh);
251+
}
252+
return $pass;
253+
}
254+
230255
sub conn {
231256
my $self = shift;
232257
my $repo = $self->{'fullrep'};
@@ -259,19 +284,23 @@ sub conn {
259284
if ($pass) {
260285
$pass = $self->_scramble($pass);
261286
} else {
262-
open(H,$ENV{'HOME'}."/.cvspass") and do {
263-
# :pserver:[email protected]:/cvsroot/zmailer Ah<Z
264-
while (<H>) {
265-
chomp;
266-
s/^\/\d+\s+//;
267-
my ($w,$p) = split(/\s/,$_,2);
268-
if ($w eq $rr or $w eq $rr2) {
269-
$pass = $p;
270-
last;
271-
}
287+
my @cvspass = ([$ENV{'HOME'}."/.cvspass", qr/\s/],
288+
[$ENV{'HOME'}."/.cvs/cvspass", qr/=/]);
289+
my @loc = ();
290+
foreach my $cvspass (@cvspass) {
291+
my $p = find_password_entry($cvspass, $rr, $rr2);
292+
if ($p) {
293+
push @loc, $cvspass->[0];
294+
$pass = $p;
272295
}
273-
};
274-
$pass = "A" unless $pass;
296+
}
297+
298+
if (1 < @loc) {
299+
die("Multiple cvs password files have ".
300+
"entries for CVSROOT $opt_d: @loc");
301+
} elsif (!$pass) {
302+
$pass = "A";
303+
}
275304
}
276305

277306
my ($s, $rep);

0 commit comments

Comments
 (0)