From 43718b3055068721a34bd39ef60ff1d02ee0ff1c Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sat, 07 Jul 2007 22:42:36 +0000
Subject: [PATCH] Update the LDIF reader so that it has the ability to perform syntax validation as well as schema checking.  It will honor the ds-cfg-invalid-attribute-syntax-behavior configuration.

---
 opends/src/server/org/opends/server/util/LDIFReader.java |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/LDIFReader.java b/opends/src/server/org/opends/server/util/LDIFReader.java
index 71ec8f0..75c5b72 100644
--- a/opends/src/server/org/opends/server/util/LDIFReader.java
+++ b/opends/src/server/org/opends/server/util/LDIFReader.java
@@ -54,6 +54,7 @@
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.protocols.ldap.LDAPAttribute;
 import org.opends.server.protocols.ldap.LDAPModification;
+import org.opends.server.types.AcceptRejectWarn;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -893,6 +894,31 @@
         return;
       }
 
+      if (checkSchema &&
+          (DirectoryServer.getSyntaxEnforcementPolicy() !=
+               AcceptRejectWarn.ACCEPT))
+      {
+        StringBuilder invalidReason = new StringBuilder(0);
+        if (! attrType.getSyntax().valueIsAcceptable(value, invalidReason))
+        {
+          int    msgID   = MSGID_LDIF_VALUE_VIOLATES_SYNTAX;
+          String message = getMessage(msgID, String.valueOf(entryDN),
+                                      lastEntryLineNumber, value.stringValue(),
+                                      attrName, invalidReason.toString());
+          if (DirectoryServer.getSyntaxEnforcementPolicy() ==
+                   AcceptRejectWarn.WARN)
+          {
+            logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.MILD_WARNING,
+                     message, msgID);
+          }
+          else
+          {
+            logToRejectWriter(lines, message);
+            throw new LDIFException(msgID, message, lastEntryLineNumber,
+                                    true);
+          }
+        }
+      }
 
       AttributeValue attributeValue = new AttributeValue(attrType, value);
       List<Attribute> attrList;

--
Gitblit v1.10.0