Пример #1
0
        private static void HandleError(int rc, ref DCInfo dch, string domainDNS, string siteName, string flags)
        {
            dch.Success = false;

            dch.ErrorString = "HResult: " + rc;

            switch (rc)
            {
            case 8:
                dch.ErrorString = string.Format("{0} (Not enough storage is available to process this command!)", dch.ErrorString);
                break;

            case 997:
                dch.ErrorString = string.Format("{0} (No DC in domain: {1}, site: {2} answered!)", dch.ErrorString, Convert.ToString(domainDNS), Convert.ToString(siteName));
                break;

            case 1004:
                dch.ErrorString = string.Format("{0} (Invalid flags: {1}!", dch.ErrorString, flags);
                break;

            case 1211:
                dch.ErrorString = string.Format("{0} (The format of the specified domain name is invalid: {1}!)", dch.ErrorString, Convert.ToString(domainDNS));
                break;

            case 1355:
                dch.ErrorString = string.Format("{0} (The specified domain either does not exist or could not be contacted: {1}!)", dch.ErrorString, Convert.ToString(domainDNS));
                break;

            default:
                dch.ErrorString = string.Format("{0} (Unknown error!)", dch.ErrorString);
                break;
            }
        }
Пример #2
0
        public static DCInfo DsGetPDCName(string domainDNS)
        {
            DCInfo scRet = new DCInfo();

            scRet = DsGetDCName(domainDNS, null, NetApi32.DS_FLAGS.DS_FORCE_REDISCOVERY | NetApi32.DS_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED | NetApi32.DS_FLAGS.DS_RETURN_DNS_NAME | NetApi32.DS_FLAGS.DS_WRITABLE_REQUIRED | NetApi32.DS_FLAGS.DS_PDC_REQUIRED);

            return(scRet);
        }
Пример #3
0
        public static DCInfo DsGetClostesGCName(string domainDNS)
        {
            DCInfo scRet = new DCInfo();

            scRet = DsGetDCName(domainDNS, null, NetApi32.DS_FLAGS.DS_FORCE_REDISCOVERY | NetApi32.DS_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED | NetApi32.DS_FLAGS.DS_RETURN_DNS_NAME | NetApi32.DS_FLAGS.DS_TRY_NEXTCLOSEST_SITE | NetApi32.DS_FLAGS.DS_GC_SERVER_REQUIRED);

            return(scRet);
        }
Пример #4
0
        public static DCInfo DsGetCachedWDCName(string domainDNS)
        {
            DCInfo scRet = new DCInfo();

            scRet = DsGetDCName(domainDNS, null, NetApi32.DS_FLAGS.DS_BACKGROUND_ONLY | NetApi32.DS_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED | NetApi32.DS_FLAGS.DS_RETURN_DNS_NAME | NetApi32.DS_FLAGS.DS_WRITABLE_REQUIRED);

            return(scRet);
        }
Пример #5
0
        public static DCInfo DsGetDCName(string domainDNS, string siteName, NetApi32.DS_FLAGS flags)
        {
            DCInfo ret = new DCInfo()
            {
                Success = false
            };

            int    iret   = -1;
            IntPtr ipinfo = IntPtr.Zero;

            NetApi32.DOMAIN_CONTROLLER_INFO stcinfo = default(NetApi32.DOMAIN_CONTROLLER_INFO);

            if (domainDNS == null)
            {
                domainDNS = String.Empty;
            }

            try
            { iret = NetApi32.DsGetDcName(null, domainDNS, new Guid(), siteName, flags, ref ipinfo); }

            catch (Win32Exception Win32Ex)
            { ret.ErrorString = Win32Ex.ErrorCode + " (Win32: " + Win32Ex.Message + ")"; }

            catch (Exception ex)
            { ret.ErrorString = ex.Message; }


            if (iret == 0)
            {
                ret.Success = true;

                stcinfo = (NetApi32.DOMAIN_CONTROLLER_INFO)Marshal.PtrToStructure(ipinfo, typeof(NetApi32.DOMAIN_CONTROLLER_INFO));

                NetApi32.NetApiBufferFree(ipinfo);

                ReturnDCINFO(stcinfo, ref ret);
            }

            else
            {
                HandleError(iret, ref ret, domainDNS, siteName, flags.ToString());
            }

            return(ret);
        }
Пример #6
0
        private static void ReturnDCINFO(NetApi32.DOMAIN_CONTROLLER_INFO DomainInfo, ref DCInfo dc)
        {
            dc.DCName    = DomainInfo.DomainControllerName.Replace("\\\\", null);
            dc.DCAddress = DomainInfo.DomainControllerAddress.Replace("\\\\", null);
            if (DomainInfo.DomainControllerAddressType == 1)
            {
                dc.IsIPAddress = true;
            }
            else
            {
                dc.IsNetBIOSAddress = true;
            }

            dc.DomainName     = DomainInfo.DomainName;
            dc.DomainGUID     = DomainInfo.DomainGuid;
            dc.DNSForestname  = DomainInfo.DnsForestName;
            dc.DCSiteName     = DomainInfo.DcSiteName;
            dc.ClientSiteName = DomainInfo.ClientSiteName;


            dc.IsPDC                    = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_PDC_FLAG);
            dc.IsGC                     = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_GC_FLAG);
            dc.IsLDAPServer             = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_LDAP_FLAG);
            dc.IsDC                     = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_DS_FLAG);
            dc.IsKDC                    = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_KDC_FLAG);
            dc.IsTimerServer            = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_TIMESERV_FLAG);
            dc.IsInClosestSite          = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_CLOSEST_FLAG);
            dc.IsWritable               = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_WRITABLE_FLAG);
            dc.IsGoodTimerServer        = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_GOOD_TIMESERV_FLAG);
            dc.IsNonDomainNC            = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_NDNC_FLAG);
            dc.HasSelectedSecrets       = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_SELECT_SECRET_DOMAIN_6_FLAG);
            dc.HasAllSecrets            = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_FULL_SECRET_DOMAIN_6_FLAG);
            dc.HasWebService            = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_WS_FLAG);
            dc.IsDirectoryService2012   = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_DS_8_FLAG);
            dc.IsDirectoryService2012R2 = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_DS_9_FLAG);
            //dc.FromPing = CBool(DomainInfo.Flags And NetApi32.DS_RETURNED_FLAGS.DS_PING_FLAG)
            dc.DCIsDNSName     = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_DNS_CONTROLLER_FLAG);
            dc.DomainIsDNSName = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_DNS_DOMAIN_FLAG);
            //dc.ForestIsDNSName = Convert.ToBoolean(DomainInfo.Flags & NetApi32.DS_RETURNED_FLAGS.DS_DNS_FOREST_FLAG);

            dc.NCInfo = new NamingContextsInfo(dc.DCName);
        }
Пример #7
0
        public static DCInfo DsGetSiteWDCName(string callInfo)
        {
            DCInfo scRet     = new DCInfo();
            string domainDNS = null;
            string SiteName  = null;


            if (callInfo.IndexOf(" ") > 0)
            {
                SiteName = callInfo.Split(Convert.ToChar(" "))[0];

                domainDNS = callInfo.Split(Convert.ToChar(" "))[1];
            }

            else
            {
                SiteName = callInfo;
            }

            scRet = DsGetDCName(domainDNS, SiteName, NetApi32.DS_FLAGS.DS_FORCE_REDISCOVERY | NetApi32.DS_FLAGS.DS_FORCE_REDISCOVERY | NetApi32.DS_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED | NetApi32.DS_FLAGS.DS_RETURN_DNS_NAME | NetApi32.DS_FLAGS.DS_WRITABLE_REQUIRED);

            return(scRet);
        }