Esempio n. 1
0
		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;
			}
		}
Esempio n. 2
0
		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;
			}
		}
Esempio n. 3
0
		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;
			}
		}
Esempio n. 4
0
		protected override void RenameItem(string path, string newName)
		{
			string root;
			this.Trace(DebugLogLevel.Verbose, "Entering RenameItem");
			if (!this.IsValidRootDSEPath(path))
			{
				path = this.ValidateAndNormalizePath(path);
				if (!string.IsNullOrEmpty(newName))
				{
					if (base.ShouldProcess(path, "Rename"))
					{
						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 = null;
							using (aDActiveObject)
							{
								try
								{
									aDActiveObject = new ADActiveObject(sessionInfo, aDObject);
									aDActiveObject.Rename(newName);
									ADProvider aDProvider = this;
									ADProvider aDProvider1 = this;
									string str = path;
									if (this.ExtendedDriveInfo != null)
									{
										root = this.ExtendedDriveInfo.Root;
									}
									else
									{
										root = "";
									}
									string str1 = aDProvider.MakePath(aDProvider1.GetParentPath(str, root), newName);
									this.Trace(DebugLogLevel.Info, string.Format("RenameItem: newPath = {0}.", str1));
									aDObject = this.GetValidatedADObject(str1, null, base.DynamicParameters as ADProviderCommonParameters, base.Credential, this.ExtendedDriveInfo);
									sessionInfo.ServerType = this.GetServerType(sessionInfo);
								}
								catch (ADException aDException1)
								{
									ADException aDException = aDException1;
									base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:RenameItem:ADError", path));
									this.Trace(DebugLogLevel.Error, "Leaving RenameItem: ADException: AD error");
									return;
								}
								catch (UnauthorizedAccessException unauthorizedAccessException1)
								{
									UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
									base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:RenameItem:AccessDenied", path));
									this.Trace(DebugLogLevel.Error, "Leaving RenameItem: ADException: access denied");
									return;
								}
								catch (AuthenticationException authenticationException1)
								{
									AuthenticationException authenticationException = authenticationException1;
									base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:RenameItem:InvalidCredentials", path));
									this.Trace(DebugLogLevel.Error, "Leaving RenameItem: ADException: invalid credentials");
									return;
								}
								catch (InvalidOperationException invalidOperationException1)
								{
									InvalidOperationException invalidOperationException = invalidOperationException1;
									base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:RenameItem:InvalidOperation", path));
									this.Trace(DebugLogLevel.Error, "Leaving RenameItem: ADException: invalid operation");
									return;
								}
								this.WriteADObject(aDObject, sessionInfo, base.DynamicParameters as ADProviderCommonParameters, this.ExtendedDriveInfo);
								this.Trace(DebugLogLevel.Verbose, "Leaving RenameItem");
								return;
							}
							return;
						}
						else
						{
							this.Trace(DebugLogLevel.Info, "Leaving RenameItem: ValidateDynamicParameters returned false.");
							return;
						}
					}
					else
					{
						this.Trace(DebugLogLevel.Info, "Leaving RenameItem: ShouldProcess returned false.");
						return;
					}
				}
				else
				{
					base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException(newName), "newName", path));
					this.Trace(DebugLogLevel.Error, "Leaving RenameItem: ArgumentNullException: newItemValue is null");
					return;
				}
			}
			else
			{
				base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path));
				this.Trace(DebugLogLevel.Error, "Leaving RenameItem: NotSupportedException: path is rootdse");
				return;
			}
		}
Esempio n. 5
0
		protected override void RemoveItem(string path, bool recurse)
		{
			this.Trace(DebugLogLevel.Verbose, "Entering RemoveItem");
			if (!this.IsValidRootDSEPath(path))
			{
				path = this.ValidateAndNormalizePath(path);
				string promptForRemove = StringResources.PromptForRemove;
				if (recurse)
				{
					promptForRemove = StringResources.PromptForRecursiveRemove;
				}
				if (base.ShouldProcess(path, "Remove"))
				{
					if (base.Force || base.ShouldContinue(path, promptForRemove))
					{
						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 = null;
							using (aDActiveObject)
							{
								try
								{
									aDActiveObject = new ADActiveObject(sessionInfo, aDObject);
									if (!recurse)
									{
										aDActiveObject.Delete();
									}
									else
									{
										aDActiveObject.DeleteTree();
									}
								}
								catch (ADException aDException1)
								{
									ADException aDException = aDException1;
									base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:RemoveItem:ADError", path));
									this.Trace(DebugLogLevel.Error, "Leaving RemoveItem: ADException: AD error");
									return;
								}
								catch (UnauthorizedAccessException unauthorizedAccessException1)
								{
									UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
									base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:RemoveItem:AccessDenied", path));
									this.Trace(DebugLogLevel.Error, "Leaving RemoveItem: ADException: access denied");
									return;
								}
								catch (AuthenticationException authenticationException1)
								{
									AuthenticationException authenticationException = authenticationException1;
									base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:RemoveItem:InvalidCredentials", path));
									this.Trace(DebugLogLevel.Error, "Leaving RemoveItem: ADException: invalid credentials");
									return;
								}
								catch (InvalidOperationException invalidOperationException1)
								{
									InvalidOperationException invalidOperationException = invalidOperationException1;
									base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:RemoveItem:InvalidOperation", path));
									this.Trace(DebugLogLevel.Error, "Leaving RemoveItem: ADException: invalid operation");
									return;
								}
								this.Trace(DebugLogLevel.Verbose, "Leaving RemoveItem");
								return;
							}
							return;
						}
						else
						{
							this.Trace(DebugLogLevel.Info, "Leaving RemoveItem: ValidateDynamicParameters returned false.");
							return;
						}
					}
					else
					{
						this.Trace(DebugLogLevel.Info, "Leaving RemoveItem: -Force not used or ShouldContinue returned false.");
						return;
					}
				}
				else
				{
					this.Trace(DebugLogLevel.Info, "Leaving RemoveItem: ShouldProcess returned false.");
					return;
				}
			}
			else
			{
				base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path));
				this.Trace(DebugLogLevel.Error, "Leaving RemoveItem: NotSupportedException: path is rootdse");
				return;
			}
		}
Esempio n. 6
0
		protected override void NewItem(string path, string itemTypeName, object newItemValue)
		{
			string root;
			this.Trace(DebugLogLevel.Verbose, "Entering NewItem");
			Collection<string> strs = new Collection<string>();
			if (this.IsValidPath(path))
			{
				string childName = this.GetChildName(path);
				ADProvider aDProvider = this;
				string str = path;
				if (this.ExtendedDriveInfo != null)
				{
					root = this.ExtendedDriveInfo.Root;
				}
				else
				{
					root = "";
				}
				string parentPath = aDProvider.GetParentPath(str, root);
				if (!this.IsValidRootDSEPath(parentPath))
				{
					parentPath = this.ValidateAndNormalizePath(parentPath);
					string str1 = ADPathModule.MakePath(parentPath, childName, ADPathFormat.X500);
					if (string.IsNullOrEmpty(itemTypeName))
					{
						base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException("itemTypeName"), "ADProvider:NewItem:InvalidItemTypeName", path));
						this.Trace(DebugLogLevel.Error, "Leaving NewItem: ArgumentException: itemType is invalid (null or empty)");
					}
					if (base.ShouldProcess(path, "New"))
					{
						ADProviderCommonParameters dynamicParameters = base.DynamicParameters as ADProviderCommonParameters;
						ADSessionInfo sessionInfo = this.GetSessionInfo(dynamicParameters, base.Credential, this.ExtendedDriveInfo);
						if (this.ValidateDynamicParameters(path, dynamicParameters, sessionInfo))
						{
							if (itemTypeName.Equals("directory", StringComparison.OrdinalIgnoreCase))
							{
								itemTypeName = "organizationalUnit";
							}
							ADObject aDObject = new ADObject(str1, itemTypeName);
							if (newItemValue != null)
							{
								Hashtable hashtables = newItemValue as Hashtable;
								if (hashtables == null)
								{
									base.WriteError(ADUtilities.GetErrorRecord(new ArgumentNullException("newItemValue"), "ADProvider:NewItem:InvalidNewItemValue", path));
									this.Trace(DebugLogLevel.Error, "Leaving NewItem: ArgumentNullException: newItemValue is null");
								}
								foreach (string key in hashtables.Keys)
								{
									object item = hashtables[key];
									if (item != null)
									{
										aDObject.Add(key, hashtables[key]);
										strs.Add(key);
									}
									else
									{
										base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException("newItemValue", "Property value to be added cannot be null."), "ADProvider: NewItem: InvalidArgument", path));
										this.Trace(DebugLogLevel.Error, "Leaving NewItem: ArgumentException: newItemValue has null value.");
										return;
									}
								}
							}
							ADActiveObject aDActiveObject = null;
							try
							{
								try
								{
									aDActiveObject = new ADActiveObject(sessionInfo, aDObject);
									aDActiveObject.Create();
									if (ProtectedFromDeletionUtil.ShouldProtectByDefault(aDObject.ObjectClass))
									{
										aDObject.TrackChanges = true;
										if (ProtectedFromDeletionUtil.ProtectFromAccidentalDeletion(aDObject, sessionInfo))
										{
											aDActiveObject.Update();
										}
									}
									aDObject = this.GetValidatedADObject(str1, strs, base.DynamicParameters as ADProviderCommonParameters, base.Credential, this.ExtendedDriveInfo);
									sessionInfo.ServerType = this.GetServerType(sessionInfo);
								}
								catch (ADException aDException1)
								{
									ADException aDException = aDException1;
									base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:NewItem:ADError", path));
									this.Trace(DebugLogLevel.Error, "Leaving NewItem: ADException: AD error");
									return;
								}
								catch (UnauthorizedAccessException unauthorizedAccessException1)
								{
									UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
									base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:NewItem:AccessDenied", path));
									this.Trace(DebugLogLevel.Error, "Leaving NewItem: ADException: access denied");
									return;
								}
								catch (AuthenticationException authenticationException1)
								{
									AuthenticationException authenticationException = authenticationException1;
									base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:NewItem:InvalidCredentials", path));
									this.Trace(DebugLogLevel.Error, "Leaving NewItem: ADException: invalid credentials");
									return;
								}
								catch (InvalidOperationException invalidOperationException1)
								{
									InvalidOperationException invalidOperationException = invalidOperationException1;
									base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:NewItem:InvalidOperation", path));
									this.Trace(DebugLogLevel.Error, "Leaving NewItem: ADException: invalid operation");
									return;
								}
								this.WriteADObject(aDObject, sessionInfo, base.DynamicParameters as ADProviderCommonParameters, this.ExtendedDriveInfo);
								this.Trace(DebugLogLevel.Verbose, "Leaving NewItem");
								return;
							}
							finally
							{
								if (aDActiveObject != null)
								{
									this.Trace(DebugLogLevel.Verbose, "Leaving NewItem: Calling Dispose on ADActiveObject.");
									aDActiveObject.Dispose();
								}
							}
							return;
						}
						else
						{
							this.Trace(DebugLogLevel.Info, "Leaving NewItem: ValidateDynamicParameters returned false.");
							return;
						}
					}
					else
					{
						this.Trace(DebugLogLevel.Info, "Leaving NewItem: ShouldProcess returned false.");
						return;
					}
				}
				else
				{
					base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path));
					this.Trace(DebugLogLevel.Error, "Leaving NewItem: NotSupportedException: path is rootdse");
					return;
				}
			}
			else
			{
				base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException(path), "InvalidPath", path));
				this.Trace(DebugLogLevel.Error, "Leaving NewItem: ArgumentException: path is invalid");
				return;
			}
		}
Esempio n. 7
0
		protected override void MoveItem(string path, string destination)
		{
			bool crossDomain;
			this.Trace(DebugLogLevel.Verbose, "Entering MoveItem");
			if (!this.IsValidRootDSEPath(path))
			{
				path = this.ValidateAndNormalizePath(path);
				string childName = ADPathModule.GetChildName(path, ADPathFormat.X500);
				if (base.ShouldProcess(path, "Move"))
				{
					ADProviderMoveParameters dynamicParameters = base.DynamicParameters as ADProviderMoveParameters;
					if (dynamicParameters != null)
					{
						crossDomain = dynamicParameters.CrossDomain != null;
					}
					else
					{
						crossDomain = false;
					}
					bool flag = crossDomain;
					ADSessionInfo sessionInfo = this.GetSessionInfo(dynamicParameters, base.Credential, this.ExtendedDriveInfo);
					if (this.ValidateDynamicParameters(path, dynamicParameters, sessionInfo))
					{
						ADObject aDObject = new ADObject();
						aDObject.DistinguishedName = path;
						ADActiveObject aDActiveObject = null;
						using (aDActiveObject)
						{
							try
							{
								aDActiveObject = new ADActiveObject(sessionInfo, aDObject);
								if (!flag)
								{
									destination = this.ValidateAndNormalizePath(destination);
									aDActiveObject.Move(destination, childName);
								}
								else
								{
									ADSessionInfo aDSessionInfo = this.GetSessionInfo(dynamicParameters, base.Credential, this.ExtendedDriveInfo);
									aDSessionInfo.Server = dynamicParameters.CrossDomain;
									destination = this.ValidateAndNormalizePath(destination, aDSessionInfo);
									aDActiveObject.CrossDomainMove(destination, childName, dynamicParameters.CrossDomain);
									sessionInfo = aDSessionInfo;
								}
								string str = ADPathModule.MakePath(destination, childName, ADPathFormat.X500);
								this.Trace(DebugLogLevel.Info, string.Format("MoveItem: newPath = {0}.", str));
								aDObject = this.GetValidatedADObject(sessionInfo, str, null, this.GetFormatType(dynamicParameters, this.ExtendedDriveInfo));
								sessionInfo.ServerType = this.GetServerType(sessionInfo);
							}
							catch (ADException aDException1)
							{
								ADException aDException = aDException1;
								base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:MoveItem:ADError", path));
								this.Trace(DebugLogLevel.Error, "Leaving MoveItem: ADException: AD error");
								return;
							}
							catch (UnauthorizedAccessException unauthorizedAccessException1)
							{
								UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
								base.WriteError(ADUtilities.GetErrorRecord(unauthorizedAccessException, "ADProvider:MoveItem:AccessDenied", path));
								this.Trace(DebugLogLevel.Error, "Leaving MoveItem: ADException: access denied");
								return;
							}
							catch (AuthenticationException authenticationException1)
							{
								AuthenticationException authenticationException = authenticationException1;
								base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:MoveItem:InvalidCredentials", path));
								this.Trace(DebugLogLevel.Error, "Leaving MoveItem: ADException: invalid credentials");
								return;
							}
							catch (InvalidOperationException invalidOperationException1)
							{
								InvalidOperationException invalidOperationException = invalidOperationException1;
								base.WriteError(ADUtilities.GetErrorRecord(invalidOperationException, "ADProvider:MoveItem:InvalidOperation", path));
								this.Trace(DebugLogLevel.Error, "Leaving MoveItem: ADException: invalid operation");
								return;
							}
							this.WriteADObject(aDObject, sessionInfo, base.DynamicParameters as ADProviderCommonParameters, this.ExtendedDriveInfo);
							this.Trace(DebugLogLevel.Verbose, "Leaving MoveItem");
							return;
						}
						return;
					}
					else
					{
						this.Trace(DebugLogLevel.Info, "Leaving MoveItem: ValidateDynamicParameters returned false.");
						return;
					}
				}
				else
				{
					this.Trace(DebugLogLevel.Info, "Leaving MoveItem: ShouldProcess returned false.");
					return;
				}
			}
			else
			{
				base.WriteError(ADUtilities.GetErrorRecord(new NotSupportedException(StringResources.ADProviderOperationNotSupportedForRootDSE), "NotSupported", path));
				this.Trace(DebugLogLevel.Error, "Leaving MoveItem: NotSupportedException: path is rootdse");
				return;
			}
		}
Esempio n. 8
0
		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));
				}
			}
		}