@matheusbsbs / matheus-bagliano / commits / 475357a32a
Fork 0

git-cvsserver: Improved error handling for pserver

- Produce an error if the user tries to supply a password for anonymous - Clarify the error message produced when there's no [gitcvs.authdb] - Produce an E error if the authdb doesn't exist instead of spewing $! to the user - do crypt($user, descramble($pass)) eq $hash; crypt($user, $hash) eq $hash would accept any password Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed May 15, 2010 at 02:46 UTC 475357a32a55c3624011e3945f9659f4cb365f1b
1 file changed +24 -5
git-cvsserver.perl
+24 -5
@@ -187,19 +187,37 @@ if ($state->{method} eq 'pserver') {
187 $line = <STDIN>; chomp $line;
188 my $password = $line;
189
190 - unless ($user eq 'anonymous') {
190 + if ($user eq 'anonymous') {
191 + # "A" will be 1 byte, use length instead in case the
192 + # encryption method ever changes (yeah, right!)
193 + if (length($password) > 1 ) {
194 + print "E Don't supply a password for the `anonymous' user\n";
195 + print "I HATE YOU\n";
196 + exit 1;
197 + }
198 +
199 + # Fall through to LOVE
200 + } else {
201 # Trying to authenticate a user
202 if (not exists $cfg->{gitcvs}->{authdb}) {
193 - print "E the repo config file needs a [gitcvs.authdb] section with a filename\n";
203 + print "E the repo config file needs a [gitcvs] section with an 'authdb' parameter set to the filename of the authentication database\n";
204 + print "I HATE YOU\n";
205 + exit 1;
206 + }
207 +
208 + my $authdb = $cfg->{gitcvs}->{authdb};
209 +
210 + unless (-e $authdb) {
211 + print "E The authentication database specified in [gitcvs.authdb] does not exist\n";
212 print "I HATE YOU\n";
213 exit 1;
214 }
215
216 my $auth_ok;
199 - open my $passwd, "<", $cfg->{gitcvs}->{authdb} or die $!;
217 + open my $passwd, "<", $authdb or die $!;
218 while (<$passwd>) {
219 if (m{^\Q$user\E:(.*)}) {
202 - if (crypt($user, $1) eq $1) {
220 + if (crypt($user, descramble($password)) eq $1) {
221 $auth_ok = 1;
222 }
223 };
@@ -210,7 +228,8 @@ if ($state->{method} eq 'pserver') {
228 print "I HATE YOU\n";
229 exit 1;
230 }
213 - # else fall through to LOVE
231 +
232 + # Fall through to LOVE
233 }
234
235 # For checking whether the user is anonymous on commit