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',
|
2023-10-13 19:05:42 +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',
|
2023-10-13 19:05:42 +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',
|
2023-10-13 19:05:42 +02:00
|
|
|
___("POSIX: The attribute %{dependency} is missing. Unable to forge the attribute %{attr}.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('POSIX_02',
|
|
|
|
___("POSIX: Fail to create user home directory.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('POSIX_03',
|
|
|
|
___("POSIX: Fail to delete user home directory.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
/**
|
|
|
|
* Verification du support POSIX par ldapSaisie
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @return boolean true si POSIX est pleinement supporté, false sinon
|
|
|
|
*/
|
|
|
|
function LSaddon_posix_support() {
|
|
|
|
$retval = true;
|
|
|
|
|
|
|
|
// Dependance de librairie
|
|
|
|
if (!function_exists('createDirsByFTP')) {
|
|
|
|
if(!LSsession :: loadLSaddon('ftp')) {
|
|
|
|
LSerror :: addErrorCode('POSIX_SUPPORT_02');
|
|
|
|
$retval = false;
|
2008-09-09 17:48:07 +02:00
|
|
|
}
|
2023-06-20 19:42:12 +02:00
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +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',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_HOST',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_PORT',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_USER',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_PWD',
|
|
|
|
'LS_POSIX_HOMEDIRECTORY_FTP_PATH',
|
|
|
|
'LS_POSIX_DN_TO_UID_PATTERN',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($MUST_DEFINE_CONST as $const) {
|
|
|
|
if ( (!defined($const)) || (constant($const) == "")) {
|
|
|
|
LSerror :: addErrorCode('POSIX_SUPPORT_O1', $const);
|
|
|
|
$retval = false;
|
2008-05-15 12:56:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
return $retval;
|
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
/**
|
|
|
|
* Generation de uidNumber
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param LSldapObject $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @return integer|false uidNumber ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_uidNumber($ldapObject) {
|
|
|
|
$objects = LSldap :: search (
|
|
|
|
LS_POSIX_UIDNUMBER_ATTR.'=*',
|
|
|
|
NULL,
|
|
|
|
array(
|
|
|
|
'attributes' => array(
|
|
|
|
LS_POSIX_UIDNUMBER_ATTR
|
2009-04-07 19:03:13 +02:00
|
|
|
)
|
2023-06-20 19:42:12 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$uidNumber = LS_POSIX_UIDNUMBER_MIN_VAL;
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
if (!is_array($objects))
|
|
|
|
return false;
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
foreach($objects as $object) {
|
|
|
|
if($object['attrs'][LS_POSIX_UIDNUMBER_ATTR] > $uidNumber)
|
|
|
|
$uidNumber = $object['attrs'][LS_POSIX_UIDNUMBER_ATTR];
|
2008-05-15 12:56:55 +02:00
|
|
|
}
|
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
$uidNumber++;
|
|
|
|
return $uidNumber;
|
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
/**
|
|
|
|
* Generation de gidNumber
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param LSldapObject $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @return integer|false gidNumber ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_gidNumber($ldapObject) {
|
|
|
|
$objects = LSldap :: search (
|
|
|
|
LS_POSIX_GIDNUMBER_ATTR . '=*',
|
|
|
|
NULL,
|
|
|
|
array(
|
|
|
|
'attributes' => array(
|
|
|
|
LS_POSIX_GIDNUMBER_ATTR
|
2009-04-07 19:03:13 +02:00
|
|
|
)
|
2023-06-20 19:42:12 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$gidNumber = LS_POSIX_GIDNUMBER_MIN_VAL;
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
if (!is_array($objects))
|
|
|
|
return false;
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
foreach($objects as $object) {
|
|
|
|
if($object['attrs'][LS_POSIX_GIDNUMBER_ATTR] > $gidNumber)
|
|
|
|
$gidNumber = $object['attrs'][LS_POSIX_GIDNUMBER_ATTR];
|
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
$gidNumber++;
|
|
|
|
return $gidNumber;
|
|
|
|
}
|
2008-05-15 12:56:55 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
/**
|
|
|
|
* Generation de homeDirectory
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param LSldapObject $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @return string|false homeDirectory ou false si il y a un problème durant la génération
|
|
|
|
*/
|
|
|
|
function generate_homeDirectory($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ LS_POSIX_UID_ATTR ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01', array('dependency' => 'uid', 'attr' => 'homeDirectory'));
|
|
|
|
return false;
|
2008-05-15 12:56:55 +02:00
|
|
|
}
|
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
$uid = $ldapObject -> attrs[ LS_POSIX_UID_ATTR ] -> getValue();
|
|
|
|
$home = LS_POSIX_HOMEDIRECTORY . $uid[0];
|
|
|
|
return $home;
|
|
|
|
}
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
/**
|
|
|
|
* Create home directory by FTP
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param LSldapObject $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @return bool True on success, false otherwise
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
LSerror :: addErrorCode('POSIX_02');
|
|
|
|
return false;
|
2023-10-13 19:05:42 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete home directory by FTP
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param LSldapObject $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @return bool True on success, false otherwise
|
|
|
|
*/
|
|
|
|
function deleteHomeDirectoryByFTP($ldapObject) {
|
|
|
|
$dir = getFData(LS_POSIX_HOMEDIRECTORY_FTP_PATH, $ldapObject, 'getValue');
|
|
|
|
if (
|
|
|
|
!removeDirsByFTP(
|
|
|
|
LS_POSIX_HOMEDIRECTORY_FTP_HOST, LS_POSIX_HOMEDIRECTORY_FTP_PORT,
|
|
|
|
LS_POSIX_HOMEDIRECTORY_FTP_USER, LS_POSIX_HOMEDIRECTORY_FTP_PWD,
|
|
|
|
$dir
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
LSerror :: addErrorCode('POSIX_03');
|
|
|
|
return false;
|
2023-06-20 19:42:12 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2023-06-20 19:42:12 +02: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 LSldapObject $ldapObject The LSldapObject
|
|
|
|
*
|
|
|
|
* @return array|false array of member attribute values or false in case of error
|
|
|
|
*/
|
|
|
|
function generateMemberFromMemberUid($ldapObject) {
|
|
|
|
if ( get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01', array('dependency' => 'memberUid', 'attr' => 'member'));
|
|
|
|
return false;
|
2008-05-15 12:56:55 +02:00
|
|
|
}
|
2016-11-17 11:37:19 +01:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
if ( get_class($ldapObject -> attrs[ 'member' ]) != 'LSattribute' ) {
|
|
|
|
LSerror :: addErrorCode('POSIX_01', array('dependency' => 'member', 'attr' => 'member'));
|
|
|
|
return false;
|
2008-09-09 17:48:07 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
$obj_type = LSconfig::get(
|
|
|
|
'LSobjects.'.get_class($ldapObject).'.attrs.memberUid.html_options.selectable_object.object_type'
|
|
|
|
);
|
|
|
|
if (empty($obj_type))
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2010-08-04 12:21:43 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
$uids = $ldapObject -> attrs[ 'memberUid' ] -> getValue();
|
|
|
|
$member = array();
|
|
|
|
if (is_array($uids)) {
|
|
|
|
foreach ( $uids as $uid ) {
|
|
|
|
$member[] = sprintf(
|
|
|
|
'uid=%s,%s,%s',
|
|
|
|
$uid,
|
|
|
|
LSconfig::get('LSobjects.'.$obj_type.'.container_dn'),
|
|
|
|
LSsession::getTopDn()
|
|
|
|
);
|
2010-08-04 12:21:43 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-20 19:42:12 +02:00
|
|
|
return $member;
|
|
|
|
}
|
2010-08-04 12:21:43 +02:00
|
|
|
|
2023-06-20 19:42:12 +02: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 LSldapObject $ldapObject The LSldapObject
|
|
|
|
*
|
|
|
|
* @return array|false array of memberUid values or false in case of error
|
|
|
|
*/
|
|
|
|
function generate_memberUidFromUniqueMember($ldapObject) {
|
|
|
|
if (get_class($ldapObject -> attrs[ 'memberUid' ]) != 'LSattribute') {
|
|
|
|
LSerror :: addErrorCode('POSIX_01', array('dependency' => 'memberUid', 'attr' => 'memberUid'));
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-24 17:38:26 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
if (get_class($ldapObject -> attrs[ 'uniqueMember' ]) != 'LSattribute') {
|
|
|
|
LSerror :: addErrorCode('POSIX_01', array('dependency' => 'uniqueMember', 'attr' => 'memberUid'));
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-24 17:38:26 +02:00
|
|
|
|
2023-06-20 19:42:12 +02:00
|
|
|
$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];
|
2013-06-24 17:38:26 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-17 11:37:19 +01:00
|
|
|
}
|
2023-06-20 19:42:12 +02:00
|
|
|
return $uids;
|
|
|
|
}
|
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>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param mixed $anything anything
|
2020-09-11 13:54:08 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return integer The shadowLastChange attribute value (=current date)
|
2020-09-11 13:54:08 +02:00
|
|
|
*/
|
|
|
|
function generate_shadowLastChange($anything) {
|
2020-12-01 16:37:01 +01:00
|
|
|
return time();
|
2020-09-11 13:54:08 +02:00
|
|
|
}
|