git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] git-cvsserver: Improved error handling for pserver

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 15, 2010, 02:46 UTC
Message-ID
<1273891564-7523-5-git-send-email-avarab@gmail.com>
In-Reply-To
<7v3an9tc5w.fsf@gitster.siamese.dyndns.org>
  - 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>
---
 git-cvsserver.perl |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 9f63c56..813df76 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -187,19 +187,37 @@ if ($state->{method} eq 'pserver') {
     $line = <STDIN>; chomp $line;
     my $password = $line;
 
-    unless ($user eq 'anonymous') {
+    if ($user eq 'anonymous') {
+        # "A" will be 1 byte, use length instead in case the
+        # encryption method ever changes (yeah, right!)
+        if (length($password) > 1 ) {
+            print "E Don't supply a password for the `anonymous' user\n";
+            print "I HATE YOU\n";
+            exit 1;
+        }
+
+        # Fall through to LOVE
+    } else {
         # Trying to authenticate a user
         if (not exists $cfg->{gitcvs}->{authdb}) {
-            print "E the repo config file needs a [gitcvs.authdb] section with a filename\n";
+            print "E the repo config file needs a [gitcvs] section with an 'authdb' parameter set to the filename of the authentication database\n";
+            print "I HATE YOU\n";
+            exit 1;
+        }
+
+        my $authdb = $cfg->{gitcvs}->{authdb};
+
+        unless (-e $authdb) {
+            print "E The authentication database specified in [gitcvs.authdb] does not exist\n";
             print "I HATE YOU\n";
             exit 1;
         }
 
         my $auth_ok;
-        open my $passwd, "<", $cfg->{gitcvs}->{authdb} or die $!;
+        open my $passwd, "<", $authdb or die $!;
         while (<$passwd>) {
             if (m{^\Q$user\E:(.*)}) {
-                if (crypt($user, $1) eq $1) {
+                if (crypt($user, descramble($password)) eq $1) {
                     $auth_ok = 1;
                 }
             };
@@ -210,7 +228,8 @@ if ($state->{method} eq 'pserver') {
             print "I HATE YOU\n";
             exit 1;
         }
-        # else fall through to LOVE
+
+        # Fall through to LOVE
     }
 
     # For checking whether the user is anonymous on commit
-- 
1.7.1.84.gd92f8
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 21 of 25 in “Authentication support for pserver”
  1. Authentication support for pserverÆvar Arnfjörð Bjarmason, Dec 14, 2007
  2. Junio C HamanoDec 14, 2007
  3. Shawn O. PearceDec 14, 2007
  4. Ævar Arnfjörð BjarmasonDec 14, 2007
  5. Junio C HamanoDec 14, 2007
  6. Ævar Arnfjörð BjarmasonDec 14, 2007
  7. Martin LanghoffDec 18, 2007
  8. Martin LanghoffDec 18, 2007
  9. Ævar Arnfjörð BjarmasonMar 7, 2008
  10. Ævar Arnfjörð BjarmasonMar 7, 2008
  11. Ævar Arnfjörð BjarmasonJun 19, 2008
  12. Martin LanghoffJun 19, 2008
  13. Junio C HamanoJun 19, 2008
  14. Junio C HamanoJun 19, 2008
  15. 0/6 git-cvsserver: password support for pserverÆvar Arnfjörð Bjarmason, May 15, 2010
  16. 1/6 git-cvsserver: authentication support for pserverÆvar Arnfjörð Bjarmason, May 15, 2010
  17. 1/6 git-cvsserver: authentication support for pserverÆvar Arnfjörð Bjarmason, May 15, 2010
  18. 2/6 git-cvsserver: use a password file cvsserver pserverÆvar Arnfjörð Bjarmason, May 15, 2010
  19. 2/6 git-cvsserver: use a password file cvsserver pserverÆvar Arnfjörð Bjarmason, May 15, 2010
  20. 3/6 git-cvsserver: indent & clean up authdb codeÆvar Arnfjörð Bjarmason, May 15, 2010
  21. 4/6 git-cvsserver: Improved error handling for pserverÆvar Arnfjörð Bjarmason, May 15, 2010
  22. 5/6 git-cvsserver: document making a password without htpasswdÆvar Arnfjörð Bjarmason, May 15, 2010
  23. 6/6 git-cvsserver: test for pserver authentication supportÆvar Arnfjörð Bjarmason, May 15, 2010
  24. Ævar Arnfjörð BjarmasonDec 18, 2007
  25. Junio C HamanoDec 18, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.