Mailman Auto-Subscription of LDAP Users


12 September 2011 at 08:15



This is a quick and dirty way on how to keep all your ldap users in sync with a specific mailman list. The sync_members script is part of the mailman package and ensures that also non-existing users will be purged. Before you start make sure that you have the ldap-utils installed.

The rest should be pretty self-explanatory, but if you got any questions so just let me know ;)

#!/bin/bash

LISTNAME="system";
TEMPFILE=$(mktemp "/tmp/$(basename $0)XXXXXX");

/usr/bin/ldapsearch -Z -x -P 3 -LLL \
        -H ldap://ldapmaster.domain.tld \
        -w 'ultrasecrectpassword' \
        -D "uid=binduser,dc=company,dc=de" \
        -s one -b "dc=users,dc=company,dc=de" \
        '(&(VirtualMailDrop=*)(VirtualMailboxForwardActive=FALSE))' \
        grep '^VirtualMailDrop:' | awk '{ print $2 }' \
        > ${TEMPFILE};

/usr/bin/sync_members \
        --notifyadmin=yes \
        --file ${TEMPFILE} \
        ${LISTNAME} >/dev/null 2>&1;

rm ${TEMPFILE};


You'd also have to adapt the filter expression to reflect your directory schemes and desired attributes. Later you might want to use cron to frequently sync your user-base.

Trackbacks

Use the following link to trackback from your own site:
http://tuxaddicted.net/trackbacks?article_id=49

Leave a comment

Comments