<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>2.6. Creación del directorio HOME para los nuevos usuarios</title><link rel="stylesheet" href="http://guepardo.dyndns.org:8080/sergio-gonzalez/doc/08-postfix-ldap/html/estilo.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.64.1" /><meta name="keywords" content="Postfix, configuración, OpenLDAP" /><link rel="home" href="index.html" title="Sistema de correo con Postfix, OpenLDAP, Courier ((POP3&amp;&amp;IMAP) + SSL), SASL, Spamassassin, Amavis-new y SquirrelMail" /><link rel="up" href="postfix-conf-ldap.html" title="Capítulo 2. Configuración del soporte LDAP en Postfix" /><link rel="previous" href="postfix-confi-ldap-aniadir-usuario.html" title="2.5. Adición de un usuario de correo" /><link rel="next" href="postfix-confi-ldap-crear-alias.html" title="2.7. Creación de un alias de correo" /><meta name="generator" content="Experimental LDP.XSL $Revision: 1.3 $" />
  <!-- Generated by LDP XSLT customization layer
      based on Norman Walsh's DocBook XSL stylesheets.
      More information at http://www.linuxdoc.org/ -->
  </head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2.6. Creación del directorio HOME para los nuevos usuarios</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="postfix-confi-ldap-aniadir-usuario.html">Anterior</a> </td><th width="60%" align="center">Capítulo 2. Configuración del soporte LDAP en Postfix</th><td width="20%" align="right"> <a accesskey="n" href="postfix-confi-ldap-crear-alias.html">Siguiente</a></td></tr></table><hr /></div><div class="sect1" lang="es" xml:lang="es"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="postfix-confi-ldap-crear-dir-vmail"></a>2.6. Creación del directorio <i class="emphasis">HOME</i> para los nuevos usuarios</h2></div></div><div></div></div><p>Es imprescindible que los buzones de correo existan antes de su uso. Por
	este motivo, cada vez que se añada un usuario de correo, se ha de crear su directorio
	<i class="emphasis">HOME</i> y el buzón de correo asociado, así como el archivo
	de recursos para <span class="application">procmail</span>.</p><p>Para automatizar esta operación se ha creado el siguiente script:</p><table border="0" bgcolor="#E0E0E0" width="90%"><tr><td><pre class="programlisting">#!/bin/sh
#
# Copyright (C) 2004 Sergio González González &lt;sergio.gonzalez@hispalinux.es&gt;
# 
# Depends on:
#               - ldapsearch
#               - maildirmake ( from courier )
#
# Based on http://jeroen.protheus.com/postfix-courier-ldap-howto.html
# (c) J.Vriesman
#
# and
#
# Based on http://bulma.net/body.phtml?nIdNoticia=2013
# (c) Jesús Roncero Franco
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#


# Password to bind to ldap server
systempass="1"  
# Bind dn
binddn="ou=postfix,dc=gsr,dc=pt" 
# Acount leave
accountleave="ou=people,dc=gsr,dc=pt" 
# ldap host
ldaphost="gsr.pt"
# Maildir name
maildir="Maildir/"
# Mail users home name
homedir="/home/vmail"
# Mail user's group
group="vmail"


usernames=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
                      -b "$accountleave" "(!(quota=-1))" uid  \
                      | grep "^[^#]" | grep "^[^dn]" | grep uid | awk '{ print $2 }'`


# create personal mailfolders

for username in $usernames
do
  homedirectory=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
                            -b "$accountleave" "(uid=$username)" homeDirectory \
                            | grep "^[^#]" | grep homeDirectory | grep "$homedir" \
                            | awk '{ print $2 }'`

  if [ ! -d $homedirectory/$maildir ] &amp;&amp; [ ! -z $homedirectory ]
  then

    mkdir -p -m 2750 $homedirectory
    maildirmake $homedirectory/$maildir

    if [ ! -f $homedirectory/.procmailrc ]
    then

      echo -ne "PATH=/usr/bin:/bin:/usr/local/bin:.\nMAILDIR=\$HOME/Maildir\n\
                DEFAULT=\$MAILDIR/" &gt; $homedirectory/.procmailrc

    fi

    chown -R $username.$group $homedirectory
  fi

done</pre></td></tr></table><p>El script anterior creará el <i class="emphasis">HOME</i> de los usuarios de correo
	que no lo tuviesen ya creado, el directorio <tt class="filename">Maildir</tt>
	en el que se almacenarán los correos enviados al usuario y el archivo
	<tt class="filename">.procmailrc</tt>, que se encargará de decirle a
	<span class="application">procmail</span> como se ha de comportar.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="http://guepardo.dyndns.org:8080/sergio-gonzalez/doc/08-postfix-ldap/html/imagenes/note.png" /></td><th align="left">Nota</th></tr><tr><td colspan="2" align="left" valign="top"><p>Para la correcta ejecución del script se necesita la herramienta
	<span class="application">maildirmake</span>. Esta herramienta, utilizada para crear
	un directorio tipo Maildir, viene junto al paquete <i class="emphasis">courier-base</i>.</p></td></tr></table></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="http://guepardo.dyndns.org:8080/sergio-gonzalez/doc/08-postfix-ldap/html/imagenes/important.png" /></td><th align="left">Importante</th></tr><tr><td colspan="2" align="left" valign="top"><p>Recuerde que cada vez que se añada un usuario al sistema, se ha de ejecutar
	este script como <i class="emphasis">root</i>.</p></td></tr></table></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="postfix-confi-ldap-aniadir-usuario.html">Anterior</a> </td><td width="20%" align="center"><a accesskey="u" href="postfix-conf-ldap.html">Subir</a></td><td width="40%" align="right"> <a accesskey="n" href="postfix-confi-ldap-crear-alias.html">Siguiente</a></td></tr><tr><td width="40%" align="left" valign="top">2.5. Adición de un usuario de correo </td><td width="20%" align="center"><a accesskey="h" href="index.html">Inicio</a></td><td width="40%" align="right" valign="top"> 2.7. Creación de un alias de correo</td></tr></table></div></body></html>

