Skip to content

Instantly share code, notes, and snippets.

@patgmac
Created March 7, 2018 02:08
Show Gist options
  • Save patgmac/29cb5213f0d1ec8741a0e0707f1b502b to your computer and use it in GitHub Desktop.
Save patgmac/29cb5213f0d1ec8741a0e0707f1b502b to your computer and use it in GitHub Desktop.
#!/bin/bash
###
#
# Name: ec_checkLDAPmatch_EA.sh
# Description: Checks if local user name matches what is authenticated in EC
# Author: Patrick Gallagher
# Created: 2018-02-16
#
###
if [[ -d "/Applications/Enterprise Connect.app" ]]; then
logged_in_user=$( python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");' )
/usr/bin/security find-generic-password -l "Enterprise Connect" "/Users/$logged_in_user/Library/Keychains/login.keychain" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
ec_user=$(/usr/bin/security find-generic-password -l "Enterprise Connect" | grep "acct" | awk -F "=" '{print $2}' | tr -d "\"")
echo "<result>$ec_user</result>"
else
echo "<result>EC Not Signed In</result>"
fi
else
echo "<result>EC Not Installed</result>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment