private bool ADReplicationSiteLinkBridgePreCommitFSRoutine(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj) { string parentPath = ADPathModule.GetParentPath(directoryObj.DistinguishedName, null, ADPathFormat.X500); if ((!directoryObj.Contains("siteLinkList") || directoryObj["siteLinkList"].Count <= 1) && operation == ADFactory <T> .DirectoryOperation.Create) { object[] objArray = new object[4]; objArray[0] = "SiteLinkBridge"; objArray[1] = 2; objArray[2] = "SiteLinks"; objArray[3] = "SiteLinksIncluded"; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.ADInvalidAttributeValueCount, objArray)); } else { if (directoryObj.Contains("siteLinkList") && directoryObj["siteLinkList"].Count > 0) { foreach (string item in directoryObj["siteLinkList"]) { string str = ADPathModule.GetParentPath(item, null, ADPathFormat.X500); if (string.Compare(str, parentPath, StringComparison.OrdinalIgnoreCase) == 0) { continue; } object[] distinguishedName = new object[2]; distinguishedName[0] = item; distinguishedName[1] = directoryObj.DistinguishedName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.SiteLinkAndSiteLinkBridgeDoNotShareSameTransportType, distinguishedName)); } } return(false); } }
private static bool SetAndValidateClaimSourceType(ADObject directoryObj, StringBuilder errorBuffer) { bool flag = false; if (!directoryObj.Contains("msDS-ClaimSource")) { if (directoryObj.Contains("msDS-ClaimAttributeSource")) { directoryObj.SetValue("msDS-ClaimSourceType", "AD"); } } else { if (!directoryObj.Contains("msDS-ClaimValueType")) { directoryObj.Add("msDS-ClaimValueType", (long)6); } else { long?value = (long?)(directoryObj["msDS-ClaimValueType"].Value as long?); if (value.Value != (long)6) { flag = true; errorBuffer.AppendLine(StringResources.CTSourceOIDValueTypeError); } } directoryObj.SetValue("msDS-ClaimSourceType", "Certificate"); } return(!flag); }
private static bool VerifyRestrictValues(ADObject directoryObj, StringBuilder errorBuffer, CmdletSessionInfo cmdletSessionInfo, ADFactory <T> .DirectoryOperation operation) { bool flag; bool value; bool value1; bool flag1 = false; if (directoryObj.ModifiedProperties.Contains("msDS-ClaimIsValueSpaceRestricted")) { flag = true; } else { flag = directoryObj.AddedProperties.Contains("msDS-ClaimIsValueSpaceRestricted"); } bool flag2 = flag; if (!directoryObj.Contains("msDS-ClaimPossibleValues")) { value = false; } else { value = directoryObj["msDS-ClaimPossibleValues"].Value != null; } bool flag3 = value; if (!directoryObj.InternalProperties.Contains("SuggestedValues")) { value1 = false; } else { value1 = directoryObj.InternalProperties["SuggestedValues"].Value != null; } bool flag4 = value1; if (operation == ADFactory <T> .DirectoryOperation.Create && !directoryObj.Contains("msDS-ClaimIsValueSpaceRestricted")) { directoryObj.SetValue("msDS-ClaimIsValueSpaceRestricted", flag4); } if (operation == ADFactory <T> .DirectoryOperation.Update && !flag2) { if (!flag3) { directoryObj.SetValue("msDS-ClaimIsValueSpaceRestricted", false); } if (flag4 && !flag3) { directoryObj.SetValue("msDS-ClaimIsValueSpaceRestricted", true); } } if (!flag4 && !flag3 && directoryObj.Contains("msDS-ClaimIsValueSpaceRestricted") && (bool)directoryObj["msDS-ClaimIsValueSpaceRestricted"].Value) { flag1 = true; errorBuffer.AppendLine(StringResources.ClaimTypeRestrictValueError); } return(!flag1); }
private static bool VerifyClaimSourceAndAttributeExclusiveness(ADObject directoryObj, StringBuilder errorBuffer, ADFactory <T> .DirectoryOperation operation) { bool flag; bool flag1; bool flag2 = false; if (directoryObj.ModifiedProperties.Contains("msDS-ClaimSource")) { flag = true; } else { flag = directoryObj.AddedProperties.Contains("msDS-ClaimSource"); } bool flag3 = flag; if (directoryObj.ModifiedProperties.Contains("msDS-ClaimAttributeSource")) { flag1 = true; } else { flag1 = directoryObj.AddedProperties.Contains("msDS-ClaimAttributeSource"); } bool flag4 = flag1; if (directoryObj.Contains("msDS-ClaimSource") && directoryObj.Contains("msDS-ClaimAttributeSource")) { if (operation != ADFactory <T> .DirectoryOperation.Create) { if (!flag3 || !flag4) { if (!flag3) { if (flag4) { directoryObj.ForceRemove("msDS-ClaimSource"); } } else { directoryObj.ForceRemove("msDS-ClaimAttributeSource"); } } else { flag2 = true; errorBuffer.AppendLine(StringResources.SPCTBothSourceWarning); } } else { flag2 = true; errorBuffer.AppendLine(StringResources.SPCTBothSourceWarning); } } return(!flag2); }
private static bool VerifySharesPossibleValueWithAndPossibleValueExclusiveness(ADObject directoryObj, ADFactory <T> .DirectoryOperation operation, StringBuilder errorBuffer) { bool flag; bool flag1 = false; if (directoryObj.ModifiedProperties.Contains("msDS-ClaimSharesPossibleValuesWith")) { flag = true; } else { flag = directoryObj.AddedProperties.Contains("msDS-ClaimSharesPossibleValuesWith"); } bool flag2 = flag; bool flag3 = directoryObj.InternalProperties.Contains("SuggestedValues"); if (directoryObj.Contains("msDS-ClaimSharesPossibleValuesWith") && directoryObj.Contains("msDS-ClaimPossibleValues")) { if (operation != ADFactory <T> .DirectoryOperation.Create) { if (!flag2 || !flag3) { if (!flag2) { if (flag3) { directoryObj.ForceRemove("msDS-ClaimSharesPossibleValuesWith"); } } else { directoryObj.ForceRemove("msDS-ClaimPossibleValues"); } } else { flag1 = true; errorBuffer.AppendLine(StringResources.CTBothPossibleValuesShareValueWarning); } } else { flag1 = true; errorBuffer.AppendLine(StringResources.CTBothPossibleValuesShareValueWarning); } } return(!flag1); }
private bool ADResourcePropertyPreCommitFSRoutine(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj) { if (operation == ADFactory <T> .DirectoryOperation.Create || ADFactory <T> .DirectoryOperation.Update == operation) { bool flag = true; ADObject aDObject = null; StringBuilder stringBuilder = new StringBuilder(); flag = flag & ADResourcePropertyFactory <T> .VerifyResourcePropertyValueType(directoryObj, base.CmdletSessionInfo, out aDObject, stringBuilder); if (aDObject != null && aDObject.Contains("ValueType")) { ADClaimValueType?value = (ADClaimValueType?)(aDObject["ValueType"].Value as ADClaimValueType?); flag = flag & ADCBACUtil.VerifyAndSetPossibleValues(directoryObj, value.Value, stringBuilder); } flag = flag & ADResourcePropertyFactory <T> .VerifySharesPossibleValueWithAndPossibleValueExclusiveness(directoryObj, operation, stringBuilder); flag = flag & ADResourcePropertyFactory <T> .VerifyIsSuggestedValuePresentAttribute(directoryObj, stringBuilder, aDObject); flag = flag & ADResourcePropertyFactory <T> .VerifySharesValuesWith(directoryObj, stringBuilder, aDObject, base.CmdletSessionInfo); if (flag) { return(false); } else { stringBuilder.AppendLine(StringResources.CTParameterValidationFailure); throw new ADException(stringBuilder.ToString()); } } else { return(false); } }
private static bool VerifySharesValuesWith(ADObject directoryObj, StringBuilder errorBuffer, ADObject resourcePropertyValueTypeObj, CmdletSessionInfo cmdletSessionInfo) { bool flag = false; if (directoryObj.Contains("msDS-ClaimSharesPossibleValuesWith") && resourcePropertyValueTypeObj != null) { ADClaimTypeFactory <ADClaimType> aDClaimTypeFactory = new ADClaimTypeFactory <ADClaimType>(); aDClaimTypeFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADClaimType aDClaimType = new ADClaimType(); aDClaimType.Identity = directoryObj["msDS-ClaimSharesPossibleValuesWith"].Value as string; string str = ADPathModule.MakePath(cmdletSessionInfo.ADRootDSE.ConfigurationNamingContext, "CN=Claims Configuration,CN=Services,", ADPathFormat.X500); str = ADPathModule.MakePath(str, "CN=Claim Types,", ADPathFormat.X500); ADObject extendedObjectFromIdentity = aDClaimTypeFactory.GetExtendedObjectFromIdentity(aDClaimType, str); if (!extendedObjectFromIdentity.Contains("CompatibleResourceTypes") || extendedObjectFromIdentity["CompatibleResourceTypes"].Value == null) { flag = true; errorBuffer.AppendLine(StringResources.ResourcePropertySharesValueWithValueTypeError); } else { List <string> value = extendedObjectFromIdentity["CompatibleResourceTypes"].Value as List <string>; if (!value.Contains(resourcePropertyValueTypeObj.Name)) { flag = true; errorBuffer.AppendLine(StringResources.ResourcePropertySharesValueWithValueTypeError); } } } return(!flag); }
public static ADObject CreateIdentityCopy(ADObject sourceObj) { object item; ADObject aDObject = new ADObject(); string[] identityPropertyNames = ADObject.IdentityPropertyNames; for (int i = 0; i < (int)identityPropertyNames.Length; i++) { string str = identityPropertyNames[i]; if (!aDObject.Contains(str)) { item = sourceObj[str]; if (item != null) { aDObject.Add(str, item); } } } foreach (string propertyName in sourceObj.InternalProperties.PropertyNames) { if (aDObject.InternalProperties.Contains(propertyName)) { continue; } item = sourceObj.InternalProperties[propertyName].Value; if (item == null) { continue; } aDObject.InternalProperties.SetValue(propertyName, item); } return(aDObject); }
private static bool VerifyClaimSourceAndPossibleValueExclusiveness(ADObject directoryObj, StringBuilder errorBuffer) { bool flag = false; if (directoryObj.Contains("msDS-ClaimSource") && directoryObj.InternalProperties.Contains("SuggestedValues")) { flag = true; errorBuffer.AppendLine(StringResources.SPCTBothSourceOIDPossibleValuesWarning); } return(!flag); }
private double GetInactiveTimeSpanDays(CmdletSessionInfo cmdletSessionInfo) { double num = 0; double num1; ADRootDSE rootDSE = this.GetRootDSE(); string defaultNamingContext = rootDSE.DefaultNamingContext; if (rootDSE.ServerType != ADServerType.ADDS || defaultNamingContext == null) { return(15); } else { SearchADAccountCmdlet._accountInactiveTimeSpanLock.EnterReadLock(); try { if (!SearchADAccountCmdlet._accountInactiveTimeSpanCache.TryGetValue(defaultNamingContext, out num)) { double value = 15; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, defaultNamingContext, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.Add("msDS-LogonTimeSyncInterval"); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject != null && aDObject.Contains("msDS-LogonTimeSyncInterval") && aDObject["msDS-LogonTimeSyncInterval"].Count > 0) { value = (double)((int)aDObject["msDS-LogonTimeSyncInterval"].Value); } } SearchADAccountCmdlet._accountInactiveTimeSpanLock.EnterWriteLock(); try { SearchADAccountCmdlet._accountInactiveTimeSpanCache[defaultNamingContext] = value; } finally { SearchADAccountCmdlet._accountInactiveTimeSpanLock.ExitWriteLock(); } return(value); } else { num1 = num; } } finally { SearchADAccountCmdlet._accountInactiveTimeSpanLock.ExitReadLock(); } return(num1); } }
private static bool VerifyIsSuggestedValuePresentAttribute(ADObject directoryObj, StringBuilder errorBuffer, ADObject resourcePropertyValueTypeObj) { bool flag = false; if (!directoryObj.Contains("msDS-ClaimSharesPossibleValuesWith") && resourcePropertyValueTypeObj != null && resourcePropertyValueTypeObj.Contains("IsSuggestedValuesPresent") && resourcePropertyValueTypeObj["IsSuggestedValuesPresent"].Value != null) { bool?value = (bool?)(resourcePropertyValueTypeObj["IsSuggestedValuesPresent"].Value as bool?); if (!value.Value || directoryObj.Contains("msDS-ClaimPossibleValues")) { if (!value.Value && directoryObj.Contains("msDS-ClaimPossibleValues")) { flag = true; errorBuffer.AppendLine(StringResources.RCTSuggestedValuePresentError); } } else { flag = true; errorBuffer.AppendLine(StringResources.RCTSuggestedValueNotPresentError); } } return(!flag); }
private bool ADClaimTypePreCommitFSRoutine(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj) { bool classes = true; StringBuilder stringBuilder = new StringBuilder(); if (operation == ADFactory <T> .DirectoryOperation.Create || ADFactory <T> .DirectoryOperation.Update == operation) { bool switchParameterBooleanValue = parameters.GetSwitchParameterBooleanValue("SourceTransformPolicy"); if (switchParameterBooleanValue) { directoryObj.SetValue("msDS-ClaimSourceType", "TransformPolicy"); directoryObj.ForceRemove("msDS-ClaimAttributeSource"); directoryObj.ForceRemove("msDS-ClaimSource"); } classes = classes & ADClaimTypeFactory <T> .VerifyClaimSourceAndAttributeExclusiveness(directoryObj, stringBuilder, operation); classes = classes & ADClaimTypeFactory <T> .VerifyClaimSourceAndPossibleValueExclusiveness(directoryObj, stringBuilder); classes = classes & ADClaimTypeFactory <T> .SetAndValidateClaimSourceType(directoryObj, stringBuilder); classes = classes & ADClaimTypeFactory <T> .VerifyRestrictValues(directoryObj, stringBuilder, base.CmdletSessionInfo, operation); if (directoryObj.Contains("msDS-ClaimValueType")) { ADClaimValueType num = (ADClaimValueType)((long)Convert.ToInt32(directoryObj["msDS-ClaimValueType"].Value, CultureInfo.InvariantCulture)); classes = classes & ADCBACUtil.VerifyAndSetPossibleValues(directoryObj, num, stringBuilder); } classes = classes & ADClaimTypeFactory <T> .VerifyAppliesToClasses(directoryObj, stringBuilder, base.CmdletSessionInfo); if (classes) { return(false); } else { stringBuilder.AppendLine(StringResources.CTParameterValidationFailure); throw new ADException(stringBuilder.ToString()); } } else { return(false); } }
protected internal virtual string GenerateNewRDN(F factory, string newName, ADObject target) { string empty = string.Empty; if (target.Contains("objectClass")) { ADSessionInfo sessionInfo = this.GetSessionInfo(); ADSchemaUtil aDSchemaUtil = new ADSchemaUtil(sessionInfo); empty = aDSchemaUtil.GetRDNPrefix(target["objectClass"].Value as string); } if (!string.IsNullOrEmpty(newName)) { newName = Utils.EscapeDNComponent(newName); } if (!string.IsNullOrEmpty(empty)) { empty = string.Concat(empty, "=", newName); } return(empty); }
internal static bool?IsProtectedFromDeletion(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo) { bool flag; ProtectedFromDeletionUtil.AddObjectToCache(directoryObj, cmdletSessionInfo); if (!directoryObj.Contains("nTSecurityDescriptor") || directoryObj["nTSecurityDescriptor"].Value == null) { bool?nullable = null; return(nullable); } else { bool flag1 = ProtectedFromDeletionUtil.EveryoneDeniedDeleteAndDeleteTree(directoryObj); if (!Utils.IsNamingContext(directoryObj) && !Utils.IsDeleted(directoryObj)) { string parentPath = ADPathModule.GetParentPath(directoryObj.DistinguishedName, null, ADPathFormat.X500); ADObject cachedObject = ProtectedFromDeletionUtil.GetCachedObject(parentPath, ProtectedFromDeletionUtil.AttributesToFetchOnParent, cmdletSessionInfo); if (cachedObject != null) { if (!cachedObject.Contains("nTSecurityDescriptor") || cachedObject["nTSecurityDescriptor"].Value == null) { bool?nullable1 = null; return(nullable1); } else { if (!ProtectedFromDeletionUtil.EveryoneDeniedDeleteChild(cachedObject)) { flag = false; } else { flag = flag1; } return(new bool?(flag)); } } } return(new bool?(flag1)); } }
internal override ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, bool showDeleted) { ADObject aDObject = identityObj; if (aDObject != null) { if (base.CmdletSessionInfo != null) { if (aDObject.IsSearchResult && aDObject.Contains("isDeleted")) { showDeleted = true; } ADObjectSearcher aDObjectSearcherFromIdentity = ADFactoryUtil.GetADObjectSearcherFromIdentity(identityObj, searchRoot, showDeleted, this.StructuralObjectFilter, this.BuildIdentityFilter(identityObj), this.IdentityResolvers, base.CmdletSessionInfo); AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(null); string[] strArrays = new string[0]; ADObject objectFromIdentitySearcher = ADFactoryUtil.GetObjectFromIdentitySearcher(aDObjectSearcherFromIdentity, identityObj, searchRoot, attributeSetRequest, base.CmdletSessionInfo, out strArrays); objectFromIdentitySearcher.TrackChanges = true; objectFromIdentitySearcher.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str = strArrays1[i]; base.CmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(str); } return(objectFromIdentitySearcher); } else { throw new ArgumentNullException(StringResources.SessionRequired); } } else { object[] type = new object[2]; type[0] = "GetDirectoryObjectFromIdentity"; type[1] = identityObj.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type)); } }
internal static bool VerifyAndSetPossibleValues(ADObject directoryObj, ADClaimValueType valueType, StringBuilder errorBuffer) { bool flag = false; if (directoryObj.InternalProperties.Contains("SuggestedValues") && directoryObj.InternalProperties["SuggestedValues"].Value != null) { if (directoryObj.Contains("msDS-ClaimPossibleValues") && directoryObj["msDS-ClaimPossibleValues"].Value != null) { bool flag1 = false; try { ADCBACUtil.ConvertSuggestedValueXmlToSuggestedValueEntryList(directoryObj["msDS-ClaimPossibleValues"].Value as string, out flag1); if (flag1) { flag = true; object[] value = new object[2]; value[0] = directoryObj["name"].Value as string; value[1] = "msDS-ClaimPossibleValues"; errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.CannotOverwriteNextVersionXml, value)); } } catch (Exception exception1) { Exception exception = exception1; if (exception as XmlException == null && exception as XmlSchemaException == null && exception as InvalidOperationException == null) { throw; } } } if (!flag) { ADSuggestedValueEntry[] valueList = directoryObj.InternalProperties["SuggestedValues"].ValueList as ADSuggestedValueEntry[]; ADCBACUtil.AddSuggestedValueXmlFromADSuggestedValueEntryList(valueList, directoryObj, valueType); } } return(!flag); }
private bool ADReplicationSiteLinkPreCommitFSRoutine(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj) { if (operation == ADFactory <T> .DirectoryOperation.Create) { if (!directoryObj.Contains("siteList") || directoryObj["siteList"].Count <= 1) { object[] objArray = new object[4]; objArray[0] = "SiteLink"; objArray[1] = 2; objArray[2] = "Sites"; objArray[3] = "SitesIncluded"; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.ADInvalidAttributeValueCount, objArray)); } else { return(false); } } else { return(false); } }
internal static bool ProtectFromAccidentalDeletion(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo) { ADObject cachedObject; string value = directoryObj["distinguishedName"].Value as string; if (!directoryObj.Contains("nTSecurityDescriptor") || !directoryObj.Contains("sdRightsEffective")) { cachedObject = ProtectedFromDeletionUtil.GetCachedObject(value, ProtectedFromDeletionUtil.AttributesToFetchOnObject, cmdletSessionInfo); } else { cachedObject = directoryObj; ProtectedFromDeletionUtil.AddObjectToCache(directoryObj, cmdletSessionInfo); } if (cachedObject == null || !cachedObject.Contains("nTSecurityDescriptor") || cachedObject["nTSecurityDescriptor"].Value == null) { object[] objArray = new object[1]; objArray[0] = directoryObj["distinguishedName"].Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray)); } else { if (ProtectedFromDeletionUtil.EveryoneDeniedDeleteAndDeleteTree(cachedObject) || Utils.HasFlagsSet((int)cachedObject["sdRightsEffective"].Value, 4)) { if (!Utils.IsNamingContext(cachedObject) && !Utils.IsDeleted(cachedObject)) { string parentPath = ADPathModule.GetParentPath(value, null, ADPathFormat.X500); ADObject aDObject = ProtectedFromDeletionUtil.GetCachedObject(parentPath, ProtectedFromDeletionUtil.AttributesToFetchOnParent, cmdletSessionInfo); if (aDObject != null && !ProtectedFromDeletionUtil.EveryoneDeniedDeleteChild(aDObject)) { if (Utils.HasFlagsSet((int)aDObject["sdRightsEffective"].Value, 4)) { ActiveDirectorySecurity activeDirectorySecurity = (ActiveDirectorySecurity)aDObject["nTSecurityDescriptor"].Value; activeDirectorySecurity.AddAccessRule(ProtectedFromDeletionUtil.ACEConstants.DeleteChildAccessRule); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject)) { aDObject.TrackChanges = true; aDObject["nTSecurityDescriptor"].Value = activeDirectorySecurity; aDActiveObject.Update(); } } else { object[] value1 = new object[2]; value1[0] = directoryObj["distinguishedName"].Value; value1[1] = aDObject["distinguishedName"].Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObjectParent, value1)); } } } ActiveDirectorySecurity activeDirectorySecurity1 = (ActiveDirectorySecurity)cachedObject["nTSecurityDescriptor"].Value; if (ProtectedFromDeletionUtil.EveryoneDeniedDeleteAndDeleteTree(cachedObject)) { return(false); } else { activeDirectorySecurity1.AddAccessRule(ProtectedFromDeletionUtil.ACEConstants.DeleteAndDeleteTreeAccessRule); if (!directoryObj.Contains("nTSecurityDescriptor")) { directoryObj.Add("nTSecurityDescriptor", activeDirectorySecurity1); } else { directoryObj["nTSecurityDescriptor"].Value = activeDirectorySecurity1; } return(true); } } else { object[] objArray1 = new object[1]; objArray1[0] = directoryObj["distinguishedName"].Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray1)); } } }
internal static bool UnprotectFromAccidentalDeletion(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo) { ADObject cachedObject; bool hasValue; string value = directoryObj["distinguishedName"].Value as string; if (!directoryObj.Contains("nTSecurityDescriptor") || !directoryObj.Contains("sdRightsEffective")) { cachedObject = ProtectedFromDeletionUtil.GetCachedObject(value, ProtectedFromDeletionUtil.AttributesToFetchOnObject, cmdletSessionInfo); } else { cachedObject = directoryObj; ProtectedFromDeletionUtil.AddObjectToCache(directoryObj, cmdletSessionInfo); } if (cachedObject != null) { bool?nullable = ProtectedFromDeletionUtil.IsProtectedFromDeletion(cachedObject, cmdletSessionInfo); if (nullable.HasValue) { bool?nullable1 = nullable; if (nullable1.GetValueOrDefault()) { hasValue = false; } else { hasValue = nullable1.HasValue; } if (!hasValue) { if (Utils.HasFlagsSet((int)cachedObject["sdRightsEffective"].Value, 4)) { ActiveDirectorySecurity activeDirectorySecurity = (ActiveDirectorySecurity)cachedObject["nTSecurityDescriptor"].Value; activeDirectorySecurity.RemoveAccessRule(ProtectedFromDeletionUtil.ACEConstants.DeleteAndDeleteTreeAccessRule); if (!directoryObj.Contains("nTSecurityDescriptor")) { directoryObj.Add("nTSecurityDescriptor", activeDirectorySecurity); } else { directoryObj["nTSecurityDescriptor"].Value = activeDirectorySecurity; } return(true); } else { object[] objArray = new object[1]; objArray[0] = directoryObj["distinguishedName"].Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray)); } } else { return(false); } } else { object[] value1 = new object[1]; value1[0] = directoryObj["distinguishedName"].Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, value1)); } } else { object[] objArray1 = new object[1]; objArray1[0] = directoryObj["distinguishedName"].Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray1)); } }
private static bool VerifyAppliesToClasses(ADObject directoryObj, StringBuilder errorBuffer, CmdletSessionInfo cmdletSessionInfo) { bool flag = false; if (directoryObj.Contains("msDS-ClaimTypeAppliesToClass")) { ADSchemaUtil aDSchemaUtil = new ADSchemaUtil(cmdletSessionInfo.ADSessionInfo); string[] valueList = directoryObj["msDS-ClaimTypeAppliesToClass"].ValueList as string[]; string[] strArrays = valueList; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; HashSet <string> allParentClassesForSchemaClassDN = aDSchemaUtil.GetAllParentClassesForSchemaClassDN(str); allParentClassesForSchemaClassDN.IntersectWith(ADClaimTypeFactory <T> .ValidAppliesToClasses); if (allParentClassesForSchemaClassDN.Count == 0) { flag = true; object[] objArray = new object[1]; objArray[0] = str; errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTInvalidAppliesToClassWarning, objArray)); } } if (directoryObj.Contains("msDS-ClaimAttributeSource")) { string value = directoryObj["msDS-ClaimAttributeSource"].Value as string; ADSchemaObjectFactory <ADSchemaObject> aDSchemaObjectFactory = new ADSchemaObjectFactory <ADSchemaObject>(); aDSchemaObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADSchemaObject aDSchemaObject = new ADSchemaObject(); aDSchemaObject.Identity = value; string[] strArrays1 = new string[1]; strArrays1[0] = "lDAPDisplayName"; ADObject extendedObjectFromIdentity = aDSchemaObjectFactory.GetExtendedObjectFromIdentity(aDSchemaObject, cmdletSessionInfo.ADRootDSE.SchemaNamingContext, strArrays1); if (extendedObjectFromIdentity.Contains("lDAPDisplayName")) { string value1 = extendedObjectFromIdentity["lDAPDisplayName"].Value as string; string[] strArrays2 = valueList; for (int j = 0; j < (int)strArrays2.Length; j++) { string str1 = strArrays2[j]; HashSet <string> attributeListForSchemaClassDN = aDSchemaUtil.GetAttributeListForSchemaClassDN(str1); if (!attributeListForSchemaClassDN.Contains(value1)) { flag = true; object[] objArray1 = new object[2]; objArray1[0] = str1; objArray1[1] = value1; errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTAttributeNotFoundInSchemaClass, objArray1)); } } } else { flag = true; object[] objArray2 = new object[1]; objArray2[0] = value; errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTSourceAttributeLdapDisplayNameError, objArray2)); } } } return(!flag); }
internal static void ToDirectoryFromSourceAttributeToDN(string extendedAttribute, string[] directoryAttributes, ADPropertyValueCollection extendedData, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo) { if (extendedData == null || extendedData.Value == null) { directoryObj.ForceRemove(directoryAttributes[0]); return; } else { ADSchemaObjectFactory <ADSchemaObject> aDSchemaObjectFactory = new ADSchemaObjectFactory <ADSchemaObject>(); aDSchemaObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADSchemaObject aDSchemaObject = new ADSchemaObject(); aDSchemaObject.Identity = extendedData.Value; ADObject extendedObjectFromIdentity = aDSchemaObjectFactory.GetExtendedObjectFromIdentity(aDSchemaObject, cmdletSessionInfo.ADRootDSE.SchemaNamingContext, ADClaimTypeFactory <T> .SchemaAttributeProperties); if (extendedObjectFromIdentity != null) { if (!extendedObjectFromIdentity.Contains("lDAPDisplayName") || !extendedObjectFromIdentity.Contains("attributeSyntax")) { object[] value = new object[1]; value[0] = extendedData.Value; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTInvalidSourceAttribute, value)); } else { string str = (string)extendedObjectFromIdentity["lDAPDisplayName"].Value; string value1 = (string)extendedObjectFromIdentity["attributeSyntax"].Value; HashSet <string> strs = new HashSet <string>(ADClaimTypeFactory <T> .BlockedAttributes, StringComparer.OrdinalIgnoreCase); if (!strs.Contains(str)) { if (!extendedObjectFromIdentity.Contains("systemFlags") || ((int)extendedObjectFromIdentity["systemFlags"].Value & ADClaimTypeFactory <T> .FLAG_ATTR_NOT_REPLICATED) == 0) { if (!extendedObjectFromIdentity.Contains("searchFlags") || ((int)extendedObjectFromIdentity["searchFlags"].Value & ADClaimTypeFactory <T> .RODCFilteredAttribute) == 0) { if (!extendedObjectFromIdentity.Contains("isDefunct") || !(bool)extendedObjectFromIdentity["isDefunct"].Value) { ADClaimValueType aDClaimValueType = ADClaimValueType.Invalid; HashSet <string> strs1 = new HashSet <string>(ADClaimTypeFactory <T> .ValidAttributeSyntaxInt, StringComparer.OrdinalIgnoreCase); HashSet <string> strs2 = new HashSet <string>(ADClaimTypeFactory <T> .ValidAttributeSyntaxString, StringComparer.OrdinalIgnoreCase); if (!strs2.Contains(value1)) { if (!strs1.Contains(value1)) { if (string.Compare(value1, ADClaimTypeFactory <T> .ValidAttributeSyntaxUInt, true, CultureInfo.InvariantCulture) != 0) { if (string.Compare(value1, ADClaimTypeFactory <T> .ValidBooleanAttributeSyntax, true, CultureInfo.InvariantCulture) != 0) { throw new ADException(StringResources.SPCTInvalidAttributeSyntax); } else { aDClaimValueType = ADClaimValueType.Boolean; } } else { aDClaimValueType = ADClaimValueType.UInt64; } } else { aDClaimValueType = ADClaimValueType.Int64; } } else { aDClaimValueType = ADClaimValueType.String; } directoryObj[directoryAttributes[0]].Value = extendedObjectFromIdentity.DistinguishedName; if (!directoryObj.Contains("msDS-ClaimValueType")) { directoryObj.Add("msDS-ClaimValueType", (long)aDClaimValueType); } else { long?nullable = (long?)(directoryObj["msDS-ClaimValueType"].Value as long?); if ((ADClaimValueType)nullable.Value != aDClaimValueType) { throw new ADException(StringResources.CTSourceAttributeValueTypeError); } } directoryObj.InternalProperties[directoryAttributes[0]].Value = str; return; } else { throw new ADException(StringResources.SPCTDefuctSourceAttr); } } else { throw new ADException(StringResources.SPCTRODCFilteredSourceAttr); } } else { throw new ADException(StringResources.SPCTNonREPLSourceAttrError); } } else { throw new ADException(StringResources.SPCTBlockedSourceAttribute); } } } else { throw new ADException(StringResources.SPCTInvalidSourceAttributeName); } } }