]> git.sur5r.net Git - openldap/blob - contrib/slapd-modules/passwd/apr1-atol.pl
Do not require ac/string.h for lber_pvt.h
[openldap] / contrib / slapd-modules / passwd / apr1-atol.pl
1 #!/usr/bin/perl -w\r
2 \r
3 # Apache $apr1$ to OpenLDAP {APR1} hash converter\r
4 # (C) 2011 Devin J. Pohly\r
5 # You may use this code freely.  It would be nice to be credited.\r
6 \r
7 use MIME::Base64;\r
8 \r
9 while (<>) {\r
10         ($user, $hash) = split(/:/, $_);\r
11         unless ($hash =~ /^\$apr1\$/) {\r
12                 print STDERR "Not an Apache MD5 hash\n";\r
13                 exit 1;\r
14         }\r
15 \r
16         chomp $hash;\r
17         ($_,$_,$salt,$hash) = split(/\$/, $hash);\r
18 \r
19         $hash =~ tr|./0-9A-Za-z|A-Za-z0-9+/|;\r
20         $hash .= "AA";\r
21         $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;\r
22         $hash = decode_base64($hash);\r
23         $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)..(.)/$1$4$7$10$13$15$2$5$8$11$14$16$3$6$9$12/s;\r
24         $hash .= $salt;\r
25         $hash = encode_base64($hash);\r
26         chop $hash;\r
27 \r
28         print "$user:{APR1}$hash\n";\r
29 }