]> git.sur5r.net Git - openldap/commitdiff
ITS#6826 conversion scripts
authorDevin J. Pohly <djpohly@gmail.com>
Fri, 4 Feb 2011 21:51:40 +0000 (21:51 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 11 Apr 2016 12:35:39 +0000 (13:35 +0100)
These were provided as part of the original ITS but not previously committed.
Perl scripts to convert between Apache and OpenLDAP hash formats.

contrib/slapd-modules/passwd/apr1-atol.pl [new file with mode: 0644]
contrib/slapd-modules/passwd/apr1-ltoa.pl [new file with mode: 0644]

diff --git a/contrib/slapd-modules/passwd/apr1-atol.pl b/contrib/slapd-modules/passwd/apr1-atol.pl
new file mode 100644 (file)
index 0000000..d6eaee7
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/perl -w\r
+\r
+# Apache $apr1$ to OpenLDAP {APR1} hash converter\r
+# (C) 2011 Devin J. Pohly\r
+# You may use this code freely.  It would be nice to be credited.\r
+\r
+use MIME::Base64;\r
+\r
+while (<>) {\r
+       ($user, $hash) = split(/:/, $_);\r
+       unless ($hash =~ /^\$apr1\$/) {\r
+               print STDERR "Not an Apache MD5 hash\n";\r
+               exit 1;\r
+       }\r
+\r
+       chomp $hash;\r
+       ($_,$_,$salt,$hash) = split(/\$/, $hash);\r
+\r
+       $hash =~ tr|./0-9A-Za-z|A-Za-z0-9+/|;\r
+       $hash .= "AA";\r
+       $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;\r
+       $hash = decode_base64($hash);\r
+       $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)..(.)/$1$4$7$10$13$15$2$5$8$11$14$16$3$6$9$12/s;\r
+       $hash .= $salt;\r
+       $hash = encode_base64($hash);\r
+       chop $hash;\r
+\r
+       print "$user:{APR1}$hash\n";\r
+}
\ No newline at end of file
diff --git a/contrib/slapd-modules/passwd/apr1-ltoa.pl b/contrib/slapd-modules/passwd/apr1-ltoa.pl
new file mode 100644 (file)
index 0000000..ee628ec
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w\r
+\r
+# OpenLDAP {APR1} to Apache $apr1$ hash converter\r
+# (C) 2011 Devin J. Pohly\r
+# You may use this code freely.  It would be nice to be credited.\r
+\r
+use MIME::Base64;\r
+\r
+while (<>) {\r
+       ($user, $hash) = split(/:/, $_);\r
+       unless ($hash =~ /^{APR1}/) {\r
+               print STDERR "Not an Apache MD5 hash\n";\r
+               next;\r
+       }\r
+\r
+       chomp $hash;\r
+       $hash = decode_base64(substr($hash, 6));\r
+       ($hash, $salt) = (substr($hash, 0, 16), substr($hash, 16));\r
+       $hash = $hash;\r
+       $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/$1$7$13$2$8$14$3$9$15$4$10$16$5$11$6\0\0$12/s;\r
+       $hash = encode_base64($hash);\r
+       chomp $hash;\r
+       $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;\r
+       unless ($hash =~ /AA$/) {\r
+               #print "Problem with hash\n";\r
+               next;\r
+       }\r
+       $hash =~ s/AA$//;\r
+       $hash =~ tr|A-Za-z0-9+/|./0-9A-Za-z|;\r
+       print "$user:\$apr1\$$salt\$$hash\n"\r
+}
\ No newline at end of file