gunnar: server/perl-kolab/bin kolabpasswd.in,1.2,1.2.2.1

cvs at kolab.org cvs at kolab.org
Tue Nov 17 18:12:37 CET 2009


Author: gunnar

Update of /kolabrepository/server/perl-kolab/bin
In directory doto:/tmp/cvs-serv19710/perl-kolab/bin

Modified Files:
      Tag: kolab_2_2_branch
	kolabpasswd.in 
Log Message:
 kolab/issue919 (kolab server has problems with some characters in passwords)

Index: kolabpasswd.in
===================================================================
RCS file: /kolabrepository/server/perl-kolab/bin/kolabpasswd.in,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- kolabpasswd.in	20 Jan 2009 17:22:12 -0000	1.2
+++ kolabpasswd.in	17 Nov 2009 17:12:35 -0000	1.2.2.1
@@ -49,6 +49,8 @@
 use IO::File;
 use File::Temp;
 use Net::LDAP;
+use Digest::SHA1;
+use MIME::Base64;
 use Kolab::Util;
 use Kolab;
 
@@ -79,6 +81,36 @@
   return $hashpw;
 }
 
+# Taken from Crypt::SaltedHash
+sub __generate_hex_salt {
+
+    my @keychars = (
+        "0", "1", "2", "3", "4", "5", "6", "7",
+        "8", "9", "a", "b", "c", "d", "e", "f"
+    );
+    my $length = shift || 8;
+
+    my $salt = '';
+    my $max  = scalar @keychars;
+    for my $i ( 0 .. $length - 1 ) {
+        my $skip = $i == 0 ? 1 : 0;    # don't let the first be 0
+        $salt .= $keychars[ $skip + int( rand( $max - $skip ) ) ];
+    }
+
+    return pack( "H*", $salt);
+}
+
+# Hash a password without using slappasswd
+sub hashPassword2 {
+  my $pw = shift;
+  my $ctx = Digest::SHA1->new;
+  my $salt = __generate_hex_salt();
+  $ctx->add($pw);
+  $ctx->add($salt);
+  my $hashpw = '{SSHA}' . encode_base64($ctx->digest . $salt ,'');
+  return $hashpw;
+}
+
 # open old kolab master config file
 my $kolabconfname = "@CONFIG_DIR@/kolab.conf";
 
@@ -129,7 +161,7 @@
 my $tmp = new File::Temp( TEMPLATE => 'tempXXXXX', DIR => '@CONFIG_DIR@', UNLINK => 0, SUFFIX => '.conf')
      || die "Error: could not create temporary file under @CONFIG_DIR@";
 $tmpfilename = $tmp->filename;
-$bind_pw_hash = hashPassword($new_password);
+$bind_pw_hash = hashPassword2($new_password);
 
 # copy and replace old config to temporary file
 foreach ($kolabconf->getlines()) {





More information about the commits mailing list