Exemplo n.º 1
0
        public void TestClientAbandon()
        {
            Guid iid = Guid.NewGuid();
            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo client, byte[] arg)
                    { return arg; };

                {
                    var endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest");
                    ExplicitBytesClient client = new ExplicitBytesClient(iid, endpoingBinding);
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                    client = null;
                }

                GC.Collect(0, GCCollectionMode.Forced);
                GC.WaitForPendingFinalizers();

                server.StopListening();
            }
        }
Exemplo n.º 2
0
        public void RpcNamedPipe_WcfNamedPipe()
        {
            var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, "127.0.0.1", "test");
            var wcf             = EndpointMapper.RpcToWcf(endpointBinding);

            Assert.AreEqual("net.pipe://127.0.0.1/test", wcf);
        }
        public void TestClientCannotConnect()
        {
            var endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpc-endpoint-doesnt-exist");

            using (ExplicitBytesClient client = new ExplicitBytesClient(Guid.NewGuid(), endpoingBinding))
                client.Execute(new byte[0]);
        }
Exemplo n.º 4
0
 public void TestClientOnLocalRpc()
 {
     Guid iid = Guid.NewGuid();
     using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
     {
         server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
         server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
         server.StartListening();
         server.OnExecute +=
             delegate(IRpcCallInfo client, byte[] arg)
                 {
                     Assert.AreEqual(0, arg.Length);
                     Assert.AreEqual(RPC_C_AUTHN.RPC_C_AUTHN_WINNT, client.AuthenticationLevel);
                     Assert.AreEqual(RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, client.ProtectionLevel);
                     Assert.AreEqual(RpcProtoseqType.LRPC, client.ProtocolType);
                     Assert.AreEqual(new byte[0], client.ClientAddress);
                     Assert.AreEqual(System.Diagnostics.Process.GetCurrentProcess().Id, client.ClientPid.ToInt32());
                     Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetCurrent().Name, client.ClientPrincipalName);
                     Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetCurrent().Name, client.ClientUser.Name);
                     Assert.AreEqual(true, client.IsClientLocal);
                     Assert.AreEqual(true, client.IsAuthenticated);
                     Assert.AreEqual(false, client.IsImpersonating);
                     using(client.Impersonate())
                         Assert.AreEqual(true, client.IsImpersonating);
                     Assert.AreEqual(false, client.IsImpersonating);
                     return arg;
                 };
         var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest");
         using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
         {
             client.AuthenticateAs(ExplicitBytesClient.Self);
             client.Execute(new byte[0]);
         }
     }
 }
Exemplo n.º 5
0
        public void RpcLocalPipe_UriLocal()
        {
            var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "test");
            var wcf             = EndpointMapper.RpcToWcf(endpointBinding);

            Assert.AreEqual("ipc:///test", wcf);
        }
        public void TestPropertyProtocol()
        {
            var endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, null, "123");

            using (ExplicitBytesClient client = new ExplicitBytesClient(Guid.NewGuid(), endpoingBinding))
                Assert.AreEqual(RpcProtseq.ncacn_ip_tcp, client.Protocol);
        }
Exemplo n.º 7
0
        public static string RpcToWcf(EndpointBindingInfo bindingInfo)
        {
            if (bindingInfo.Protseq == RpcProtseq.ncacn_ip_tcp)
            {
                return(new UriBuilder(Uri.UriSchemeNetTcp, bindingInfo.NetworkAddr, Int32.Parse(bindingInfo.EndPoint)).Uri.ToString());
            }
            if (bindingInfo.Protseq == RpcProtseq.ncalrpc)
            {
                var path = bindingInfo.EndPoint;

                var builder = new UriBuilder(UriSchemeIpc, null);
                builder.Path = path;
                //TODO: use builder to build with empty host ///
                //builder.Host = string.Empty;
                //return builder.Uri.ToString();
                string local = ":///";
                return(builder.Scheme + local + builder.Path);
            }
            if (bindingInfo.Protseq == RpcProtseq.ncacn_np)
            {
                var path    = bindingInfo.EndPoint.Replace(@"\pipe", string.Empty).Replace("\\", "/");
                var builder = new UriBuilder(Uri.UriSchemeNetPipe, bindingInfo.NetworkAddr);
                builder.Path = path;
                return(builder.Uri.ToString());
            }
            throw new NotImplementedException(bindingInfo.Protseq + " not implemented");
        }
        public void TestUnregisterListener()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcExecuteHandler handler =
                    delegate(IRpcCallInfo client, byte[] arg)
                { return(arg); };
                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);

                    server.OnExecute += handler;
                    client.Execute(new byte[0]);

                    server.OnExecute -= handler;
                    try
                    {
                        client.Execute(new byte[0]);
                        Assert.Fail();
                    }
                    catch (RpcException)
                    { }
                }
            }
        }
Exemplo n.º 9
0
        public static string RpcToWcf(EndpointBindingInfo bindingInfo)
        {
            if (bindingInfo.Protseq == RpcProtseq.ncacn_ip_tcp)
            {
                return new UriBuilder(Uri.UriSchemeNetTcp, bindingInfo.NetworkAddr, Int32.Parse(bindingInfo.EndPoint)).Uri.ToString();
            }
            if (bindingInfo.Protseq == RpcProtseq.ncalrpc)
            {

                var path = bindingInfo.EndPoint;

                var builder = new UriBuilder(UriSchemeIpc,null);
                builder.Path = path;
                //TODO: use builder to build with empty host ///
                //builder.Host = string.Empty;
                //return builder.Uri.ToString();
                string local = ":///";
                return builder.Scheme + local + builder.Path;
            }
            if (bindingInfo.Protseq == RpcProtseq.ncacn_np)
            {
                var path = bindingInfo.EndPoint.Replace(@"\pipe", string.Empty).Replace("\\", "/");
                var builder = new UriBuilder(Uri.UriSchemeNetPipe, bindingInfo.NetworkAddr);
                builder.Path = path;
                return builder.Uri.ToString();
            }
            throw new NotImplementedException(bindingInfo.Protseq + " not implemented");
        }
Exemplo n.º 10
0
        public void ClientSecurityCallbackCalled()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_ip_tcp, "18080", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo clientInfo, byte[] arg)
                {
                    return(arg);
                };


                var  endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, "127.0.0.1", "18080");
                bool securityCalled  = false;
                using (var client = new ExplicitBytesClient(iid, endpoingBinding)) {
                    var authCallback = new FunctionPtr <RPC_C_SECURITY_CALLBACK>(x => {
                        securityCalled         = true;
                        IntPtr securityContext = IntPtr.Zero;
                        var getSecurityStatus  = NativeMethods.I_RpcBindingInqSecurityContext(x, out securityContext);
                        Assert.AreEqual(RPC_STATUS.RPC_S_OK, getSecurityStatus);
                        Assert.AreNotEqual(IntPtr.Zero, securityContext);
                    });
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                    var setStatus = NativeMethods.RpcBindingSetOption(client.Handle, (uint)RpcBindingOptions.RPC_C_OPT_SECURITY_CALLBACK, authCallback.Handle);
                    Assert.AreEqual(RPC_STATUS.RPC_S_OK, setStatus);
                    client.Execute(new byte[0]);
                }
                Assert.IsTrue(securityCalled);
            }
        }
        private void CreateRpcConnection(string server, RpcProtocol protocol, NetworkCredential credential = null)
        {
            EndpointBindingInfo binding;

            switch (protocol)
            {
            case RpcProtocol.TCP:
                binding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, server, null);
                break;

            case RpcProtocol.SMB:
                binding = new EndpointBindingInfo(RpcProtseq.ncacn_np, server, DrsNamedPipeName);
                if (credential != null)
                {
                    // Connect named pipe
                    this.npConnection = new NamedPipeConnection(server, credential);
                }
                break;

            default:
                // TODO: Extract as string
                throw new NotImplementedException("The requested RPC protocol is not supported.");
            }
            this.rpcConnection = new NativeClient(binding);

            NetworkCredential rpcCredential = credential ?? Client.Self;
            string            spn           = String.Format(ServicePrincipalNameFormat, server);

            this.rpcConnection.AuthenticateAs(spn, rpcCredential, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_GSS_NEGOTIATE);
        }
Exemplo n.º 12
0
        public void TestNestedClientImpersonate()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo client, byte[] arg)
                {
                    Assert.AreEqual(false, client.IsImpersonating);
                    using (client.Impersonate())
                    {
                        Assert.AreEqual(true, client.IsImpersonating);
                        using (client.Impersonate())
                            Assert.AreEqual(true, client.IsImpersonating);
                        //does not dispose, we are still impersonating
                        Assert.AreEqual(true, client.IsImpersonating);
                    }
                    Assert.AreEqual(false, client.IsImpersonating);
                    return(arg);
                };
                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, null, @"\pipe\testpipename");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(ExplicitBytesClient.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
Exemplo n.º 13
0
        private void CreateRpcConnection(string server, RpcProtocol protocol, NetworkCredential credential = null)
        {
            EndpointBindingInfo binding;

            switch (protocol)
            {
            case RpcProtocol.TCP:
                binding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, server, null);
                break;

            case RpcProtocol.SMB:
                binding = new EndpointBindingInfo(RpcProtseq.ncacn_np, server, DrsNamedPipeName);
                if (credential != null)
                {
                    // Connect named pipe
                    this.npConnection = new NamedPipeConnection(server, credential);
                }
                break;

            default:
                // TODO: Custom exception type
                // TODO: Extract as string
                throw new Exception("Unsupported RPC protocol");
            }
            NetworkCredential rpcCredential = credential ?? Client.Self;

            this.rpcConnection = new NativeClient(binding);
            this.rpcConnection.AuthenticateAs(rpcCredential);
        }
Exemplo n.º 14
0
        public void ClientSecurityCallbackCalled()
        {
            Guid iid = Guid.NewGuid();
            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_ip_tcp, "18080", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo clientInfo, byte[] arg)
                {
                    return arg;
                };

                var endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, "127.0.0.1", "18080");
                bool securityCalled = false;
                using (var client = new ExplicitBytesClient (iid, endpoingBinding)) {

                    var authCallback = new FunctionPtr<RPC_C_SECURITY_CALLBACK>(x=>{
                        securityCalled = true;
                        IntPtr securityContext = IntPtr.Zero;
                        var getSecurityStatus = NativeMethods.I_RpcBindingInqSecurityContext(x, out securityContext);
                        Assert.AreEqual (RPC_STATUS.RPC_S_OK, getSecurityStatus);
                        Assert.AreNotEqual(IntPtr.Zero,securityContext);
                    });
                    client.AuthenticateAs (null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                    var setStatus = NativeMethods.RpcBindingSetOption (client.Handle, (uint)RpcBindingOptions.RPC_C_OPT_SECURITY_CALLBACK, authCallback.Handle);
                    Assert.AreEqual (RPC_STATUS.RPC_S_OK, setStatus);
                    client.Execute (new byte[0]);

                }
                Assert.IsTrue (securityCalled);

            }
        }
Exemplo n.º 15
0
        public void TestClientAbandon()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo client, byte[] arg)
                { return(arg); };

                {
                    var endpoingBinding        = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest");
                    ExplicitBytesClient client = new ExplicitBytesClient(iid, endpoingBinding);
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                    client = null;
                }

                GC.Collect(0, GCCollectionMode.Forced);
                GC.WaitForPendingFinalizers();

                server.StopListening();
            }
        }
Exemplo n.º 16
0
        public void TestErrorsNoServerListening()
        {
            var endPointName = Implementer + DateTime.Now.Ticks;

            var endpointBindingInfo = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, endPointName);


            var client = new NativeClient(endpointBindingInfo);

            CallErrorHandlingServer(client.Binding);
        }
Exemplo n.º 17
0
        public NativeClient(EndpointBindingInfo info)
            : base(info)
        {
            //string szStringBinding = Client.StringBindingCompose(clientInfo, null);

            //IntPtr bindingHandle;
            //status = NativeMethods.RpcBindingFromStringBinding(
            //   szStringBinding, // The string binding to validate.
            //   out bindingHandle); // Put the result in the explicit binding handle.

            //_handle = GCHandle.Alloc(bindingHandle, GCHandleType.Pinned);
            //Guard.Assert(status);
        }
Exemplo n.º 18
0
        public NativeClient(EndpointBindingInfo info) : base(info)
        {
            //string szStringBinding = Client.StringBindingCompose(clientInfo, null);

            //IntPtr bindingHandle;
            //status = NativeMethods.RpcBindingFromStringBinding(
            //   szStringBinding, // The string binding to validate.
            //   out bindingHandle); // Put the result in the explicit binding handle.


            //_handle = GCHandle.Alloc(bindingHandle, GCHandleType.Pinned);
            //Guard.Assert(status);
        }
Exemplo n.º 19
0
        public void TestCppExceptions()
        {
            var server = GetErrorHandlingServer();

            var serverInterface = (RPC_SERVER_INTERFACE)Marshal.PtrToStructure(server, typeof(RPC_SERVER_INTERFACE));
            var endPointName = Implementer + DateTime.Now.Ticks + serverInterface.InterfaceId.SyntaxGUID.ToString("N");

            var endpointBindingInfo = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, endPointName);

            NativeHost.StartServer(endpointBindingInfo, server);

            RPC_STATUS status;

            var client = new NativeClient(endpointBindingInfo);
            CallErrorThrowingServer(client.Binding);
        }
 private static string CanonizeEndpoint(EndpointBindingInfo endpointBinding)
 {
     var endpoint = endpointBinding.EndPoint;
     // Windows XP has restiction on names of local transport
        //  RPC_S_STRING_TOO_LONG is thrown on XP, but not 7
        // http://msdn.microsoft.com/en-us/library/windows/desktop/aa367115.aspx
        //so generating GUID for each
     if (endpointBinding.Protseq == RpcProtseq.ncalrpc
         && Environment.OSVersion.Platform == PlatformID.Win32NT
         && Environment.OSVersion.Version.Major < 6
         )
     {
         //hope will not clash on Windows, can leave part of old one, but need to find out limits
         endpoint = "NET"+GuidUtility.Create(EndpointMapper.RpcNamespace, endpoint).ToString("N");
     }
     return endpoint;
 }
Exemplo n.º 21
0
        public void TestCppExceptions()
        {
            var server = GetErrorHandlingServer();

            var serverInterface = (RPC_SERVER_INTERFACE)Marshal.PtrToStructure(server, typeof(RPC_SERVER_INTERFACE));
            var endPointName    = Implementer + DateTime.Now.Ticks + serverInterface.InterfaceId.SyntaxGUID.ToString("N");

            var endpointBindingInfo = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, endPointName);

            NativeHost.StartServer(endpointBindingInfo, server);

            RPC_STATUS status;

            var client = new NativeClient(endpointBindingInfo);

            CallErrorThrowingServer(client.Binding);
        }
Exemplo n.º 22
0
        public void TestCallback()
        {
            var server = GetExplicitWithCallbacksServer();

            var endPointName =Implementer + DateTime.Now.Ticks;

            var serverInterface = (RPC_SERVER_INTERFACE)Marshal.PtrToStructure(server, typeof(RPC_SERVER_INTERFACE));

            var endpointBindingInfo = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, endPointName);

            NativeHost.StartServer(endpointBindingInfo, server);

            RPC_STATUS status;

            var client = new NativeClient(endpointBindingInfo);
            CallExplicitWithCallbacksServer(client.Binding);
        }
        private static string CanonizeEndpoint(EndpointBindingInfo endpointBinding)
        {
            var endpoint = endpointBinding.EndPoint;

            // Windows XP has restiction on names of local transport
            //  RPC_S_STRING_TOO_LONG is thrown on XP, but not 7
            // http://msdn.microsoft.com/en-us/library/windows/desktop/aa367115.aspx
            //so generating GUID for each
            if (endpointBinding.Protseq == RpcProtseq.ncalrpc &&
                Environment.OSVersion.Platform == PlatformID.Win32NT &&
                Environment.OSVersion.Version.Major < 6
                )
            {
                //hope will not clash on Windows, can leave part of old one, but need to find out limits
                endpoint = "NET" + GuidUtility.Create(EndpointMapper.RpcNamespace, endpoint).ToString("N");
            }
            return(endpoint);
        }
Exemplo n.º 24
0
        public static NativeServer StartServer(EndpointBindingInfo info, IntPtr dummyPtr, IntPtr mgrTypeUuid, IntPtr mgrEpv)
        {
            var server = new NativeServer(dummyPtr, mgrTypeUuid, mgrEpv);

            server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_NONE);
            server.AddProtocol(info.Protseq, info.EndPoint, NativeServer.MAX_CALL_LIMIT);
            server.StartListening();
            return(server);
            //TODO: make server isolated of other process services, make it not static as possible
            //    RPC_STATUS status;
            //    status = NDceRpc.Interop.NativeMethods.RpcServerUseProtseqEp(
            //        info.Protseq.ToString(),
            //        NDceRpc.Interop.CONSTANTS.RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
            //        info.EndPoint,
            //        IntPtr.Zero); // No security.

            //    Guard.Assert(status);
            //    RPC_IF_CALLBACK_FN securityCallback = SecurityCallback;

            //    Guid guid = Guid.Empty;
            //    status = NativeMethods.RpcServerRegisterIf2(
            //        dummyPtr,
            //        ref guid, // Use the MIDL generated entry-point vector.
            //        IntPtr.Zero, // Use the MIDL generated entry-point vector.
            //        (uint)InterfacRegistrationFlags.RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback.
            //        CONSTANTS.RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls.
            //        int.MaxValue, // Infinite max size of incoming data blocks.
            //        ref securityCallback); // Naive security callback.
            //    _pinned.Add(securityCallback);
            //    Guard.Assert(status);


            //    // Start to listen for remote procedure
            //    // calls for all registered interfaces.
            //    // This call will not return until
            //    // RpcMgmtStopServerListening is called.
            //    status = NativeMethods.RpcServerListen(
            //        1, // Recommended minimum number of threads.
            //        CONSTANTS.RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended maximum number of threads.
            //        1); // Start listening now.

            //    if (status == RPC_STATUS.RPC_S_ALREADY_LISTENING) return;
            //    Guard.Assert(status);
        }
Exemplo n.º 25
0
        public static NativeServer StartServer(EndpointBindingInfo info, IntPtr dummyPtr, IntPtr mgrTypeUuid, IntPtr mgrEpv)
        {
            var server = new NativeServer(dummyPtr, mgrTypeUuid, mgrEpv);
            server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_NONE);
            server.AddProtocol(info.Protseq,info.EndPoint,NativeServer.MAX_CALL_LIMIT);
            server.StartListening();
            return server;
            //TODO: make server isolated of other process services, make it not static as possible
            //    RPC_STATUS status;
            //    status = NDceRpc.Interop.NativeMethods.RpcServerUseProtseqEp(
            //        info.Protseq.ToString(),
            //        NDceRpc.Interop.CONSTANTS.RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
            //        info.EndPoint,
            //        IntPtr.Zero); // No security.

            //    Guard.Assert(status);
            //    RPC_IF_CALLBACK_FN securityCallback = SecurityCallback;

            //    Guid guid = Guid.Empty;
            //    status = NativeMethods.RpcServerRegisterIf2(
            //        dummyPtr,
            //        ref guid, // Use the MIDL generated entry-point vector.
            //        IntPtr.Zero, // Use the MIDL generated entry-point vector.
            //        (uint)InterfacRegistrationFlags.RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH, // Forces use of security callback.
            //        CONSTANTS.RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Use default number of concurrent calls.
            //        int.MaxValue, // Infinite max size of incoming data blocks.
            //        ref securityCallback); // Naive security callback.
            //    _pinned.Add(securityCallback);
            //    Guard.Assert(status);

            //    // Start to listen for remote procedure
            //    // calls for all registered interfaces.
            //    // This call will not return until
            //    // RpcMgmtStopServerListening is called.
            //    status = NativeMethods.RpcServerListen(
            //        1, // Recommended minimum number of threads.
            //        CONSTANTS.RPC_C_LISTEN_MAX_CALLS_DEFAULT, // Recommended maximum number of threads.
            //        1); // Start listening now.

            //    if (status == RPC_STATUS.RPC_S_ALREADY_LISTENING) return;
            //    Guard.Assert(status);
        }
Exemplo n.º 26
0
        public void TestCallback()
        {
            var server = GetExplicitWithCallbacksServer();

            var endPointName = Implementer + DateTime.Now.Ticks;

            var serverInterface = (RPC_SERVER_INTERFACE)Marshal.PtrToStructure(server, typeof(RPC_SERVER_INTERFACE));

            var endpointBindingInfo = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, endPointName);

            NativeHost.StartServer(endpointBindingInfo, server);



            RPC_STATUS status;


            var client = new NativeClient(endpointBindingInfo);

            CallExplicitWithCallbacksServer(client.Binding);
        }
Exemplo n.º 27
0
        public void TestClientOnAnonymousPipe()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_NONE);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo client, byte[] arg)
                {
                    Assert.AreEqual(0, arg.Length);
                    Assert.AreEqual(RPC_C_AUTHN.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
                    Assert.AreEqual(RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_NONE, client.ProtectionLevel);
                    Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
                    Assert.AreEqual(new byte[0], client.ClientAddress);
                    Assert.AreEqual(0, client.ClientPid.ToInt32());
                    Assert.AreEqual(null, client.ClientPrincipalName);
                    Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetAnonymous().Name, client.ClientUser.Name);
                    Assert.AreEqual(true, client.IsClientLocal);
                    Assert.AreEqual(false, client.IsAuthenticated);
                    Assert.AreEqual(false, client.IsImpersonating);

                    bool failed = false;
                    try { client.Impersonate().Dispose(); }
                    catch (UnauthorizedAccessException) { failed = true; }
                    Assert.AreEqual(true, failed);
                    return(arg);
                };

                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, null, @"\pipe\testpipename");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(ExplicitBytesClient.Anonymous);
                    client.Execute(new byte[0]);
                }
            }
        }
Exemplo n.º 28
0
        public void TestClientOnAnonymousPipe()
        {
            Guid iid = Guid.NewGuid();
            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_NONE);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo client, byte[] arg)
                    {
                        Assert.AreEqual(0, arg.Length);
                        Assert.AreEqual(RPC_C_AUTHN.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
                        Assert.AreEqual(RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_NONE, client.ProtectionLevel);
                        Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
                        Assert.AreEqual(new byte[0], client.ClientAddress);
                        Assert.AreEqual(0, client.ClientPid.ToInt32());
                        Assert.AreEqual(null, client.ClientPrincipalName);
                        Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetAnonymous().Name, client.ClientUser.Name);
                        Assert.AreEqual(true, client.IsClientLocal);
                        Assert.AreEqual(false, client.IsAuthenticated);
                        Assert.AreEqual(false, client.IsImpersonating);

                        bool failed = false;
                        try { client.Impersonate().Dispose(); }
                        catch (UnauthorizedAccessException) { failed = true; }
                        Assert.AreEqual(true, failed);
                        return arg;
                    };

                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, null, @"\pipe\testpipename");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(ExplicitBytesClient.Anonymous);
                    client.Execute(new byte[0]);
                }
            }
        }
Exemplo n.º 29
0
        public void TestClientOnNamedPipe()
        {
            Guid iid = Guid.NewGuid();

            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcCallInfo client, byte[] arg)
                {
                    Assert.AreEqual(0, arg.Length);
                    Assert.AreEqual(RPC_C_AUTHN.RPC_C_AUTHN_WINNT, client.AuthenticationLevel);
                    Assert.AreEqual(RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, client.ProtectionLevel);
                    Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
                    Assert.AreEqual(new byte[0], client.ClientAddress);
                    Assert.AreEqual(0, client.ClientPid.ToInt32());
                    Assert.AreEqual(String.Empty, client.ClientPrincipalName);
                    Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetCurrent().Name, client.ClientUser.Name);
                    Assert.AreEqual(true, client.IsClientLocal);
                    Assert.AreEqual(true, client.IsAuthenticated);
                    Assert.AreEqual(false, client.IsImpersonating);
                    using (client.Impersonate())
                        Assert.AreEqual(true, client.IsImpersonating);
                    Assert.AreEqual(false, client.IsImpersonating);
                    return(arg);
                };

                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, null, @"\pipe\testpipename");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(ExplicitBytesClient.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
Exemplo n.º 30
0
        public void TestUnregisterListener()
        {
            Guid iid = Guid.NewGuid();
            using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcExecuteHandler handler =
                    delegate(IRpcCallInfo client, byte[] arg)
                    { return arg; };
                var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpctest");
                using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
                {
                    client.AuthenticateAs(null, ExplicitBytesClient.Self, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_WINNT);

                    server.OnExecute += handler;
                    client.Execute(new byte[0]);

                    server.OnExecute -= handler;
                    try
                    {
                        client.Execute(new byte[0]);
                        Assert.Fail();
                    }
                    catch (RpcException)
                    { }
                }
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// Connects to the provided server interface with the given protocol and server:endpoint
 /// </summary>
 public ExplicitBytesClient(Guid iid, EndpointBindingInfo endpointBindingInfo)
     : base(endpointBindingInfo)
 {
     IID = iid;
 }
Exemplo n.º 32
0
 /// <summary>
 /// Connects to the provided server interface with the given protocol and server:endpoint
 /// </summary>
 public ExplicitBytesClient(Guid iid, EndpointBindingInfo endpointBindingInfo) : base(endpointBindingInfo)
 {
     IID = iid;
 }
Exemplo n.º 33
0
 public void RpcNamedPipe_WcfNamedPipe()
 {
     var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, "127.0.0.1", "test");
     var wcf = EndpointMapper.RpcToWcf(endpointBinding);
     Assert.AreEqual("net.pipe://127.0.0.1/test", wcf);
 }
Exemplo n.º 34
0
 public void RpcLocalPipe_UriLocal()
 {
     var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "test");
     var wcf = EndpointMapper.RpcToWcf(endpointBinding);
     Assert.AreEqual("ipc:///test", wcf);
 }
Exemplo n.º 35
0
        public void TestErrorsNoServerListening()
        {
            var endPointName = Implementer + DateTime.Now.Ticks;

            var endpointBindingInfo = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, endPointName);

            var client = new NativeClient(endpointBindingInfo);
            CallErrorHandlingServer(client.Binding);
        }
Exemplo n.º 36
0
 public static NativeServer StartServer(EndpointBindingInfo info, IntPtr dummyPtr)
 {
     return StartServer(info, dummyPtr, IntPtr.Zero,  IntPtr.Zero);
 }
Exemplo n.º 37
0
 public void TestNestedClientImpersonate()
 {
     Guid iid = Guid.NewGuid();
     using (ExplicitBytesServer server = new ExplicitBytesServer(iid))
     {
         server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
         server.AddAuthentication(RPC_C_AUTHN.RPC_C_AUTHN_WINNT);
         server.StartListening();
         server.OnExecute +=
             delegate(IRpcCallInfo client, byte[] arg)
             {
                 Assert.AreEqual(false, client.IsImpersonating);
                 using (client.Impersonate())
                 {
                     Assert.AreEqual(true, client.IsImpersonating);
                     using (client.Impersonate())
                         Assert.AreEqual(true, client.IsImpersonating);
                     //does not dispose, we are still impersonating
                     Assert.AreEqual(true, client.IsImpersonating);
                 }
                 Assert.AreEqual(false, client.IsImpersonating);
                 return arg;
             };
         var endpointBinding = new EndpointBindingInfo(RpcProtseq.ncacn_np, null, @"\pipe\testpipename");
         using (ExplicitBytesClient client = new ExplicitBytesClient(iid, endpointBinding))
         {
             client.AuthenticateAs(ExplicitBytesClient.Self);
             client.Execute(new byte[0]);
         }
     }
 }
Exemplo n.º 38
0
 public void TestClientCannotConnect()
 {
     var endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncalrpc, null, "lrpc-endpoint-doesnt-exist");
     using (ExplicitBytesClient client = new ExplicitBytesClient(Guid.NewGuid(), endpoingBinding))
         client.Execute(new byte[0]);
 }
Exemplo n.º 39
0
 public void TestPropertyProtocol()
 {
     var endpoingBinding = new EndpointBindingInfo(RpcProtseq.ncacn_ip_tcp, null, "123");
     using (ExplicitBytesClient client = new ExplicitBytesClient(Guid.NewGuid(), endpoingBinding))
         Assert.AreEqual(RpcProtseq.ncacn_ip_tcp, client.Protocol);
 }
Exemplo n.º 40
0
 public static NativeServer StartServer(EndpointBindingInfo info, IntPtr dummyPtr)
 {
     return(StartServer(info, dummyPtr, IntPtr.Zero, IntPtr.Zero));
 }