Friday, August 27, 2010

LDAP import: From Microsoft Active Directory to ApacheDS

Migrating stuff from Active Directory to ApacheDS is a question that we find in forums every so often.

As the ldif (ldf extension in MS world) format is a plain text file you can use any tool that do search and replace. Here is where Unix Power Tools come (like so often) to your rescue.

My original file came with fields I wanted to delete, others I wanted to rename and even some missing fields. All that can be done with sed (The stream Editor).

Here is a fragment of the original Financing.ldf file:
dn: CN=Peter Pan,OU=Financing,DC=Sample,DC=com
changetype: add
sn: Pan
givenName: Peter
proxyAddresses: X400:c=US;a= ;p=Sample;o=NL;s=NS;
proxyAddresses: smtp:peter.pan@sample.COM
proxyAddresses: smtp:pp@SAMPLE.COM
proxyAddresses: MS:SAMPLE/NL/NS
proxyAddresses: CCMAIL:PP at NL
sAMAccountName: ppan

Here is a fragment of the needed output format:
dn: CN=Peter Pan,o=nl
sn: Pan
givenName: Peter
uid: pp
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
objectclass: top

Here is the command line statement that makes it happen. Please respect the "\new line" as it is responsible for adding the new lines you need.

cat Financing.ldf | sed s/OU=Financing,DC=Sample,DC=com/ou=people,o=nl/ | sed /changetype.*/d | sed /proxyAddresses:.[^S].*/d | sed 's/proxyAddresses:.SMTP:/mail: /' | sed 's/sAMAccountName/uid/' | sed 's/\(uid:.*\)/\1\
userPassword: \
objectclass: person\
objectclass: organizationalPerson\
objectclass: inetOrgPerson\
objectclass: top\
/g' > financing.ldif

Of course we are creating empty passwords here.

No comments: