protected bool ADSetCmdletBaseBeginCSRoutine() { bool flag; if (this._cmdletParameters.Contains("Instance")) { O item = (O)(this._cmdletParameters["Instance"] as O); this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); if (item.IsSearchResult) { if (item.GetType() == typeof(O)) { this._factory.ValidateObjectClass(item); ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, cmdletSessionInfo.DefaultPartitionPath); using (ADActiveObject aDActiveObject = new ADActiveObject(base.GetSessionInfo(), directoryObjectFromIdentity)) { if (base.ShouldProcessOverride(item.IdentifyingString, "Set")) { this._factory.UpdateFromObject(item, directoryObjectFromIdentity); this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Update, item, this._cmdletParameters, directoryObjectFromIdentity); aDActiveObject.Update(); if (this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Update, item, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } if (this._cmdletParameters.Contains("PassThru")) { O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(directoryObjectFromIdentity.DistinguishedName); if (extendedObjectFromDN != null) { base.WriteObject(extendedObjectFromDN); } } this._setProcessed = true; return(true); } else { flag = false; } } return(flag); } else { object[] str = new object[1]; str[0] = typeof(O).ToString(); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InstanceMustBeOfType, str)); } } else { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.OnlySearchResultsSupported, new object[0])); } } return(true); }
protected internal virtual bool SetFromIdentity(O identity) { bool flag; ADSessionInfo sessionInfo = base.GetSessionInfo(); string item = this._cmdletParameters["Partition"] as string; if (item == null) { item = this.GetDefaultPartitionPath(); if (item == null && !identity.IsSearchResult) { object[] objArray = new object[1]; objArray[0] = "Partition"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } } ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(identity, item); using (ADActiveObject aDActiveObject = new ADActiveObject(sessionInfo, directoryObjectFromIdentity)) { if (base.ShouldProcessOverride(directoryObjectFromIdentity.IdentifyingString, "Set")) { this._factory.UpdateFromParameters(this._cmdletParameters, this._cmdletParameters["Add"] as Hashtable, this._cmdletParameters["Replace"] as Hashtable, this._cmdletParameters["Remove"] as Hashtable, this._cmdletParameters["Clear"] as string[], directoryObjectFromIdentity); O o = default(O); this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Update, o, this._cmdletParameters, directoryObjectFromIdentity); aDActiveObject.Update(); directoryObjectFromIdentity.TrackChanges = true; O o1 = default(O); if (this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Update, o1, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(directoryObjectFromIdentity.DistinguishedName); base.WriteObject(extendedObjectFromDN); } return(true); } else { flag = true; } } return(flag); }
private bool ADNewCmdletBaseProcessCSRoutine() { bool flag; this.ValidateParameters(); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); string item = this._cmdletParameters["Path"] as string; if (string.IsNullOrEmpty(item)) { item = this.GetDefaultCreationPath(); if (string.IsNullOrEmpty(item)) { object[] objArray = new object[1]; objArray[0] = "Path"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } } string str = this.GenerateObjectClass(this._factory, this._cmdletParameters, this._cmdletParameters); string str1 = this.GenerateDN(this._factory, this._cmdletParameters, this._cmdletParameters, item); this._currentIdentity = str1; ADObject aDObject = new ADObject(str1, str); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject)) { if (base.ShouldProcessOverride(aDObject.DistinguishedName, "New")) { this._factory.UpdateFromParameters(this._defaultParamSet, null, null, null, null, aDObject); if (this._cmdletParameters.Contains("Instance")) { this._factory.UpdateFromTemplate((O)(this._cmdletParameters["Instance"] as O), aDObject); } this._factory.UpdateFromParameters(this._cmdletParameters, null, this._cmdletParameters["OtherAttributes"] as Hashtable, null, null, aDObject); this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Create, (O)(this._cmdletParameters["Instance"] as O), this._cmdletParameters, aDObject); aDActiveObject.Create(); aDObject.TrackChanges = true; bool flag1 = this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Create, (O)(this._cmdletParameters["Instance"] as O), this._cmdletParameters, aDObject); if (flag1) { aDActiveObject.Update(); } if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(aDObject.DistinguishedName); base.WriteObject(extendedObjectFromDN); } return(true); } else { flag = false; } } return(flag); }
private bool ADRenameCmdletBaseProcessCSRoutine() { bool flag; O item = (O)this._cmdletParameters["Identity"]; this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); string defaultPartitionPath = this._cmdletParameters["Partition"] as string; if (defaultPartitionPath == null) { defaultPartitionPath = this.GetDefaultPartitionPath(); if (defaultPartitionPath == null && !item.IsSearchResult) { object[] objArray = new object[1]; objArray[0] = "Partition"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } } ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, defaultPartitionPath); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity)) { string str = this.GenerateNewRDN(this._factory, this._cmdletParameters, this._cmdletParameters, directoryObjectFromIdentity.DistinguishedName); if (base.ShouldProcessOverride(directoryObjectFromIdentity.DistinguishedName, "Rename")) { O o = default(O); if (this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Rename, o, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } aDActiveObject.Rename(str); O o1 = default(O); this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Rename, o1, this._cmdletParameters, directoryObjectFromIdentity); if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { string value = directoryObjectFromIdentity["distinguishedName"].Value as string; string parentPath = ADPathModule.GetParentPath(value, null, ADPathFormat.X500); string str1 = ADPathModule.MakePath(parentPath, str, ADPathFormat.X500); O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(str1); base.WriteObject(extendedObjectFromDN); } return(true); } else { flag = false; } } return(flag); }
private static void UpdateNTMixedDomainMode(CmdletSessionInfo cmdletSessionInfo, int ntMixedDomainMode) { ADObject aDObject = new ADObject(); aDObject.DistinguishedName = cmdletSessionInfo.ADRootDSE.DefaultNamingContext; using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject)) { aDObject.TrackChanges = true; aDObject.Add("ntMixedDomain", ntMixedDomainMode); aDActiveObject.Update(); } }
private void CreateSiteChildObjects(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj) { AttributeConverterEntry attributeConverterEntry = null; bool flag = ADFactory <T> .DirectoryOperation.Create == operation; MappingTable <AttributeConverterEntry> item = ADNtdsSiteSettingFactory <ADNtdsSiteSetting> .AttributeTable[base.ConnectedStore]; MappingTable <AttributeConverterEntry> mappingTable = ADReplicationSiteFactory <T> .AttributeTable[base.ConnectedStore]; IDictionary <string, ADPropertyValueCollection> strs = new Dictionary <string, ADPropertyValueCollection>(); if (instance != null) { foreach (string propertyName in instance.PropertyNames) { if (flag && instance[propertyName].Value == null || mappingTable.TryGetValue(propertyName, out attributeConverterEntry) || !item.TryGetValue(propertyName, out attributeConverterEntry)) { continue; } strs.Add(propertyName, instance[propertyName]); } } IDictionary <string, ADPropertyValueCollection> aDPVCDictionary = parameters.GetADPVCDictionary(); foreach (string key in aDPVCDictionary.Keys) { if (mappingTable.TryGetValue(key, out attributeConverterEntry) || !item.TryGetValue(key, out attributeConverterEntry)) { continue; } if (!strs.ContainsKey(key)) { strs.Add(key, aDPVCDictionary[key]); } else { strs[key] = aDPVCDictionary[key]; } } string str = ADPathModule.MakePath(directoryObj.DistinguishedName, "CN=NTDS Site Settings,", ADPathFormat.X500); ADNtdsSiteSettingFactory <ADNtdsSiteSetting> aDNtdsSiteSettingFactory = new ADNtdsSiteSettingFactory <ADNtdsSiteSetting>(); aDNtdsSiteSettingFactory.SetCmdletSessionInfo(base.CmdletSessionInfo); ADObject directoryObjectFromIdentity = null; if (!flag) { try { ADNtdsSiteSetting aDNtdsSiteSetting = new ADNtdsSiteSetting(str); directoryObjectFromIdentity = aDNtdsSiteSettingFactory.GetDirectoryObjectFromIdentity(aDNtdsSiteSetting, directoryObj.DistinguishedName); } catch (ADIdentityNotFoundException aDIdentityNotFoundException) { DebugLogger.LogInfo(this._debugCategory, string.Format("ADReplicationSiteFactory: Ntds-Site-Setting object not found for the site {0}, while updating the properties of the ntds-site-settings", directoryObj.DistinguishedName)); } } if (directoryObjectFromIdentity == null) { flag = true; directoryObjectFromIdentity = new ADObject(str, aDNtdsSiteSettingFactory.StructuralObjectClass); } foreach (string key1 in strs.Keys) { if (!item.TryGetValue(key1, out attributeConverterEntry) || !attributeConverterEntry.IsDirectoryConverterDefined) { continue; } attributeConverterEntry.InvokeToDirectoryConverter(strs[key1], directoryObjectFromIdentity, base.CmdletSessionInfo); } using (ADActiveObject aDActiveObject = new ADActiveObject(base.CmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity)) { if (!flag) { aDActiveObject.Update(); } else { aDActiveObject.Create(); } } if (operation == ADFactory <T> .DirectoryOperation.Create) { this.CreateServerContainer(directoryObj.DistinguishedName); } }
private bool ADMoveCmdletBaseProcessCSRoutine() { bool flag; O item = (O)this._cmdletParameters["Identity"]; this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); string defaultPartitionPath = this.GetDefaultPartitionPath(); ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, defaultPartitionPath); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity)) { if (base.ShouldProcessOverride(directoryObjectFromIdentity.DistinguishedName, "Move")) { O o = default(O); if (this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } string str = this._cmdletParameters["TargetPath"] as string; string childName = ADPathModule.GetChildName(directoryObjectFromIdentity.DistinguishedName, ADPathFormat.X500); string item1 = null; if (!this._cmdletParameters.Contains("TargetServer")) { aDActiveObject.Move(str, childName); } else { item1 = this._cmdletParameters["TargetServer"] as string; aDActiveObject.CrossDomainMove(str, childName, item1); } O o1 = default(O); this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o1, this._cmdletParameters, directoryObjectFromIdentity); if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo; if (this._cmdletParameters.Contains("TargetServer")) { aDSessionInfo.Server = item1; } string str1 = ADPathModule.MakePath(str, childName, ADPathFormat.X500); F f = Activator.CreateInstance <F>(); using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); ADCmdletCache aDCmdletCache = new ADCmdletCache(); aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE); CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, this, this._cmdletParameters); f.SetCmdletSessionInfo(cmdletSessionInfo1); O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(str1); base.WriteObject(extendedObjectFromDN); aDCmdletCache.Clear(); } } return(true); } else { flag = false; } } return(flag); }
private bool ADRemoveCmdletBaseProcessCSRoutine() { bool flag; bool hasValue; O item = (O)this._cmdletParameters["Identity"]; this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); string defaultPartitionPath = this._cmdletParameters["Partition"] as string; if (defaultPartitionPath == null) { defaultPartitionPath = this.GetDefaultPartitionPath(); if (defaultPartitionPath == null && !item.IsSearchResult) { object[] objArray = new object[1]; objArray[0] = "Partition"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } } if (this._showDeleted) { hasValue = true; } else { if (!item.Contains("Deleted")) { hasValue = false; } else { bool?value = (bool?)(item.GetValue("Deleted") as bool?); if (!value.GetValueOrDefault()) { hasValue = false; } else { hasValue = value.HasValue; } } } bool flag1 = hasValue; ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, defaultPartitionPath, flag1); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity)) { bool flag2 = this._cmdletParameters.Contains("Recursive"); if (!flag2) { if (!base.ShouldProcessOverride(directoryObjectFromIdentity.DistinguishedName, "Remove")) { flag = false; return(flag); } } else { object[] distinguishedName = new object[1]; distinguishedName[0] = directoryObjectFromIdentity.DistinguishedName; string str = string.Format(CultureInfo.CurrentCulture, StringResources.PerformingRecursiveRemove, distinguishedName); if (!base.ShouldProcessOverride(str, str, StringResources.PromptForRecursiveRemove)) { flag = false; return(flag); } } O o = default(O); if (this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Delete, o, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } if (!flag2) { aDActiveObject.Delete(flag1); } else { aDActiveObject.DeleteTree(flag1); } O o1 = default(O); this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Delete, o1, this._cmdletParameters, directoryObjectFromIdentity); return(true); } return(flag); }
private bool SyncADObjectProcessCSRoutine() { CmdletSessionInfo cmdletSessionInfo; ADRootDSE rootDSE; ADObject directoryObjectFromIdentity; bool flag; string empty; this.ValidateParameters(); ADObject obj = this._cmdletParameters.Object; string destination = this._cmdletParameters.Destination; if (this.sourceServer == null) { if (!obj.IsSearchResult) { if (this.currentADDriveServer == null) { object[] objArray = new object[1]; objArray[0] = "Source"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } else { this.sourceServer = this.currentADDriveServer; } } else { this.sourceServer = obj.SessionInfo.Server; } } try { cmdletSessionInfo = this.GetCmdletSessionInfo(); } catch (ADServerDownException aDServerDownException1) { ADServerDownException aDServerDownException = aDServerDownException1; object[] objArray1 = new object[1]; objArray1[0] = destination; throw new ADServerDownException(string.Format(CultureInfo.CurrentCulture, StringResources.DestinationServerDown, objArray1), aDServerDownException.InnerException, destination); } if (!cmdletSessionInfo.ADRootDSE.IsWritable() || !this._cmdletParameters.GetSwitchParameterBooleanValue("PasswordOnly")) { string dSServiceName = null; ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy(); aDSessionInfo.Server = this.sourceServer; string distinguishedName = null; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { try { rootDSE = aDObjectSearcher.GetRootDSE(); dSServiceName = rootDSE.DSServiceName; } catch (ADIdentityNotFoundException aDIdentityNotFoundException) { object[] objArray2 = new object[1]; objArray2[0] = this.sourceServer; throw new ADServerDownException(string.Format(CultureInfo.CurrentCulture, StringResources.SourceServerDown, objArray2), this.sourceServer); } if (!obj.IsSearchResult) { ADCmdletCache aDCmdletCache = new ADCmdletCache(); aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE); CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, null, this._cmdletParameters); this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo1); try { directoryObjectFromIdentity = this._adObjectFactory.GetDirectoryObjectFromIdentity(obj, cmdletSessionInfo1.DefaultPartitionPath); distinguishedName = directoryObjectFromIdentity.DistinguishedName; } catch (ADIdentityNotFoundException aDIdentityNotFoundException2) { this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); try { directoryObjectFromIdentity = this._adObjectFactory.GetDirectoryObjectFromIdentity(obj, cmdletSessionInfo.DefaultPartitionPath); Guid?objectGuid = directoryObjectFromIdentity.ObjectGuid; distinguishedName = string.Concat("<GUID=", objectGuid.ToString(), ">"); } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { object[] str = new object[1]; str[0] = obj.ToString(); throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectToReplicateNotFoundOnSource, str)); } } aDCmdletCache.Clear(); } else { distinguishedName = obj.DistinguishedName; } } ADObject aDObject = new ADObject(); aDObject.DistinguishedName = ""; string str1 = string.Concat(dSServiceName, ":", distinguishedName); if (this._cmdletParameters.GetSwitchParameterBooleanValue("PasswordOnly")) { str1 = string.Concat(str1, ":SECRETS_ONLY"); } aDObject.Add("replicateSingleObject", str1); aDObject.TrackChanges = false; using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject)) { if (base.ShouldProcessOverride(obj.IdentifyingString, "Sync")) { try { aDActiveObject.Update(); } catch (ADIdentityNotFoundException aDIdentityNotFoundException3) { object[] objArray3 = new object[2]; objArray3[0] = this.sourceServer; objArray3[1] = destination; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.SourceServerObjNotFoundOrObjToReplicateNotFound, objArray3)); } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; Win32Exception win32Exception = new Win32Exception(0x200a); if (string.Compare(win32Exception.Message, 0, argumentException.Message, 0, win32Exception.Message.Length, StringComparison.OrdinalIgnoreCase) != 0 || string.Compare("replicateSingleObject", argumentException.ParamName, StringComparison.OrdinalIgnoreCase) != 0) { throw argumentException; } else { object[] objArray4 = new object[1]; objArray4[0] = destination; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.DestinationServerDoesNotSupportSynchronizingObject, objArray4)); } } if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { this._adObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject extendedObjectFromDN = this._adObjectFactory.GetExtendedObjectFromDN(distinguishedName); base.WriteObject(extendedObjectFromDN); } return(false); } else { flag = false; } } return(flag); } else { CultureInfo currentCulture = CultureInfo.CurrentCulture; string passwordOnlySwitchAllowedOnlyOnRODC = StringResources.PasswordOnlySwitchAllowedOnlyOnRODC; object[] objArray5 = new object[1]; object[] objArray6 = objArray5; int num = 0; string dNSHostName = cmdletSessionInfo.ADRootDSE.DNSHostName; int? portLDAP = cmdletSessionInfo.ADRootDSE.PortLDAP; if (!portLDAP.HasValue) { empty = string.Empty; } else { int?nullable = cmdletSessionInfo.ADRootDSE.PortLDAP; empty = string.Concat(":", nullable.ToString()); } objArray6[num] = string.Concat(dNSHostName, empty); throw new ArgumentException(string.Format(currentCulture, passwordOnlySwitchAllowedOnlyOnRODC, objArray5)); } }
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)); } } }
private bool ADRestoreCmdletBaseProcessCSRoutine() { string str; string item; bool flag; string str1; string value; O o = (O)this._cmdletParameters["Identity"]; this.SetPipelinedSessionInfo(o.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); string defaultPartitionPath = this.GetDefaultPartitionPath(); string[] strArrays = new string[3]; strArrays[0] = "objectClass"; strArrays[1] = "lastKnownParent"; strArrays[2] = "msDS-LastKnownRDN"; string[] strArrays1 = strArrays; ADObject extendedObjectFromIdentity = this._factory.GetExtendedObjectFromIdentity(o, defaultPartitionPath, strArrays1, true); if (!this._cmdletParameters.Contains("NewName")) { if (extendedObjectFromIdentity["msDS-LastKnownRDN"] == null) { str1 = null; } else { str1 = this.GenerateNewRDN(this._factory, extendedObjectFromIdentity["msDS-LastKnownRDN"].Value as string, extendedObjectFromIdentity); } str = str1; } else { str = this.GenerateNewRDN(this._factory, this._cmdletParameters["NewName"] as string, extendedObjectFromIdentity); } if (string.IsNullOrEmpty(str)) { object[] objArray = new object[1]; objArray[0] = "NewName"; base.WriteError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)), "0", ErrorCategory.InvalidArgument, extendedObjectFromIdentity)); } if (!this._cmdletParameters.Contains("TargetPath")) { if (extendedObjectFromIdentity["lastKnownParent"] == null) { value = null; } else { value = extendedObjectFromIdentity["lastKnownParent"].Value as string; } item = value; } else { item = this._cmdletParameters["TargetPath"] as string; } if (string.IsNullOrEmpty(item)) { object[] objArray1 = new object[1]; objArray1[0] = "TargetPath"; base.WriteError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray1)), "0", ErrorCategory.InvalidArgument, extendedObjectFromIdentity)); } string str2 = ADPathModule.MakePath(item, str, ADPathFormat.X500); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, extendedObjectFromIdentity)) { if (base.ShouldProcessOverride(extendedObjectFromIdentity.DistinguishedName, "Restore")) { O o1 = default(O); this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Restore, o1, this._cmdletParameters, extendedObjectFromIdentity); try { aDActiveObject.Undelete(str2); } catch (Exception exception1) { Exception exception = exception1; if (exception as ADException != null || exception as ADInvalidOperationException != null || exception as ADIdentityResolutionException != null || exception as UnauthorizedAccessException != null || exception as AuthenticationException != null || exception as ArgumentException != null) { base.WriteErrorBuffered(new ErrorRecord(exception, "0", ErrorCategory.InvalidOperation, extendedObjectFromIdentity)); flag = false; return(flag); } else { throw; } } O o2 = default(O); if (this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Restore, o2, this._cmdletParameters, extendedObjectFromIdentity)) { aDActiveObject.Update(); } if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(str2); base.WriteObject(extendedObjectFromDN); } return(true); } else { flag = false; } } return(flag); }