/// <summary>
		/// Sets security descriptor for given object
		/// </summary>
		public static void SetSecurity(
			string objectName,
			SecureObjectType objectType,
			SecurityInformationType securityInfo,
			SecurityDescriptor securityDescriptor)
		{
			// parameters validation
			if (objectName == null)
				throw new ArgumentNullException("objectName");
			if (securityDescriptor == null)
				throw new ArgumentNullException("securityDescriptor");

			// set security descriptor
			int error = SecurityNative.SetNamedSecurityInfo(
				objectName,
				(uint)objectType,
				(uint)securityInfo,
				securityDescriptor.Owner == null ? IntPtr.Zero : securityDescriptor.Owner.Handle,
				securityDescriptor.Group == null ? IntPtr.Zero : securityDescriptor.Group.Handle,
				securityDescriptor.DiscretionaryAcl == null ? IntPtr.Zero : securityDescriptor.DiscretionaryAcl.Handle,
				securityDescriptor.SystemAcl == null ? IntPtr.Zero : securityDescriptor.SystemAcl.Handle);

			if (error != Win32.ERROR_SUCCESS)
				throw new Win32Exception(error);
		}
Beispiel #2
0
		/// <summary>
		/// Creates pipe on the server side to allow client to connect to
		/// </summary>
		public void Bind(PipeName pipeName, SecurityDescriptor securityDescriptor)
		{
			// check object state
			if (_disposed)
				throw new ObjectDisposedException(GetType().FullName);
			if (_instance != null)
				throw new InvalidOperationException("Pipe is already connected");

			// store security descriptor
			_securityDescriptor = securityDescriptor;

			// create pipe
			_instance = PipeInstance.Create(pipeName, true, _securityDescriptor);
			_instancePool = new PipeInstancePool(this);
		}
		public void BindAuth(string url, SecurityDescriptor securityDescriptor)
		{
			_transport.BindAuth(url, securityDescriptor);
		}
		public void BindAuth(string url, SecurityDescriptor securityDescriptor)
		{
			throw new NotSupportedException();
		}
        /// <summary>
        /// Starts listening to network requests
        /// </summary>
        public void Start(int backLog, SecurityDescriptor securityDescriptor)
        {
            // check object state
            if (_disposed)
                throw new ObjectDisposedException(GetType().FullName);

            if (_transport == null)
            {
                ITransport transport = CreateTransport();
                transport.BindAuth(_url, securityDescriptor);
                transport.Listen(backLog);
                _transport = transport;
            }
        }
		public static PipeInstance Create(PipeName pipeName, bool firstInstance, SecurityDescriptor securityDescriptor)
		{
			// parameters validation
			if (pipeName == null)
				throw new ArgumentNullException("pipeName", "Pipe name must be specified");
			if (!pipeName.IsLocal)
				throw new ArgumentException("Could not bind to the remote pipe");

			PipeNative.SecurityAttributes secAttrs = new PipeNative.SecurityAttributes();
			secAttrs.SecurityDescriptor = (securityDescriptor == null ? IntPtr.Zero : securityDescriptor.Handle);
			secAttrs.InheritHandle = true;

			// try to create pipe
			IntPtr handle = PipeNative.CreateNamedPipe(pipeName.ToString(),
				PipeNative.PIPE_ACCESS_DUPLEX | PipeNative.FILE_FLAG_OVERLAPPED | (firstInstance ? PipeNative.FILE_FLAG_FIRST_PIPE_INSTANCE : 0),
				PipeNative.PIPE_TYPE_BYTE | PipeNative.PIPE_READMODE_BYTE | PipeNative.PIPE_WAIT,
				PipeNative.PIPE_UNLIMITED_INSTANCES,
				OutBufferSize,
				InBufferSize,
				PipeNative.NMPWAIT_USE_DEFAULT_WAIT,
				secAttrs);

			if (handle == Win32.InvalidHandle)
			{
				throw new PipeIOException(Marshal.GetLastWin32Error(), "Could not create pipe: " + pipeName);
			}
			else
			{
				return new PipeInstance(pipeName, handle, false);
			}
		}
		private void Initialize(IDictionary properties, IServerChannelSinkProvider sinkProvider)
		{
			if (properties != null)
			{
				// read property values
				foreach (DictionaryEntry property in properties)
				{
					switch ((string)property.Key)
					{
						case "name": _channelName = Convert.ToString(property.Value); break;
						case "priority": _channelPriority = Convert.ToInt32(property.Value); break;
						case "pipe": _pipe = Convert.ToString(property.Value); break;
						case "securityDescriptor": _securityDescriptor = (property.Value as SecurityDescriptor); break;
					}
				}
			}

			// setup pipe name
			_pipeName = new PipeName(@"\\.\pipe\" + _pipe);

			// create the chain of the sink providers that will process all messages
			_sinkProvider = ChannelHelper.ServerChannelCreateSinkProviderChain(sinkProvider);
			_channelData = ChannelHelper.ServerChannelCreateDataStore(ChannelUri, _sinkProvider);

			// create transport sink
			IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this);
			_transportSink = new ServerTransportSink(nextSink);

			// create listener thread
			_transportListener = new TransportListener(ChannelUri, typeof(PipeTransport));
			_listenerThread = new Thread(new ThreadStart(ListenerStart));
			_listenerThread.IsBackground = true;

			_requestHandler = new ProcessRequestCallback(_transportSink.ProcessRequest);

			// start listening on the channel
			StartListening(null);
		}
		public void BindAuth(string url, SecurityDescriptor securityDescriptor)
		{
			_pipe.Bind(GetPipeName(url), securityDescriptor);
			_url = url;
		}