Skip to content

Commit a7775c7

Browse files
carenasgitster
authored andcommitted
git-cvsserver: use crypt correctly to compare password hashes
c057bad (git-cvsserver: use a password file cvsserver pserver, 2010-05-15) adds a way for `git cvsserver` to provide authenticated pserver accounts without having clear text passwords, but uses the username instead of the password to the call for crypt(3). Correct that, and make sure the documentation correctly indicates how to obtain hashed passwords that could be used to populate this configuration, as well as correcting the hash that was used for the tests. This change will require that any user of this feature updates the hashes in their configuration, but has the advantage of using a more similar format than cvs uses, probably also easying any migration. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit a7775c7

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Documentation/git-cvsserver.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,11 @@ for example:
118118
myuser:$1$BA)@$vbnMJMDym7tA32AamXrm./
119119
------
120120
You can use the 'htpasswd' facility that comes with Apache to make these
121-
files, but Apache's MD5 crypt method differs from the one used by most C
122-
library's crypt() function, so don't use the -m option.
121+
files, but only with the -d option (or -B if your system suports it).
123122

124-
Alternatively you can produce the password with perl's crypt() operator:
125-
-----
126-
perl -e 'my ($user, $pass) = @ARGV; printf "%s:%s\n", $user, crypt($user, $pass)' $USER password
127-
-----
123+
Preferably use the system specific utility that manages password hash
124+
creation in your platform (e.g. mkpasswd in Linux, encrypt in OpenBSD or
125+
pwhash in NetBSD) and paste it in the right location.
128126

129127
Then provide your password via the pserver method, for example:
130128
------

git-cvsserver.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
open my $passwd, "<", $authdb or die $!;
223223
while (<$passwd>) {
224224
if (m{^\Q$user\E:(.*)}) {
225-
if (crypt($user, descramble($password)) eq $1) {
225+
if (crypt(descramble($password), $1) eq $1) {
226226
$auth_ok = 1;
227227
}
228228
};

t/t9400-git-cvsserver-server.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ CVSWORK="$PWD/cvswork"
3636
CVS_SERVER=git-cvsserver
3737
export CVSROOT CVS_SERVER
3838

39+
PWDHASH='lac2ItudM3.KM'
40+
3941
rm -rf "$CVSWORK" "$SERVERDIR"
4042
test_expect_success 'setup' '
4143
git config push.default matching &&
@@ -54,7 +56,7 @@ test_expect_success 'setup' '
5456
GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
5557
GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" &&
5658
GIT_DIR="$SERVERDIR" git config gitcvs.authdb "$SERVERDIR/auth.db" &&
57-
echo cvsuser:cvGVEarMLnhlA > "$SERVERDIR/auth.db"
59+
echo "cvsuser:$PWDHASH" >"$SERVERDIR/auth.db"
5860
'
5961

6062
# note that cvs doesn't accept absolute pathnames

0 commit comments

Comments
 (0)