Saturday, 5 May 2012

Postfix With LDAP

       
        POstfix Wiht Ldap

# yum install postfix* php* http*  openldap* rpm*
# yum install system-switch-mail*
# system-switch-mail
Change sendmail to postfix
[*] sendmail
[] postfix
change
[] sendmail
[*] postfix

# useradd  raju
#password raju
# useradd  virtual
# vim /etc/passwd  ==> change
virtual:x:1001:1001::/home/virtual:/bin/bash
# vim /etc/group ==> change
virtual:x:1001:

Download Sum Tar & RPM
# su - raju
$ wget http://ftp.wl0.org/official/2.8/SRPMS/postfix-2.8.2-1.src.rpm
$ wget http://citylan.dl.sourceforge.net/project/courier/imap/4.9.2/courier-imap-4.9.2.tar.bz2
$ wget https://sourceforge.net/projects/courier/files/authlib/0.63.0/courier-authlib-0.63.0.tar.bz2/download
$ echo "%_topdir    $HOME/rpm" >> $HOME/.rpmmacros
$ mkdir rpm
$ cd rpm/
$ mkdir  BUILD  RPMS  SOURCES  SPECS  SRPMS
$ cd RPMS/
$ mkdir  i386
$ rpm -ivh postfix-2.8.2-1.src.rpm
$ cd rpm/SPECS/
$ vim postfix.spec  ===> Change The Lines
%define with_mysql_redhat 1
%define with_sasl         2
and find 'rhel-4' to change 'rhel-5' and 'rhel4' to 'rhel5'

$ rpmbuild -ba postfix.spec
# yum install zlib-devel mysql-devel openssl-devel  ===> for root
$ rpmbuild -ba postfix.spec
# cd /home/raju/rpm/RPMS/i386/  ==> for root
# rpm -Uvh postfix-2.8.2-1.rhel5.i386.rpm ==> for root
$ rpmbuild -ta courier-authlib-0.63.tar.bz2
# yum install libtool postgresql-devel  gdbm-devel pam-devel  expect gcc-c++ *tdl*   ==> for root
$ rpmbuild -ta courier-authlib-0.63.tar.bz2
# cd /home/raju/rpm/RPMS/i386/  ==> for root
# rpm -Uvh courier-authlib*   ==> for root

$ tar -xvf courier-imap-4.9.2.tar.bz2
$ cp courier-imap-4.9.2/courier-imap.spec rpm/SPECS/
$ cp courier-imap-4.9.2.tar.bz2 rpm/SOURCES/
$ cd rpm/SPECS
$ vim couries-imap.spec ==> Change The Line
BuildPreReq: rpm >= 3.0.5 /usr/bin/sed openldap2 openldap2-devel %([ %{suse_version} -gt 819 ] && echo /usr/include/fam.h)
BuildPreReq: rpm >= 4.0.2 sed /usr/include/fam.h openldap-devel openldap-servers
change To
BuildPreReq: rpm >= 3.0.5 /usr/bin/sed openldap2 openldap2-devel
BuildPreReq: rpm >= 4.0.2  openldap-devel openldap-servers
$ rpmbuild -ba courier-imap.spec
# cd /home/raju/rpm/RPMS/i386/  ==> for root
# rpm -ivh courier-imap-4.9.2-1.5Server.i386.rpm   ===> for root
# postconf  -m  ( It is command should show LDAP ) ==> for root
# /etc/init.d/postfix  restart
# /etc/init.d/courier-imap  restart
# /etc/init.d/courier-authlib  restart
# cd /etc/postfix
# cp main.cf main.cf-ORG
# vim main.cf  ==> change & edit The Lines

inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.100.0/24, 127.0.0.0/8
virtual_mailbox_base = /home/virtual
virtual_mailbox_maps = ldap:/etc/postfix/ldap-mailbox.cf
virtual_mailbox_domains = ldap:/etc/postfix/ldap-domains.cf
virtual_minimum_uid = 1001
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
smtpd_recipient_restrictions =
        permit_sasl_authenticated
        permit_mynetworks
        reject_unauth_destination
        permit

# vim /etc/postfix/ldap-domains.cf
server_host=192.168.100.88
search_base=o=virtual,dc=new,dc=com
query_filter=(&(&(objectClass=VirtualDomain)(vd=%s))(accountActive=TRUE)(delete=FALSE))
result_attribute=vd

# vim /etc/postfix/ldap-mailbox.cf
server_host=192.168.100.88
search_base=o=virtual,dc=new,dc=com
query_filter=(&(&(objectClass=VirtualMailAccount)(mail=%s))(accountActive=TRUE)(delete=FALSE))
result_attribute=mailbox

# cd /etc/authlib/
# cp authdaemonrc authdaemonrc-ORG
# cp authldaprc authldaprc-ORG
# vim authdaemonrc
authmodulelist="authldap"
# vim authldaprc
LDAP_URI        ldap://127.0.0.1
LDAP_PROTOCOL_VERSION   3
LDAP_BASEDN             o=virtual,dc=new,dc=com
LDAP_BINDDN             cn=admin,dc=new,dc=com
LDAP_BINDPW             keenable@123
LDAP_TIMEOUT            5
LDAP_AUTHBIND           1
LDAP_MAIL               mail
LDAP_FILTER           (objectClass=VirtualMailAccount)
LDAP_DOMAIN             new.com
LDAP_GLOB_UID           virtual
LDAP_GLOB_GID           virtual
LDAP_HOMEDIR            vdHome
LDAP_MAILDIR            mailbox
LDAP_MAILDIRQUOTA       quota
LDAP_FULLNAME           cn
LDAP_CRYPTPW            userPassword
LDAP_AUXOPTIONS o=group
LDAP_DEREF              never
LDAP_TLS                0
#################################################################
Create Ldap
#################################################################


Download openldap.tar
# tar -xvf openldap.tar
# mv /etc/openldap  /etc/openldap-ORG
# cp -r openldap /etc/
# chown -R ldap.ldap /etc/openldap/
# /etc/init.d/ldap restart

Create base.ldif File
# vim base.ldif ==> edit The Line
# virtual, new.com
dn: dc=new,dc=com
objectClass: top
objectClass: domain
dc: new

dn: o=virtual,dc=new,dc=com
objectClass: top
objectClass: organization
o: virtual
description: mail.new.com virtual root

# new.com, virtual, new.com
dn: vd=new.com,o=virtual,dc=new,dc=com
objectClass: top
objectClass: VirtualDomain
lastChange: 15346541
postfixTransport: maildrop:
vd: new.com
delete: FALSE
accountActive: TRUE

Save & Quit

# vim Useradd.ldif  ==> edit the Line
# raju@new.com, new.com, virtual, new.com
dn: mail=raju@new.com,vd=new.com,o=virtual,dc=new,dc=com
mail: raju@new.com
sn: raju
cn: raju
givenName: raju
mailbox: new.com/raju/
uid: raju.new.com
mailAlternateAddress: raju@new.com
vdHome: /home/virtual/
accountActive: TRUE
lastChange: 1297453
objectClass: top
objectClass: VirtualMailAccount
objectClass: mailAccount
objectClass: Vacation
objectClass: VirtualForward
mailAutoreply: raju@new.com.autoreply
quota: 10000
delete: FALSE
userPassword: Password
vacationActive: FALSE
vacationInfo: Out Of Office
vacationStart: 200906150000
vacationEnd: 200906170000
forwardActive: FALSE

File Save & Quit

##################################################################################
Add Ldap Base
##################################################################################
# ldapadd -x -h  localhost -D "cn=admin,dc=new,dc=com" -wkeenable@123 -f /root/base.ldif
# ldapadd -x -h  localhost -D "cn=admin,dc=new,dc=com" -wkeenable@123 -f /root/Useradd.ldif

# echo "test" | mail -v -s "test" raju@new,com ; tailf /var/log/maillog
# cd /home/virtual
# cd your Domain
# cd your User
# cd new
# cat "Message ID"

# /etc/init.d/postfix  restart
# /etc/init.d/courier-imap  restart
# /etc/init.d/courier-authlib  restart
# /etc/init.d/ldap restart
# chkconfig  postfix on
# chkconfig courier-imap on
# chkconfig courier-authlib on
# chkconfig ldap on



2 comments: