Example #1
0
        internal static unsafe SECURITY_ATTRIBUTES GetSecAttrs(
            HandleInheritability inheritability,
            PipeSecurity pipeSecurity,
            out object pinningHandle)
        {
            pinningHandle = (object)null;
            SECURITY_ATTRIBUTES securityAttributes = (SECURITY_ATTRIBUTES)null;

            if ((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None || pipeSecurity != null)
            {
                securityAttributes         = new SECURITY_ATTRIBUTES();
                securityAttributes.nLength = Marshal.SizeOf((object)securityAttributes);
                if ((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None)
                {
                    securityAttributes.bInheritHandle = 1;
                }
                if (pipeSecurity != null)
                {
                    byte[] descriptorBinaryForm = pipeSecurity.GetSecurityDescriptorBinaryForm();
                    pinningHandle = (object)GCHandle.Alloc((object)descriptorBinaryForm, GCHandleType.Pinned);

                    fixed(byte *numPtr = descriptorBinaryForm)
                    securityAttributes.pSecurityDescriptor = numPtr;
                }
            }
            return(securityAttributes);
        }
Example #2
0
        // AnonymousPipeServerStream owner;

        public unsafe Win32AnonymousPipeServer(AnonymousPipeServerStream owner, PipeDirection direction,
                                               HandleInheritability inheritability, int bufferSize,
                                               PipeSecurity pipeSecurity)
        {
            IntPtr r, w;

            byte[] securityDescriptor = null;
            if (pipeSecurity != null)
            {
                securityDescriptor = pipeSecurity.GetSecurityDescriptorBinaryForm();

                fixed(byte *securityDescriptorPtr = securityDescriptor)
                {
                    SecurityAttributes att = new SecurityAttributes(inheritability, (IntPtr)securityDescriptorPtr);

                    if (!Win32Marshal.CreatePipe(out r, out w, ref att, bufferSize))
                    {
                        throw Win32PipeError.GetException();
                    }
                }

                var rh = new SafePipeHandle(r, true);
                var wh = new SafePipeHandle(w, true);

                if (direction == PipeDirection.Out)
                {
                    server_handle = wh;
                    client_handle = rh;
                }
                else
                {
                    server_handle = rh;
                    client_handle = wh;
                }
        }
Example #3
0
 internal static unsafe Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, out object pinningHandle)
 {
     pinningHandle = null;
     Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES structure = null;
     if (((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None) || (pipeSecurity != null))
     {
         structure = new Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES {
             nLength = Marshal.SizeOf(structure)
         };
         if ((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None)
         {
             structure.bInheritHandle = 1;
         }
         if (pipeSecurity == null)
         {
             return(structure);
         }
         byte[] securityDescriptorBinaryForm = pipeSecurity.GetSecurityDescriptorBinaryForm();
         pinningHandle = GCHandle.Alloc(securityDescriptorBinaryForm, GCHandleType.Pinned);
         fixed(byte *numRef = securityDescriptorBinaryForm)
         {
             structure.pSecurityDescriptor = numRef;
         }
     }
     return(structure);
 }
Example #4
0
        internal static unsafe Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, ref GCHandle pinningHandle)
        {
            Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);

            if (pipeSecurity != null)
            {
                byte[] securityDescriptor = pipeSecurity.GetSecurityDescriptorBinaryForm();
                pinningHandle = GCHandle.Alloc(securityDescriptor, GCHandleType.Pinned);
                fixed(byte *pSecurityDescriptor = securityDescriptor)
                {
                    secAttrs.lpSecurityDescriptor = (IntPtr)pSecurityDescriptor;
                }
            }

            return(secAttrs);
        }
Example #5
0
        // .ctor without handle - create new
        public unsafe Win32NamedPipeServer(NamedPipeServerStream owner, string pipeName, int maxNumberOfServerInstances,
                                           PipeTransmissionMode transmissionMode, PipeAccessRights rights,
                                           PipeOptions options, int inBufferSize, int outBufferSize,
                                           PipeSecurity pipeSecurity, HandleInheritability inheritability)
        {
            string name = String.Format("\\\\.\\pipe\\{0}", pipeName);

            uint openMode;

            openMode = (uint)rights | (uint)options;             // Enum values match Win32 flags exactly.

            int pipeMode = 0;

            if ((owner.TransmissionMode & PipeTransmissionMode.Message) != 0)
            {
                pipeMode |= 4;
            }
            //if ((readTransmissionMode & PipeTransmissionMode.Message) != 0)
            //	pipeMode |= 2;
            if ((options & PipeOptions.Asynchronous) != 0)
            {
                pipeMode |= 1;
            }

            byte[] securityDescriptor = null;
            if (pipeSecurity != null)
                securityDescriptor = pipeSecurity.GetSecurityDescriptorBinaryForm();

            fixed(byte *securityDescriptorPtr = securityDescriptor)
            {
                // FIXME: is nDefaultTimeout = 0 ok?
                var att = new SecurityAttributes(inheritability, (IntPtr)securityDescriptorPtr);
                var ret = Win32Marshal.CreateNamedPipe(name, openMode, pipeMode, maxNumberOfServerInstances,
                                                       outBufferSize, inBufferSize, 0, ref att, IntPtr.Zero);

                if (ret == new IntPtr(-1L))
                {
                    throw Win32PipeError.GetException();
                }
                handle = new SafePipeHandle(ret, true);
            }
        }
Example #6
0
        internal static unsafe Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, ref GCHandle pinningHandle)
        {
            Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default(Interop.Kernel32.SECURITY_ATTRIBUTES);
            secAttrs.nLength = (uint)sizeof(Interop.Kernel32.SECURITY_ATTRIBUTES);

            if ((inheritability & HandleInheritability.Inheritable) != 0)
            {
                secAttrs.bInheritHandle = Interop.BOOL.TRUE;
            }

            if (pipeSecurity != null)
            {
                byte[] securityDescriptor = pipeSecurity.GetSecurityDescriptorBinaryForm();
                pinningHandle = GCHandle.Alloc(securityDescriptor, GCHandleType.Pinned);
                fixed(byte *pSecurityDescriptor = securityDescriptor)
                {
                    secAttrs.lpSecurityDescriptor = (IntPtr)pSecurityDescriptor;
                }
            }

            return(secAttrs);
        }
Example #7
0
        internal unsafe static UnsafeNativeMethods.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, out Object pinningHandle) {
            pinningHandle = null;
            UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = null;
            if ((inheritability & HandleInheritability.Inheritable) != 0 || pipeSecurity != null) {
                secAttrs = new UnsafeNativeMethods.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);

                if ((inheritability & HandleInheritability.Inheritable) != 0) {
                    secAttrs.bInheritHandle = 1;
                }

                // For ACLs, get the security descriptor from the PipeSecurity.
                if (pipeSecurity != null) {
                    byte[] sd = pipeSecurity.GetSecurityDescriptorBinaryForm();
                    pinningHandle = GCHandle.Alloc(sd, GCHandleType.Pinned);
                    fixed (byte* pSecDescriptor = sd) {
                        secAttrs.pSecurityDescriptor = pSecDescriptor;
                    }
                }
            }
            return secAttrs;
        }
Example #8
0
		// AnonymousPipeServerStream owner;

		public unsafe Win32AnonymousPipeServer (AnonymousPipeServerStream owner, PipeDirection direction,
							HandleInheritability inheritability, int bufferSize,
							PipeSecurity pipeSecurity)
		{
			IntPtr r, w;
			
			byte[] securityDescriptor = null;
			if (pipeSecurity != null)
				securityDescriptor = pipeSecurity.GetSecurityDescriptorBinaryForm ();
				
			fixed (byte* securityDescriptorPtr = securityDescriptor) {
				SecurityAttributes att = new SecurityAttributes (inheritability, (IntPtr)securityDescriptorPtr);
				if (!Win32Marshal.CreatePipe (out r, out w, ref att, bufferSize))
					throw Win32PipeError.GetException ();
			}

			var rh = new SafePipeHandle (r, true);
			var wh = new SafePipeHandle (w, true);

			if (direction == PipeDirection.Out) {
				server_handle = wh;
				client_handle = rh;
			} else {
				server_handle = rh;
				client_handle = wh;
			}
		}
Example #9
0
		// .ctor without handle - create new
		public unsafe Win32NamedPipeServer (NamedPipeServerStream owner, string pipeName, int maxNumberOfServerInstances,
						    PipeTransmissionMode transmissionMode, PipeAccessRights rights,
						    PipeOptions options, int inBufferSize, int outBufferSize,
						    PipeSecurity pipeSecurity, HandleInheritability inheritability)
		{
			string name = String.Format ("\\\\.\\pipe\\{0}", pipeName);

			uint openMode;
			openMode = (uint)rights | (uint)options; // Enum values match Win32 flags exactly.
			
			int pipeMode = 0;
			if ((owner.TransmissionMode & PipeTransmissionMode.Message) != 0)
				pipeMode |= 4;
			//if ((readTransmissionMode & PipeTransmissionMode.Message) != 0)
			//	pipeMode |= 2;
			if ((options & PipeOptions.Asynchronous) != 0)
				pipeMode |= 1;

			byte[] securityDescriptor = null;
			if (pipeSecurity != null)
				securityDescriptor = pipeSecurity.GetSecurityDescriptorBinaryForm ();
			
			fixed (byte* securityDescriptorPtr = securityDescriptor) {
				// FIXME: is nDefaultTimeout = 0 ok?
				var att = new SecurityAttributes (inheritability, (IntPtr)securityDescriptorPtr);
				var ret = Win32Marshal.CreateNamedPipe (name, openMode, pipeMode, maxNumberOfServerInstances,
									outBufferSize, inBufferSize, 0, ref att, IntPtr.Zero);
				if (ret == new IntPtr (-1L))
					throw Win32PipeError.GetException ();
				handle = new SafePipeHandle (ret, true);
			}
		}
 internal static unsafe Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability, PipeSecurity pipeSecurity, out object pinningHandle)
 {
     pinningHandle = null;
     Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES structure = null;
     if (((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None) || (pipeSecurity != null))
     {
         structure = new Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES {
             nLength = Marshal.SizeOf(structure)
         };
         if ((inheritability & HandleInheritability.Inheritable) != HandleInheritability.None)
         {
             structure.bInheritHandle = 1;
         }
         if (pipeSecurity == null)
         {
             return structure;
         }
         byte[] securityDescriptorBinaryForm = pipeSecurity.GetSecurityDescriptorBinaryForm();
         pinningHandle = GCHandle.Alloc(securityDescriptorBinaryForm, GCHandleType.Pinned);
         fixed (byte* numRef = securityDescriptorBinaryForm)
         {
             structure.pSecurityDescriptor = numRef;
         }
     }
     return structure;
 }