Пример #1
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));
            }
        }
Пример #2
0
        public static LsaAgentStatus GetLSAMgmtStatus(string hostname)
        {
            LsaAgentStatus agentStatus = null;
            IntPtr pLsaStatus = IntPtr.Zero;

            try
            {
                LSAMgmtAPI.LSA_STATUS LsaStatus = new LSAMgmtAPI.LSA_STATUS();

                int ret = (int)LSAMgmtAPI.LWMGMTQueryLsaStatus(hostname, out pLsaStatus);
                if (ret != 0)
                {
                    //return null;
                    throw new ApplicationException("Failed to query LSA Agent status");
                }

                Marshal.PtrToStructure(pLsaStatus, LsaStatus);

                agentStatus = new LsaAgentStatus();

                agentStatus.MajorVersion = LsaStatus.version.majorVersion;
                agentStatus.MinorVersion = LsaStatus.version.minorVersion;
                agentStatus.BuildVersion = LsaStatus.version.buildVersion;

                agentStatus.Uptime = LsaStatus.dwUptime;

                if (LsaStatus.dwCount > 0)
                {
                    IntPtr pCur = LsaStatus.pAuthProviderStatusArray;

                    for (int index = 0; index < LsaStatus.dwCount; index++)
                    {
                        LsaAuthProviderStatus authProviderStatus = new LsaAuthProviderStatus();
                        LSAMgmtAPI.LSA_AUTH_PROVIDER_STATUS pProviderStatus = new LSAMgmtAPI.LSA_AUTH_PROVIDER_STATUS();

                        Marshal.PtrToStructure(pCur, pProviderStatus);

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszId))
                        {
                            authProviderStatus.Id = Marshal.PtrToStringAuto(pProviderStatus.pszId);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszDomain))
                        {
                            authProviderStatus.Domain = Marshal.PtrToStringAuto(pProviderStatus.pszDomain);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszForest))
                        {
                            authProviderStatus.Forest = Marshal.PtrToStringAuto(pProviderStatus.pszForest);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszSite))
                        {
                            authProviderStatus.Site = Marshal.PtrToStringAuto(pProviderStatus.pszSite);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszCell))
                        {
                            authProviderStatus.Cell = Marshal.PtrToStringAuto(pProviderStatus.pszCell);
                        }

                        authProviderStatus.Mode = (LsaAuthProviderMode)Enum.Parse(typeof(LsaAuthProviderMode), pProviderStatus.mode.ToString());
                        authProviderStatus.Submode = (LsaAuthProviderSubMode)Enum.Parse(typeof(LsaAuthProviderSubMode), pProviderStatus.subMode.ToString());
                        authProviderStatus.State = (LsaAuthProviderState)Enum.Parse(typeof(LsaAuthProviderState), pProviderStatus.status.ToString());

                        GetLSAMgmtTrustedDomainInfo(pProviderStatus, ref authProviderStatus);

                        agentStatus.AuthProviderList.Add(authProviderStatus);

                        pCur = (IntPtr)((int)pCur + Marshal.SizeOf(pProviderStatus));
                    }
                }
            }
            catch (Exception e)
            {
                //Logger.ShowUserError(e.Message.ToString());
                Logger.LogException("LSAMgmtStatus.GetLSAMgmtStatus", e);
                agentStatus = null;
            }
            finally
            {
                if (!IntPtr.Zero.Equals(pLsaStatus))
                {
                    LSAMgmtAPI.LWMGMTFreeLsaStatus(pLsaStatus);
                }
            }

            return agentStatus;
        }
Пример #3
0
        public static LsaAgentStatus GetLSAMgmtStatus(string hostname)
        {
            LsaAgentStatus agentStatus = null;
            IntPtr         pLsaStatus  = IntPtr.Zero;

            try
            {
                LSAMgmtAPI.LSA_STATUS LsaStatus = new LSAMgmtAPI.LSA_STATUS();

                int ret = (int)LSAMgmtAPI.LWMGMTQueryLsaStatus(hostname, out pLsaStatus);
                if (ret != 0)
                {
                    //return null;
                    throw new ApplicationException("Failed to query LSA Agent status");
                }

                Marshal.PtrToStructure(pLsaStatus, LsaStatus);

                agentStatus = new LsaAgentStatus();

                agentStatus.MajorVersion = LsaStatus.version.majorVersion;
                agentStatus.MinorVersion = LsaStatus.version.minorVersion;
                agentStatus.BuildVersion = LsaStatus.version.buildVersion;

                agentStatus.Uptime = LsaStatus.dwUptime;

                if (LsaStatus.dwCount > 0)
                {
                    IntPtr pCur = LsaStatus.pAuthProviderStatusArray;

                    for (int index = 0; index < LsaStatus.dwCount; index++)
                    {
                        LsaAuthProviderStatus authProviderStatus            = new LsaAuthProviderStatus();
                        LSAMgmtAPI.LSA_AUTH_PROVIDER_STATUS pProviderStatus = new LSAMgmtAPI.LSA_AUTH_PROVIDER_STATUS();

                        Marshal.PtrToStructure(pCur, pProviderStatus);

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszId))
                        {
                            authProviderStatus.Id = Marshal.PtrToStringAuto(pProviderStatus.pszId);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszDomain))
                        {
                            authProviderStatus.Domain = Marshal.PtrToStringAuto(pProviderStatus.pszDomain);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszForest))
                        {
                            authProviderStatus.Forest = Marshal.PtrToStringAuto(pProviderStatus.pszForest);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszSite))
                        {
                            authProviderStatus.Site = Marshal.PtrToStringAuto(pProviderStatus.pszSite);
                        }

                        if (!IntPtr.Zero.Equals(pProviderStatus.pszCell))
                        {
                            authProviderStatus.Cell = Marshal.PtrToStringAuto(pProviderStatus.pszCell);
                        }

                        authProviderStatus.Mode    = (LsaAuthProviderMode)Enum.Parse(typeof(LsaAuthProviderMode), pProviderStatus.mode.ToString());
                        authProviderStatus.Submode = (LsaAuthProviderSubMode)Enum.Parse(typeof(LsaAuthProviderSubMode), pProviderStatus.subMode.ToString());
                        authProviderStatus.State   = (LsaAuthProviderState)Enum.Parse(typeof(LsaAuthProviderState), pProviderStatus.status.ToString());

                        GetLSAMgmtTrustedDomainInfo(pProviderStatus, ref authProviderStatus);

                        agentStatus.AuthProviderList.Add(authProviderStatus);

                        pCur = (IntPtr)((int)pCur + Marshal.SizeOf(pProviderStatus));
                    }
                }
            }
            catch (Exception e)
            {
                //Logger.ShowUserError(e.Message.ToString());
                Logger.LogException("LSAMgmtStatus.GetLSAMgmtStatus", e);
                agentStatus = null;
            }
            finally
            {
                if (!IntPtr.Zero.Equals(pLsaStatus))
                {
                    LSAMgmtAPI.LWMGMTFreeLsaStatus(pLsaStatus);
                }
            }

            return(agentStatus);
        }