@matheusbsbs / matheus-bagliano / commits / 58fdef0cff
Fork 0

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 <guyr@burntmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Guy Rouillier committed May 1, 2011 at 01:33 UTC 58fdef0cff5bcf10f2621d00466b33a5b8a39bf7
1 file changed +41 -12
git-cvsimport.perl
+41 -12
@@ -227,6 +227,31 @@ sub new {
227 return $self;
228 }
229
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:cvs@mea.tmt.tele.fi:/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 +
255 sub conn {
256 my $self = shift;
257 my $repo = $self->{'fullrep'};
@@ -259,19 +284,23 @@ sub conn {
284 if ($pass) {
285 $pass = $self->_scramble($pass);
286 } else {
262 - open(H,$ENV{'HOME'}."/.cvspass") and do {
263 - # :pserver:cvs@mea.tmt.tele.fi:/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;
295 }
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 + }
304 }
305
306 my ($s, $rep);