Esempio n. 1
0
        private static void GetIntegerConstraints(ADSchemaAttributeObject schemaObject, ADPropertyDefinition propDef, List <PropertyDefinitionConstraint> constraints)
        {
            bool isUnlimited;
            bool isNullable;
            Type typeInformation = ADSchemaDataProvider.GetTypeInformation(propDef.Type, out isUnlimited, out isNullable);

            if (typeInformation == typeof(int))
            {
                int minValue = schemaObject.RangeLower ?? int.MinValue;
                int maxValue = schemaObject.RangeUpper ?? int.MaxValue;
                constraints.Add(ADSchemaDataProvider.GetRangedConstraint <int>(minValue, maxValue, isUnlimited, isNullable));
                return;
            }
            if (typeInformation == typeof(ByteQuantifiedSize))
            {
                IFormatProvider formatProvider           = propDef.FormatProvider;
                ByteQuantifiedSize.Quantifier quantifier = (formatProvider != null) ? ((ByteQuantifiedSize.Quantifier)formatProvider.GetFormat(typeof(ByteQuantifiedSize.Quantifier))) : ByteQuantifiedSize.Quantifier.None;
                ulong number                 = (ulong)((long)(schemaObject.RangeLower ?? 0));
                int?  rangeUpper             = schemaObject.RangeUpper;
                ulong number2                = ((rangeUpper != null) ? new ulong?((ulong)((long)rangeUpper.GetValueOrDefault())) : null) ?? Math.Min((ulong)((ByteQuantifiedSize.Quantifier) 18446744073709551615UL / quantifier), 2147483647UL);
                ByteQuantifiedSize minValue2 = ByteQuantifiedSize.FromSpecifiedUnit(number, quantifier);
                ByteQuantifiedSize maxValue2 = ByteQuantifiedSize.FromSpecifiedUnit(number2, quantifier);
                constraints.Add(ADSchemaDataProvider.GetRangedConstraint <ByteQuantifiedSize>(minValue2, maxValue2, isUnlimited, isNullable));
                return;
            }
            ExTraceGlobals.SchemaInitializationTracer.TraceDebug <DataSyntax, ADPropertyDefinition>(0L, "Unsupported property type '{1}' for data syntax '{0}'.", schemaObject.DataSyntax, propDef);
        }
Esempio n. 2
0
        private static void GetStringConstraints(ADSchemaAttributeObject schemaObject, ADPropertyDefinition propDef, List <PropertyDefinitionConstraint> constraints)
        {
            int num = schemaObject.RangeLower ?? 0;

            if (num == 1)
            {
                num = 0;
            }
            int maxLength = schemaObject.RangeUpper ?? 0;

            constraints.Add(new StringLengthConstraint(num, maxLength));
        }
Esempio n. 3
0
 private static void GetByteConstraints(ADSchemaAttributeObject schemaObject, ADPropertyDefinition propDef, List <PropertyDefinitionConstraint> constraints)
 {
     if (propDef.Type == typeof(byte[]))
     {
         constraints.Add(new ByteArrayLengthConstraint(schemaObject.RangeLower ?? 0, schemaObject.RangeUpper ?? 0));
         return;
     }
     if (propDef.Type == typeof(string))
     {
         ADSchemaDataProvider.GetStringConstraints(schemaObject, propDef, constraints);
         return;
     }
     ExTraceGlobals.SchemaInitializationTracer.TraceDebug <DataSyntax, ADPropertyDefinition>(0L, "Unsupported property type '{1}' for data syntax '{0}'.", schemaObject.DataSyntax, propDef);
 }
Esempio n. 4
0
        private PropertyDefinitionConstraint[] GeneratePropertyConstraints(ADSchemaAttributeObject schemaObject, ADPropertyDefinition propDef)
        {
            List <PropertyDefinitionConstraint> list = new List <PropertyDefinitionConstraint>();

            switch (schemaObject.DataSyntax)
            {
            case DataSyntax.Boolean:
            case DataSyntax.Sid:
            case DataSyntax.ObjectIdentifier:
            case DataSyntax.UTCTime:
            case DataSyntax.GeneralizedTime:
            case DataSyntax.Interval:
            case DataSyntax.NTSecDesc:
            case DataSyntax.AccessPoint:
            case DataSyntax.DNBinary:
            case DataSyntax.DNString:
            case DataSyntax.DSDN:
            case DataSyntax.ORName:
            case DataSyntax.PresentationAddress:
            case DataSyntax.ReplicaLink:
                goto IL_BE;

            case DataSyntax.Integer:
            case DataSyntax.Enumeration:
                ADSchemaDataProvider.GetIntegerConstraints(schemaObject, propDef, list);
                goto IL_BE;

            case DataSyntax.Octet:
                ADSchemaDataProvider.GetByteConstraints(schemaObject, propDef, list);
                goto IL_BE;

            case DataSyntax.Numeric:
            case DataSyntax.Printable:
            case DataSyntax.Teletex:
            case DataSyntax.IA5:
            case DataSyntax.CaseSensitive:
            case DataSyntax.Unicode:
                ADSchemaDataProvider.GetStringConstraints(schemaObject, propDef, list);
                goto IL_BE;

            case DataSyntax.LargeInteger:
                ADSchemaDataProvider.GetLargeIntegerConstraints(schemaObject, propDef, list);
                goto IL_BE;
            }
            ExTraceGlobals.SchemaInitializationTracer.TraceDebug <DataSyntax, ADPropertyDefinition>((long)this.GetHashCode(), "Unsupported DataSyntax '{0}' found for property '{1}'.", schemaObject.DataSyntax, propDef);
IL_BE:
            return(list.ToArray());
        }
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     this.Clear();
     base.InternalValidate();
     this.CheckRbac();
     if (base.IsInherited)
     {
         return;
     }
     if (base.ParameterSetName == "Owner")
     {
         return;
     }
     if (base.Instance.AccessRights == null && base.Instance.ExtendedRights == null)
     {
         base.WriteError(new MustSpecifyEitherAccessOrExtendedRightsException(), ErrorCategory.InvalidData, null);
     }
     if (base.ParameterSetName == "Instance")
     {
         if (base.Instance.User == null)
         {
             base.WriteError(new ArgumentException(Strings.ErrorUserNull, "User"), ErrorCategory.InvalidArgument, null);
         }
         if (base.Instance.AccessRights == null || base.Instance.AccessRights.Length == 0)
         {
             base.WriteError(new ArgumentException(Strings.ErrorAccessRightsEmpty, "AccessRights"), ErrorCategory.InvalidArgument, null);
         }
         this.genericAll = this.IsGenericAllAccessRight(base.Instance);
     }
     else
     {
         bool flag  = false;
         bool flag2 = false;
         if (base.Instance.AccessRights != null)
         {
             foreach (ActiveDirectoryRights activeDirectoryRights in base.Instance.AccessRights)
             {
                 if (activeDirectoryRights == ActiveDirectoryRights.GenericAll)
                 {
                     this.genericAll = true;
                     break;
                 }
                 if (activeDirectoryRights == ActiveDirectoryRights.CreateChild || activeDirectoryRights == ActiveDirectoryRights.DeleteChild)
                 {
                     flag2 = true;
                 }
                 else if (activeDirectoryRights == ActiveDirectoryRights.ReadProperty || activeDirectoryRights == ActiveDirectoryRights.WriteProperty || activeDirectoryRights == ActiveDirectoryRights.Self)
                 {
                     flag = true;
                 }
             }
             if (this.genericAll && base.Instance.AccessRights.Length > 1)
             {
                 base.WriteError(new ArgumentException(Strings.ErrorGenericAllCannotbeUsedWithOtherAccessRights, "AccessRights"), ErrorCategory.InvalidArgument, null);
             }
         }
         if (!this.genericAll && base.Instance.ChildObjectTypes != null && !flag2 && !flag)
         {
             base.WriteError(new ArgumentException(Strings.ErrorChildObjectTypeParameter, "ChildObjectTypes"), ErrorCategory.InvalidArgument, null);
         }
         if (!this.genericAll && base.Instance.Properties != null && !flag)
         {
             base.WriteError(new ArgumentException(Strings.ErrorPropertyParameter, "Properties"), ErrorCategory.InvalidArgument, null);
         }
     }
     if (base.Instance.ExtendedRights != null)
     {
         for (int j = 0; j < base.Instance.ExtendedRights.Length; j++)
         {
             if (string.Compare(base.Instance.ExtendedRights[j].RawIdentity, "all", StringComparison.InvariantCultureIgnoreCase) == 0)
             {
                 this.allExtendedRightsSpecified = true;
                 break;
             }
             this.extendedRight.Add((ExtendedRight)base.GetDataObject <ExtendedRight>(base.Instance.ExtendedRights[j], base.ReadOnlyConfigurationSession, null, new LocalizedString?(Strings.ErrorExtendedRightNotFound(base.Instance.ExtendedRights[j].ToString())), new LocalizedString?(LocalizedString.Empty)));
         }
     }
     if (base.Instance.ChildObjectTypes != null)
     {
         for (int k = 0; k < base.Instance.ChildObjectTypes.Length; k++)
         {
             this.childObjectType.Add((ADSchemaClassObject)base.GetDataObject <ADSchemaClassObject>(base.Instance.ChildObjectTypes[k], base.ReadOnlyConfigurationSession, null, new LocalizedString?(Strings.ErrorChildObjectTypeNotFound(base.Instance.ChildObjectTypes[k].ToString())), new LocalizedString?(Strings.ErrorChildObjectTypeNotUnique(base.Instance.ChildObjectTypes[k].ToString()))));
         }
     }
     if (base.Instance.Properties != null)
     {
         for (int l = 0; l < base.Instance.Properties.Length; l++)
         {
             IEnumerable <ADSchemaAttributeObject> objects = base.Instance.Properties[l].GetObjects <ADSchemaAttributeObject>(null, base.ReadOnlyConfigurationSession);
             using (IEnumerator <ADSchemaAttributeObject> enumerator = objects.GetEnumerator())
             {
                 if (enumerator.MoveNext())
                 {
                     ADSchemaAttributeObject item = enumerator.Current;
                     if (enumerator.MoveNext())
                     {
                         base.WriteError(new ManagementObjectAmbiguousException(Strings.ErrorPropertyTypeNotUnique(base.Instance.Properties[l].ToString())), ErrorCategory.InvalidData, null);
                     }
                     else
                     {
                         this.propertyType.Add(item);
                     }
                 }
                 else
                 {
                     ExtendedRightIdParameter extendedRightIdParameter = ExtendedRightIdParameter.Parse(base.Instance.Properties[l].RawIdentity);
                     this.propertyType.Add((ExtendedRight)base.GetDataObject <ExtendedRight>(extendedRightIdParameter, base.ReadOnlyConfigurationSession, null, new LocalizedString?(Strings.ErrorPropertyTypeNotFound(extendedRightIdParameter.ToString())), new LocalizedString?(Strings.ErrorPropertyTypeNotUnique(extendedRightIdParameter.ToString()))));
                 }
             }
         }
     }
     if (base.Instance.InheritedObjectType != null)
     {
         this.inheritedObjectType = (ADSchemaClassObject)base.GetDataObject <ADSchemaClassObject>(base.Instance.InheritedObjectType, base.ReadOnlyConfigurationSession, null, new LocalizedString?(Strings.ErrorInheritedObjectTypeNotFound(base.Instance.InheritedObjectType.ToString())), new LocalizedString?(Strings.ErrorInheritedObjectTypeNotUnique(base.Instance.InheritedObjectType.ToString())));
     }
     TaskLogger.LogExit();
 }
        private static NspiPropertyDefinition CreatePropertyDefinition(ADSchemaAttributeObject mapiAttribute)
        {
            ADPropertyDefinitionFlags adpropertyDefinitionFlags = ADPropertyDefinitionFlags.None;
            Type     typeFromHandle;
            PropType propType;
            object   defaultValue;

            switch (mapiAttribute.DataSyntax)
            {
            case DataSyntax.Boolean:
                typeFromHandle = typeof(bool);
                propType       = PropType.Boolean;
                defaultValue   = false;
                goto IL_13B;

            case DataSyntax.Integer:
            case DataSyntax.Enumeration:
            case DataSyntax.LargeInteger:
                typeFromHandle             = typeof(int);
                propType                   = PropType.Int;
                defaultValue               = 0;
                adpropertyDefinitionFlags |= ADPropertyDefinitionFlags.PersistDefaultValue;
                goto IL_13B;

            case DataSyntax.Sid:
            case DataSyntax.Octet:
                typeFromHandle             = typeof(byte[]);
                propType                   = PropType.Binary;
                defaultValue               = null;
                adpropertyDefinitionFlags |= ADPropertyDefinitionFlags.Binary;
                goto IL_13B;

            case DataSyntax.Numeric:
            case DataSyntax.Printable:
            case DataSyntax.Teletex:
            case DataSyntax.IA5:
            case DataSyntax.CaseSensitive:
            case DataSyntax.Unicode:
                typeFromHandle = typeof(string);
                propType       = PropType.String;
                defaultValue   = string.Empty;
                goto IL_13B;

            case DataSyntax.UTCTime:
            case DataSyntax.GeneralizedTime:
                typeFromHandle = typeof(DateTime?);
                propType       = PropType.SysTime;
                defaultValue   = null;
                goto IL_13B;

            case DataSyntax.DNBinary:
            case DataSyntax.DNString:
            case DataSyntax.DSDN:
            case DataSyntax.ORName:
                typeFromHandle = typeof(ADObjectId);
                defaultValue   = null;
                if (mapiAttribute.LinkID == 0)
                {
                    propType = PropType.String;
                    goto IL_13B;
                }
                propType = PropType.Object;
                if (mapiAttribute.LinkID % 2 == 1)
                {
                    adpropertyDefinitionFlags |= ADPropertyDefinitionFlags.BackLink;
                    goto IL_13B;
                }
                goto IL_13B;
            }
            NspiSchemaProperties.Tracer.TraceDebug <DataSyntax>(0L, "Unsupported DataSyntax {0} -- Skipped", mapiAttribute.DataSyntax);
            return(null);

IL_13B:
            if (!mapiAttribute.IsSingleValued)
            {
                PropType propType2 = propType;
                if (propType2 > PropType.Object)
                {
                    if (propType2 != PropType.String)
                    {
                        if (propType2 == PropType.SysTime)
                        {
                            goto IL_188;
                        }
                        if (propType2 != PropType.Binary)
                        {
                            goto IL_19C;
                        }
                    }
                    propType |= PropType.MultiValueFlag;
                    goto IL_1A7;
                }
                if (propType2 != PropType.Int)
                {
                    switch (propType2)
                    {
                    case PropType.Boolean:
                        break;

                    case (PropType)12:
                        goto IL_19C;

                    case PropType.Object:
                        goto IL_1A7;

                    default:
                        goto IL_19C;
                    }
                }
IL_188:
                NspiSchemaProperties.Tracer.TraceDebug <PropType>(0L, "Unsupported multivalue property type {0} -- Skipped", propType);
                return(null);

IL_19C:
                throw new InvalidOperationException("Invalid PropType");
IL_1A7:
                defaultValue = null;
                adpropertyDefinitionFlags |= ADPropertyDefinitionFlags.MultiValued;
                adpropertyDefinitionFlags &= ~ADPropertyDefinitionFlags.PersistDefaultValue;
            }
            return(new NspiPropertyDefinition(PropTagHelper.PropTagFromIdAndType(mapiAttribute.MapiID, propType), typeFromHandle, mapiAttribute.LdapDisplayName, adpropertyDefinitionFlags, defaultValue, mapiAttribute.IsMemberOfPartialAttributeSet));
        }