public static void GetLSAMgmtTrustedDomainInfo(LSAMgmtAPI.LSA_AUTH_PROVIDER_STATUS pProviderStatus, ref LsaAuthProviderStatus authProviderStatus)
        {
            authProviderStatus.NetworkCheckInterval = pProviderStatus.dwNetworkCheckInterval;
            authProviderStatus.NumTrustedDomains = pProviderStatus.dwNumTrustedDomains;

            IntPtr pTrustedDomainInfoCur = pProviderStatus.pTrustedDomainInfoArray;

            for (int index = 0; index < authProviderStatus.NumTrustedDomains; index++)
            {
                LsaTrustedDomainInfo lsaTrustedDomainInfo = new LsaTrustedDomainInfo();

                LSAMgmtAPI.LSA_TRUSTED_DOMAIN_INFO pTrustedDomainInfoArray = new LSAMgmtAPI.LSA_TRUSTED_DOMAIN_INFO();

                Marshal.PtrToStructure(pTrustedDomainInfoCur, pTrustedDomainInfoArray);

                if (pTrustedDomainInfoArray != null)
                {
                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszDnsDomain))
                    {
                        lsaTrustedDomainInfo.DnsDomain = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszDnsDomain);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszNetbiosDomain))
                    {
                        lsaTrustedDomainInfo.NetbiosDomain = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszNetbiosDomain);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszTrusteeDnsDomain))
                    {
                        lsaTrustedDomainInfo.TrusteeDnsDomain = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszTrusteeDnsDomain);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszDomainSID))
                    {
                        lsaTrustedDomainInfo.DomainSID = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszDomainSID);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszDomainGUID))
                    {
                        lsaTrustedDomainInfo.DomainGUID = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszDomainGUID);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszForestName))
                    {
                        lsaTrustedDomainInfo.ForestName = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszForestName);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszClientSiteName))
                    {
                        lsaTrustedDomainInfo.ClientSiteName = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszClientSiteName);
                    }

                    lsaTrustedDomainInfo.TrustFlags = (LSA_TRUST_FLAG)Enum.Parse(typeof(LSA_TRUST_FLAG), pTrustedDomainInfoArray.dwTrustFlags.ToString());
                    lsaTrustedDomainInfo.TrustType = (LSA_TRUST_TYPE)Enum.Parse(typeof(LSA_TRUST_TYPE), pTrustedDomainInfoArray.dwTrustType.ToString());
                    lsaTrustedDomainInfo.TrustAttributes = (LSA_TRUST_ATTRIBUTE)Enum.Parse(typeof(LSA_TRUST_ATTRIBUTE), pTrustedDomainInfoArray.dwTrustAttributes.ToString());
                    lsaTrustedDomainInfo.DomainFlags = (LSA_DM_DOMAIN_FLAGS)Enum.Parse(typeof(LSA_DM_DOMAIN_FLAGS), pTrustedDomainInfoArray.dwDomainFlags.ToString());

                    if (pTrustedDomainInfoArray.pDCInfo != IntPtr.Zero)
                    {
                        LSAMgmtAPI.LSA_DC_INFO pDCInfo = new LSAMgmtAPI.LSA_DC_INFO();

                        Marshal.PtrToStructure(pTrustedDomainInfoArray.pDCInfo, pDCInfo);

                        lsaTrustedDomainInfo.pDCInfo = new LsaDCInfo();

                        if (!IntPtr.Zero.Equals(pDCInfo.pszName))
                        {
                            lsaTrustedDomainInfo.pDCInfo.Name = Marshal.PtrToStringAuto(pDCInfo.pszName);
                        }

                        if (!IntPtr.Zero.Equals(pDCInfo.pszAddress))
                        {
                            lsaTrustedDomainInfo.pDCInfo.Address = Marshal.PtrToStringAuto(pDCInfo.pszAddress);
                        }

                        if (!IntPtr.Zero.Equals(pDCInfo.pszSiteName))
                        {
                            lsaTrustedDomainInfo.pDCInfo.SiteName = Marshal.PtrToStringAuto(pDCInfo.pszSiteName);
                        }

                        lsaTrustedDomainInfo.pDCInfo.DSflags = (LSA_DS_FLAGS)Enum.Parse(typeof(LSA_DS_FLAGS), pDCInfo.dwFlags.ToString());
                    }

                    if (pTrustedDomainInfoArray.pGCInfo != IntPtr.Zero)
                    {
                        LSAMgmtAPI.LSA_DC_INFO pGCInfo = new LSAMgmtAPI.LSA_DC_INFO();

                        Marshal.PtrToStructure(pTrustedDomainInfoArray.pGCInfo, pGCInfo);

                        lsaTrustedDomainInfo.pGCInfo = new LsaDCInfo();

                        if (!IntPtr.Zero.Equals(pGCInfo.pszName))
                        {
                            lsaTrustedDomainInfo.pGCInfo.Name = Marshal.PtrToStringAuto(pGCInfo.pszName);
                        }

                        if (!IntPtr.Zero.Equals(pGCInfo.pszAddress))
                        {
                            lsaTrustedDomainInfo.pGCInfo.Address = Marshal.PtrToStringAuto(pGCInfo.pszAddress);
                        }

                        if (!IntPtr.Zero.Equals(pGCInfo.pszSiteName))
                        {
                            lsaTrustedDomainInfo.pGCInfo.SiteName = Marshal.PtrToStringAuto(pGCInfo.pszSiteName);
                        }

                        lsaTrustedDomainInfo.pGCInfo.DSflags = (LSA_DS_FLAGS)Enum.Parse(typeof(LSA_DS_FLAGS), pGCInfo.dwFlags.ToString());
                    }

                    authProviderStatus.TrustedDomainInfo.Add(lsaTrustedDomainInfo);
                }

                pTrustedDomainInfoCur = (IntPtr)((int)pTrustedDomainInfoCur + Marshal.SizeOf(pTrustedDomainInfoArray));
            }
        }
示例#2
0
        public static void GetLSAMgmtTrustedDomainInfo(LSAMgmtAPI.LSA_AUTH_PROVIDER_STATUS pProviderStatus, ref LsaAuthProviderStatus authProviderStatus)
        {
            authProviderStatus.NetworkCheckInterval = pProviderStatus.dwNetworkCheckInterval;
            authProviderStatus.NumTrustedDomains    = pProviderStatus.dwNumTrustedDomains;

            IntPtr pTrustedDomainInfoCur = pProviderStatus.pTrustedDomainInfoArray;

            for (int index = 0; index < authProviderStatus.NumTrustedDomains; index++)
            {
                LsaTrustedDomainInfo lsaTrustedDomainInfo = new LsaTrustedDomainInfo();

                LSAMgmtAPI.LSA_TRUSTED_DOMAIN_INFO pTrustedDomainInfoArray = new LSAMgmtAPI.LSA_TRUSTED_DOMAIN_INFO();

                Marshal.PtrToStructure(pTrustedDomainInfoCur, pTrustedDomainInfoArray);

                if (pTrustedDomainInfoArray != null)
                {
                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszDnsDomain))
                    {
                        lsaTrustedDomainInfo.DnsDomain = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszDnsDomain);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszNetbiosDomain))
                    {
                        lsaTrustedDomainInfo.NetbiosDomain = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszNetbiosDomain);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszTrusteeDnsDomain))
                    {
                        lsaTrustedDomainInfo.TrusteeDnsDomain = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszTrusteeDnsDomain);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszDomainSID))
                    {
                        lsaTrustedDomainInfo.DomainSID = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszDomainSID);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszDomainGUID))
                    {
                        lsaTrustedDomainInfo.DomainGUID = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszDomainGUID);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszForestName))
                    {
                        lsaTrustedDomainInfo.ForestName = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszForestName);
                    }

                    if (!IntPtr.Zero.Equals(pTrustedDomainInfoArray.pszClientSiteName))
                    {
                        lsaTrustedDomainInfo.ClientSiteName = Marshal.PtrToStringAuto(pTrustedDomainInfoArray.pszClientSiteName);
                    }

                    lsaTrustedDomainInfo.TrustFlags      = (LSA_TRUST_FLAG)Enum.Parse(typeof(LSA_TRUST_FLAG), pTrustedDomainInfoArray.dwTrustFlags.ToString());
                    lsaTrustedDomainInfo.TrustType       = (LSA_TRUST_TYPE)Enum.Parse(typeof(LSA_TRUST_TYPE), pTrustedDomainInfoArray.dwTrustType.ToString());
                    lsaTrustedDomainInfo.TrustAttributes = (LSA_TRUST_ATTRIBUTE)Enum.Parse(typeof(LSA_TRUST_ATTRIBUTE), pTrustedDomainInfoArray.dwTrustAttributes.ToString());
                    lsaTrustedDomainInfo.DomainFlags     = (LSA_DM_DOMAIN_FLAGS)Enum.Parse(typeof(LSA_DM_DOMAIN_FLAGS), pTrustedDomainInfoArray.dwDomainFlags.ToString());

                    if (pTrustedDomainInfoArray.pDCInfo != IntPtr.Zero)
                    {
                        LSAMgmtAPI.LSA_DC_INFO pDCInfo = new LSAMgmtAPI.LSA_DC_INFO();

                        Marshal.PtrToStructure(pTrustedDomainInfoArray.pDCInfo, pDCInfo);

                        lsaTrustedDomainInfo.pDCInfo = new LsaDCInfo();

                        if (!IntPtr.Zero.Equals(pDCInfo.pszName))
                        {
                            lsaTrustedDomainInfo.pDCInfo.Name = Marshal.PtrToStringAuto(pDCInfo.pszName);
                        }

                        if (!IntPtr.Zero.Equals(pDCInfo.pszAddress))
                        {
                            lsaTrustedDomainInfo.pDCInfo.Address = Marshal.PtrToStringAuto(pDCInfo.pszAddress);
                        }

                        if (!IntPtr.Zero.Equals(pDCInfo.pszSiteName))
                        {
                            lsaTrustedDomainInfo.pDCInfo.SiteName = Marshal.PtrToStringAuto(pDCInfo.pszSiteName);
                        }

                        lsaTrustedDomainInfo.pDCInfo.DSflags = (LSA_DS_FLAGS)Enum.Parse(typeof(LSA_DS_FLAGS), pDCInfo.dwFlags.ToString());
                    }

                    if (pTrustedDomainInfoArray.pGCInfo != IntPtr.Zero)
                    {
                        LSAMgmtAPI.LSA_DC_INFO pGCInfo = new LSAMgmtAPI.LSA_DC_INFO();

                        Marshal.PtrToStructure(pTrustedDomainInfoArray.pGCInfo, pGCInfo);

                        lsaTrustedDomainInfo.pGCInfo = new LsaDCInfo();

                        if (!IntPtr.Zero.Equals(pGCInfo.pszName))
                        {
                            lsaTrustedDomainInfo.pGCInfo.Name = Marshal.PtrToStringAuto(pGCInfo.pszName);
                        }

                        if (!IntPtr.Zero.Equals(pGCInfo.pszAddress))
                        {
                            lsaTrustedDomainInfo.pGCInfo.Address = Marshal.PtrToStringAuto(pGCInfo.pszAddress);
                        }

                        if (!IntPtr.Zero.Equals(pGCInfo.pszSiteName))
                        {
                            lsaTrustedDomainInfo.pGCInfo.SiteName = Marshal.PtrToStringAuto(pGCInfo.pszSiteName);
                        }

                        lsaTrustedDomainInfo.pGCInfo.DSflags = (LSA_DS_FLAGS)Enum.Parse(typeof(LSA_DS_FLAGS), pGCInfo.dwFlags.ToString());
                    }

                    authProviderStatus.TrustedDomainInfo.Add(lsaTrustedDomainInfo);
                }

                pTrustedDomainInfoCur = (IntPtr)((int)pTrustedDomainInfoCur + Marshal.SizeOf(pTrustedDomainInfoArray));
            }
        }