2007-11-15 19:07:24 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* https://ldapsaisie.org
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Messages d'erreur
|
|
|
|
|
|
|
|
// Support
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('POSIX_SUPPORT_01',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("POSIX Support : The constant %{const} is not defined.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('POSIX_SUPPORT_02',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("POSIX Support : Unable to load LSaddon::FTP.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Autres erreurs
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('POSIX_01',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("POSIX : The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2007-11-15 19:07:24 +01:00
|
|
|
* Verification du support POSIX par ldapSaisie
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2010-03-15 12:25:34 +01:00
|
|
|
* @retval boolean true si POSIX est pleinement supporté, false sinon
|
2008-05-15 12:56:55 +02:00
|
|
|
*/
|
|
|
|
function LSaddon_posix_support() {
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
$retval=true;
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2008-09-09 17:48:07 +02:00
|
|
|
// Dependance de librairie
|
|
|
|
if (!function_exists('createDirsByFTP')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
if(!LSsession :: loadLSaddon('ftp')) {
|
|
|
|
LSerror :: addErrorCode('POSIX_SUPPORT_02');
|
2008-09-09 17:48:07 +02:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
|
|
|
$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',
|
2008-09-09 17:48:07 +02:00
|
|
|
'LS_POSIX_HOMEDIRECTORY',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_HOST',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_PORT',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_USER',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_PWD',
|
2013-06-24 17:38:26 +02:00
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_PATH',
|
|
|
|
'LS_POSIX_DN_TO_UID_PATTERN',
|
2008-05-15 12:56:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach($MUST_DEFINE_CONST as $const) {
|
2009-01-12 11:57:27 +01:00
|
|
|
if ( (!defined($const)) || (constant($const) == "")) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('POSIX_SUPPORT_O1',$const);
|
2008-05-15 12:56:55 +02:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generation de uidNumber
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @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) {
|
|
|
|
|
2009-04-07 19:03:13 +02:00
|
|
|
$objects = LSldap :: search (
|
|
|
|
LS_POSIX_UIDNUMBER_ATTR.'=*',
|
|
|
|
NULL,
|
|
|
|
array(
|
|
|
|
'attributes' => array(
|
|
|
|
LS_POSIX_UIDNUMBER_ATTR
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-05-15 12:56:55 +02:00
|
|
|
$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
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @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) {
|
|
|
|
|
2009-04-07 19:03:13 +02:00
|
|
|
$objects = LSldap :: search (
|
|
|
|
LS_POSIX_GIDNUMBER_ATTR.'=*',
|
|
|
|
NULL,
|
|
|
|
array(
|
|
|
|
'attributes' => array(
|
|
|
|
LS_POSIX_GIDNUMBER_ATTR
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2008-05-15 12:56:55 +02:00
|
|
|
$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
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-05-15 12:56:55 +02:00
|
|
|
* @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' ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'uid', 'attr' => 'homeDirectory'));
|
2008-05-15 12:56:55 +02:00
|
|
|
return;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2016-11-17 11:37:19 +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
|
|
|
}
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2008-09-09 17:48:07 +02:00
|
|
|
/**
|
|
|
|
* Generation de homeDirectory
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-09-09 17:48:07 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2016-11-17 11:37:19 +01:00
|
|
|
*
|
2008-09-09 17:48:07 +02:00
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string homeDirectory ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function createHomeDirectoryByFTP($ldapObject) {
|
|
|
|
$dir = getFData(LS_POSIX_HOMEDIRECTORY_FTP_PATH,$ldapObject,'getValue');
|
|
|
|
if (!createDirsByFTP(LS_POSIX_HOMEDIRECTORY_FTP_HOST,LS_POSIX_HOMEDIRECTORY_FTP_PORT,LS_POSIX_HOMEDIRECTORY_FTP_USER,LS_POSIX_HOMEDIRECTORY_FTP_PWD,$dir)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('POSIX_02');
|
2008-09-09 17:48:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2016-11-17 11:37:19 +01:00
|
|
|
/**
|
|
|
|
* Generate member attribute value from memberUid
|
|
|
|
*
|
|
|
|
* IMPORTANT : The attribute memberUid must be define in configuration
|
|
|
|
* of the same object and must use HTML type select_object.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject The LSldapObject
|
|
|
|
*
|
|
|
|
* @retval array|null array of member attribute values or null in case of error
|
|
|
|
*/
|
|
|
|
function generateMemberFromMemberUid($ldapObject) {
|
2010-08-04 12:21:43 +02:00
|
|
|
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'memberUid', 'attr' => 'member'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( get_class($ldapObject -> attrs[ 'member' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'member', 'attr' => 'member'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:37:19 +01:00
|
|
|
$obj_type=LSconfig::get('LSobjects.'.get_class($ldapObject).'.attrs.memberUid.html_options.selectable_object.object_type');
|
|
|
|
if (empty($obj_type))
|
|
|
|
return;
|
|
|
|
|
2010-08-04 12:21:43 +02:00
|
|
|
$uids = $ldapObject -> attrs[ 'memberUid' ] -> getValue();
|
|
|
|
$member = array();
|
|
|
|
if (is_array($uids)) {
|
|
|
|
foreach ( $uids as $uid ) {
|
2016-11-17 11:37:19 +01:00
|
|
|
$member[]='uid='.$uid.','.LSconfig::get('LSobjects.'.$obj_type.'.container_dn').','.LSsession::getTopDn();
|
2010-08-04 12:21:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $member;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-11-17 11:37:19 +01:00
|
|
|
/**
|
|
|
|
* Generate memberUid attribute value from uniqueMember
|
|
|
|
*
|
|
|
|
* IMPORTANT : The attribute uniqueMember must be define in configuration
|
|
|
|
* of the same object.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject The LSldapObject
|
|
|
|
*
|
|
|
|
* @retval array|null array of memberUid values or null in case of error
|
|
|
|
*/
|
|
|
|
function generate_memberUidFromUniqueMember($ldapObject) {
|
2013-06-24 17:38:26 +02:00
|
|
|
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'memberUid', 'attr' => 'memberUid'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( get_class($ldapObject -> attrs[ 'uniqueMember' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01',array('dependency' => 'uniqueMember', 'attr' => 'memberUid'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dns = $ldapObject -> attrs[ 'uniqueMember' ] -> getValue();
|
|
|
|
$uids = array();
|
|
|
|
if (is_array($dns)) {
|
|
|
|
foreach($dns as $dn) {
|
|
|
|
if(preg_match(LS_POSIX_DN_TO_UID_PATTERN,$dn,$matches)) {
|
|
|
|
$uids[]=$matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $uids;
|
2016-11-17 11:37:19 +01:00
|
|
|
}
|
2020-09-11 13:54:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate shadowLastChange attribute value
|
|
|
|
*
|
|
|
|
* Just return a shadowLastChange value corresponding to current date.
|
|
|
|
*
|
2020-12-01 16:37:01 +01:00
|
|
|
* Important: this function is designed to be used with LSattr_html_date
|
|
|
|
* & LSattr_ldap_shadowExpire classes. The returned value is just a timestamp
|
|
|
|
* and it will be converted by LSattr_ldap_shadowExpire as raw LDAP value, that is,
|
|
|
|
* divided by 86400.
|
|
|
|
*
|
2020-09-11 13:54:08 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $anything anything
|
|
|
|
*
|
|
|
|
* @retval integer The shadowLastChange attribute value (=current date)
|
|
|
|
*/
|
|
|
|
function generate_shadowLastChange($anything) {
|
2020-12-01 16:37:01 +01:00
|
|
|
return time();
|
2020-09-11 13:54:08 +02:00
|
|
|
}
|