mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-29 02:59:34 -05:00
ITS#6826 conversion scripts
These were provided as part of the original ITS but not previously committed. Perl scripts to convert between Apache and OpenLDAP hash formats.
This commit is contained in:
parent
2335285502
commit
fb5b3a0df2
2 changed files with 60 additions and 0 deletions
29
contrib/slapd-modules/passwd/apr1-atol.pl
Normal file
29
contrib/slapd-modules/passwd/apr1-atol.pl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
# Apache $apr1$ to OpenLDAP {APR1} hash converter
|
||||
# (C) 2011 Devin J. Pohly
|
||||
# You may use this code freely. It would be nice to be credited.
|
||||
|
||||
use MIME::Base64;
|
||||
|
||||
while (<>) {
|
||||
($user, $hash) = split(/:/, $_);
|
||||
unless ($hash =~ /^\$apr1\$/) {
|
||||
print STDERR "Not an Apache MD5 hash\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
chomp $hash;
|
||||
($_,$_,$salt,$hash) = split(/\$/, $hash);
|
||||
|
||||
$hash =~ tr|./0-9A-Za-z|A-Za-z0-9+/|;
|
||||
$hash .= "AA";
|
||||
$hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;
|
||||
$hash = decode_base64($hash);
|
||||
$hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)..(.)/$1$4$7$10$13$15$2$5$8$11$14$16$3$6$9$12/s;
|
||||
$hash .= $salt;
|
||||
$hash = encode_base64($hash);
|
||||
chop $hash;
|
||||
|
||||
print "$user:{APR1}$hash\n";
|
||||
}
|
||||
31
contrib/slapd-modules/passwd/apr1-ltoa.pl
Normal file
31
contrib/slapd-modules/passwd/apr1-ltoa.pl
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
# OpenLDAP {APR1} to Apache $apr1$ hash converter
|
||||
# (C) 2011 Devin J. Pohly
|
||||
# You may use this code freely. It would be nice to be credited.
|
||||
|
||||
use MIME::Base64;
|
||||
|
||||
while (<>) {
|
||||
($user, $hash) = split(/:/, $_);
|
||||
unless ($hash =~ /^{APR1}/) {
|
||||
print STDERR "Not an Apache MD5 hash\n";
|
||||
next;
|
||||
}
|
||||
|
||||
chomp $hash;
|
||||
$hash = decode_base64(substr($hash, 6));
|
||||
($hash, $salt) = (substr($hash, 0, 16), substr($hash, 16));
|
||||
$hash = $hash;
|
||||
$hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/$1$7$13$2$8$14$3$9$15$4$10$16$5$11$6\0\0$12/s;
|
||||
$hash = encode_base64($hash);
|
||||
chomp $hash;
|
||||
$hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;
|
||||
unless ($hash =~ /AA$/) {
|
||||
#print "Problem with hash\n";
|
||||
next;
|
||||
}
|
||||
$hash =~ s/AA$//;
|
||||
$hash =~ tr|A-Za-z0-9+/|./0-9A-Za-z|;
|
||||
print "$user:\$apr1\$$salt\$$hash\n"
|
||||
}
|
||||
Loading…
Reference in a new issue