#!/usr/bin/perl

use strict;

print("dn: DC=company,DC=org
objectClass: top
objectclass: dcObject
objectClass: organization
o: company
dc: company

dn: OU=users,DC=company,DC=org
objectClass: top
objectClass: organizationalUnit
ou: users
description: organizational unit users

");

while (<>) {
	chomp($_);
	my($mailbox, $domain, $pass, $name) = (/^([^:\@]+)\@([^:]+):([^:]+):::([^:]*)/);
	my($mail) = $mailbox.'@'.$domain;
	if ($pass =~ /^\{MD5\}/) {
		$pass =~ s/^\{MD5\}/{CRYPT}/;
	} else {
		$pass = '{CRYPT}'.$pass;
	}
	printf("dn: UID=%s,OU=users,DC=company,DC=org
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
userPassword: %s
uid: %s
mail: %s
o: %s
cn: %s
sn: %s
displayName: %s

", $mail, $pass, $mail, $mail, $domain, $name, $name, $name);
}
