2010-11-30

BOM Squad

So you have a lovely LDIF file of Active Directory schema that you want to import using the ldbmodify tool provided with Samba4... but when you attempt the import it fails with the error:
Error: First line of ldif must be a dn not 'dn'
Modified 0 records with 0 failures
Eh? @&^$*&@  &@^&*@ ^@&*^@&* It does start with a dn: attribute!
Once you cool down you look at the file using od, just in case, and you see:
0000000   o   ;   ?   d   n   :  sp   c   n   =   H   o   r   d   e   -
You've been bitten by the BOM! But even opening the file in vi you can't see the BOM because every tool knows about the BOM and deals with it - with the exception of anything LDIF related.
The trick is to break out dusty old sed and remove the BOM -
sed -e '1s/^\xef\xbb\xbf//' horde-person.ldf  > nobom.ldf
And double checking it with od again:
0000000   d   n   :  sp   c   n   =   H   o   r   d   e   -   A   g   o
The file now actually starts with a dn attribute!

0 comments:

Post a Comment