public Int32 SamrLookupDomainInSamServer(IntPtr ServerHandle, string Name, out SecurityIdentifier DomainId) { IntPtr result = IntPtr.Zero; DomainId = null; IntPtr sid = IntPtr.Zero; using (var NameString = new OxidResolver.NativeMethods.UNICODE_STRING()) { try { NameString.Initialize(Name); if (IntPtr.Size == 8) { result = NativeMethods.NdrClientCall2x64(GetStubHandle(), GetProcStringHandle(190), ServerHandle, NameString, out sid); } else { GCHandle handle1 = GCHandle.Alloc(NameString, GCHandleType.Pinned); IntPtr tempValuePointer1 = handle1.AddrOfPinnedObject(); IntPtr tempValue2 = sid; GCHandle handle2 = GCHandle.Alloc(tempValue2, GCHandleType.Pinned); IntPtr tempValuePointer2 = handle2.AddrOfPinnedObject(); try { result = CallNdrClientCall2x86(180, ServerHandle, tempValuePointer1, tempValuePointer2); // each pinvoke work on a copy of the arguments (without an out specifier) // get back the data sid = Marshal.ReadIntPtr(tempValuePointer2); } finally { handle1.Free(); handle2.Free(); } } DomainId = new SecurityIdentifier(sid); FreeMemory(sid); } catch (SEHException) { Trace.WriteLine("SamrLookupDomainInSamServer failed 0x" + Marshal.GetExceptionCode().ToString("x")); return(Marshal.GetExceptionCode()); } } return((int)result.ToInt64()); }
internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr ServerHandle, OxidResolver.NativeMethods.UNICODE_STRING NameString, out IntPtr sid);