Example #1
0
        private bool VerifySecureChannel(string domain, string localMachineName)
        {
            IntPtr zero                = IntPtr.Zero;
            IntPtr coTaskMemAuto       = Marshal.StringToCoTaskMemAuto(domain);
            bool   pdcConnectionStatus = false;

            try
            {
                int num = SAMAPI.I_NetLogonControl2(null, 6, 2, ref coTaskMemAuto, out zero);
                if (num != 0)
                {
                    Win32Exception win32Exception = new Win32Exception(num);
                    string         str            = StringUtil.Format(ComputerResources.FailToTestSecureChannel, win32Exception.Message);
                    ErrorRecord    errorRecord    = new ErrorRecord(new InvalidOperationException(str), "FailToTestSecureChannel", ErrorCategory.OperationStopped, localMachineName);
                    base.ThrowTerminatingError(errorRecord);
                }
                SAMAPI.NetLogonInfo2 structure = (SAMAPI.NetLogonInfo2)Marshal.PtrToStructure(zero, typeof(SAMAPI.NetLogonInfo2));
                pdcConnectionStatus = structure.PdcConnectionStatus == 0;
            }
            finally
            {
                if (coTaskMemAuto != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(coTaskMemAuto);
                }
                if (zero != IntPtr.Zero)
                {
                    SAMAPI.NetApiBufferFree(zero);
                }
            }
            return(pdcConnectionStatus);
        }
Example #2
0
        private bool ResetSecureChannel(string domain)
        {
            IntPtr zero          = IntPtr.Zero;
            IntPtr coTaskMemAuto = Marshal.StringToCoTaskMemAuto(domain);
            bool   trustedDcName = false;

            try
            {
                int num = SAMAPI.I_NetLogonControl2(null, 5, 2, ref coTaskMemAuto, out zero);
                if (num == 0)
                {
                    SAMAPI.NetLogonInfo2 structure = (SAMAPI.NetLogonInfo2)Marshal.PtrToStructure(zero, typeof(SAMAPI.NetLogonInfo2));
                    trustedDcName = structure.TrustedDcName != null;
                }
            }
            finally
            {
                if (coTaskMemAuto != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(coTaskMemAuto);
                }
                if (zero != IntPtr.Zero)
                {
                    SAMAPI.NetApiBufferFree(zero);
                }
            }
            return(trustedDcName);
        }