示例#1
0
        private string BuildPathFromDN(string dn)
        {
            string userSuppliedServername = _storeCtx.UserSuppliedServerName;

            UnsafeNativeMethods.Pathname     pathCracker = new UnsafeNativeMethods.Pathname();
            UnsafeNativeMethods.IADsPathname pathName    = (UnsafeNativeMethods.IADsPathname)pathCracker;
            pathName.EscapedMode = 2 /* ADS_ESCAPEDMODE_ON */;
            pathName.Set(dn, 4 /* ADS_SETTYPE_DN */);
            string escapedDn = pathName.Retrieve(7 /* ADS_FORMAT_X500_DN */);

            if (userSuppliedServername.Length > 0)
            {
                return("LDAP://" + _storeCtx.UserSuppliedServerName + "/" + escapedDn);
            }
            else
            {
                return("LDAP://" + escapedDn);
            }
        }
示例#2
0
        private string BuildPathFromDN(string dn)
        {
            string userSuppliedServerName = this.storeCtx.UserSuppliedServerName;

            UnsafeNativeMethods.Pathname     pathname    = new UnsafeNativeMethods.Pathname();
            UnsafeNativeMethods.IADsPathname aDsPathname = (UnsafeNativeMethods.IADsPathname)pathname;
            aDsPathname.EscapedMode = 2;
            aDsPathname.Set(dn, 4);
            string str = aDsPathname.Retrieve(7);

            if (userSuppliedServerName.Length <= 0)
            {
                return(string.Concat("LDAP://", str));
            }
            else
            {
                return(string.Concat("LDAP://", this.storeCtx.UserSuppliedServerName, "/", str));
            }
        }
示例#3
0
 protected override void LoadDomainInfo()
 {
     this.dnsHostName    = ADUtils.GetServerName(this.ctxBase);
     this.domainFlatName = this.userSuppliedServerName;
     this.forestDnsName  = this.userSuppliedServerName;
     this.domainDnsName  = this.userSuppliedServerName;
     using (DirectoryEntry directoryEntry = new DirectoryEntry(string.Concat("LDAP://", this.userSuppliedServerName, "/rootDse"), "", "", AuthenticationTypes.Anonymous))
     {
         string item   = (string)this.ctxBase.Properties["distinguishedName"][0];
         int    length = -1;
         foreach (string str in directoryEntry.Properties["namingContexts"])
         {
             if (str.Length <= length || !item.EndsWith(str, StringComparison.OrdinalIgnoreCase))
             {
                 continue;
             }
             length = str.Length;
             this.contextBasePartitionDN = str;
         }
     }
     UnsafeNativeMethods.Pathname     pathname    = new UnsafeNativeMethods.Pathname();
     UnsafeNativeMethods.IADsPathname aDsPathname = (UnsafeNativeMethods.IADsPathname)pathname;
     aDsPathname.Set(this.ctxBase.Path, 1);
     try
     {
         this.userSuppliedServerName = aDsPathname.Retrieve(9);
     }
     catch (COMException cOMException1)
     {
         COMException cOMException = cOMException1;
         if (cOMException.ErrorCode != -2147463168)
         {
             throw;
         }
         else
         {
             this.userSuppliedServerName = "";
         }
     }
 }
示例#4
0
        // Must be called inside of lock(domainInfoLock)
        protected override void LoadDomainInfo()
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "LoadComputerInfo");

            Debug.Assert(this.ctxBase != null);

            //
            // DNS Domain Name
            //
            this.dnsHostName = ADUtils.GetServerName(this.ctxBase);
            // Treat the user supplied server name as the domain and forest name...
            this.domainFlatName = userSuppliedServerName;
            this.forestDnsName  = userSuppliedServerName;
            this.domainDnsName  = userSuppliedServerName;

            //
            // Find the partition in which the supplied ctxBase belongs by comparing it with the list of partitions hosted by this
            // LDS (ADAM) instance.
            //
            using (DirectoryEntry rootDse = new DirectoryEntry("LDAP://" + this.userSuppliedServerName + "/rootDse", "", "", AuthenticationTypes.Anonymous))
            {
                string ctxBaseDN      = (string)this.ctxBase.Properties["distinguishedName"][0];
                int    maxMatchLength = -1;
                foreach (string partitionDN in rootDse.Properties["namingContexts"])
                {
                    if ((partitionDN.Length > maxMatchLength) && ctxBaseDN.EndsWith(partitionDN, StringComparison.OrdinalIgnoreCase))
                    {
                        maxMatchLength = partitionDN.Length;
                        this.contextBasePartitionDN = partitionDN;
                    }
                }
            }

            //
            // User supplied name
            //
            UnsafeNativeMethods.Pathname     pathCracker = new UnsafeNativeMethods.Pathname();
            UnsafeNativeMethods.IADsPathname pathName    = (UnsafeNativeMethods.IADsPathname)pathCracker;

            pathName.Set(this.ctxBase.Path, 1 /* ADS_SETTYPE_FULL */);

            try
            {
                this.userSuppliedServerName = pathName.Retrieve(9 /*ADS_FORMAT_SERVER */);
                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "LoadComputerInfo: using user-supplied name {0}", this.userSuppliedServerName);
            }
            catch (COMException e)
            {
                if (((uint)e.ErrorCode) == ((uint)0x80005000))  // E_ADS_BAD_PATHNAME
                {
                    // Serverless path
                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "LoadComputerInfo: using empty string as user-supplied name");
                    this.userSuppliedServerName = "";
                }
                else
                {
                    GlobalDebug.WriteLineIf(GlobalDebug.Error,
                                            "ADStoreCtx",
                                            "LoadComputerInfo: caught COMException {0} {1} looking for user-supplied name",
                                            e.ErrorCode,
                                            e.Message);

                    throw;
                }
            }
        }