From 2406449c5f0309525bfd5d86de417b32bcc7c1b3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 03 Sep 2007 14:35:07 +0000
Subject: [PATCH] Fix a bug with certificates in the uninstaller and replication command lines. Improve the error messages to be displayed to the user when the uninstall fails.Fix a infinite loop that occurred when the user provided a protocol not configured in the server to access the registration information. Fix a bug that prevented the uninstall to proceed when the user specified forceOnError and an error accessing the remote servers configuration occurred. Fix a bug that occurred when the user specified to use start TLS and it was not configured in the server (this bug applies to both the uninstaller and status command-lines).

---
 opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java              |   47 ++++
 opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java                 |   30 --
 opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java |  105 +++++-----
 opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java        |  240 +++++++++++++++--------
 opends/src/messages/messages/quicksetup.properties                                 |    3 
 opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java     |   17 +
 opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java               |   50 +++-
 opends/src/messages/messages/admin_tool.properties                                 |   16 +
 opends/src/guitools/org/opends/guitools/uninstaller/UninstallUserData.java         |   61 +++++
 9 files changed, 367 insertions(+), 202 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
index c69bab0..c5919e4 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
+++ b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -519,7 +519,8 @@
         if (Utils.isCertificateException(ne))
         {
           String usedUrl = ConnectionUtils.getLDAPUrl(host1, port1, useSSL1);
-          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
+          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl,
+              getTrustManager()))
           {
             cancelled = true;
           }
@@ -716,7 +717,8 @@
         if (Utils.isCertificateException(ne))
         {
           String usedUrl = ConnectionUtils.getLDAPUrl(host2, port2, useSSL2);
-          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
+          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl,
+              getTrustManager()))
           {
             cancelled = true;
           }
@@ -993,7 +995,8 @@
         if (Utils.isCertificateException(ne))
         {
           String usedUrl = ConnectionUtils.getLDAPUrl(host, port, useSSL);
-          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
+          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl,
+              getTrustManager()))
           {
             cancelled = true;
           }
@@ -1171,7 +1174,8 @@
         {
           String usedUrl = ConnectionUtils.getLDAPUrl(hostSource, portSource,
               useSSLSource);
-          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
+          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl,
+              getTrustManager()))
           {
             cancelled = true;
           }
@@ -1271,7 +1275,8 @@
         {
           String usedUrl = ConnectionUtils.getLDAPUrl(hostDestination,
               portDestination, useSSLDestination);
-          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
+          if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl,
+              getTrustManager()))
           {
             cancelled = true;
           }
@@ -1737,7 +1742,7 @@
               {
                 reloadTopology = true;
                 cancelled = !promptForCertificateConfirmation(e.getCause(),
-                      getTrustManager(), e.getLdapUrl());
+                    e.getTrustManager(), e.getLdapUrl(), e.getTrustManager());
               }
               else
               {
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
index 5276892..b5e810a 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -382,6 +382,7 @@
                 LOG.log(Level.WARNING, "Error reading config file: "+ce, ce);
                 printLineBreak();
                 printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+                printLineBreak();
                 useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
                 if (!useSSL)
                 {
@@ -399,7 +400,7 @@
                   String usedUrl = ConnectionUtils.getLDAPUrl(host, port,
                       useSSL);
                   if (!promptForCertificateConfirmation(ne, getTrustManager(),
-                      usedUrl))
+                      usedUrl, getTrustManager()))
                   {
                     cancelled = true;
                   }
@@ -1209,31 +1210,4 @@
   {
     return argParser.getTrustManager();
   }
-
-  /**
-   * Returns the ConnectionPolicy to be used with the parameters provided
-   * by the user.
-   * @param useSSL whether the user asked to use SSL or not.
-   * @param useStartTLS whether the user asked to use Start TLS or not.
-   * @return the ConnectionPolicy to be used with the parameters provided
-   * by the user.
-   */
-  private ConnectionProtocolPolicy getConnectionPolicy(boolean useSSL,
-      boolean useStartTLS)
-  {
-    ConnectionProtocolPolicy policy;
-    if (useStartTLS)
-    {
-      policy = ConnectionProtocolPolicy.USE_STARTTLS;
-    }
-    if (useSSL)
-    {
-      policy = ConnectionProtocolPolicy.USE_LDAPS;
-    }
-    else
-    {
-      policy = ConnectionProtocolPolicy.USE_LESS_SECURE_AVAILABLE;
-    }
-    return policy;
-  }
 }
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 5a7b847..9a6715b 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -33,7 +33,7 @@
 import org.opends.admin.ads.ServerDescriptor;
 import org.opends.admin.ads.TopologyCache;
 import org.opends.admin.ads.TopologyCacheException;
-import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.guitools.statuspanel.ConfigException;
 import org.opends.guitools.statuspanel.ConfigFromFile;
 import org.opends.messages.Message;
 import org.opends.messages.MessageBuilder;
@@ -46,6 +46,7 @@
 import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
 import org.opends.quicksetup.util.ServerController;
 import org.opends.quicksetup.util.Utils;
+import org.opends.server.tools.ToolConstants;
 import org.opends.server.util.args.ArgumentException;
 
 
@@ -56,6 +57,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.io.IOException;
+import java.net.URI;
 
 import javax.naming.NamingException;
 import javax.naming.ldap.InitialLdapContext;
@@ -205,8 +207,19 @@
     if ((referencedHostName == null) && !args.isInteractive())
     {
       referencedHostName = args.getDefaultReferencedHostName();
+      try
+      {
+        UninstallData d = new UninstallData(Installation.getLocal());
+        userData.setReplicationServer(
+            referencedHostName+":"+d.getReplicationServerPort());
+      }
+      catch (Throwable t)
+      {
+        LOG.log(Level.SEVERE, "Could not create UninstallData: "+t, t);
+      }
     }
-    userData.setReferencedHostName(referencedHostName);
+    userData.setUseSSL(parser.useSSL());
+    userData.setUseStartTLS(parser.useStartTLS());
 
     /*
      * Step 4: check if server is running.  Depending if it is running and the
@@ -214,7 +227,7 @@
      */
     if (!isCancelled)
     {
-      isCancelled = checkServerState(userData, isInteractive);
+      isCancelled = checkServerState(userData);
     }
 
     if (isCancelled && !userData.isForceOnError())
@@ -222,6 +235,11 @@
       userData = null;
     }
 
+    if ((userData != null) && !args.isQuiet())
+    {
+      printLineBreak();
+    }
+
 
     return userData;
   }
@@ -387,19 +405,18 @@
    * be stopped or not.  It also prompts (if required) for authentication.
    * @param userData the UserData object to be updated with the
    * authentication of the user.
-   * @param interactive boolean telling whether this is an interactive uninstall
-   * or not.
    * @return <CODE>true</CODE> if the user wants to continue with uninstall and
    * <CODE>false</CODE> otherwise.
    * @throws UserDataException if there is a problem with the data
    * provided by the user (in the particular case where we are on quiet
    * uninstall and some data is missing or not valid).
    */
-  private boolean checkServerState(UninstallUserData userData,
-                                        boolean interactive)
+  private boolean checkServerState(UninstallUserData userData)
   throws UserDataException
   {
     boolean cancelled = false;
+    boolean interactive = parser.isInteractive();
+    boolean forceOnError = parser.isForceOnError();
     UninstallData conf = null;
     try
     {
@@ -429,8 +446,7 @@
             }
             else
             {
-              cancelled = !updateUserUninstallDataWithRemoteServers(userData,
-                  interactive);
+              cancelled = !updateUserUninstallDataWithRemoteServers(userData);
               if (cancelled)
               {
                 printLineBreak();
@@ -449,7 +465,7 @@
         else
         {
           cancelled =
-            !updateUserUninstallDataWithRemoteServers(userData, interactive);
+            !updateUserUninstallDataWithRemoteServers(userData);
         }
       }
       else
@@ -472,8 +488,7 @@
               }
               else
               {
-                cancelled = !updateUserUninstallDataWithRemoteServers(userData,
-                    interactive);
+                cancelled = !updateUserUninstallDataWithRemoteServers(userData);
                 if (cancelled)
                 {
                   printLineBreak();
@@ -505,15 +520,21 @@
           {
             userData.setStopServer(true);
             cancelled =
-              !updateUserUninstallDataWithRemoteServers(userData, interactive);
+              !updateUserUninstallDataWithRemoteServers(userData);
           }
           else
           {
-            cancelled  = !userData.isForceOnError();
+            cancelled  = !forceOnError;
             userData.setStopServer(false);
           }
         }
       }
+      if (!cancelled || parser.isForceOnError())
+      {
+        /* During all the confirmations, the server might be stopped. */
+        userData.setStopServer(
+            Installation.getLocal().getStatus().isServerRunning());
+      }
     }
     else
     {
@@ -609,12 +630,13 @@
     boolean accepted = true;
     String uid = userData.getAdminUID();
     String pwd = userData.getAdminPwd();
+    boolean useSSL = userData.useSSL();
+    boolean useStartTLS = userData.useStartTLS();
+    String host = "localhost";
+    int port = 389;
     boolean couldConnect = false;
     ConfigFromFile conf = new ConfigFromFile();
     conf.readConfiguration();
-    String ldapUrl = conf.getLDAPURL();
-    String startTlsUrl = conf.getStartTLSURL();
-    String ldapsUrl = conf.getLDAPSURL();
     while (!couldConnect && accepted)
     {
       boolean prompted = false;
@@ -634,44 +656,31 @@
       }
       userData.setAdminUID(uid);
       userData.setAdminPwd(pwd);
+      userData.setUseSSL(useSSL);
+      userData.setUseStartTLS(useStartTLS);
       InitialLdapContext ctx = null;
-      String usedUrl = null;
+      String ldapUrl = null;
       try
       {
-        String dn = ADSContext.getAdministratorDN(uid);
-        if ((ldapsUrl != null) && (parser.useSSL() || !parser.useStartTLS()))
+        ldapUrl = conf.getURL(getConnectionPolicy(useSSL, useStartTLS));
+        try
         {
-          usedUrl = ldapsUrl;
-          ctx = Utils.createLdapsContext(ldapsUrl, dn, pwd,
-              Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager());
+          URI uri = new URI(ldapUrl);
+          host = uri.getHost();
+          port = uri.getPort();
         }
-        else if ((startTlsUrl != null) &&
-            (!parser.useSSL() || parser.useStartTLS()))
+        catch (Throwable t)
         {
-          usedUrl = startTlsUrl;
-          ctx = Utils.createStartTLSContext(startTlsUrl, dn, pwd,
-              Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager(),
-              null);
+          LOG.log(Level.SEVERE, "Error parsing url: "+ldapUrl);
         }
-        else if ((ldapUrl != null) && !parser.useSSL() && !parser.useStartTLS())
-        {
-          usedUrl = ldapUrl;
-          ctx = Utils.createLdapContext(ldapUrl, dn, pwd,
-              Utils.getDefaultLDAPTimeout(), null);
-        }
-        else
-        {
+        ctx = createContext(host, port, useSSL, useStartTLS,
+            ADSContext.getAdministratorDN(uid), pwd,
+            userData.getTrustManager());
 
-          LOG.log(Level.WARNING,
-              "Error retrieving a valid LDAP URL in conf file");
-          printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
-        }
-        if (usedUrl != null)
-        {
-          userData.setLocalServerUrl(usedUrl);
-          couldConnect = true;
-        }
-      } catch (NamingException ne)
+        userData.setLocalServerUrl(ldapUrl);
+        couldConnect = true;
+      }
+      catch (NamingException ne)
       {
         LOG.log(Level.WARNING, "Error connecting to server: "+ne, ne);
 
@@ -679,7 +688,7 @@
         {
           printLineBreak();
           accepted = promptForCertificateConfirmation(ne,
-              userData.getTrustManager(), usedUrl);
+              userData.getTrustManager(), ldapUrl, userData.getTrustManager());
         }
         else
         {
@@ -691,8 +700,24 @@
           printLineBreak();
           accepted = promptToProvideAuthenticationAgain();
         }
-
-      } catch (Throwable t)
+      }
+      catch (ConfigException ce)
+      {
+        LOG.log(Level.WARNING,
+        "Error retrieving a valid LDAP URL in conf file: "+ce, ce);
+        printLineBreak();
+        printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+        printLineBreak();
+        useSSL = false;
+        useStartTLS = false;
+        useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
+        if (!useSSL)
+        {
+          useStartTLS =
+            confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
+        }
+      }
+      catch (Throwable t)
       {
         LOG.log(Level.WARNING, "Error connecting to server: "+t, t);
         uid = null;
@@ -720,13 +745,22 @@
 
     if (accepted)
     {
-      String referencedHostName = userData.getReferencedHostName();
+      String referencedHostName = parser.getReferencedHostName();
       while (referencedHostName == null)
       {
         printLineBreak();
         referencedHostName = askForReferencedHostName(userData.getHostName());
       }
-      userData.setReferencedHostName(referencedHostName);
+      try
+      {
+        UninstallData d = new UninstallData(Installation.getLocal());
+        userData.setReplicationServer(
+            referencedHostName+":"+d.getReplicationServerPort());
+      }
+      catch (Throwable t)
+      {
+        LOG.log(Level.SEVERE, "Could not create UninstallData: "+t, t);
+      }
     }
     userData.setUpdateRemoteReplication(accepted);
     return accepted;
@@ -842,58 +876,65 @@
    * <CODE>false</CODE> otherwise.
    * continue if
    * @param userData the user data to be updated.
-   * @param interactive whether we are in interactive mode or not.
    * @return <CODE>true</CODE> if we could connect
    * to the remote servers and all the presented certificates were accepted and
    * <CODE>false</CODE> otherwise.
    */
   private boolean updateUserUninstallDataWithRemoteServers(
-      UninstallUserData userData, boolean interactive)
+      UninstallUserData userData)
   {
     boolean accepted = false;
+    boolean interactive = parser.isInteractive();
+    boolean forceOnError = parser.isForceOnError();
+
+    boolean exceptionOccurred = true;
+
     InitialLdapContext ctx = null;
     try
     {
       ConfigFromFile conf = new ConfigFromFile();
       conf.readConfiguration();
-      String ldapUrl = conf.getLDAPURL();
-      String startTlsUrl = conf.getStartTLSURL();
-      String ldapsUrl = conf.getLDAPSURL();
+
+      String host = "localhost";
+      int port = 389;
+      boolean useSSL = userData.useSSL();
+      boolean useStartTLS = userData.useStartTLS();
       String adminUid = userData.getAdminUID();
       String pwd = userData.getAdminPwd();
       String dn = ADSContext.getAdministratorDN(adminUid);
-      if ((ldapsUrl != null) && (parser.useSSL() || !parser.useStartTLS()))
+
+      String ldapUrl = conf.getURL(
+          getConnectionPolicy(useSSL, useStartTLS));
+      try
       {
-        ctx = Utils.createLdapsContext(ldapsUrl, dn, pwd,
-            Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager());
+        URI uri = new URI(ldapUrl);
+        host = uri.getHost();
+        port = uri.getPort();
       }
-      else if ((startTlsUrl != null) &&
-          (!parser.useSSL() || parser.useStartTLS()))
+      catch (Throwable t)
       {
-        ctx = Utils.createStartTLSContext(startTlsUrl, dn, pwd,
-            Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager(),
-            null);
+        LOG.log(Level.SEVERE, "Error parsing url: "+ldapUrl);
       }
-      else if ((ldapUrl != null) && !parser.useSSL() && !parser.useStartTLS())
-      {
-        ctx = Utils.createLdapContext(ldapUrl, dn, pwd,
-            Utils.getDefaultLDAPTimeout(), null);
-      }
-      else
-      {
-        LOG.log(Level.WARNING,
-            "Error retrieving a valid LDAP URL in conf file");
-        printLineBreak();
-        printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
-      }
+      ctx = createContext(host, port, useSSL, useStartTLS, dn, pwd,
+          userData.getTrustManager());
+
       ADSContext adsContext = new ADSContext(ctx);
       TopologyCache cache = new TopologyCache(adsContext,
           userData.getTrustManager());
       cache.reloadTopology();
 
-      accepted = handleTopologyCache(cache, interactive, userData);
-      userData.setRemoteServers(cache.getServers());
-    } catch (NamingException ne)
+      accepted = handleTopologyCache(cache, userData);
+
+      exceptionOccurred = false;
+    }
+    catch (ConfigException ce)
+    {
+      LOG.log(Level.WARNING,
+          "Error retrieving a valid LDAP URL in conf file: "+ce, ce);
+      printLineBreak();
+      printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+    }
+    catch (NamingException ne)
     {
       LOG.log(Level.WARNING, "Error connecting to server: "+ne, ne);
       if (Utils.isCertificateException(ne))
@@ -934,6 +975,32 @@
         }
       }
     }
+    if (exceptionOccurred)
+    {
+      if (!interactive)
+      {
+        if (forceOnError)
+        {
+          printWarningMessage(ERR_UNINSTALL_ERROR_UPDATING_REMOTE_FORCE.get(
+              parser.adminUidArg.getLongIdentifier(),
+              ToolConstants.OPTION_LONG_BINDPWD,
+              ToolConstants.OPTION_LONG_BINDPWD_FILE));
+        }
+        else
+        {
+          printErrorMessage(
+              ERR_UNINSTALL_ERROR_UPDATING_REMOTE_NO_FORCE.get(
+                  parser.adminUidArg.getLongIdentifier(),
+                  ToolConstants.OPTION_LONG_BINDPWD,
+                  ToolConstants.OPTION_LONG_BINDPWD_FILE,
+                  parser.forceOnErrorArg.getLongIdentifier()));
+        }
+      }
+      else
+      {
+        accepted = confirm(ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT.get(), false);
+      }
+    }
     userData.setUpdateRemoteReplication(accepted);
     return accepted;
   }
@@ -945,15 +1012,15 @@
    * Returns <CODE>true</CODE> if the user accepts all the problems encountered
    * and <CODE>false</CODE> otherwise.
    * @param userData the user data.
-   * @param interactive if we are in interactive mode or not.
    */
-  private boolean handleTopologyCache(TopologyCache cache, boolean interactive,
+  private boolean handleTopologyCache(TopologyCache cache,
       UninstallUserData userData)
   {
     boolean returnValue;
     boolean stopProcessing = false;
     boolean reloadTopologyCache = false;
-    ApplicationTrustManager trustManager = userData.getTrustManager();
+    boolean interactive = parser.isInteractive();
+
     Set<TopologyCacheException> exceptions =
       new HashSet<TopologyCacheException>();
     /* Analyze if we had any exception while loading servers.  For the moment
@@ -962,6 +1029,7 @@
      * or if there is a certificate problem.
      */
     Set<ServerDescriptor> servers = cache.getServers();
+    userData.setRemoteServers(servers);
     for (ServerDescriptor server : servers)
     {
       TopologyCacheException e = server.getLastException();
@@ -993,7 +1061,8 @@
           {
             printLineBreak();
             if (promptForCertificateConfirmation(e.getCause(),
-                trustManager, e.getLdapUrl()))
+                e.getTrustManager(), e.getLdapUrl(),
+                userData.getTrustManager()))
             {
               stopProcessing = true;
               reloadTopologyCache = true;
@@ -1033,8 +1102,7 @@
       }
       else if (reloadTopologyCache)
       {
-       returnValue = updateUserUninstallDataWithRemoteServers(userData,
-           interactive);
+       returnValue = updateUserUninstallDataWithRemoteServers(userData);
       }
       else
       {
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallUserData.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallUserData.java
index f1ffbe8..99c4353 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallUserData.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallUserData.java
@@ -52,10 +52,12 @@
     new ApplicationTrustManager(null);
   private String adminUID;
   private String adminPwd;
-  private String referencedHostName;
   private String localServerUrl;
   private HashSet<ServerDescriptor> remoteServers =
     new HashSet<ServerDescriptor>();
+  private boolean useSSL;
+  private boolean useStartTLS;
+  private String replicationServer;
 
   /**
    * Sets the database directories located outside the installation which must
@@ -289,19 +291,20 @@
   }
 
   /**
-   * Returns the referenced host name provided by the user.
-   * @return the referenced host name provided by the user.
+   * Returns the replication server as referenced in other servers.
+   * @return the replication server as referenced in other servers.
    */
-  public String getReferencedHostName() {
-    return referencedHostName;
+  public String getReplicationServer() {
+    return replicationServer;
   }
 
   /**
-   * Sets the referenced host name provided by the user.
-   * @param referencedHostName the referenced host name provided by the user.
+   * Sets the replication server as referenced in other servers.
+   * @param replicationServer the replication server as referenced in other
+   * servers.
    */
-  public void setReferencedHostName(String referencedHostName) {
-    this.referencedHostName = referencedHostName;
+  public void setReplicationServer(String replicationServer) {
+    this.replicationServer = replicationServer;
   }
 
   /**
@@ -342,4 +345,44 @@
     this.remoteServers.clear();
     this.remoteServers.addAll(remoteServers);
   }
+
+  /**
+   * Whether we must use SSL to connect to the local server or not.
+   * @return <CODE>true</CODE> if we must use SSL to connect to the local server
+   * and <CODE>false</CODE> otherwise.
+   */
+  public boolean useSSL()
+  {
+    return useSSL;
+  }
+
+  /**
+   * Sets whether we must use SSL to connect to the local server or not.
+   * @param useSSL whether we must use SSL to connect to the local server or
+   * not.
+   */
+  public void setUseSSL(boolean useSSL)
+  {
+    this.useSSL = useSSL;
+  }
+
+  /**
+   * Whether we must use Start TLS to connect to the local server or not.
+   * @return <CODE>true</CODE> if we must use Start TLS to connect to the local
+   * server and <CODE>false</CODE> otherwise.
+   */
+  public boolean useStartTLS()
+  {
+    return useStartTLS;
+  }
+
+  /**
+   * Sets whether we must use Start TLS to connect to the local server or not.
+   * @param useStartTLS whether we must use Start TLS to connect to the local
+   * server or not.
+   */
+  public void setUseStartTLS(boolean useStartTLS)
+  {
+    this.useStartTLS = useStartTLS;
+  }
 }
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java b/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
index b27b742..3c9163a 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
@@ -108,8 +108,6 @@
   private ProgressDialog startProgressDlg;
   private MessageBuilder startProgressDetails = new MessageBuilder();
   private UninstallData conf;
-  private String replicationServerHostPort;
-
   /**
    * Default constructor.
    */
@@ -828,12 +826,14 @@
       }
 
     } catch (ApplicationException ex) {
+      LOG.log(Level.SEVERE, "Error: "+ex, ex);
       ue = ex;
       status = UninstallProgressStep.FINISHED_WITH_ERROR;
       Message msg = getFormattedError(ex, true);
       notifyListeners(msg);
     }
     catch (Throwable t) {
+      LOG.log(Level.SEVERE, "Error: "+t, t);
       ue = new ApplicationException(
               ReturnCode.BUG,
               getThrowableMsg(INFO_BUG_MSG.get(), t), t);
@@ -1348,7 +1348,6 @@
     {
       getUninstallUserData().setAdminUID(loginDialog.getAdministratorUid());
       getUninstallUserData().setAdminPwd(loginDialog.getAdministratorPwd());
-      getUninstallUserData().setReferencedHostName(loginDialog.getHostName());
       final InitialLdapContext ctx = loginDialog.getContext();
       try
       {
@@ -1360,8 +1359,9 @@
         LOG.log(Level.WARNING, "Could not find local server: "+ne, ne);
         getUninstallUserData().setLocalServerUrl("ldap://localhost:389");
       }
-      replicationServerHostPort = loginDialog.getHostName() + ":" +
-      conf.getReplicationServerPort();
+      getUninstallUserData().setReplicationServer(
+          loginDialog.getHostName() + ":" +
+          conf.getReplicationServerPort());
 
       BackgroundTask worker = new BackgroundTask()
       {
@@ -1449,6 +1449,7 @@
     /* Check the exceptions and see if we throw them or not. */
     for (TopologyCacheException e : exceptions)
     {
+      LOG.log(Level.INFO, "Analyzing exception: "+e, e);
       if (stopProcessing)
       {
         break;
@@ -1641,6 +1642,7 @@
       LOG.log(Level.WARNING, "The server ADS properties for the server to "+
           "uninstall could not be found.");
     }
+
     for (ServerDescriptor server : servers)
     {
       if (server.getAdsProperties() != serverADSProperties)
@@ -1652,8 +1654,7 @@
 
   /**
    * This method updates the replication in the remote server represented by
-   * a given ServerProperty object.  It does not thrown any exception and works
-   * in a best effort mode.
+   * a given ServerProperty object.
    * It also tries to delete the server registration entry from the remote ADS
    * servers if the serverADSProperties object passed is not null.
    * @param server the ServerDescriptor object representing the server where
@@ -1681,7 +1682,8 @@
       {
         for (Object o : replicationServers)
         {
-          if (replicationServerHostPort.equalsIgnoreCase((String)o))
+          if (getUninstallUserData().getReplicationServer().equalsIgnoreCase(
+              (String)o))
           {
             hasReferences = true;
             break;
@@ -1698,7 +1700,8 @@
         {
           for (Object o : replica.getReplicationServers())
           {
-            if (replicationServerHostPort.equalsIgnoreCase((String)o))
+            if (getUninstallUserData().getReplicationServer().equalsIgnoreCase(
+                (String)o))
             {
               hasReferences = true;
               break;
@@ -1799,7 +1802,8 @@
           String replServer = null;
           for (String o : replServers)
           {
-            if (replicationServerHostPort.equalsIgnoreCase(o))
+            if (getUninstallUserData().getReplicationServer().equalsIgnoreCase(
+                o))
             {
               replServer = o;
               break;
@@ -1836,7 +1840,8 @@
             String replServer = null;
             for (String o : replServers)
             {
-              if (replicationServerHostPort.equalsIgnoreCase(o))
+              if (getUninstallUserData().getReplicationServer().
+                  equalsIgnoreCase(o))
               {
                 replServer = o;
                 break;
@@ -1938,7 +1943,28 @@
           property = ServerDescriptor.ServerProperty.LDAP_PORT;
         }
         ArrayList ports = (ArrayList)server.getServerProperties().get(property);
-        isServerToUninstall = ports.contains(port);
+        if (ports == null)
+        {
+          isServerToUninstall = ports.contains(port);
+        }
+        else
+        {
+          // This occurs if the instance could not be loaded.
+          ADSContext.ServerProperty adsProperty;
+          if (isSecure)
+          {
+            adsProperty = ADSContext.ServerProperty.LDAPS_PORT;
+          }
+          else
+          {
+            adsProperty = ADSContext.ServerProperty.LDAPS_PORT;
+          }
+          String v = (String)server.getAdsProperties().get(adsProperty);
+          if (v != null)
+          {
+            isServerToUninstall = v.equals(String.valueOf(port));
+          }
+        }
       }
       catch (Throwable t)
       {
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
index 0e4a8d7..0abcedf 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -53,21 +53,21 @@
  */
 public class UninstallerArgumentParser extends SecureConnectionCliParser
 {
-  private BooleanArgument noPrompt;
-  private BooleanArgument forceOnError;
-  private BooleanArgument quiet;
-  private BooleanArgument removeAll;
-  private BooleanArgument removeServerLibraries;
-  private BooleanArgument removeDatabases;
-  private BooleanArgument removeLogFiles;
-  private BooleanArgument removeConfigurationFiles;
-  private BooleanArgument removeBackupFiles;
-  private BooleanArgument removeLDIFFiles;
+  private BooleanArgument noPromptArg;
+  BooleanArgument forceOnErrorArg;
+  private BooleanArgument quietArg;
+  private BooleanArgument removeAllArg;
+  private BooleanArgument removeServerLibrariesArg;
+  private BooleanArgument removeDatabasesArg;
+  private BooleanArgument removeLogFilesArg;
+  private BooleanArgument removeConfigurationFilesArg;
+  private BooleanArgument removeBackupFilesArg;
+  private BooleanArgument removeLDIFFilesArg;
 
   /**
    * The 'admin UID' global argument.
    */
-  private StringArgument adminUidArg;
+  StringArgument adminUidArg;
   private StringArgument referencedHostNameArg;
 
   /**
@@ -103,73 +103,74 @@
   throws ArgumentException
   {
     LinkedHashSet<Argument> args = new LinkedHashSet<Argument>();
-    removeAll = new BooleanArgument(
+    removeAllArg = new BooleanArgument(
         "remove-all",
         'a',
         "remove-all",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_ALL.get()
         );
-    args.add(removeAll);
-    removeServerLibraries = new BooleanArgument(
+    args.add(removeAllArg);
+    removeServerLibrariesArg = new BooleanArgument(
         "server-libraries",
         'l',
         "server-libraries",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_SERVER_LIBRARIES.get()
         );
-    args.add(removeServerLibraries);
-    removeDatabases = new BooleanArgument(
+    args.add(removeServerLibrariesArg);
+    removeDatabasesArg = new BooleanArgument(
         "databases",
         'd',
         "databases",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_DATABASES.get()
         );
-    args.add(removeDatabases);
-    removeLogFiles = new BooleanArgument(
+    args.add(removeDatabasesArg);
+    removeLogFilesArg = new BooleanArgument(
         "log-files",
         'L',
         "log-files",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_LOG_FILES.get()
         );
-    args.add(removeLogFiles);
-    removeConfigurationFiles = new BooleanArgument(
+    args.add(removeLogFilesArg);
+    removeConfigurationFilesArg = new BooleanArgument(
         "configuration-files",
         'c',
         "configuration-files",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_CONFIGURATION_FILES.get()
         );
-    args.add(removeConfigurationFiles);
-    removeBackupFiles = new BooleanArgument(
+    args.add(removeConfigurationFilesArg);
+    removeBackupFilesArg = new BooleanArgument(
         "backup-files",
         'b',
         "backup-files",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_BACKUP_FILES.get()
         );
-    args.add(removeBackupFiles);
-    removeLDIFFiles = new BooleanArgument(
+    args.add(removeBackupFilesArg);
+    removeLDIFFilesArg = new BooleanArgument(
         "ldif-files",
         'e',
         "ldif-files",
         INFO_UNINSTALLDS_DESCRIPTION_REMOVE_LDIF_FILES.get()
         );
-    args.add(removeLDIFFiles);
-    noPrompt = new BooleanArgument(
+    args.add(removeLDIFFilesArg);
+    noPromptArg = new BooleanArgument(
         OPTION_LONG_NO_PROMPT,
         OPTION_SHORT_NO_PROMPT,
         OPTION_LONG_NO_PROMPT,
         INFO_DESCRIPTION_NO_PROMPT.get());
-    args.add(noPrompt);
-    forceOnError = new BooleanArgument(
+    args.add(noPromptArg);
+    forceOnErrorArg = new BooleanArgument(
         "forceOnError",
         'f',
         "forceOnError",
-        INFO_UNINSTALLDS_DESCRIPTION_FORCE.get(noPrompt.getLongIdentifier()));
-    args.add(forceOnError);
-    quiet = new BooleanArgument(
+        INFO_UNINSTALLDS_DESCRIPTION_FORCE.get(
+            noPromptArg.getLongIdentifier()));
+    args.add(forceOnErrorArg);
+    quietArg = new BooleanArgument(
         OPTION_LONG_QUIET,
         OPTION_SHORT_QUIET,
         OPTION_LONG_QUIET,
         INFO_UNINSTALLDS_DESCRIPTION_QUIET.get());
-    args.add(quiet);
+    args.add(quietArg);
 
     adminUidArg = new StringArgument("adminUID", 'I',
         "adminUID", false, false, true, "adminUID",
@@ -210,7 +211,7 @@
    */
   public boolean isInteractive()
   {
-    return !noPrompt.isPresent();
+    return !noPromptArg.isPresent();
   }
 
   /**
@@ -221,7 +222,7 @@
    */
   public boolean isForceOnError()
   {
-    return forceOnError.isPresent();
+    return forceOnErrorArg.isPresent();
   }
 
   /**
@@ -232,7 +233,7 @@
    */
   public boolean isQuiet()
   {
-    return quiet.isPresent();
+    return quietArg.isPresent();
   }
 
   /**
@@ -243,7 +244,7 @@
    */
   public boolean removeAll()
   {
-    return removeAll.isPresent();
+    return removeAllArg.isPresent();
   }
 
   /**
@@ -254,7 +255,7 @@
    */
   public boolean removeServerLibraries()
   {
-    return removeServerLibraries.isPresent();
+    return removeServerLibrariesArg.isPresent();
   }
 
   /**
@@ -265,7 +266,7 @@
    */
   public boolean removeDatabases()
   {
-    return removeDatabases.isPresent();
+    return removeDatabasesArg.isPresent();
   }
 
   /**
@@ -276,7 +277,7 @@
    */
   public boolean removeConfigurationFiles()
   {
-    return removeConfigurationFiles.isPresent();
+    return removeConfigurationFilesArg.isPresent();
   }
 
   /**
@@ -287,7 +288,7 @@
    */
   public boolean removeBackupFiles()
   {
-    return removeBackupFiles.isPresent();
+    return removeBackupFilesArg.isPresent();
   }
 
   /**
@@ -298,7 +299,7 @@
    */
   public boolean removeLDIFFiles()
   {
-    return removeLDIFFiles.isPresent();
+    return removeLDIFFilesArg.isPresent();
   }
 
   /**
@@ -309,7 +310,7 @@
    */
   public boolean removeLogFiles()
   {
-    return removeLogFiles.isPresent();
+    return removeLogFilesArg.isPresent();
   }
 
   /**
@@ -371,32 +372,32 @@
   public int validateGlobalOptions(MessageBuilder buf)
   {
     int returnValue;
-    if (!noPrompt.isPresent() && forceOnError.isPresent())
+    if (!noPromptArg.isPresent() && forceOnErrorArg.isPresent())
     {
       Message message = ERR_UNINSTALL_FORCE_REQUIRES_NO_PROMPT.get(
-          forceOnError.getLongIdentifier(), noPrompt.getLongIdentifier());
+          forceOnErrorArg.getLongIdentifier(), noPromptArg.getLongIdentifier());
       if (buf.length() > 0)
       {
         buf.append(EOL);
       }
       buf.append(message);
     }
-    if (removeAll.isPresent())
+    if (removeAllArg.isPresent())
     {
       BooleanArgument[] removeArgs = {
-          removeServerLibraries,
-          removeDatabases,
-          removeLogFiles,
-          removeConfigurationFiles,
-          removeBackupFiles,
-          removeLDIFFiles
+          removeServerLibrariesArg,
+          removeDatabasesArg,
+          removeLogFilesArg,
+          removeConfigurationFilesArg,
+          removeBackupFilesArg,
+          removeLDIFFilesArg
       };
       for (int i=0; i<removeArgs.length; i++)
       {
         if (removeArgs[i].isPresent())
         {
           Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              removeAll.getLongIdentifier(),
+              removeAllArg.getLongIdentifier(),
               removeArgs[i].getLongIdentifier());
           if (buf.length() > 0)
           {
diff --git a/opends/src/messages/messages/admin_tool.properties b/opends/src/messages/messages/admin_tool.properties
index 61d537e..1c47e04 100644
--- a/opends/src/messages/messages/admin_tool.properties
+++ b/opends/src/messages/messages/admin_tool.properties
@@ -172,6 +172,22 @@
  following errors were encountered reading the configuration of the existing \
  servers:\n%s\nDo you want the uninstaller to try to remove the references to \
  this server in a best-effort mode?
+MILD_ERR_UNINSTALL_ERROR_UPDATING_REMOTE_FORCE=This server is configured \
+ to replicate some of its Base DNs.  There was an error retrieving the \
+ references to it in the replicated servers.  Note that to be able to remove \
+ remote references you must provide Global Administrator credentials using the \
+ {%s} and {%s} (or {%s}) options.%nContinuing uninstall as we are \
+ on force on error mode.
+SEVERE_ERR_UNINSTALL_ERROR_UPDATING_REMOTE_NO_FORCE=This server is configured \
+ to replicate some of its Base DNs.  There was an error retrieving the \
+ references to it in the replicated servers.  Note that to be able to remove \
+ remote references you must provide Global Administrator credentials using the \
+ {%s} and {%s} (or {%s}) options.%nCheck that the connection parameters you \
+ provided are correct.%nIf you want to uninstall the server even when remote \
+ references cannot be removed, you can use the {%s} option.
+MILD_ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT=This server is configured \
+ to replicate some of its Base DNs.  There was an error retrieving the \
+ references to it in the replicated servers.%nDo you want to continue?
 INFO_CONFIRM_UNINSTALL_SERVER_RUNNING_TITLE=Server is Running
 INFO_CONNECTIONS_LABEL=Open Connections:
 MILD_ERR_COULD_NOT_FIND_VALID_LDAPURL=Error reading the configuration file.%n\
diff --git a/opends/src/messages/messages/quicksetup.properties b/opends/src/messages/messages/quicksetup.properties
index 107dbc5..a27f727 100644
--- a/opends/src/messages/messages/quicksetup.properties
+++ b/opends/src/messages/messages/quicksetup.properties
@@ -292,8 +292,7 @@
 INFO_ERROR_CONFIGURING_CERTIFICATE=Error Configuring Certificates.
 INFO_ERROR_CONFIGURING_REMOTE_GENERIC=An unexpected error occurred \
  configuring server %s.%nThe error is: %s
-INFO_ERROR_CONNECTING_TO_LOCAL=An unexpected error occurred connecting to the \
- server.
+INFO_ERROR_CONNECTING_TO_LOCAL=An error occurred connecting to the server.
 INFO_ERROR_COPYING=An unexpected error occurred extracting file %s.
 INFO_ERROR_COPYING_FILE=Error copying file %s to %s.
 INFO_ERROR_COULD_NOT_CREATE_PARENT_DIR=Could not create parent directory %s. \
diff --git a/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java b/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
index 6587a2c..82df03c 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
@@ -30,6 +30,7 @@
 
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.guitools.statuspanel.ConnectionProtocolPolicy;
 import org.opends.quicksetup.ui.CertificateDialog;
 import org.opends.messages.Message;
 import org.opends.messages.MessageBuilder;
@@ -758,17 +759,21 @@
    * Prompts the user to accept the certificate.
    * @param t the throwable that was generated because the certificate was
    * not trusted.
-   * @param trustManager the global trustManager that contains the certificates
-   * accepted by the user.
+   * @param usedTrustManager the trustManager used when trying to establish the
+   * connection.
    * @param usedUrl the LDAP URL used to connect to the server.
+   * @param trustManager the global trustManager that contains the certificates
+   * accepted by the user and that will be updated.
    * @return <CODE>true</CODE> if the user accepted the certificate and
    * <CODE>false</CODE> otherwise.
    */
   protected boolean promptForCertificateConfirmation(Throwable t,
-      ApplicationTrustManager trustManager, String usedUrl)
+      ApplicationTrustManager usedTrustManager, String usedUrl,
+      ApplicationTrustManager trustManager)
   {
     boolean returnValue = false;
-    ApplicationTrustManager.Cause cause = trustManager.getLastRefusedCause();
+    ApplicationTrustManager.Cause cause =
+      usedTrustManager.getLastRefusedCause();
 
     LOG.log(Level.INFO, "Certificate exception cause: "+cause);
     UserDataCertificateException.Type excType = null;
@@ -807,8 +812,8 @@
       UserDataCertificateException udce =
         new UserDataCertificateException(Step.REPLICATION_OPTIONS,
             INFO_CERTIFICATE_EXCEPTION.get(h, String.valueOf(p)), t, h, p,
-                trustManager.getLastRefusedChain(),
-                trustManager.getLastRefusedAuthType(), excType);
+                usedTrustManager.getLastRefusedChain(),
+                usedTrustManager.getLastRefusedAuthType(), excType);
 
       returnValue = handleCertificateException(udce, trustManager, true);
     }
@@ -816,13 +821,41 @@
   }
 
   /**
+   * Returns the ConnectionPolicy to be used with the parameters provided
+   * by the user.
+   * @param useSSL whether the user asked to use SSL or not.
+   * @param useStartTLS whether the user asked to use Start TLS or not.
+   * @return the ConnectionPolicy to be used with the parameters provided
+   * by the user.
+   */
+  protected ConnectionProtocolPolicy getConnectionPolicy(boolean useSSL,
+      boolean useStartTLS)
+  {
+    ConnectionProtocolPolicy policy;
+    if (useStartTLS)
+    {
+      policy = ConnectionProtocolPolicy.USE_STARTTLS;
+    }
+    else if (useSSL)
+    {
+      policy = ConnectionProtocolPolicy.USE_LDAPS;
+    }
+    else
+    {
+      policy = ConnectionProtocolPolicy.USE_LESS_SECURE_AVAILABLE;
+    }
+    return policy;
+  }
+
+  /**
    * Prompts the user to accept the certificate that generated the provided
    * UserDataCertificateException.
    * @param trustManager the global trustManager that contains the certificates
    * accepted by the user.
    * @param udce the UserDataCertificateException that was generated.
    * @param trustManager the global trustManager that contains the certificates
-   * accepted by the user.
+   * accepted by the user and that will be updated if the user accepts the
+   * certificate.
    * @param displayErrorMessage whether to display the message describing
    * the error encountered (certificate not trusted) or only prompt to accept
    * the certificate.

--
Gitblit v1.10.0