Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Created May 10, 2018 03:10
Show Gist options
  • Select an option

  • Save rawiriblundell/b3cc4e28990392c411aa8860f7196250 to your computer and use it in GitHub Desktop.

Select an option

Save rawiriblundell/b3cc4e28990392c411aa8860f7196250 to your computer and use it in GitHub Desktop.
Poll the sssd cache for locally stored information about a user. Usernames are case sensitive!
getAD-User-Info() {
local userName adUserName
userName="${1:?Username not supplied}"
# Poll 'id' to either ensure the info is cached
# or to error out if the user doesn't exist
if ! id "${userName}" &>/dev/null; then
printf -- '%s\n' "User '${userName}' could not be found"
return 1
fi
# We pull the AD acceptable username from the cache
# This helps us to sort out case sensitivity issues
adUserName=$(
ldbsearch -H /var/lib/sss/db/cache_$(dnsdomainname).ldb -b cn=sysdb 2>/dev/null \
| grep -m1 -i "^memberuid: ${userName}" \
| awk '{print $2}'
)
# Dump out the info
ldbsearch -H /var/lib/sss/db/cache_$(dnsdomainname).ldb -b cn=sysdb "(name="${adUserName}")" 2>/dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment