<?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>Apéndice H. Script para la creación/eliminación de los homes de los usuarios</title><link rel="stylesheet" href="./estilo.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.64.1" /><link rel="home" href="index.html" title="Integración de redes con OpenLDAP, Samba, CUPS y PyKota" /><link rel="up" href="apendice-otros-archivos.html" title="Parte V. Misceláneo" /><link rel="previous" href="ldap-account-manager-configuracion.html" title="G.2. Configuración" /><link rel="next" href="phpldapadmin-instalacion-conf.html" title="Apéndice I. Instalación y configuración de phpLDAPadmin" /><meta xmlns="http://www.w3.org/TR/xhtml1/transitional" name="generator" content="Experimental LDP.XSL $Revision: 1.3 $"></meta>
  <!-- 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">Apéndice H. Script para la creación/eliminación de los homes de los usuarios</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ldap-account-manager-configuracion.html">Anterior</a> </td><th width="60%" align="center">Parte V. Misceláneo</th><td width="20%" align="right"> <a accesskey="n" href="phpldapadmin-instalacion-conf.html">Siguiente</a></td></tr></table><hr /></div><div class="appendix" lang="es" xml:lang="es"><div class="titlepage"><div><div><h2 class="title"><a id="make-deleteHomedirectory"></a>Apéndice H. Script para la creación/eliminación de los homes de los usuarios</h2></div></div><div></div></div><p>Cuando se añaden/borran usuarios en la base de datos de <span class="acronym">LDAP</span>
	no se crea el directorio destinado a almacenar sus archivos personales
	(el directorio <i class="emphasis">HOME</i>). La aplicación
	<span class="acronym">LDAP</span> Account Manager (ver el
	<a href="ldap-account-manager-instalacion-conf.html" title="Apéndice G. Instalación y configuración de LAM (LDAP&#10;&#9;Account Manager)">Apéndice G, <i>Instalación y configuración de LAM (LDAP
	Account Manager)</i></a> para más información)
	adjunta un script destinado a la creación/eliminación de los directorios
	home de los usuarios: <span class="application">lamdaemon.pl</span>; pero en esta
	documentación no se hará uso del mismo.</p><p>En su lugar se ha creado el siguiente script, que ha de ser ejecutado
	como usuario root cada vez que se cree un nuevo usuario, sobre todo si este
	está destinado a hacer uso de Samba (la creación del directorio
	home cuando se accede a la shell ya está solucionado: vea la
	<a href="openldap-autentificacion-usuarios-configuracion.html#openldap-autentificacion-usuarios-configuracion-pam-common-session" title="5.3.2.3. /etc/pam.d/common-session">Sección 5.3.2.3, “/etc/pam.d/common-session”</a>
	para más detalles):</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="./imagenes/note.png" /></td><th align="left">Nota</th></tr><tr><td colspan="2" align="left" valign="top"><p>El script no está pensado para sistemas en producción, simplemente
	es un ejemplo utilizado para facilitar la creación de esta documentación.</p></td></tr></table></div><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="./imagenes/warning.png" /></td><th align="left">Aviso</th></tr><tr><td colspan="2" align="left" valign="top"><p>Tenga mucho cuidado con el uso del siguiente script, ya que
	añade y borra, ¡sin preguntar!, los homes de los usuarios en relación
	al estado de la base de datos de usuarios <span class="acronym">LDAP</span>.</p><p>Su comportamiento es el siguiete:</p><div class="itemizedlist"><ul type="disc"><li><p>Crea el directorio home y copia el contenido del directorio
			<tt class="filename">/etc/skel</tt>, de aquellos usuarios
			que no tengan creado su directorio home.</p></li><li><p>Borra, sin preguntar ni hacer una copia de seguridad,
			los homes de los usuarios que ya no existan en la base de datos
			<span class="acronym">LDAP</span>, pero aun posean un directorio home
			en el sistem.</p></li></ul></div></td></tr></table></div><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="./imagenes/note.png" /></td><th align="left">Nota</th></tr><tr><td colspan="2" align="left" valign="top"><p>Este script se ha basado en los scripts creados
	por J. Vriesman y Jesús Roncero Franco para la elaboración de los
	siguientes documentos, respectivamente:</p><div class="itemizedlist"><ul type="disc"><li><p><a href="http://jeroen.protheus.com/postfix-courier-ldap-howto.html" target="_top">http://jeroen.protheus.com/postfix-courier-ldap-howto.html</a></p></li><li><p><a href="http://bulma.net/body.phtml?nIdNoticia=2013" target="_top">http://bulma.net/body.phtml?nIdNoticia=2013</a></p></li></ul></div></td></tr></table></div><table xmlns="http://www.w3.org/TR/xhtml1/transitional" 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
#
# 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
#
#
# This script manage the home directories of LDAP users (make the new users home
# directory and delete the non-existent users home directory)



# Password to bind to ldap server
systempass="1"  
# Bind dn
binddn="cn=admin,dc=gsr,dc=pt" 
# Acount leave
accountleave="ou=people,dc=gsr,dc=pt" 
# ldap host
ldaphost="gsr.pt"
# skel directory
skel="/etc/skel/"
# Home leave (without final slash: '/')
homeleave="/home/samba/users"


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

# create personal home directories

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

  group=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
                    -b "$accountleave" "(uid=$username)" gidNumber \
                    | grep "^[^#]" | grep gidNumber \
                    | awk '{ print $2 }'`

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

    cp -a $skel $homedirectory
    chown -R $username.$group $homedirectory
  fi

done

# delete personal home directories

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

  if [ -z $name ]
  then
    rm -rf $homeleave/$username
  fi
done</pre></td></tr></table></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ldap-account-manager-configuracion.html">Anterior</a> </td><td width="20%" align="center"><a accesskey="u" href="apendice-otros-archivos.html">Subir</a></td><td width="40%" align="right"> <a accesskey="n" href="phpldapadmin-instalacion-conf.html">Siguiente</a></td></tr><tr><td width="40%" align="left" valign="top">G.2. Configuración </td><td width="20%" align="center"><a accesskey="h" href="index.html">Inicio</a></td><td width="40%" align="right" valign="top"> Apéndice I. Instalación y configuración de phpLDAPadmin</td></tr></table></div></body></html>
