From 07205c4180040250b4504aa1ed719056d29bcc84 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 14 Jun 2007 22:22:08 +0000
Subject: [PATCH] Update the Directory Server schema processing code so that it will detect the case in which there is more than one entry in a schema configuration file (or if there is garbage after the first entry) and log it as a warning message.

---
 opendj-sdk/opends/src/server/org/opends/server/core/SchemaConfigManager.java |   27 +++++++++++++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java  |   30 ++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/core/SchemaConfigManager.java b/opendj-sdk/opends/src/server/org/opends/server/core/SchemaConfigManager.java
index 7122e5b..2cb2cc6 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/core/SchemaConfigManager.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/core/SchemaConfigManager.java
@@ -865,6 +865,7 @@
       if (entry == null)
       {
         // The file was empty -- skip it.
+        reader.close();
         return new LinkedList<Modification>();
       }
     }
@@ -891,6 +892,32 @@
       }
     }
 
+    // If there are any more entries in the file, then print a warning message.
+    try
+    {
+      Entry e = reader.readEntry(false);
+      if (e != null)
+      {
+        int    msgID   = MSGID_CONFIG_SCHEMA_MULTIPLE_ENTRIES_IN_FILE;
+        String message = getMessage(msgID, schemaFile, schemaDirPath);
+        logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING,
+                 message, msgID);
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+
+      int    msgID   = MSGID_CONFIG_SCHEMA_UNPARSEABLE_EXTRA_DATA_IN_FILE;
+      String message = getMessage(msgID, schemaFile, schemaDirPath,
+                                  getExceptionMessage(e));
+      logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING,
+               message, msgID);
+    }
+
     try
     {
       reader.close();
diff --git a/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java b/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
index a7ba3d4..4b2328e 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
@@ -6673,6 +6673,27 @@
 
 
 
+  /**
+   * The message ID for the message that will be used if a schema configuration
+   * file is found to have multiple entries.  This takes two arguments, which
+   * are the name of the schema file and the path to the schema directory.
+   */
+  public static final int MSGID_CONFIG_SCHEMA_MULTIPLE_ENTRIES_IN_FILE =
+       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_WARNING | 662;
+
+
+
+  /**
+   * The message ID for the message that will be used if a schema configuration
+   * file is found to have unparseable data after the first entry.  This takes
+   * three arguments, which are the name of the schema file, the path to the
+   * schema directory, and a message explaining the problem that occurred.
+   */
+  public static final int MSGID_CONFIG_SCHEMA_UNPARSEABLE_EXTRA_DATA_IN_FILE =
+       CATEGORY_MASK_CONFIG | SEVERITY_MASK_SEVERE_WARNING | 663;
+
+
+
 
   /**
    * Associates a set of generic messages with the message IDs defined in this
@@ -7975,6 +7996,15 @@
                     "Schema configuration file %s in directory %s cannot be " +
                     "parsed because an unexpected error occurred while " +
                     "trying to read its contents as an LDIF entry:  %s");
+    registerMessage(MSGID_CONFIG_SCHEMA_MULTIPLE_ENTRIES_IN_FILE,
+                    "Schema configuration file %s in directory %s contains " +
+                    "more than one entry.  Only the first entry will be " +
+                    "examined, and the additional entries will be ignored");
+    registerMessage(MSGID_CONFIG_SCHEMA_UNPARSEABLE_EXTRA_DATA_IN_FILE,
+                    "Schema configuration file %s in directory %s contains " +
+                    "additional data after the schema entry that cannot be " +
+                    "parsed by the LDIF reader:  %s.  The first entry will " +
+                    "be processed, but the remaining data will be ignored");
     registerMessage(MSGID_CONFIG_SCHEMA_CANNOT_PARSE_ATTR_TYPE,
                     "Unable to parse an attribute type definition from " +
                     "schema configuration file %s:  %s");

--
Gitblit v1.10.0