Tue 30 May 2006 10:21:02 PM UTC, original submission:
The attached perl script uses VCS::LibCVS::Datum::Root, and
demonstrates an issue with handling a CVSROOT of the form
"hostname:/repository" without a username, but it is only
an issue if the script is run through an ssh connection.
The issue is mainly a perl issue where getlogin() does not
work through an ssh connection:
> perl -w -e print\ getlogin\(\)\.\"\\\n\"
kurtg
> ssh `hostname` 'perl -w -e print\ getlogin\(\)\.\"\\\n\"'
Use of uninitialized value in concatenation (.) or string at -e line 1.
However, getpwuid($<) does work:
> perl -w -e print\ getpwuid\(\$\<\)\.\"\\\n\"
kurtg
> ssh `hostname` 'perl -w -e print\ getpwuid\(\$\<\)\.\"\\\n\"'
kurtg
Likewise, since Root.pm uses getlogin(), the attached script
works properly when run by itself on the commandline.
"Working properly" means the hostname and username of the
CVSROOT are printed, even if the username is not stated,
i.e. only implied due to the form "hostname:/repository".
% bug_getlogin.pl
However, when run through an ssh connection, the username
is left undefined due to the getlogin() call, and the
script complains about uninitialized items.
% ssh `hostname` bug_getlogin.pl
A release note states:
> 2004-09-21 dissent
>
> * libcvs-perl/VCS/LibCVS/Client/Connection/CvsPass.pm [1.3]
> * libcvs-perl/VCS/LibCVS/Datum/Root.pm [1.16]
>
> Handle a pserver CVSROOT where the username isn't specified.
> Use the result of getlogin() instead.
>
> I'm not sure this is the best way to fix this bug. See
> issue 65 for further discussion.
It seems that getpwuid($<) should be used instead of getlogin().
According to http://perldoc.perl.org/functions/getlogin.html,
which states that getlogin() can be null, line 77 in the
file "VCS/LibCVS/Datum/Root.pm":
$that->{UserName} = $3 || getlogin();
should probably be:
$that->{UserName} = $3 || getlogin() || getpwuid($<);
or perhaps just:
$that->{UserName} = $3 || getpwuid($<);
This happens again at line 88 with:
$that->{UserName} = $2 || getlogin();
The 'connect' method of VCS/LibCVS/Client/Connection/Ext.pm
contains some code for dealing with the situation where
the username is not defined, but the IPC::Open2::open2 call
ultimately fails anyway for such a case.
|