]> git.sur5r.net Git - openldap/blobdiff - contrib/slapd-modules/passwd/apr1-atol.pl
ITS#6826 conversion scripts
[openldap] / contrib / slapd-modules / passwd / apr1-atol.pl
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