Skip to content

Instantly share code, notes, and snippets.

@jagland
Last active March 27, 2019 15:47
Show Gist options
  • Save jagland/b943ff8bc1ea031c99cd8e28e4921889 to your computer and use it in GitHub Desktop.
Save jagland/b943ff8bc1ea031c99cd8e28e4921889 to your computer and use it in GitHub Desktop.
ldapsearch based on FreeRADIUS configuration
#!/bin/bash
#
# ldapsearch based on FreeRADIUS configuration
# Known issue(s) - Checks only the first LDAP server, doesn't read the configuration file properly, i.e. it's just greping for what might work...
if [ -z "$1" ]; then
FILE=/etc/freeradius/mods-enabled/ldap
else
FILE=$1
fi
if [ ! -f $FILE ]; then
echo $FILE not found
exit 1
else
LDAPURL=$(grep "server =" $FILE | head -1 | awk -F\" '{ print ""$2""}')
BINDDN=$(grep "identity =" $FILE | awk -F\" '{ print ""$2""}')
PASSWORD=$(grep "password =" $FILE | head -1 | awk '{ print ""$3""}')
BASEDN=$(grep "base_dn =" $FILE | head -1 | awk -F\" '{ print ""$2""}')
CERTPATH=$(grep "ca_file" $FILE | head -1 | awk -F\= '{ print ""$2""}')
# workaround issue with permissions on the CA file
TEMPFILE=$(mktemp)
cp $CERTPATH $TEMPFILE
env LDAPTLS_CACERT=$TEMPFILE ldapsearch -H $LDAPURL -b "$BASEDN" -D "$BINDDN" -w "$PASSWORD" -s sub -x -v dn '(objectClass=*)'
rm $TEMPFILE
fi
@jiscfoo
Copy link

jiscfoo commented Mar 27, 2019

On Line 23, TEMPFILE is explicitly a static file called mktemp -- this should be a callout to mktemp instead?

TEMPFILE=$(mktemp)

@jagland
Copy link
Author

jagland commented Mar 27, 2019

OK done, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment