Verified Commit 995ba931 authored by dockx thibault's avatar dockx thibault
Browse files

:ambulance: Fix(Tools) - InsertSchema - ReplaceSchema

ReplaceSchema method is now taking proper path definitions.
No related merge requests found
Showing with 16 additions and 13 deletions
+16 -13
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
namespace FusionDirectory\Tools; namespace FusionDirectory\Tools;
...@@ -348,17 +348,20 @@ class InsertSchema extends Cli\Application ...@@ -348,17 +348,20 @@ class InsertSchema extends Cli\Application
*/ */
protected function gatherSchemaInformation (string $path): array protected function gatherSchemaInformation (string $path): array
{ {
if (preg_match('|^/|', $path) !== 1) { if (!is_file($path)) {
$path = $this->defaultSchemaDir.'/'.$path; $path = $this->defaultSchemaDir.'/'.$path;
} }
if (preg_match('/\.(schema|ldif)$/i', $path) !== 1) {
$path .= '.schema'; // Recuperate the filename and verify if the file contains the proper extension.
} $name = basename($path);
if (preg_match('@^/.+/([^/]+).(schema|ldif)$@', $path, $m) === 1) { preg_match('/(.*)\.(ldif|schema)/', $name, $match);
$name = $m[1];
if (isset($match[1]) && !empty($match[1])) {
$name = $match[1];
} else { } else {
throw new \Exception('Preg match failed on path '.$path); throw new \Exception('File extension error, must be .ldif or .schema');
} }
$list = $this->searchForSchemas($name); $list = $this->searchForSchemas($name);
$count = $list->count(); $count = $list->count();
if ($count < 0) { if ($count < 0) {
...@@ -458,11 +461,11 @@ class InsertSchema extends Cli\Application ...@@ -458,11 +461,11 @@ class InsertSchema extends Cli\Application
$list = $this->ldap->search( $list = $this->ldap->search(
'cn=schema,cn=config', 'cn=schema,cn=config',
'(&'. '(&'.
'(objectClass=olcSchemaConfig)'. '(objectClass=olcSchemaConfig)'.
'(|'. '(|'.
'(olcAttributeTypes=*'.ldap_escape('NAME \''.$attribute.'\'', '', LDAP_ESCAPE_FILTER).'*)'. '(olcAttributeTypes=*'.ldap_escape('NAME \''.$attribute.'\'', '', LDAP_ESCAPE_FILTER).'*)'.
'(olcAttributeTypes=*'.ldap_escape('NAME ( \''.$attribute.'\'', '', LDAP_ESCAPE_FILTER).'*)'. '(olcAttributeTypes=*'.ldap_escape('NAME ( \''.$attribute.'\'', '', LDAP_ESCAPE_FILTER).'*)'.
')'. ')'.
')', ')',
['cn','olcAttributeTypes','olcObjectClasses','createTimestamp','modifyTimestamp'], ['cn','olcAttributeTypes','olcObjectClasses','createTimestamp','modifyTimestamp'],
'subtree' 'subtree'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment