Пример #1
0
        public static AdamInstance FindOne(DirectoryContext context, string partitionName)
        {
            // validate parameters (partitionName validated by the call to ConfigSet)
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // contexttype should be ConfigurationSet
            if (context.ContextType != DirectoryContextType.ConfigurationSet)
            {
                throw new ArgumentException(SR.TargetShouldBeConfigSet, nameof(context));
            }

            if (partitionName == null)
            {
                throw new ArgumentNullException(nameof(partitionName));
            }

            if (partitionName.Length == 0)
            {
                throw new ArgumentException(SR.EmptyStringParameter, nameof(partitionName));
            }

            //  work with copy of the context
            context = new DirectoryContext(context);

            return(ConfigurationSet.FindOneAdamInstance(context, partitionName, null));
        }
Пример #2
0
 public static AdamInstance FindOne(DirectoryContext context, string partitionName)
 {
     if (context != null)
     {
         if (context.ContextType == DirectoryContextType.ConfigurationSet)
         {
             if (partitionName != null)
             {
                 if (partitionName.Length != 0)
                 {
                     context = new DirectoryContext(context);
                     return(ConfigurationSet.FindOneAdamInstance(context, partitionName, null));
                 }
                 else
                 {
                     throw new ArgumentException(Res.GetString("EmptyStringParameter"), "partitionName");
                 }
             }
             else
             {
                 throw new ArgumentNullException("partitionName");
             }
         }
         else
         {
             throw new ArgumentException(Res.GetString("TargetShouldBeConfigSet"), "context");
         }
     }
     else
     {
         throw new ArgumentNullException("context");
     }
 }
Пример #3
0
 public AdamInstance FindAdamInstance(string partitionName, string siteName)
 {
     this.CheckIfDisposed();
     if (siteName != null)
     {
         return(ConfigurationSet.FindOneAdamInstance(this.Name, this.context, partitionName, siteName));
     }
     else
     {
         throw new ArgumentNullException("siteName");
     }
 }
 public DirectoryServer FindDirectoryServer(bool forceRediscovery)
 {
     base.CheckIfDisposed();
     if (this.appType == ApplicationPartitionType.ADApplicationPartition)
     {
         return(this.FindDirectoryServerInternal(null, forceRediscovery));
     }
     if (!this.committed)
     {
         throw new InvalidOperationException(Res.GetString("CannotPerformOperationOnUncommittedObject"));
     }
     return(ConfigurationSet.FindOneAdamInstance(base.context, base.Name, null));
 }
 public DirectoryServer FindDirectoryServer(string siteName)
 {
     base.CheckIfDisposed();
     if (siteName == null)
     {
         throw new ArgumentNullException("siteName");
     }
     if (this.appType == ApplicationPartitionType.ADApplicationPartition)
     {
         return(this.FindDirectoryServerInternal(siteName, false));
     }
     if (!this.committed)
     {
         throw new InvalidOperationException(Res.GetString("CannotPerformOperationOnUncommittedObject"));
     }
     return(ConfigurationSet.FindOneAdamInstance(base.context, base.Name, siteName));
 }
Пример #6
0
 internal static AdamInstance FindOneAdamInstance(DirectoryContext context, string partitionName, string siteName)
 {
     return(ConfigurationSet.FindOneAdamInstance(null, context, partitionName, siteName));
 }
Пример #7
0
 public AdamInstance FindAdamInstance()
 {
     this.CheckIfDisposed();
     return(ConfigurationSet.FindOneAdamInstance(this.Name, this.context, null, null));
 }
        public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName)
        {
            DirectoryEntryManager directoryEntryMgr = null;
            DirectoryContext      context2          = null;

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if ((context.Name == null) && !context.isRootDomain())
            {
                throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
            }
            if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer()))
            {
                throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
            }
            if (distinguishedName == null)
            {
                throw new ArgumentNullException("distinguishedName");
            }
            if (distinguishedName.Length == 0)
            {
                throw new ArgumentException(Res.GetString("EmptyStringParameter"), "distinguishedName");
            }
            if (!Utils.IsValidDNFormat(distinguishedName))
            {
                throw new ArgumentException(Res.GetString("InvalidDNFormat"), "distinguishedName");
            }
            context           = new DirectoryContext(context);
            directoryEntryMgr = new DirectoryEntryManager(context);
            DirectoryEntry searchRoot = null;

            try
            {
                searchRoot = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
            }
            StringBuilder builder = new StringBuilder(15);

            builder.Append("(&(");
            builder.Append(PropertyManager.ObjectCategory);
            builder.Append("=crossRef)(");
            builder.Append(PropertyManager.SystemFlags);
            builder.Append(":1.2.840.113556.1.4.804:=");
            builder.Append(1);
            builder.Append(")(!(");
            builder.Append(PropertyManager.SystemFlags);
            builder.Append(":1.2.840.113556.1.4.803:=");
            builder.Append(2);
            builder.Append("))(");
            builder.Append(PropertyManager.NCName);
            builder.Append("=");
            builder.Append(Utils.GetEscapedFilterValue(distinguishedName));
            builder.Append("))");
            string filter = builder.ToString();

            string[]     propertiesToLoad = new string[] { PropertyManager.DnsRoot, PropertyManager.NCName };
            ADSearcher   searcher         = new ADSearcher(searchRoot, filter, propertiesToLoad, SearchScope.OneLevel, false, false);
            SearchResult res = null;

            try
            {
                res = searcher.FindOne();
            }
            catch (COMException exception2)
            {
                if (exception2.ErrorCode == -2147016656)
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
                }
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
            }
            finally
            {
                searchRoot.Dispose();
            }
            if (res == null)
            {
                throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
            }
            string domainName = null;

            try
            {
                domainName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? ((string)res.Properties[PropertyManager.DnsRoot][0]) : null;
            }
            catch (COMException exception3)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
            }
            ApplicationPartitionType applicationPartitionType = GetApplicationPartitionType(context);

            if (context.ContextType != DirectoryContextType.DirectoryServer)
            {
                if (applicationPartitionType == ApplicationPartitionType.ADApplicationPartition)
                {
                    DomainControllerInfo info;
                    int errorCode = 0;
                    errorCode = Locator.DsGetDcNameWrapper(null, domainName, null, 0x8000L, out info);
                    if (errorCode == 0x54b)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
                    }
                    if (errorCode != 0)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                    }
                    context2 = Utils.GetNewDirectoryContext(info.DomainControllerName.Substring(2), DirectoryContextType.DirectoryServer, context);
                }
                else
                {
                    context2 = Utils.GetNewDirectoryContext(ConfigurationSet.FindOneAdamInstance(context.Name, context, distinguishedName, null).Name, DirectoryContextType.DirectoryServer, context);
                }
                goto Label_03FC;
            }
            bool flag                        = false;
            DistinguishedName dn             = new DistinguishedName(distinguishedName);
            DirectoryEntry    directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);

            try
            {
                foreach (string str3 in directoryEntry.Properties[PropertyManager.NamingContexts])
                {
                    DistinguishedName name2 = new DistinguishedName(str3);
                    if (name2.Equals(dn))
                    {
                        flag = true;
                        goto Label_0352;
                    }
                }
            }
            catch (COMException exception4)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception4);
            }
            finally
            {
                directoryEntry.Dispose();
            }
Label_0352:
            if (!flag)
            {
                throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
            }
            context2 = context;
Label_03FC:
            return(new ApplicationPartition(context2, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName), domainName, applicationPartitionType, directoryEntryMgr));
        }