예제 #1
0
        // This method calls a delegate while impersonating the client. Note that we will not have
        // access to the client's security token until it has written at least once to the pipe
        // (and has set its impersonationLevel argument appropriately).
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
        {
            CheckWriteOperations();
            ExecuteHelper execHelper      = new ExecuteHelper(impersonationWorker, InternalHandle);
            bool          exceptionThrown = true;

            try
            {
                ImpersonateAndTryCode(execHelper);
                exceptionThrown = false;
            }
            finally
            {
                RevertImpersonationOnBackout(execHelper, exceptionThrown);
            }

            // now handle win32 impersonate/revert specific errors by throwing corresponding exceptions
            if (execHelper._impersonateErrorCode != 0)
            {
                throw WinIOError(execHelper._impersonateErrorCode);
            }
            else if (execHelper._revertImpersonateErrorCode != 0)
            {
                throw WinIOError(execHelper._revertImpersonateErrorCode);
            }
        }
예제 #2
0
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// pipestreamimpersonationworker.BeginInvoke(callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this PipeStreamImpersonationWorker pipestreamimpersonationworker, AsyncCallback callback)
        {
            if (pipestreamimpersonationworker == null)
            {
                throw new ArgumentNullException("pipestreamimpersonationworker");
            }

            return(pipestreamimpersonationworker.BeginInvoke(callback, null));
        }
예제 #3
0
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
        {
            base.CheckWriteOperations();
            ExecuteHelper userData = new ExecuteHelper(impersonationWorker, base.InternalHandle);

            RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(tryCode, cleanupCode, userData);
            if (userData.m_impersonateErrorCode != 0)
            {
                base.WinIOError(userData.m_impersonateErrorCode);
            }
            else if (userData.m_revertImpersonateErrorCode != 0)
            {
                base.WinIOError(userData.m_revertImpersonateErrorCode);
            }
        }
예제 #4
0
        // This method calls a delegate while impersonating the client. Note that we will not have
        // access to the client's security token until it has written at least once to the pipe
        // (and has set its impersonationLevel argument appropriately).
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
        {
            CheckWriteOperations();
            ExecuteHelper execHelper = new ExecuteHelper(impersonationWorker, InternalHandle);

            RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(tryCode, cleanupCode, execHelper);

            // now handle win32 impersonate/revert specific errors by throwing corresponding exceptions
            if (execHelper._impersonateErrorCode != 0)
            {
                throw WinIOError(execHelper._impersonateErrorCode);
            }
            else if (execHelper._revertImpersonateErrorCode != 0)
            {
                throw WinIOError(execHelper._revertImpersonateErrorCode);
            }
        }
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        // This method calls a delegate while impersonating the client.
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
        {
            CheckWriteOperations();
            SafeHandle handle = InternalHandle?.NamedPipeSocketHandle;

            if (handle == null)
            {
                throw new InvalidOperationException(SR.InvalidOperation_PipeHandleNotSet);
            }
            // Get the current effective ID to fallback to after the impersonationWorker is run
            uint currentEUID = Interop.Sys.GetEUid();

            // Get the userid of the client process at the end of the pipe
            uint peerID;

            if (Interop.Sys.GetPeerID(handle, out peerID) == -1)
            {
                Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
                throw error.Error == Interop.Error.ENOTSUP ?
                      new PlatformNotSupportedException() :
                      Interop.GetExceptionForIoErrno(error, _path);
            }

            // set the effective userid of the current (server) process to the clientid
            if (Interop.Sys.SetEUid(peerID) == -1)
            {
                Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
                throw error.Error == Interop.Error.ENOTSUP ?
                      new PlatformNotSupportedException() :
                      Interop.GetExceptionForIoErrno(error, _path);
            }

            try
            {
                impersonationWorker();
            }
            finally
            {
                // set the userid of the current (server) process back to its original value
                Interop.Sys.SetEUid(currentEUID);
            }
        }
예제 #6
0
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        // This method calls a delegate while impersonating the client.
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
        {
            CheckWriteOperations();
            SafeHandle handle = InternalHandle?.NamedPipeSocketHandle;

            if (handle == null)
            {
                throw new InvalidOperationException(SR.InvalidOperation_PipeHandleNotSet);
            }
            // Get the current effective ID to fallback to after the impersonationWorker is run
            uint currentEUID = Interop.Sys.GetEUid();

            // Get the userid of the client process at the end of the pipe
            uint peerID;

            if (Interop.Sys.GetPeerID(handle, out peerID) == -1)
            {
                throw CreateExceptionForLastError(_instance?.PipeName);
            }

            // set the effective userid of the current (server) process to the clientid
            if (Interop.Sys.SetEUid(peerID) == -1)
            {
                throw CreateExceptionForLastError(_instance?.PipeName);
            }

            try
            {
                impersonationWorker();
            }
            finally
            {
                // set the userid of the current (server) process back to its original value
                Interop.Sys.SetEUid(currentEUID);
            }
        }
예제 #7
0
 internal ExecuteHelper(PipeStreamImpersonationWorker userCode, SafePipeHandle handle)
 {
     this.m_userCode = userCode;
     this.m_handle   = handle;
 }
예제 #8
0
  internal ExecuteHelper(PipeStreamImpersonationWorker userCode, SafePipeHandle handle) {
     m_userCode = userCode;
     m_handle = handle;
 }
예제 #9
0
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker) {
             CheckWriteOperations();
             ExecuteHelper execHelper = new ExecuteHelper(impersonationWorker, InternalHandle);
             RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(tryCode, cleanupCode, execHelper);

             // now handle win32 impersonate/revert specific errors by throwing corresponding exceptions
             if (execHelper.m_impersonateErrorCode != 0) {
                 WinIOError(execHelper.m_impersonateErrorCode);
             }
             else if (execHelper.m_revertImpersonateErrorCode != 0) {
                 WinIOError(execHelper.m_revertImpersonateErrorCode);
             }
        }
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
     base.CheckWriteOperations();
     ExecuteHelper userData = new ExecuteHelper(impersonationWorker, base.InternalHandle);
     RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(tryCode, cleanupCode, userData);
     if (userData.m_impersonateErrorCode != 0)
     {
         base.WinIOError(userData.m_impersonateErrorCode);
     }
     else if (userData.m_revertImpersonateErrorCode != 0)
     {
         base.WinIOError(userData.m_revertImpersonateErrorCode);
     }
 }
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
 }
예제 #12
0
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
     throw new NotImplementedException();
 }
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
 }
예제 #14
0
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
     throw new PlatformNotSupportedException();
 }
 /// <summary>
 /// Calls a delegate while impersonating the client.
 ///
 /// The client needs to set NamedPipeChannelOptions.ImpersonationLevel for this to work.
 /// </summary>
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
     _ctx.PipeStream.RunAsClient(impersonationWorker);
 }
 /// <inheritdoc />
 public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
 {
     Implementation.RunAsClient(impersonationWorker);
 }
예제 #17
0
		public void RunAsClient (PipeStreamImpersonationWorker impersonationWorker)
		{
			throw new NotImplementedException ();
		}
예제 #18
0
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        // This method calls a delegate while impersonating the client.
        public void RunAsClient(PipeStreamImpersonationWorker impersonationWorker)
        {
            CheckWriteOperations();
            SafeHandle handle = InternalHandle?.NamedPipeSocketHandle;
            if (handle == null)
            {
                throw new InvalidOperationException(SR.InvalidOperation_PipeHandleNotSet);
            }
            // Get the current effective ID to fallback to after the impersonationWorker is run
            uint currentEUID = Interop.Sys.GetEUid();

            // Get the userid of the client process at the end of the pipe
            uint peerID;
            if (Interop.Sys.GetPeerID(handle, out peerID) == -1)
            {
                Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
                throw error.Error == Interop.Error.ENOTSUP ?
                    new PlatformNotSupportedException() :
                    Interop.GetExceptionForIoErrno(error, _path);
            }

            // set the effective userid of the current (server) process to the clientid
            if (Interop.Sys.SetEUid(peerID) == -1)
            {
                Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
                throw error.Error == Interop.Error.ENOTSUP ?
                    new PlatformNotSupportedException() :
                    Interop.GetExceptionForIoErrno(error, _path);
            }

            try
            {
                impersonationWorker();
            }
            finally
            {
                // set the userid of the current (server) process back to its original value
                Interop.Sys.SetEUid(currentEUID);
            }
        }