2007-11-15 19:07:24 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
|
|
|
* Données de configuration pour le support POSIX
|
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Nom de l'attribut LDAP uid
|
|
|
|
define('LS_POSIX_UID_ATTR','uid');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Nom de l'attribut LDAP uidNumber
|
|
|
|
define('LS_POSIX_UIDNUMBER_ATTR','uidNumber');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Valeur minimum d'un uidNumber
|
|
|
|
define('LS_POSIX_UIDNUMBER_MIN_VAL','100000');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Nom de l'attribut LDAP gidNumber
|
|
|
|
define('LS_POSIX_GIDNUMBER_ATTR','gidNumber');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Valeur minimum d'un gidNumber
|
|
|
|
define('LS_POSIX_GIDNUMBER_MIN_VAL','100000');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Dossier contenant les homes des utilisateurs (defaut: /home/)
|
|
|
|
define('LS_POSIX_HOMEDIRECTORY','/home/');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// -- Message d'erreur --
|
|
|
|
// Support
|
|
|
|
$GLOBALS['error_code']['POSIX_SUPPORT_01']= array (
|
|
|
|
'msg' => _("POSIX Support : La constante %{const} n'est pas définie."),
|
|
|
|
'level' => 'c'
|
|
|
|
);
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
// Autres erreurs
|
|
|
|
$GLOBALS['error_code']['POSIX_01']= array (
|
|
|
|
'msg' => _("POSIX : L'attribut %{dependency} est introuvable. Impossible de générer l'attribut %{attr}."),
|
|
|
|
'level' => 'c'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fin des données de configuration
|
|
|
|
*/
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2007-11-15 19:07:24 +01:00
|
|
|
* Verification du support POSIX par ldapSaisie
|
2008-05-15 12:56:55 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval boolean true si Samba est pleinement supporté, false sinon
|
|
|
|
*/
|
|
|
|
function LSaddon_posix_support() {
|
|
|
|
|
|
|
|
$retval=true;
|
|
|
|
|
|
|
|
$MUST_DEFINE_CONST= array(
|
|
|
|
'LS_POSIX_UID_ATTR',
|
|
|
|
'LS_POSIX_UIDNUMBER_ATTR',
|
|
|
|
'LS_POSIX_GIDNUMBER_ATTR',
|
|
|
|
'LS_POSIX_UIDNUMBER_MIN_VAL',
|
|
|
|
'LS_POSIX_GIDNUMBER_MIN_VAL',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($MUST_DEFINE_CONST as $const) {
|
|
|
|
if ( constant($const) == '' ) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode('POSIX_SUPPORT_O1',$const);
|
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generation de uidNumber
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval integer uidNumber ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_uidNumber($ldapObject) {
|
|
|
|
|
|
|
|
$objects = $GLOBALS['LSldap'] -> search (LS_POSIX_UIDNUMBER_ATTR.'=*');
|
|
|
|
$uidNumber = LS_POSIX_UIDNUMBER_MIN_VAL;
|
|
|
|
|
|
|
|
if (!is_array($objects))
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach($objects as $object) {
|
|
|
|
if($object['attrs'][LS_POSIX_UIDNUMBER_ATTR] > $uidNumber)
|
|
|
|
$uidNumber = $object['attrs'][LS_POSIX_UIDNUMBER_ATTR];
|
|
|
|
}
|
|
|
|
|
|
|
|
$uidNumber++;
|
|
|
|
return $uidNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generation de gidNumber
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval integer gidNumber ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_gidNumber($ldapObject) {
|
|
|
|
|
|
|
|
$objects = $GLOBALS['LSldap'] -> search (LS_POSIX_GIDNUMBER_ATTR.'=*');
|
|
|
|
$gidNumber = LS_POSIX_GIDNUMBER_MIN_VAL;
|
|
|
|
|
|
|
|
if (!is_array($objects))
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach($objects as $object) {
|
|
|
|
if($object['attrs'][LS_POSIX_GIDNUMBER_ATTR] > $gidNumber)
|
|
|
|
$gidNumber = $object['attrs'][LS_POSIX_GIDNUMBER_ATTR];
|
|
|
|
}
|
|
|
|
|
|
|
|
$gidNumber++;
|
|
|
|
return $gidNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generation de homeDirectory
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string homeDirectory ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_homeDirectory($ldapObject) {
|
2007-11-15 19:07:24 +01:00
|
|
|
if ( get_class($ldapObject -> attrs[ LS_POSIX_UID_ATTR ]) != 'LSattribute' ) {
|
2008-05-15 12:56:55 +02:00
|
|
|
$GLOBALS['LSerror'] -> addErrorCode('POSIX_01',array('dependency' => 'uid', 'attr' => 'homeDirectory'));
|
|
|
|
return;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
|
|
|
$uid = $ldapObject -> attrs[ LS_POSIX_UID_ATTR ] -> getValue();
|
|
|
|
$home = LS_POSIX_HOMEDIRECTORY . $uid[0];
|
|
|
|
return $home;
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
?>
|