2020-09-09 18:45:34 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* https://ldapsaisie.org
|
2020-09-09 18:45:34 +02: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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LDAP attribute type for sambaAcctFlags
|
|
|
|
**/
|
|
|
|
class LSattr_ldap_sambaAcctFlags extends LSattr_ldap {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return display value of attribute after treatment related to LDAP type
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param mixed $data Attribute data
|
2020-09-09 18:45:34 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed Attribute display value
|
2020-09-09 18:45:34 +02:00
|
|
|
**/
|
|
|
|
public function getDisplayValue($data) {
|
|
|
|
$values = self :: parse_flags($data);
|
|
|
|
if (is_array($values))
|
|
|
|
return $values;
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return attribute value after treatment related to LDAP type
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param mixed $data Attribute data
|
2020-09-09 18:45:34 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed Attribute data
|
2020-09-09 18:45:34 +02:00
|
|
|
**/
|
|
|
|
public function getUpdateData($data) {
|
|
|
|
$values = self :: format_flags($data);
|
|
|
|
if (is_array($values))
|
|
|
|
return $values;
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse flags
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array|string|null $data Attribute data
|
2020-09-09 18:45:34 +02:00
|
|
|
*
|
2023-01-02 01:17:46 +01:00
|
|
|
* @return array|false Array of enabled flags, or false
|
2020-09-09 18:45:34 +02:00
|
|
|
**/
|
|
|
|
public static function parse_flags($data) {
|
2021-06-10 19:02:19 +02:00
|
|
|
if (!$data)
|
|
|
|
return array();
|
2020-11-30 19:37:44 +01:00
|
|
|
$data = ensureIsArray($data);
|
2020-09-09 18:45:34 +02:00
|
|
|
if (count($data) > 1) {
|
|
|
|
LSerror :: addErrorCode('LSattr_ldap_sambaAcctFlags_01');
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2020-09-09 18:45:34 +02:00
|
|
|
}
|
|
|
|
$value = $data[0];
|
|
|
|
$preg_pattern = "/^\[([ ";
|
|
|
|
foreach(self :: get_available_flags() as $group_label => $flags)
|
|
|
|
foreach($flags as $flag => $label)
|
|
|
|
$preg_pattern .= $flag;
|
|
|
|
$preg_pattern .= "]{0,16})\]$/";
|
|
|
|
self :: log_trace("parse($value): PREG composed pattern = '$preg_pattern'");
|
|
|
|
if (!preg_match($preg_pattern, $value, $m)) {
|
|
|
|
self :: log_error("parse($value): fail to parse value.");
|
|
|
|
LSerror :: addErrorCode('LSattr_ldap_sambaAcctFlags_02');
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2020-09-09 18:45:34 +02:00
|
|
|
}
|
|
|
|
$flags = array();
|
|
|
|
foreach(str_split($m[1]) as $flag) {
|
|
|
|
if ($flag == ' ')
|
|
|
|
continue;
|
|
|
|
if (in_array($flag, $flags))
|
|
|
|
continue;
|
|
|
|
$flags[] = $flag;
|
|
|
|
}
|
|
|
|
return $flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format flags as one LDAP attribute value
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array $flags of string Flags
|
2020-09-09 18:45:34 +02:00
|
|
|
*
|
2023-01-02 01:17:46 +01:00
|
|
|
* @return array|false Array of LDAP attribute value, or false
|
2020-09-09 18:45:34 +02:00
|
|
|
**/
|
|
|
|
public static function format_flags($flags) {
|
2020-11-30 19:37:44 +01:00
|
|
|
$flags = ensureIsArray($flags);
|
2020-09-09 18:45:34 +02:00
|
|
|
foreach($flags as $flag) {
|
|
|
|
if (!self :: check_flag($flag)) {
|
|
|
|
LSerror :: addErrorCode('LSattr_ldap_sambaAcctFlags_03', $flag);
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2020-09-09 18:45:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add some space if need
|
|
|
|
for ($i=count($flags); $i <= 11; $i++)
|
|
|
|
$flags[] = ' ';
|
|
|
|
return array(
|
|
|
|
"[".implode("", $flags)."]"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a flag is valid
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $flag The flag
|
2020-09-09 18:45:34 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True if flag is valid, False otherwise
|
2020-09-09 18:45:34 +02:00
|
|
|
**/
|
|
|
|
public static function check_flag($flag) {
|
|
|
|
foreach(self :: get_available_flags() as $group_label => $flags)
|
|
|
|
if (array_key_exists($flag, $flags))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of available flags grouped by type
|
|
|
|
*
|
|
|
|
* @return array List of available flags grouped by type
|
|
|
|
*/
|
|
|
|
public static function get_available_flags() {
|
|
|
|
return array(
|
|
|
|
___('Account types') => array(
|
|
|
|
'U' => ___('Regular user account'),
|
|
|
|
'W' => ___('Workstation Trust Account'),
|
|
|
|
'S' => ___('Server Trust Account'),
|
|
|
|
'I' => ___('Domain Trust Account'),
|
|
|
|
'M' => ___('Majority Node Set (MNS) logon account'),
|
|
|
|
),
|
|
|
|
___('Account settings') => array(
|
|
|
|
'H' => ___('Home directory required'),
|
|
|
|
'N' => ___('Account without password'),
|
|
|
|
'X' => ___('Password does not expire'),
|
|
|
|
'D' => ___('Account disabled'),
|
|
|
|
'T' => ___('Temporary duplicate of other account'),
|
|
|
|
'L' => ___('Account automatically locked'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error Codes
|
|
|
|
**/
|
|
|
|
LSerror :: defineError('LSattr_ldap_sambaAcctFlags_01',
|
|
|
|
___("LSattr_ldap_sambaAcctFlags: invalid attribute values count. This attribute type could only handle single value attribute.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_ldap_sambaAcctFlags_02',
|
|
|
|
___("LSattr_ldap_sambaAcctFlags: invalid attribute value. Fail to parse current flags set.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSattr_ldap_sambaAcctFlags_03',
|
|
|
|
___("LSattr_ldap_sambaAcctFlags: invalid flag '%{flag}'. Can't format the LDAP attribute value.")
|
|
|
|
);
|