private static void ExtractRangeRetrievalDataFromAttributes(ADObject fetchedObject, ADObject targetObject, HashSet <string> rangeRetrievedObjects, HashSet <string> rangeRetrievedAttributes, ref int rangeRetrievalNextIndex) { string str = null; int num = 0; string[] strArrays = new string[fetchedObject.PropertyNames.Count]; fetchedObject.PropertyNames.CopyTo(strArrays, 0); string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str1 = strArrays1[i]; if (ADObjectSearcher.ContainsRangeRetrievalTag(str1, out str, out num)) { rangeRetrievedObjects.Add(fetchedObject.DistinguishedName); if (num != -1) { rangeRetrievedAttributes.Add(str); if (rangeRetrievalNextIndex == -2147483648) { rangeRetrievalNextIndex = num + 1; } } //targetObject[str]; targetObject[str].AddRange(fetchedObject[str1]); if (targetObject.Contains(str1)) { targetObject.Remove(str1); } } } }
internal HashSet <string> GetAttributeListForSchemaClass(string schemaClassName) { Dictionary <string, ADObject> schemaClasses = this._adSchema.SchemaClasses; if (schemaClasses.ContainsKey(schemaClassName)) { ADObject item = schemaClasses[schemaClassName]; if (!item.Contains(SchemaConstants.Attributelist)) { HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase); HashSet <string> allParentClassesForSchemaClass = this.GetAllParentClassesForSchemaClass(schemaClassName); allParentClassesForSchemaClass.Add(schemaClassName); string[] strArrays = new string[4]; strArrays[0] = "systemMayContain"; strArrays[1] = "mayContain"; strArrays[2] = "mustContain"; strArrays[3] = "systemMustContain"; string[] strArrays1 = strArrays; foreach (string str in allParentClassesForSchemaClass) { ADObject aDObject = schemaClasses[str]; string[] strArrays2 = strArrays1; for (int i = 0; i < (int)strArrays2.Length; i++) { string str1 = strArrays2[i]; if (aDObject.Contains(str1)) { string[] valueList = aDObject[str1].ValueList as string[]; strs.UnionWith(valueList); } } } ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(new HashSet <string>(strs, StringComparer.OrdinalIgnoreCase)); item[SchemaConstants.Attributelist].Value = aDPropertyValueCollection; return(strs); } else { return(new HashSet <string>(item[SchemaConstants.Attributelist].Value as HashSet <string>, StringComparer.OrdinalIgnoreCase)); } } else { object[] objArray = new object[1]; objArray[0] = schemaClassName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.NoSchemaClassInSchemaCache, objArray)); } }
private static void ExtractRangeRetrievalDataFromAttributes(ADObject fetchedObject, ADObject targetObject, HashSet<string> rangeRetrievedObjects, HashSet<string> rangeRetrievedAttributes, ref int rangeRetrievalNextIndex) { string str = null; int num = 0; string[] strArrays = new string[fetchedObject.PropertyNames.Count]; fetchedObject.PropertyNames.CopyTo(strArrays, 0); string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str1 = strArrays1[i]; if (ADObjectSearcher.ContainsRangeRetrievalTag(str1, out str, out num)) { rangeRetrievedObjects.Add(fetchedObject.DistinguishedName); if (num != -1) { rangeRetrievedAttributes.Add(str); if (rangeRetrievalNextIndex == -2147483648) { rangeRetrievalNextIndex = num + 1; } } //targetObject[str]; targetObject[str].AddRange(fetchedObject[str1]); if (targetObject.Contains(str1)) { targetObject.Remove(str1); } } } }
public void ClearProperty(string path, Collection<string> propertyToClear) { this.Trace(DebugLogLevel.Verbose, "Entering ClearProperty"); PSObject pSObject = new PSObject(); if (!this.IsValidRootDSEPath(path)) { path = this.ValidateAndNormalizePath(path); if (propertyToClear != null) { if (base.ShouldProcess(path, "Clear")) { ADProviderCommonParameters dynamicParameters = base.DynamicParameters as ADProviderCommonParameters; ADSessionInfo sessionInfo = this.GetSessionInfo(dynamicParameters, base.Credential, this.ExtendedDriveInfo); if (this.ValidateDynamicParameters(path, dynamicParameters, sessionInfo)) { ADObject aDObject = new ADObject(); aDObject.DistinguishedName = path; ADActiveObject aDActiveObject = new ADActiveObject(sessionInfo, aDObject); foreach (string str in propertyToClear) { aDObject.Add(str, null); } using (aDActiveObject) { try { aDActiveObject.Update(); this.Trace(DebugLogLevel.Verbose, "ClearProperty: ADObject updated in store."); aDObject = this.GetValidatedADObject(path, propertyToClear, dynamicParameters, base.Credential, this.ExtendedDriveInfo); } catch (ADException aDException1) { ADException aDException = aDException1; base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:ClearProperty:ADError", path)); this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: ADException: AD error"); return; } catch (UnauthorizedAccessException unauthorizedAccessException1) { UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1; base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:ClearProperty:AccessDenied", path)); this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: ADException: access denied"); return; } catch (AuthenticationException authenticationException1) { AuthenticationException authenticationException = authenticationException1; base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:ClearProperty:InvalidCredentials", path)); this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: ADException: invalid credentials"); return; } catch (InvalidOperationException invalidOperationException1) { InvalidOperationException invalidOperationException = invalidOperationException1; base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:ClearProperty:InvalidOperation", path)); this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: ADException: invalid operation"); return; } foreach (string str1 in propertyToClear) { if (!aDObject.Contains(str1)) { continue; } pSObject.Properties.Add(new PSNoteProperty(str1, aDObject[str1].Value)); } this.WriteADObjectProperties(aDObject, pSObject, dynamicParameters, this.ExtendedDriveInfo); this.Trace(DebugLogLevel.Verbose, "Leaving ClearProperty"); return; } return; } else { this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: ValidateDynamicParameters: returned false"); return; } } else { this.Trace(DebugLogLevel.Info, "Leaving ClearProperty: ShouldProcess returned false."); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException(StringResources.ADProviderPropertiesToClearNotSpecified), "ADProvider:ClearProperty:propertyToClear", path)); this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: ArgumentException: propertyToClear is clear"); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path)); this.Trace(DebugLogLevel.Error, "Leaving ClearProperty: NotSupportedException: path is rootdse"); return; } }
private void WriteADRootDSEChildName(ADObject adObj, ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo) { if (this.GetFormatType(parameters, extendedDriveInfo) != ADPathFormat.Canonical) { this.WriteItemObjectWithAbsolutePath(adObj.DistinguishedName, adObj.DistinguishedName, true); return; } else { if (!adObj.Contains("canonicalName")) { base.WriteError(ADUtilities.GetErrorRecord(new ADException(string.Format(StringResources.ADProviderUnableToReadProperty, "canonicalName", adObj.DistinguishedName)), "ADProvider:WriteADRootDSEChildName:UnableToReadCanonicalName", adObj.DistinguishedName)); this.Trace(DebugLogLevel.Error, string.Format("Leaving WriteADRootDSEChildName: Unable to read canonical name for object {0}.", adObj.DistinguishedName)); return; } else { string value = (string)adObj["canonicalName"].Value; this.WriteItemObjectWithAbsolutePath(value, value, true); return; } } }
public void SetSecurityDescriptor(string path, ObjectSecurity securityDescriptor) { ADPropertyValueCollection aDPropertyValueCollection; this.Trace(DebugLogLevel.Verbose, "Entering SetSecurityDescriptor"); Collection<string> strs = new Collection<string>(); if (!this.IsValidRootDSEPath(path)) { path = this.ValidateAndNormalizePath(path); if (securityDescriptor != null) { ActiveDirectorySecurity activeDirectorySecurity = securityDescriptor as ActiveDirectorySecurity; if (activeDirectorySecurity != null) { if (base.ShouldProcess(path, "Set")) { ADSessionInfo sessionInfo = this.GetSessionInfo(null, base.Credential, this.ExtendedDriveInfo); ADObject aDObject = new ADObject(); aDObject.DistinguishedName = path; ADActiveObject aDActiveObject = new ADActiveObject(sessionInfo, aDObject); strs.Add("ntSecurityDescriptor"); aDActiveObject.SecurityDescriptorFlags = SecurityMasks.None; using (aDActiveObject) { try { if (!aDObject.Contains("ntSecurityDescriptor")) { aDPropertyValueCollection = new ADPropertyValueCollection(); aDObject.Add("ntSecurityDescriptor", aDPropertyValueCollection); } else { aDPropertyValueCollection = aDObject["ntSecurityDescriptor"]; } aDObject["ntSecurityDescriptor"].Value = activeDirectorySecurity; aDActiveObject.Update(); aDObject = this.GetValidatedADObject(path, strs, null, base.Credential, this.ExtendedDriveInfo); } catch (ADException aDException1) { ADException aDException = aDException1; base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:SetSecurityDescriptor:ADError", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: ADException: AD error"); return; } catch (UnauthorizedAccessException unauthorizedAccessException1) { UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1; base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:SetSecurityDescriptor:AccessDenied", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: ADException: access denied"); return; } catch (AuthenticationException authenticationException1) { AuthenticationException authenticationException = authenticationException1; base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:SetSecurityDescriptor:InvalidCredentials", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: ADException: invalid credentials"); return; } catch (InvalidOperationException invalidOperationException1) { InvalidOperationException invalidOperationException = invalidOperationException1; base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:SetSecurityDescriptor:InvalidOperation", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: ADException: invalid operation"); return; } this.WriteADObjectSecurityDescriptor(aDObject, activeDirectorySecurity, null, this.ExtendedDriveInfo); this.Trace(DebugLogLevel.Verbose, "Leaving SetSecurityDescriptor"); return; } return; } else { this.Trace(DebugLogLevel.Info, "Leaving SetSecurityDescriptor: ShouldProcess returned false."); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException("securityDescriptor"), "ADProvider:SetSecurityDescriptor:InvalidSecurityDescriptor", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: ArgumentException: securityDescriptor is of incorrect type"); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException("securityDescriptor"), "ADProvider:SetSecurityDescriptor:InvalidSecurityDescriptor", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: ArgumentException: securityDescriptor is null"); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path)); this.Trace(DebugLogLevel.Error, "Leaving SetSecurityDescriptor: NotSupportedException: path is rootdse"); return; } }
public void SetProperty(string path, PSObject propertyValue) { ADPropertyValueCollection aDPropertyValueCollection; ADPropertyValueCollection item; ADPropertyValueCollection aDPropertyValueCollection1; ADPropertyValueCollection item1; PSObject pSObject = new PSObject(); Collection<string> strs = new Collection<string>(); this.Trace(DebugLogLevel.Verbose, "Entering SetProperty"); if (propertyValue != null) { if (!this.IsValidRootDSEPath(path)) { path = this.ValidateAndNormalizePath(path); ADProviderSetPropertyParameters dynamicParameters = base.DynamicParameters as ADProviderSetPropertyParameters; ADSessionInfo sessionInfo = this.GetSessionInfo(dynamicParameters, base.Credential, this.ExtendedDriveInfo); if (this.ValidateDynamicParameters(path, dynamicParameters, sessionInfo)) { ADObject aDObject = new ADObject(); aDObject.DistinguishedName = path; ADActiveObject aDActiveObject = new ADActiveObject(sessionInfo, aDObject); if (dynamicParameters != null) { if (dynamicParameters.ReplacePropertyValue != null) { foreach (string key in dynamicParameters.ReplacePropertyValue.Keys) { object obj = dynamicParameters.ReplacePropertyValue[key]; if (!aDObject.Contains(key)) { aDPropertyValueCollection = new ADPropertyValueCollection(); aDObject.Add(key, aDPropertyValueCollection); } else { aDPropertyValueCollection = aDObject[key]; aDPropertyValueCollection.Clear(); } if (obj.GetType() != typeof(object[])) { aDPropertyValueCollection.Add(obj); } else { object[] objArray = (object[])obj; for (int i = 0; i < (int)objArray.Length; i++) { object obj1 = objArray[i]; aDPropertyValueCollection.Add(obj1); } } strs.Add(key); } } if (dynamicParameters.AddPropertyValue != null) { foreach (string str in dynamicParameters.AddPropertyValue.Keys) { object item2 = dynamicParameters.AddPropertyValue[str]; if (item2 != null) { if (!aDObject.Contains(str)) { item = new ADPropertyValueCollection(); item.TrackChanges = true; aDObject.Add(str, item); } else { item = aDObject[str]; } if (item2.GetType() != typeof(object[])) { item.Add(item2); } else { object[] objArray1 = (object[])item2; for (int j = 0; j < (int)objArray1.Length; j++) { object obj2 = objArray1[j]; item.Add(obj2); } } strs.Add(str); } else { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException(StringResources.ADProviderPropertyValueCannotBeNull), "ADProvider: SetProperty: InvalidArgument", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: ArgumentException: addPropertyValue has null value."); return; } } } if (dynamicParameters.RemovePropertyValue != null) { foreach (string key1 in dynamicParameters.RemovePropertyValue.Keys) { object item3 = dynamicParameters.RemovePropertyValue[key1]; if (!aDObject.Contains(key1)) { aDPropertyValueCollection1 = new ADPropertyValueCollection(); aDPropertyValueCollection1.TrackChanges = true; aDObject.Add(key1, aDPropertyValueCollection1); } else { aDPropertyValueCollection1 = aDObject[key1]; } if (item3.GetType() != typeof(object[])) { aDPropertyValueCollection1.Remove(item3); } else { object[] objArray2 = (object[])item3; for (int k = 0; k < (int)objArray2.Length; k++) { object obj3 = objArray2[k]; aDPropertyValueCollection1.Remove(obj3); } } strs.Add(key1); } } } foreach (PSMemberInfo property in propertyValue.Properties) { string name = property.Name; object value = property.Value; if (!aDObject.Contains(name)) { item1 = new ADPropertyValueCollection(); item1.TrackChanges = true; aDObject.Add(name, item1); } else { item1 = aDObject[name]; } if (value.GetType() != typeof(object[])) { item1.Value = value; } else { item1.Clear(); object[] objArray3 = (object[])value; for (int l = 0; l < (int)objArray3.Length; l++) { object obj4 = objArray3[l]; item1.Add(obj4); } } strs.Add(name); } if (base.ShouldProcess(path, "Set")) { using (aDActiveObject) { try { aDActiveObject.Update(); aDObject = this.GetValidatedADObject(path, strs, dynamicParameters, base.Credential, this.ExtendedDriveInfo); } catch (ADException aDException1) { ADException aDException = aDException1; base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:SetProperty:ADError", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: ADException: AD error"); return; } catch (UnauthorizedAccessException unauthorizedAccessException1) { UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1; base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:SetProperty:AccessDenied", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: ADException: access denied"); return; } catch (AuthenticationException authenticationException1) { AuthenticationException authenticationException = authenticationException1; base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:SetProperty:InvalidCredentials", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: ADException: invalid credentials"); return; } catch (InvalidOperationException invalidOperationException1) { InvalidOperationException invalidOperationException = invalidOperationException1; base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:SetProperty:InvalidOperation", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: ADException: invalid operation"); return; } } foreach (string str1 in strs) { pSObject.Properties.Add(new PSNoteProperty(str1, aDObject[str1].Value)); } this.WriteADObjectProperties(aDObject, pSObject, dynamicParameters, this.ExtendedDriveInfo); this.Trace(DebugLogLevel.Verbose, "Leaving SetProperty"); return; } else { this.Trace(DebugLogLevel.Info, "Leaving SetProperty: ShouldProcess returned false."); } return; } else { this.Trace(DebugLogLevel.Error, "Leaving GetProperty: ValidateDynamicParameters: returned false"); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: NotSupportedException: path is rootdse"); return; } } else { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentNullException("propertyValue"), "ADProvider:SetProperty:NullArgument", path)); this.Trace(DebugLogLevel.Error, "Leaving SetProperty: ArgumentNullException: propertyValue is null"); return; } }
internal HashSet <string> GetAllParentClassesForSchemaClass(string schemaClassName) { Dictionary <string, ADObject> schemaClasses = this._adSchema.SchemaClasses; if (schemaClasses.ContainsKey(schemaClassName)) { ADObject item = schemaClasses[schemaClassName]; if (!item.Contains(SchemaConstants.ParentClasslist)) { HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase); HashSet <string> strs1 = new HashSet <string>(StringComparer.OrdinalIgnoreCase); if (item.Contains("subClassOf")) { string value = (string)item["subClassOf"].Value; if (string.Compare(value, schemaClassName, StringComparison.OrdinalIgnoreCase) != 0) { strs1.Add(value); } } if (item.Contains("auxiliaryClass")) { string[] valueList = item["auxiliaryClass"].ValueList as string[]; strs1.UnionWith(valueList); } if (item.Contains("systemAuxiliaryClass")) { string[] strArrays = item["systemAuxiliaryClass"].ValueList as string[]; strs1.UnionWith(strArrays); } strs.UnionWith(strs1); foreach (string str in strs1) { if (schemaClasses.ContainsKey(str)) { HashSet <string> allParentClassesForSchemaClass = this.GetAllParentClassesForSchemaClass(str); strs.UnionWith(allParentClassesForSchemaClass); } else { object[] objArray = new object[1]; objArray[0] = str; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.NoSchemaClassInSchemaCache, objArray)); } } strs.Add(schemaClassName); ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(new HashSet <string>(strs, StringComparer.OrdinalIgnoreCase)); item[SchemaConstants.ParentClasslist].Value = aDPropertyValueCollection; return(strs); } else { return(new HashSet <string>(item[SchemaConstants.ParentClasslist].Value as HashSet <string>, StringComparer.OrdinalIgnoreCase)); } } else { object[] objArray1 = new object[1]; objArray1[0] = schemaClassName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.NoSchemaClassInSchemaCache, 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)); } }
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? 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); } }