From 98102d4c0e19df15b2bf65c13350183e17b48b00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Bernigaud?= <come.bernigaud@opensides.be>
Date: Mon, 29 Jun 2015 17:10:40 +0200
Subject: [PATCH] Fixes #3897 Setup fails if root object is missing

---
 setup/class_setupStep_Config.inc  |  7 +++++
 setup/class_setupStep_Migrate.inc | 48 -------------------------------
 2 files changed, 7 insertions(+), 48 deletions(-)

diff --git a/setup/class_setupStep_Config.inc b/setup/class_setupStep_Config.inc
index 269312c44..ee17ba8f7 100644
--- a/setup/class_setupStep_Config.inc
+++ b/setup/class_setupStep_Config.inc
@@ -98,6 +98,13 @@ class Step_Config extends configInLdap
     parent::save_object();
     $tmp = $this->check();
     if (count($tmp) == 0) {
+      /* Create root object if missing */
+      $ldap = $config->get_ldap_link();
+      $ldap->cd($config->current['BASE']);
+      $ldap->create_missing_trees($config->current['BASE']);
+      if (!$ldap->success()) {
+        return msgPool::ldaperror($ldap->get_error(), $config->current['BASE'], 'create_missing_trees', get_class());
+      }
       /* Save in LDAP */
       $this->save();
       /* Reload config from LDAP */
diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc
index a1da9131a..47b6fa625 100644
--- a/setup/class_setupStep_Migrate.inc
+++ b/setup/class_setupStep_Migrate.inc
@@ -255,7 +255,6 @@ class Step_Migrate extends setupStep
     $config->get_departments();
 
     $checks = array(
-      'base'          => new StepMigrateCheck($this, 'base',          _('Checking for root object')),
       'baseOC'        => new StepMigrateCheck($this, 'baseOC',        _('Inspecting object classes in root object')),
       'permissions'   => new StepMigrateCheck($this, 'permissions',   _('Checking permission for LDAP database')),
       'gosaAccounts'  => new StepMigrateCheck($this, 'gosaAccounts',  _('Checking for invisible users')),
@@ -313,53 +312,6 @@ class Step_Migrate extends setupStep
     }
   }
 
-  /* Check if the root object exists.
-   * If the parameter just_check is TRUE, then just check if the
-   *  root object is missing and update the info messages.
-   * If the Parameter is FALSE, try to create a new root object.
-   */
-  function check_base(&$checkobj)
-  {
-    global $config;
-
-    $ldap = $config->get_ldap_link();
-
-    /* Check if root object exists */
-    $ldap->cd($config->current['BASE']);
-    $ldap->set_size_limit(1);
-    $res = $ldap->search("(objectClass=*)");
-    $ldap->set_size_limit(0);
-    $err = ldap_errno($ldap->cid);
-
-    if ( !$res ||
-        $err == 0x20 || // LDAP_NO_SUCH_OBJECT
-        $err == 0x40) { // LDAP_NAMING_VIOLATION
-
-      /* Root object doesn't exists */
-      throw new CheckFailedException(
-        _('Failed'),
-        _('The LDAP root object is missing. It is required to use your LDAP service.').'&nbsp;'.
-        $checkobj->submit(_('Try to create root object'), 'create')
-      );
-    }
-
-    /* Root object exists */
-    return '';
-  }
-
-  function check_base_create (&$checkobj)
-  {
-    global $config;
-
-    $ldap = $config->get_ldap_link();
-
-    /* Add root object */
-    $ldap->cd($config->current['BASE']);
-    $ldap->create_missing_trees($config->current['BASE']);
-    /* Re-run test */
-    $checkobj->run();
-  }
-
   /* Check if the root object includes the required object classes, e.g. gosaDepartment is required for ACLs.
    * If the parameter just_check is TRUE, then just check for the OCs.
    * If the Parameter is FALSE, try to add the required object classes.
-- 
GitLab