#! /bin/bash
#------------------------------------------#
# LDAP2PostfixMap #
#------------------------------------------#
# #
# Script that updates a Postfix virtual #
# map with emails on LDAP #
# #
# Yvan Godard #
# godardyvan@gmail.com #
# #
# Version 0.2 -- may, 29 2015 #
# Under Licence #
# Creative Commons 4.0 BY NC SA #
# #
# http://goo.gl/9FauYh #
# #
#------------------------------------------#
# Variables initialisation
VERSION="Ldap2PostfixMap v0.2 - 2013, Yvan Godard [godardyvan@gmail.com]"
help="no"
SCRIPT_DIR=$(dirname $0)
SCRIPT_NAME=$(basename $0)
DNBASE=""
VIRTUAL_MAP_FILE=""
VIRTUAL_MAP_FILE_NEW=$(mktemp /tmp/ldap2postfixmap_mapfilenew.XXXXX)
VIRTUAL_DOMAIN_RELAYED=""
LDAP_SERVER_URL="ldap://127.0.0.1"
DN_USER_BRANCH="cn=users"
LDAPGROUP_OBJECTCLASS="allusers"
LDAPGROUP=""
LDAPADMIN_UID=""
WITH_LDAP_BIND="no"
LDAPADMIN_PASS=""
POSTMAP_COMMAND="/usr/sbin/postmap"
MAIN_DOMAIN=""
MAIN_DOMAIN_DEFINED="no"
EMAIL_REPORT="nomail"
EMAIL_LEVEL=0
LOG="/var/log/ldap2postfixmap.log"
LOG_ACTIVE=0
EMAIL_ADDRESS=""
LOG_TEMP=$(mktemp /tmp/ldap2postfixmap_log.XXXXX)
LIST_USERS=$(mktemp /tmp/ldap2postfixmap_users.XXXXX)
LIST_DUPLICATED_EMAILS=$(mktemp /tmp/ldap2postfixmap_duplicatedemails.XXXXX)
DUPLICATED_EMAILS=0
help () {
echo -e "$VERSION\n"
echo -e "This tool is designed to create/update a Postifx virtual map with addresses from a LDAP group or alls users on LDAP."
echo -e "It works both with LDAP groups defined by objectClass posixGroup or groupOfNames."
echo -e "The domain name of virtual addresses must be defined in /etc/postfix/main.cf as (e.g. as 'virtual_alias_domain')"
echo -e "and the Postfix map filename must be defined as 'virtual_alias_maps' in /etc/postfix/main.cf."
echo -e "\nDisclamer:"
echo -e "This tool is provide without any support and guarantee."
echo -e "\nSynopsis:"
echo -e "./$SCRIPT_NAME [-h] | -d -f