5

I am using ldapsearch for getting radius secret, but it is giving truncated result

Command I am using is :

./ldapsearch -p 1545 -Z -X -D "cn=Directory Manager" -w passwd -b "o=platform" "(objectClass=*)" | grep -i secret

result produced is :

ss-secret=ahksdf6fakh7fajkfhaffjkfjfhafajkfh234578fajf171jkh25/525jhsfasjh8jjk7

where as actual value in LDAP is

ss-secret=ahksdf6fakh7fajkfhaffjkfjfhafajkfh234578fajf171jkh25/525jhsfasjh8jjk7afjfh8/gSqtulkjfa8lfjakl3

I am using OpenDJ LDAP.

user579527
  • 53
  • 1
  • 3
  • 1
    `ldapsearch` is wrapping by default. Your grep is only getting the matching line and not the subsequently line(s) that are part of it. As @curtis-yallop noted below, `ldapsearch -o ldif-wrap=no ...` with your grep should solve this problem. Pls give him cred. – Mike D Aug 28 '18 at 16:34

5 Answers5

14

Try "ldapsearch -o ldif-wrap=no ...".

Search the man page for "wrap".

I am using OpenLDAP in the ldap-utils package on debian.

Curtis Yallop
  • 6,696
  • 3
  • 46
  • 36
1

Use -T argument like

./ldapsearch -p 1545 -T -Z -X -D "cn=Directory Manager" -w passwd -b "o=platform" "(objectClass=*)" | grep -i secret

This will give you complete output.

codingenious
  • 8,385
  • 12
  • 60
  • 90
1

for Debian based system you have to add "-o ldif-wrap=no "
example: ldapsearch -xLLL -o ldif-wrap=no -H ldap://hostname:port/
from the man page of ldapsearch ubuntu 16.04:

-T path
Write temporary files to directory specified by path (default: /var/tmp/)

so it has no relation with formatting the output

Armali
  • 18,255
  • 14
  • 57
  • 171
Amine
  • 11
  • 3
1

Unfortunately, none of those options worked for me. I went to trusty sed and awk and solved the problem.

ldapsearch options > outfile
## sed to remove the space at the beginning of wrapped lines.
sed -i 's/^ //g' outfile
## Awk to join the lines if 78
awk '{if(length($0) == 78) {printf $0} else {print $0} }' outfile > outfile.nowrap
Doj
  • 1,244
  • 6
  • 13
  • 19
awkLover
  • 11
  • 1
-1

Going to try the wrap thing but this has been my go-to for years:

ldapsearch -xLLL cn=WHATEVER | perl -p00e 's/\n /g'

It’s ugly, which is why I landed here looking for a better way, but it works without fail.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77