user579527
user579527

Reputation: 63

ldapsearch - truncating the result

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.

Upvotes: 6

Views: 7812

Answers (6)

StackzOfZtuff
StackzOfZtuff

Reputation: 3102

Alias for Perl

I've been using this Perl alias for a while:

$ cat wrap-example.ldif
MyLineA: 123456789,123456789,123456789,123456789,123456789,123456789,12345678
MyLineB: 123456789,123456789,123456789,123456789,123456789,123456789,12345678
 9,123456789,123456789
MyLineC: 123456789,123456789,123456789,123456789,123456789,123456789,12345678
✓
$ alias remove-ldif-linebreaks="dos2unix | perl -p0e 's/\n //g'"
✓
$ cat wrap-example.ldif | remove-ldif-linebreaks
MyLineA: 123456789,123456789,123456789,123456789,123456789,123456789,12345678
MyLineB: 123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789
MyLineC: 123456789,123456789,123456789,123456789,123456789,123456789,12345678
✓

As you can see: MyLineB has been un-wrapped

Upvotes: 0

awkLover
awkLover

Reputation: 11

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

Upvotes: 1

Jason Baker
Jason Baker

Reputation: 3

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.

Upvotes: -1

Amine
Amine

Reputation: 21

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

Upvotes: 2

Curtis Yallop
Curtis Yallop

Reputation: 7319

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

Search the man page for "wrap".

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

Upvotes: 19

codingenious
codingenious

Reputation: 8653

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.

Upvotes: 0

Related Questions