Last active
March 27, 2019 15:47
-
-
Save jagland/b943ff8bc1ea031c99cd8e28e4921889 to your computer and use it in GitHub Desktop.
ldapsearch based on FreeRADIUS configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Line 23,
TEMPFILE
is explicitly a static file calledmktemp
-- this should be a callout tomktemp
instead?TEMPFILE=$(mktemp)