Add method LSldapObject::isValidTypeName() and use it in LSsession::loadLSobject()

This commit is contained in:
Benjamin Renard 2020-09-03 15:40:59 +02:00
parent 4c427b26d6
commit 406b017023
2 changed files with 24 additions and 2 deletions

View file

@ -2862,6 +2862,23 @@ class LSldapObject extends LSlog_staticLoggerClass {
return LScli :: autocomplete_opts($opts, $comp_word); return LScli :: autocomplete_opts($opts, $comp_word);
} }
/*
* Check validity of a LSobject type name
*
* A LSobjet type name must only contain letter, digits or dash or
* underscore.
*
* @param[in] $name string The LSobject type name to check
*
* @retval boolean True is type name is valid, False otherwise
*/
public static function isValidTypeName($name) {
if (preg_match('/^[a-zA-Z0-9\_\-]+$/', $name))
return True;
self :: log_warning("isValidTypeName($name): Invalid LSobject type name !");
return False;
}
} }
/** /**

View file

@ -447,11 +447,16 @@ class LSsession {
} }
$error = 0; $error = 0;
self :: loadLSclass('LSldapObject'); self :: loadLSclass('LSldapObject');
if (!self :: loadLSclass($object,'LSobjects')) { // Check LSobject type name
if (!LSldapObject :: isValidTypeName($object)) {
self :: log_error("loadLSobject($object): invalid LSobject type name");
$error = 1;
}
elseif (!self :: loadLSclass($object,'LSobjects')) {
self :: log_error("loadLSobject($object): Fail to load LSldapObject class"); self :: log_error("loadLSobject($object): Fail to load LSldapObject class");
$error = 1; $error = 1;
} }
if (!self :: includeFile( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) { elseif (!self :: includeFile( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) {
self :: log_error("loadLSobject($object): Fail to include 'config.LSobjects.$object.php' file"); self :: log_error("loadLSobject($object): Fail to include 'config.LSobjects.$object.php' file");
$error = 1; $error = 1;
} }