Last active
September 14, 2015 11:35
-
-
Save Finkregh/40b9369dd85b3a1365b7 to your computer and use it in GitHub Desktop.
ActiveDirectory / LDAP groups to prosody
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 | |
# hacked together, might eat your kittens. | |
# for auth agains LDAP/AD look at https://blogs.mafia-server.net/nur-bahnhof/2013/12/prosody-authentification-ldapactivedirectory/ | |
tmpfile=/tmp/sharedgroups.txt | |
XMPP_DOMAIN=xmpp.example.org | |
AD_DC=dc1.corp.example.org | |
LDAP_ROOT="dc=example,dc=org" | |
LDAP_SUB_OU="ou=OE" | |
ALL_USERS_GROUP="Everybody" | |
for org in some AD orgs ; do echo "[${org}]" ; ldapsearch -x -h ${AD_DC} -D "admin-user" -w password -LLL -b "ou=${org},${LDAP_SUB_OU},${LDAP_ROOT}" "(&(objectClass=user)(mail=*))" | grep -E "^cn: |sAMAccountName: "; done > ${tmpfile} | |
echo "[${ALL_USERS_GROUP}]" >> ${tmpfile} | |
ldapsearch -x -h ${AD_DC} -D "admin-user" -w password -LLL -b "${LDAP_SUB_OU},${LDAP_ROOT}" "(&(objectClass=user)(mail=*))" | grep -E "^cn: |sAMAccountName: " >> ${tmpfile} | |
while read line ; do | |
if echo ${line} | grep -qE "^\[" ; then | |
echo "" | |
echo $line | |
else | |
if echo ${line} | grep -qE "^cn" ; then | |
fullname=$(echo ${line} | cut -d ' ' -f 2-) | |
elif echo ${line} | grep -qE "^sAMAccountName" ; then | |
uid=$(echo ${line} | cut -d ' ' -f 2 | tr '[:upper:]' '[:lower:]') | |
echo "${uid}@${XMPP_DOMAIN}=${fullname}" | |
fi | |
fi | |
done < ${tmpfile} |
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
0 0 * * * root /usr/local/bin/create-prosody-groups.sh > /var/lib/prosody/sharedgroups.txt ; chown prosody.prosody /var/lib/prosody/sharedgroups.txt ; systemctl restart prosody.service |
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
groups_file = "/var/lib/prosody/sharedgroups.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment