コード例 #1
0
        internal static IpcPort Create(string portName, CommonSecurityDescriptor securityDescriptor, bool exclusive)
        {
            SECURITY_ATTRIBUTES security_attributes;

            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new NotSupportedException(CoreChannel.GetResourceString("Remoting_Ipc_Win9x"));
            }
            PipeHandle handle = null;
            string     lpName = @"\\.\pipe\" + portName;

            security_attributes = new SECURITY_ATTRIBUTES {
                nLength = Marshal.SizeOf(security_attributes)
            };
            byte[] binaryForm = null;
            if (securityDescriptor == null)
            {
                securityDescriptor = s_securityDescriptor;
            }
            binaryForm = new byte[securityDescriptor.BinaryLength];
            securityDescriptor.GetBinaryForm(binaryForm, 0);
            GCHandle handle2 = GCHandle.Alloc(binaryForm, GCHandleType.Pinned);

            security_attributes.lpSecurityDescriptor = Marshal.UnsafeAddrOfPinnedArrayElement(binaryForm, 0);
            handle = NativePipe.CreateNamedPipe(lpName, (uint)(0x40000003 | (exclusive ? 0x80000 : 0)), 0, 0xff, 0x2000, 0x2000, uint.MaxValue, security_attributes);
            handle2.Free();
            if (handle.Handle.ToInt32() == -1)
            {
                int errorCode = Marshal.GetLastWin32Error();
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_CreateIpcFailed"), new object[] { GetMessage(errorCode) }));
            }
            return(new IpcPort(portName, handle));
        }
コード例 #2
0
 private IpcPort(string portName, PipeHandle handle)
 {
     this._portName  = portName;
     this._handle    = handle;
     this._cacheable = true;
     ThreadPool.BindHandle(this._handle.Handle);
 }
コード例 #3
0
 public static unsafe extern bool WriteFile(
     PipeHandle hFile,                                            // handle to file
     byte *lpBuffer,                                              // data buffer
     int nNumberOfBytesToWrite,                                   // number of bytes to write
     ref int lpNumberOfBytesWritten,                              // number of bytes written
     IntPtr lpOverlapped                                          // overlapped buffer
     );
コード例 #4
0
 private IpcPort(string portName, PipeHandle handle)
 {
     this._portName = portName;
     this._handle = handle;
     this._cacheable = true;
     ThreadPool.BindHandle(this._handle.Handle);
 }
コード例 #5
0
        internal static IpcPort Connect(String portName, bool secure, TokenImpersonationLevel impersonationLevel, int timeout)
        {
            string pipeName      = prefix + portName;
            uint   impersonation = NativePipe.SECURITY_SQOS_PRESENT;

            // convert the impersonation Level to the correct flag
            if (secure)
            {
                switch (impersonationLevel)
                {
                case TokenImpersonationLevel.None:
                    impersonation = NativePipe.SECURITY_SQOS_PRESENT;
                    break;

                case TokenImpersonationLevel.Identification:
                    impersonation = NativePipe.SECURITY_SQOS_PRESENT | NativePipe.SECURITY_IDENTIFICATION;
                    break;

                case TokenImpersonationLevel.Impersonation:
                    impersonation = NativePipe.SECURITY_SQOS_PRESENT | NativePipe.SECURITY_IMPERSONATION;
                    break;

                case TokenImpersonationLevel.Delegation:
                    impersonation = NativePipe.SECURITY_SQOS_PRESENT | NativePipe.SECURITY_DELEGATION;
                    break;
                }
            }

            while (true)
            {
                // Invoke CreateFile with the pipeName to open a client side connection
                PipeHandle handle = NativePipe.CreateFile(pipeName,
                                                          NativePipe.GENERIC_READ | NativePipe.GENERIC_WRITE,
                                                          NativePipe.FILE_SHARE_READ |
                                                          NativePipe.FILE_SHARE_WRITE,
                                                          IntPtr.Zero,
                                                          NativePipe.OPEN_EXISTING,
                                                          NativePipe.FILE_ATTRIBUTE_NORMAL |
                                                          NativePipe.FILE_FLAG_OVERLAPPED |
                                                          impersonation,
                                                          IntPtr.Zero);

                if (handle.Handle.ToInt32() != NativePipe.INVALID_HANDLE_VALUE)
                {
                    return(new IpcPort(portName, handle));
                }

                int error = Marshal.GetLastWin32Error();
                if (error != NativePipe.ERROR_PIPE_BUSY)
                {
                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ConnectIpcFailed"), GetMessage(error)));
                }

                if (!NativePipe.WaitNamedPipe(pipeName, timeout))
                {
                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_Busy"), GetMessage(error)));
                }
            }
        }
コード例 #6
0
        private IpcPort(string portName, PipeHandle handle)
        {
            _portName  = portName;
            _handle    = handle;
            _cacheable = true;
#pragma warning disable 618
            // Bind the current handle to the threadpool for IOCompletion
            ThreadPool.BindHandle(_handle.Handle);
#pragma warning restore 618
        }
コード例 #7
0
        private IpcPort(string portName, PipeHandle handle)
        {
            _portName = portName;
            _handle = handle;
            _cacheable = true;
#pragma warning disable 618
            // Bind the current handle to the threadpool for IOCompletion
            ThreadPool.BindHandle(_handle.Handle);
#pragma warning restore 618
        }
コード例 #8
0
        internal static IpcPort Create(String portName, CommonSecurityDescriptor securityDescriptor, bool exclusive)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new NotSupportedException(CoreChannel.GetResourceString("Remoting_Ipc_Win9x"));
            }
            PipeHandle handle = null;
            // Add the prefix to the portName
            string pipeName          = prefix + portName;
            SECURITY_ATTRIBUTES attr = new SECURITY_ATTRIBUTES();

            attr.nLength = (int)Marshal.SizeOf(attr);
            byte[] sd = null;
            // If no securityDescriptor was set by the user use the default
            if (securityDescriptor == null)
            {
                securityDescriptor = s_securityDescriptor;
            }

            sd = new byte[securityDescriptor.BinaryLength];
            // Get the binary form of the descriptor
            securityDescriptor.GetBinaryForm(sd, 0);

            GCHandle pinningHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);

            // get the address of the security descriptor
            attr.lpSecurityDescriptor = Marshal.UnsafeAddrOfPinnedArrayElement(sd, 0);

            // Create the named pipe with the appropriate name
            handle = NativePipe.CreateNamedPipe(pipeName,
                                                NativePipe.PIPE_ACCESS_DUPLEX | NativePipe.FILE_FLAG_OVERLAPPED
                                                | (exclusive ? NativePipe.FILE_FLAG_FIRST_PIPE_INSTANCE : 0x0), // Or exclusive flag
                                                NativePipe.PIPE_TYPE_BYTE | NativePipe.PIPE_READMODE_BYTE | NativePipe.PIPE_WAIT,
                                                NativePipe.PIPE_UNLIMITED_INSTANCES,
                                                8192,
                                                8192,
                                                NativePipe.NMPWAIT_WAIT_FOREVER,
                                                attr);

            pinningHandle.Free();
            if (handle.Handle.ToInt32() == NativePipe.INVALID_HANDLE_VALUE)
            {
                int error = Marshal.GetLastWin32Error();
                throw new RemotingException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_CreateIpcFailed"), GetMessage(error)));
            }

            return(new IpcPort(portName, handle));
        }
コード例 #9
0
        internal static IpcPort Connect(string portName, bool secure, TokenImpersonationLevel impersonationLevel, int timeout)
        {
            string lpFileName = @"\\.\pipe\" + portName;
            uint   num        = 0x100000;

            if (secure)
            {
                switch (impersonationLevel)
                {
                case TokenImpersonationLevel.None:
                    num = 0x100000;
                    break;

                case TokenImpersonationLevel.Identification:
                    num = 0x110000;
                    break;

                case TokenImpersonationLevel.Impersonation:
                    num = 0x120000;
                    break;

                case TokenImpersonationLevel.Delegation:
                    num = 0x130000;
                    break;
                }
            }
            while (true)
            {
                PipeHandle handle = NativePipe.CreateFile(lpFileName, 0xc0000000, 3, IntPtr.Zero, 3, 0x40000080 | num, IntPtr.Zero);
                if (handle.Handle.ToInt32() != -1)
                {
                    return(new IpcPort(portName, handle));
                }
                int errorCode = Marshal.GetLastWin32Error();
                if (errorCode != 0xe7L)
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ConnectIpcFailed"), new object[] { GetMessage(errorCode) }));
                }
                if (!NativePipe.WaitNamedPipe(lpFileName, timeout))
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_Busy"), new object[] { GetMessage(errorCode) }));
                }
            }
        }
コード例 #10
0
 public static extern bool ConnectNamedPipe(PipeHandle hNamedPipe,        // handle to named pipe
                                             Overlapped lpOverlapped  // overlapped structure
                                             );
コード例 #11
0
 public static extern unsafe bool ReadFile(PipeHandle hFile, byte* lpBuffer, int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, IntPtr mustBeZero);
コード例 #12
0
 public static extern unsafe bool WriteFile(PipeHandle hFile, byte* lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, IntPtr lpOverlapped);
コード例 #13
0
 public static extern unsafe bool ReadFile(PipeHandle hFile, byte* lpBuffer, int nNumberOfBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped* lpOverlapped);
コード例 #14
0
 public static extern unsafe bool ReadFile(PipeHandle hFile, byte *lpBuffer, int nNumberOfBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped *lpOverlapped);
コード例 #15
0
 public static extern unsafe bool WriteFile(PipeHandle hFile, byte *lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, IntPtr lpOverlapped);
コード例 #16
0
 public static extern bool ConnectNamedPipe(PipeHandle hNamedPipe, Overlapped lpOverlapped);
コード例 #17
0
 public static extern unsafe bool ReadFile(PipeHandle hFile, byte *lpBuffer, int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, IntPtr mustBeZero);
コード例 #18
0
 public static unsafe extern bool ReadFile(PipeHandle hFile,                       // handle to file
                                    byte* lpBuffer,                 // data buffer
                                    int nNumberOfBytesToRead,   // number of bytes to read
                                    IntPtr numBytesRead_mustBeZero,  // number of bytes must be zero
                                    NativeOverlapped* lpOverlapped   // overlapped buffer
                                    );
コード例 #19
0
 public static extern bool ImpersonateNamedPipeClient(PipeHandle hNamedPipe        // handle to named pipe
                                                );
コード例 #20
0
 public static extern bool ConnectNamedPipe(PipeHandle hNamedPipe,    // handle to named pipe
                                            Overlapped lpOverlapped   // overlapped structure
                                            );
コード例 #21
0
 public static unsafe extern bool ReadFile(PipeHandle hFile,            // handle to file
                                           byte *lpBuffer,              // data buffer
                                           int nNumberOfBytesToRead,    // number of bytes to read
                                           ref int lpNumberOfBytesRead, // number of bytes read
                                           IntPtr mustBeZero            // this should be IntPtr.Zero
                                           );
コード例 #22
0
 public static unsafe extern bool ReadFile(PipeHandle hFile,               // handle to file
                                           byte *lpBuffer,                 // data buffer
                                           int nNumberOfBytesToRead,       // number of bytes to read
                                           IntPtr numBytesRead_mustBeZero, // number of bytes must be zero
                                           NativeOverlapped *lpOverlapped  // overlapped buffer
                                           );
コード例 #23
0
 public static unsafe extern bool ReadFile(PipeHandle hFile,                       // handle to file
                                    byte* lpBuffer,                 // data buffer
                                    int nNumberOfBytesToRead,   // number of bytes to read
                                    ref int lpNumberOfBytesRead,  // number of bytes read
                                    IntPtr mustBeZero               // this should be IntPtr.Zero
                                    );
コード例 #24
0
 public static extern bool ConnectNamedPipe(PipeHandle hNamedPipe, Overlapped lpOverlapped);
コード例 #25
0
 public static unsafe extern bool WriteFile(
                                     PipeHandle hFile,                          // handle to file
                                     byte* lpBuffer,                  // data buffer
                                     int nNumberOfBytesToWrite,   // number of bytes to write
                                     ref int lpNumberOfBytesWritten, // number of bytes written
                                     IntPtr lpOverlapped                 // overlapped buffer
                                     );
コード例 #26
0
 public static extern bool ImpersonateNamedPipeClient(PipeHandle hNamedPipe);