Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created October 22, 2020 22:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkingmoose/92a29520de5235214295a4bca377fb63 to your computer and use it in GitHub Desktop.
Save talkingmoose/92a29520de5235214295a4bca377fb63 to your computer and use it in GitHub Desktop.
Syntax for looking up user information from a non-bound LDAP directory.
#!/bin/sh
# -H = LDAP URI
# -x = use simple authentication instead of SASL
# -b = search base
# -D = user principal name (UPN) of authenticating user
# -w = password of authenticating user
# look up a user's manager's distinguished name
/usr/bin/ldapsearch -H ldap://192.168.5.250:389 -x -b 'cn=users,dc=talkingmoose,dc=pvt' -D 'mmoose@talkingmoose.pvt' -w 'P@55w0rd' cn="Martin Moose" manager | /usr/bin/grep 'manager:' | /usr/bin/awk -F ": " '{ print $2 }'
<<RESULTS
-----------------------------------------------------------------
CN=Clark Griswold,CN=Users,DC=talkingmoose,DC=pvt
-----------------------------------------------------------------
RESULTS
# look up manager's email address
/usr/bin/ldapsearch -H ldap://192.168.5.250:389 -x -b 'cn=users,dc=talkingmoose,dc=pvt' -D 'mmoose@talkingmoose.pvt' -w 'P@55w0rd' distinguishedName='CN=Clark Griswold,CN=Users,DC=talkingmoose,DC=pvt' mail | /usr/bin/grep 'mail:' | /usr/bin/awk '{ print $2 }'
<<RESULTS
-----------------------------------------------------------------
cgriswold@talkingmoose.net
-----------------------------------------------------------------
RESULTS
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment