Exemplo n.º 1
0
		private ADPathHostType GetHostType(ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo)
		{
			ADPathHostType hostType = ADProviderDefaults.HostType;
			if (parameters == null || !parameters.IsPropertySet("GlobalCatalog") || !parameters.GlobalCatalog)
			{
				if (extendedDriveInfo != null && extendedDriveInfo.GlobalCatalog)
				{
					hostType = ADPathHostType.GC;
				}
			}
			else
			{
				hostType = ADPathHostType.GC;
			}
			return hostType;
		}
Exemplo n.º 2
0
		private PSCredential GetCredential(PSCredential credential, ADDriveInfo extendedDriveInfo)
		{
			PSCredential pSCredential = null;
			if (credential == null || credential.UserName == null || !(credential.UserName != ""))
			{
				if (extendedDriveInfo != null)
				{
					PSCredential pSCredential1 = extendedDriveInfo.Credential;
					if (pSCredential1 != null && pSCredential1.UserName != null && pSCredential1.UserName != "")
					{
						pSCredential = pSCredential1;
					}
				}
			}
			else
			{
				pSCredential = credential;
			}
			return pSCredential;
		}
Exemplo n.º 3
0
		private ADPathFormat GetFormatType(ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo)
		{
			ADPathFormat pathFormat = ADProviderDefaults.PathFormat;
			if (parameters == null || !parameters.IsPropertySet("FormatType"))
			{
				if (extendedDriveInfo != null)
				{
					pathFormat = extendedDriveInfo.FormatType;
				}
			}
			else
			{
				pathFormat = parameters.FormatType;
			}
			return pathFormat;
		}
Exemplo n.º 4
0
		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;
				}
			}
		}
Exemplo n.º 5
0
		private string GetContainingPartition(string path, ADProviderCommonParameters parameters, PSCredential credential, ADDriveInfo driveInfo)
		{
			bool flag = false;
			string parentPath = path;
			this.Trace(DebugLogLevel.Verbose, "Entering GetContainingPartition");
			this.Trace(DebugLogLevel.Info, string.Format("GetContainingPartition: path = {0}", path));
			if (driveInfo == null)
			{
				this.Trace(DebugLogLevel.Verbose, "GetContainingPartition: ExtendedDriveInfo is null");
			}
			ADSessionInfo sessionInfo = this.GetSessionInfo(parameters, credential, driveInfo);
			ADObjectSearcher aDObjectSearcher = this.BuildADObjectSearcher(sessionInfo);
			using (aDObjectSearcher)
			{
				aDObjectSearcher.Scope = ADSearchScope.Base;
				aDObjectSearcher.Properties.Clear();
				aDObjectSearcher.Properties.Add("instanceType");
				while (!flag && parentPath != "")
				{
					aDObjectSearcher.SearchRoot = parentPath;
					ADObject aDObject = aDObjectSearcher.FindOne();
					if (aDObject == null)
					{
						this.Trace(DebugLogLevel.Error, string.Format("Leaving GetContainingPartition: ADException: instanceType not set for {0}.", parentPath));
						object[] objArray = new object[1];
						objArray[0] = path;
						throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.ADProviderUnableToGetPartition, objArray));
					}
					else
					{
						if (((int)aDObject["instanceType"].Value & 1) != 1)
						{
							parentPath = ADPathModule.GetParentPath(parentPath, "", ADPathFormat.X500);
						}
						else
						{
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					this.Trace(DebugLogLevel.Error, string.Format("Leaving GetContainingPartition: ADException: could not find partition containing {0}.", path));
					object[] objArray1 = new object[1];
					objArray1[0] = path;
					throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.ADProviderUnableToGetPartition, objArray1));
				}
			}
			this.Trace(DebugLogLevel.Info, string.Format("GetContainingPartition: partition path = {0}", parentPath));
			this.Trace(DebugLogLevel.Verbose, "Leaving GetContainingPartition");
			return parentPath;
		}
Exemplo n.º 6
0
		private HashSet<ADObject> GetAllHostedNamingContexts(ADSessionInfo sessionInfo, ADRootDSE rootDSE, ADDriveInfo extendedDriveInfo, Collection<string> propertiesToRetrieve)
		{
			HashSet<ADObject> aDObjects = new HashSet<ADObject>();
			this.Trace(DebugLogLevel.Verbose, "Entering GetAllHostedNamingContexts");
			if (!this.IsServerGlobalCatalog(sessionInfo, rootDSE, base.DynamicParameters as ADProviderCommonParameters, extendedDriveInfo))
			{
				string[] namingContexts = rootDSE.NamingContexts;
				for (int i = 0; i < (int)namingContexts.Length; i++)
				{
					string str = namingContexts[i];
					ADPathFormat formatType = this.GetFormatType(base.DynamicParameters as ADProviderCommonParameters, extendedDriveInfo);
					ADObject validatedADObject = this.GetValidatedADObject(sessionInfo, str, propertiesToRetrieve, formatType);
					aDObjects.Add(validatedADObject);
				}
			}
			else
			{
				this.Trace(DebugLogLevel.Verbose, "GetAllHostedNamingContexts: Server is GC and we are connected to GC port.");
				string str1 = "(|(objectcategory=domainDNS)(objectcategory=DMD)(objectcategory=configuration))";
				ADObjectSearcher aDObjectSearcher = this.GetADObjectSearcher("", ADSearchScope.Subtree, new LdapFilterADOPathNode(str1), null, base.Credential, extendedDriveInfo);
				using (aDObjectSearcher)
				{
					if (propertiesToRetrieve != null)
					{
						aDObjectSearcher.Properties.AddRange(propertiesToRetrieve);
					}
					foreach (ADObject aDObject in aDObjectSearcher.FindAll())
					{
						aDObjects.Add(aDObject);
					}
				}
			}
			this.Trace(DebugLogLevel.Verbose, "Leaving GetAllHostedNamingContexts");
			return aDObjects;
		}
Exemplo n.º 7
0
		private PSObject WrapADObjectInPSObject(ADObject adObj, ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo)
		{
			PSObject pSObject = new PSObject(adObj);
			ADProviderSearchParameters aDProviderSearchParameter = parameters as ADProviderSearchParameters;
			bool flag = true;
			if (aDProviderSearchParameter != null && aDProviderSearchParameter.Properties != null && (int)aDProviderSearchParameter.Properties.Length > 0)
			{
				flag = false;
			}
			if (flag)
			{
				if (this.GetFormatType(parameters, extendedDriveInfo) != ADPathFormat.Canonical)
				{
					pSObject.TypeNames.Add(string.Concat(adObj.GetType().ToString(), "#ProviderX500DefaultPropertySet"));
				}
				else
				{
					pSObject.TypeNames.Add(string.Concat(adObj.GetType().ToString(), "#ProviderCanonicalDefaultPropertySet"));
				}
			}
			return pSObject;
		}
Exemplo n.º 8
0
		private ADObjectSearcher GetADObjectSearcher(string path, ADSearchScope scope, IADOPathNode filter, ADProviderSearchParameters parameters, PSCredential credential, ADDriveInfo extendedDriveInfo)
		{
			this.Trace(DebugLogLevel.Verbose, "Entering GetADObjectSearcher");
			ADSessionInfo sessionInfo = this.GetSessionInfo(parameters, credential, extendedDriveInfo);
			ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(sessionInfo);
			aDObjectSearcher.SearchRoot = path;
			aDObjectSearcher.Scope = scope;
			if (filter != null)
			{
				aDObjectSearcher.Filter = filter;
			}
			if (parameters != null)
			{
				if (parameters.Properties != null)
				{
					aDObjectSearcher.Properties.AddRange(parameters.Properties);
				}
				aDObjectSearcher.PageSize = parameters.PageSize;
			}
			if (this.GetFormatType(parameters, extendedDriveInfo) == ADPathFormat.Canonical)
			{
				aDObjectSearcher.Properties.Add("canonicalName");
			}
			this.Trace(DebugLogLevel.Verbose, "Leaving GetADObjectSearcher");
			return aDObjectSearcher;
		}
Exemplo n.º 9
0
		private ADObject GetADObjectSecurityDescriptor(string path, AccessControlSections includeSections, ADProviderCommonParameters parameters, PSCredential credential, ADDriveInfo driveInfo)
		{
			ADObject aDObject;
			this.Trace(DebugLogLevel.Verbose, "Entering GetADObjectSecuritDescriptor");
			this.Trace(DebugLogLevel.Info, string.Format("GetADObjectSecuritDescriptor: path = {0}", path));
			if (driveInfo == null)
			{
				this.Trace(DebugLogLevel.Verbose, "GetADObjectSecuritDescriptor: ExtendedDriveInfo is null");
			}
			ADSessionInfo sessionInfo = this.GetSessionInfo(parameters, credential, driveInfo);
			ADObjectSearcher securityMasks = this.BuildADObjectSearcher(sessionInfo);
			using (securityMasks)
			{
				securityMasks.SearchRoot = path;
				securityMasks.Scope = ADSearchScope.Base;
				securityMasks.Properties.Add("ntSecurityDescriptor");
				securityMasks.SecurityDescriptorFlags = this.GetSecurityMasks(includeSections);
				if (this.GetFormatType(parameters, driveInfo) == ADPathFormat.Canonical)
				{
					securityMasks.Properties.Add("canonicalName");
				}
				aDObject = securityMasks.FindOne();
			}
			this.Trace(DebugLogLevel.Verbose, "Leaving GetADObjectSecuritDescriptor");
			return aDObject;
		}
Exemplo n.º 10
0
		protected override PSDriveInfo NewDrive(PSDriveInfo drive)
		{
			PSDriveInfo pSDriveInfo;
			this.Trace(DebugLogLevel.Verbose, "Entering NewDrive");
			ADSession session = null;
			if (drive != null)
			{
				if (drive.Root != null)
				{
					object[] name = new object[1];
					name[0] = drive.Name;
					ProgressRecord progressRecord = new ProgressRecord(0, string.Format(CultureInfo.CurrentCulture, StringResources.LoadingDriveProgressMessage, name), " ");
					progressRecord.PercentComplete = 0;
					try
					{
						base.WriteProgress(progressRecord);
						string str = ADProvider.RemoveAbsolutePathPrefix(drive.Root);
						ADDriveInfo aDDriveInfo = new ADDriveInfo(drive.Name, drive.Provider, str, ADProvider.AddAbsolutePathPrefix(str), drive.Description, drive.Credential);
						ADProviderCommonParameters dynamicParameters = base.DynamicParameters as ADProviderCommonParameters;
						if (dynamicParameters != null)
						{
							aDDriveInfo.FormatType = dynamicParameters.FormatType;
							aDDriveInfo.Server = dynamicParameters.Server;
							aDDriveInfo.AuthType = dynamicParameters.AuthType;
							aDDriveInfo.GlobalCatalog = dynamicParameters.GlobalCatalog;
						}
						ProgressRecord percentComplete = progressRecord;
						percentComplete.PercentComplete = percentComplete.PercentComplete + 25;
						base.WriteProgress(progressRecord);
						ADSessionInfo sessionInfo = this.GetSessionInfo(null, null, aDDriveInfo);
						if (this.ValidateDynamicParameters(aDDriveInfo.RootWithoutAbsolutePathToken, dynamicParameters, sessionInfo))
						{
							this.Trace(DebugLogLevel.Info, string.Format("NewDrive: Root = {0}", aDDriveInfo.Root));
							this.Trace(DebugLogLevel.Info, string.Format("NewDrive: FormatType = {0}", aDDriveInfo.FormatType));
							this.Trace(DebugLogLevel.Info, string.Format("NewDrive: Server = {0}", aDDriveInfo.Server));
							this.Trace(DebugLogLevel.Info, string.Format("NewDrive: AuthType = {0}", aDDriveInfo.AuthType));
							this.Trace(DebugLogLevel.Info, string.Format("NewDrive: GlobalCatalog = {0}", aDDriveInfo.GlobalCatalog));
							try
							{
								try
								{
									aDDriveInfo.SessionInfo = sessionInfo;
									aDDriveInfo.Session = ADSession.ConstructSession(aDDriveInfo.SessionInfo);
									session = aDDriveInfo.Session;
									this.Trace(DebugLogLevel.Verbose, "NewDrive: Session created.");
									ProgressRecord percentComplete1 = progressRecord;
									percentComplete1.PercentComplete = percentComplete1.PercentComplete + 25;
									base.WriteProgress(progressRecord);
									if (!this.IsValidRootDSEPath(aDDriveInfo.RootWithoutAbsolutePathToken))
									{
										string x500Path = ADProvider.RemoveAbsolutePathPrefix(aDDriveInfo.Root);
										if (this.GetFormatType(dynamicParameters, null) == ADPathFormat.Canonical)
										{
											x500Path = this.ConvertToX500Path(x500Path, sessionInfo);
											this.Trace(DebugLogLevel.Info, string.Format("NewDrive: rootPath (after conversion to X500) = {0}", x500Path));
										}
										ADObject validatedADObject = this.GetValidatedADObject(x500Path, null, null, null, aDDriveInfo);
										ProgressRecord progressRecord1 = progressRecord;
										progressRecord1.PercentComplete = progressRecord1.PercentComplete + 25;
										base.WriteProgress(progressRecord);
										if (validatedADObject != null)
										{
											aDDriveInfo.RootPartitionPath = this.GetContainingPartition(x500Path, null, null, aDDriveInfo);
										}
										else
										{
											base.WriteError(ADUtilities.GetErrorRecord(new ArgumentNullException("drive.Root"), "ADProvider:NewDrive:InvalidRoot", drive));
											this.Trace(DebugLogLevel.Error, "Leaving NewDrive: ArgumentNullException: Invalid drive root.");
											aDDriveInfo = null;
											pSDriveInfo = null;
											return pSDriveInfo;
										}
									}
									else
									{
										ADRootDSE rootDSE = this.GetRootDSE(sessionInfo);
										ProgressRecord percentComplete2 = progressRecord;
										percentComplete2.PercentComplete = percentComplete2.PercentComplete + 25;
										base.WriteProgress(progressRecord);
										aDDriveInfo.RootPartitionPath = aDDriveInfo.RootWithoutAbsolutePathToken;
										aDDriveInfo.NamingContexts = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
										foreach (ADObject allHostedNamingContext in this.GetAllHostedNamingContexts(sessionInfo, rootDSE, aDDriveInfo, null))
										{
											string distinguishedName = null;
											if (aDDriveInfo.FormatType != ADPathFormat.Canonical)
											{
												distinguishedName = allHostedNamingContext.DistinguishedName;
											}
											else
											{
												if (allHostedNamingContext.Contains("canonicalName"))
												{
													distinguishedName = (string)allHostedNamingContext["canonicalName"].Value;
												}
												else
												{
													this.Trace(DebugLogLevel.Warning, string.Format("NewDrive: Unable to read canonical name for naming context {0}, skipping..", allHostedNamingContext.DistinguishedName));
													continue;
												}
											}
											aDDriveInfo.NamingContexts.Add(distinguishedName);
										}
									}
								}
								catch (ADException aDException1)
								{
									ADException aDException = aDException1;
									base.WriteError(ADUtilities.GetErrorRecord(aDException, "ADProvider:NewDrive:InvalidRoot:ADError", drive));
									this.Trace(DebugLogLevel.Error, "Leaving NewDrive: ADException: AD error.");
									aDDriveInfo = null;
									pSDriveInfo = null;
									return pSDriveInfo;
								}
								catch (AuthenticationException authenticationException1)
								{
									AuthenticationException authenticationException = authenticationException1;
									base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "ADProvider:NewDrive:InvalidRoot:InvalidCredentials", drive));
									this.Trace(DebugLogLevel.Error, "Leaving NewDrive: AuthenticationException: Invalid credentials.");
									aDDriveInfo = null;
									pSDriveInfo = null;
									return pSDriveInfo;
								}
							}
							finally
							{
								if (null == aDDriveInfo && session != null)
								{
									session.Delete();
									this.Trace(DebugLogLevel.Info, string.Format("Leaving NewDrive:Session to server terminated.", new object[0]));
								}
							}
							this.Trace(DebugLogLevel.Verbose, "Leaving NewDrive");
							ProgressRecord progressRecord2 = progressRecord;
							progressRecord2.PercentComplete = progressRecord2.PercentComplete + 25;
							base.WriteProgress(progressRecord);
							pSDriveInfo = aDDriveInfo;
						}
						else
						{
							this.Trace(DebugLogLevel.Error, "Leaving NewDrive: ValidateDynamicParameters returned false.");
							pSDriveInfo = null;
						}
					}
					finally
					{
						progressRecord.RecordType = ProgressRecordType.Completed;
						base.WriteProgress(progressRecord);
					}
					return pSDriveInfo;
				}
				else
				{
					base.WriteError(ADUtilities.GetErrorRecord(new ArgumentNullException("drive.Root"), "ADProvider:NewDrive:NullRoot", drive));
					this.Trace(DebugLogLevel.Error, "Leaving NewDrive: ArgumentNullException: drive.Root is null.");
					return null;
				}
			}
			else
			{
				base.WriteError(ADUtilities.GetErrorRecord(new ArgumentNullException("drive"), "ADProvider:NewDrive:NullDrive", null));
				this.Trace(DebugLogLevel.Error, "Leaving NewDrive: ArgumentNullException: drive is null.");
				return null;
			}
		}
Exemplo n.º 11
0
		private bool IsServerGlobalCatalog(ADSessionInfo sessionInfo, ADRootDSE rootDSE, ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo)
		{
			bool hasValue;
			bool flag = false;
			if (this.GetHostType(parameters, extendedDriveInfo) != ADPathHostType.GC)
			{
				bool? globalCatalogReady = rootDSE.GlobalCatalogReady;
				if (!globalCatalogReady.GetValueOrDefault())
				{
					hasValue = false;
				}
				else
				{
					hasValue = globalCatalogReady.HasValue;
				}
				if (hasValue)
				{
					string server = null;
					if (sessionInfo.Server != null)
					{
						server = sessionInfo.Server;
					}
					if (server != null)
					{
						this.Trace(DebugLogLevel.Info, string.Format("IsServerGlobalCatalog: server = {0}", server));
						if (server.EndsWith(":3268") || server.EndsWith(":3269"))
						{
							flag = true;
						}
					}
				}
			}
			else
			{
				flag = true;
			}
			this.Trace(DebugLogLevel.Info, string.Format("IsServerGlobalCatalog: result = {0}", flag));
			return flag;
		}
Exemplo n.º 12
0
		private ADObject GetValidatedADObject(string path, Collection<string> propertiesToRetrieve, ADProviderCommonParameters parameters, PSCredential credential, ADDriveInfo driveInfo)
		{
			return this.GetValidatedADObject(this.GetSessionInfo(parameters, credential, driveInfo), path, propertiesToRetrieve, this.GetFormatType(parameters, driveInfo));
		}
Exemplo n.º 13
0
		private ADSessionInfo GetSessionInfo(ADProviderCommonParameters parameters, PSCredential credential, ADDriveInfo extendedDriveInfo)
		{
			ADAuthType authType;
			ADAuthType aDAuthType;
			this.Trace(DebugLogLevel.Verbose, "Entering GetSessionInfo");
			string server = ADProviderDefaults.Server;
			bool isGC = ADProviderDefaults.IsGC;
			ADAuthType authType1 = ADProviderDefaults.AuthType;
			if (parameters == null || !(extendedDriveInfo != null))
			{
				if (parameters == null)
				{
					if (extendedDriveInfo != null)
					{
						server = extendedDriveInfo.Server;
						isGC = extendedDriveInfo.GlobalCatalog;
						authType1 = extendedDriveInfo.AuthType;
					}
				}
				else
				{
					if (parameters.Server != null)
					{
						server = parameters.Server;
						if (parameters.IsPropertySet("GlobalCatalog"))
						{
							isGC = parameters.GlobalCatalog;
						}
					}
					if (parameters.IsPropertySet("AuthType"))
					{
						authType = parameters.AuthType;
					}
					else
					{
						authType = ADProviderDefaults.AuthType;
					}
					authType1 = authType;
				}
			}
			else
			{
				if (parameters.Server == null)
				{
					server = extendedDriveInfo.Server;
					isGC = extendedDriveInfo.GlobalCatalog;
				}
				else
				{
					server = parameters.Server;
					if (parameters.IsPropertySet("GlobalCatalog"))
					{
						isGC = parameters.GlobalCatalog;
					}
				}
				if (parameters.IsPropertySet("AuthType"))
				{
					aDAuthType = parameters.AuthType;
				}
				else
				{
					aDAuthType = extendedDriveInfo.AuthType;
				}
				authType1 = aDAuthType;
			}
			ADSessionInfo aDSessionInfo = new ADSessionInfo(server);
			if (isGC)
			{
				aDSessionInfo.SetDefaultPort(LdapConstants.LDAP_GC_PORT);
			}
			aDSessionInfo.Credential = this.GetCredential(credential, extendedDriveInfo);
			aDSessionInfo.AuthType = this.GetAuthType(authType1);
			this.Trace(DebugLogLevel.Verbose, "Leaving GetSessionInfo");
			return aDSessionInfo;
		}
Exemplo n.º 14
0
		private string GetServer(ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo)
		{
			string server = null;
			if (parameters == null || parameters.Server == null)
			{
				if (extendedDriveInfo != null)
				{
					server = extendedDriveInfo.Server;
				}
			}
			else
			{
				server = parameters.Server;
			}
			return server;
		}