Convert a Base64 LDIF file to plaintext (for import)

十年热恋 提交于 2019-12-23 04:22:45

问题


I have a LDIF file which has a multi-value Base64-encoded attribute, and I'd like to convert it in non-Base64-encoded syntax. How can this be done?

Context

The LDIF file is as such:

dn: cn=johndoe,ou=clients,ou=management,dc=example,dc=com
changetype: modify
replace: foobarStatus
foobarStatus:: ZW5hYmxl... (Base64 string) ...ZCA9IHRydWU

where the decoded Base64 string is as such:

market = "US"
mgmt.account.mode = "X12"
foo.field = "Something"
bar.field = "Something else" 
...

Problem

When I try to import this LDIF file into a LDAP server via ldapmodify, I get an error:

ldapmodify: invalid format (line 4) entry: "cn=johndoe,ou=clients,ou=management,dc=example,dc=com"

I've been trying to solve this for a while but couldn't find the error. It could be some spurious character somewhere. Therefore I thought of converting the Base64 part of the LDIF and importing it on this format. The attribute values don't contain any non-printable ASCII (e.g. accented letters) so it should work fine.

Note

This could be a XY problem so if anyone has another suggestion, I'm eager to read it.


回答1:


It turns out ldapmodify doesn't like long lines. Therefore, after splitting the Base64 code here

foobarStatus:: ZW5hYmxl... (Base64 string) ...ZCA9IHRydWU

into multiple lines of 79 chars or less, ldapmodify was able to import it.

This solved my original problem. I'm leaving the solution here for future readers.




回答2:


To convert a base64 string to plain text, i use base64 -d -d stands for decode.

an example in both directions:

$ echo https://stackoverflow.com/ | base64
aHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS8K
$ echo aHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS8K | base64 -d
https://stackoverflow.com/

And yes, i think it is an xy Problem.



来源:https://stackoverflow.com/questions/43117733/convert-a-base64-ldif-file-to-plaintext-for-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!