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; }
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; }
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; } } }
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; }
private bool ValidateDynamicParameters(string path, ADProviderCommonParameters parameters, ADSessionInfo sessionInfo) { bool flag; if (parameters != null) { try { parameters.ValidateParameters(); goto Label0; } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; base.WriteError(ADUtilities.GetErrorRecord(argumentException, "ADProvider:ValidateDynamicParameters:InvalidArgument", path)); this.Trace(DebugLogLevel.Error, "Leaving ValidateDynamicParameters: ArgumentException: InvalidArgument"); flag = false; } return flag; } return true; Label0: if (this.GetHostType(parameters, this.ExtendedDriveInfo) == ADPathHostType.GC) { ADRootDSE rootDSE = this.GetRootDSE(sessionInfo); if (rootDSE.ServerType != ADServerType.ADLDS) { if (sessionInfo.EffectivePortNumber != LdapConstants.LDAP_GC_PORT && sessionInfo.EffectivePortNumber != LdapConstants.LDAP_SSL_GC_PORT) { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException(StringResources.ADProviderGCInvalidWithAppendedPort), "ADProvider:ValidateDynamicParameters:GC with appened server port which is not equal to the GC port ", path)); this.Trace(DebugLogLevel.Error, "Leaving ValidateDynamicParameters: ArgumentException: GC with appened server port which is not equal to the GC port "); return false; } else { return true; } } else { base.WriteError(ADUtilities.GetErrorRecord(new ArgumentException(StringResources.ADProviderGCInvalidForADLDS), "ADProvider:ValidateDynamicParameters:GC with ADLDS", path)); this.Trace(DebugLogLevel.Error, "Leaving ValidateDynamicParameters: ArgumentException: GC with ADLDS"); return false; } } else { return true; } }
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; }
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; }
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; }
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)); }
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; }
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; }