예제 #1
0
        public void TestUnregisterListener()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcServerApi.RpcExecuteHandler handler = 
                    delegate(IRpcClientInfo client, byte[] arg)
                    { return arg; };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.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)
                    { }
                }
            }
        }
예제 #2
0
        public void TestPerformanceOnLocalRpc()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    { return arg; };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);

                    byte[] bytes = new byte[512];
                    new Random().NextBytes(bytes);

                    Stopwatch timer = new Stopwatch();
                    timer.Start();

                    for (int i = 0; i < 10000; i++)
                        client.Execute(bytes);

                    timer.Stop();
                    Trace.WriteLine(timer.ElapsedMilliseconds.ToString(), "ncalrpc-timming");
                }
            }
        }
        public void TestUnregisterListener()
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                RpcServerApi.RpcExecuteHandler handler =
                    delegate(IRpcClientInfo client, byte[] arg)
                { return(arg); };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.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)
                    { }
                }
            }
        }
예제 #4
0
        public void TestPerformanceOnLocalRpc()
        {
            Guid iid = Guid.NewGuid();

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

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);

                    byte[] bytes = new byte[512];
                    new Random().NextBytes(bytes);

                    Stopwatch timer = new Stopwatch();
                    timer.Start();

                    for (int i = 0; i < 10000; i++)
                    {
                        client.Execute(bytes);
                    }

                    timer.Stop();
                    Trace.WriteLine(timer.ElapsedMilliseconds.ToString(), "ncalrpc-timming");
                }
            }
        }
예제 #5
0
        void f_sendData()
        {
            client.Execute(new byte[1] {
                0xEC
            });

            // Send the request and get a response
            try
            {
                for (int i = 0; i < 3; i++)
                {
                    var response = client.Execute(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
                    Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));
                }

                //client.Execute(new byte[0]);

                //byte[] bytes = new byte[1 * 1024 * 1024]; //1mb in/out
                //new Random().NextBytes(bytes);

                //Stopwatch stopWatch = new Stopwatch();
                //stopWatch.Start();

                //for (int i = 0; i < 2; i++)
                //    client.Execute(bytes);

                //stopWatch.Stop();
                //TimeSpan ts = stopWatch.Elapsed;
                //string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
                //Console.WriteLine(elapsedTime + " ncalrpc-large-timming");
            }
            catch (RpcException rx)
            {
                if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                {
                    //Use a wait handle if your on the same box...
                    Console.Error.WriteLine("Waiting for server...");
                    Thread.Sleep(1000);
                }
                else
                {
                    Console.Error.WriteLine(rx);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
        }
예제 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            subscribeEvent();

            var request = new Rpc.Event.Protocol.Request()
            {
                value = ++number
            };

            try
            {
                client.Execute(request.toByteArray());
            }
            catch (RpcException ex)
            {
                if (RpcError.RPC_S_SERVER_UNAVAILABLE == ex.RpcError || RpcError.RPC_S_SERVER_TOO_BUSY == ex.RpcError)
                {
                    textBox1.AppendText(String.Format("RPC Server Unavailable, Error={0}\r\n", ex));
                }
                else
                {
                    throw;
                }
            }
        }
        public void TestClientAbandon()
        {
            var iid = Guid.NewGuid();

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

                {
                    RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest");
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                    client = null;
                }

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

                server.StopListening();
            }
        }
        public void TestClientOnLocalRpc()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                        {
                            Assert.AreEqual(0, arg.Length);
                            Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_WINNT, client.AuthenticationLevel);
                            Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_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;
                        };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            var iid = Guid.NewGuid();

            using (var server = new RpcServerApi(iid, 1234, -1, true))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.StartListening();
                Console.WriteLine("Is listening");
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    string tmp = "";
                    return(new byte[0]);
                };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    // client.AuthenticateAs(RpcClientApi.Self);
                    byte[] response = client.Execute(new byte[0]);
                }
                Console.ReadLine();
                string s = "";
            }
        }
예제 #10
0
        public void TestClientAbandon()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncalrpc, "lrpctest", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    { return arg; };

                {
                    RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "lrpctest");
                    client.AuthenticateAs(null, RpcClientApi.Self, RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY, RpcAuthentication.RPC_C_AUTHN_WINNT);
                    client.Execute(new byte[0]);
                    client = null;
                }

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

                server.StopListening();
            }
        }
        public void TestNestedClientImpersonate()
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo 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);
                };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
예제 #12
0
        static void Main(string[] args)
        {
            RpcLibrary.Log.VerboseEnabled = true;
            // The client and server must agree on the interface id to use:
            var iid = new Guid("{f4db45dc-0dcb-4003-b680-56c40f6cb6a8}");

            bool attempt = true;

            while (attempt)
            {
                attempt = false;
                // Open the connection based on the endpoint information and interface IID
                using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "1234"))
                //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
                {
                    // Provide authentication information (not nessessary for LRPC)
                    client.AuthenticateAs(RpcClientApi.Self);

                    // Send the request and get a response
                    try
                    {
                        var response = client.Execute(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetings" : args[0]));
                        Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));

                        var task = client.ExecuteAsync(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetines" : args[0])).
                                   ContinueWith <String>(r =>
                        {
                            return(Encoding.UTF8.GetString(r.Result.response));
                        });

                        task.Wait();

                        Console.WriteLine("Server response by async way: {0}", task.Result);
                    }
                    catch (RpcException rx)
                    {
                        if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                        {
                            //Use a wait handle if your on the same box...
                            Console.Error.WriteLine("Waiting for server...");
                            System.Threading.Thread.Sleep(1000);
                            attempt = true;
                        }
                        else
                        {
                            Console.Error.WriteLine(rx);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                    }
                }
            }
            // done...
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
예제 #13
0
        static byte[] Execute(RpcClientApi client, Stream stream)
        {
            byte[] buffer = new byte[stream.Length];

            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(buffer, 0, buffer.Length);

            return(client.Execute(buffer));
        }
예제 #14
0
        public override void Initialize(IEventSource eventSource)
        {
            if (eventSource == null)
            {
                return;
            }

            var p = Parameters.Split(';');

            if (p.Length < 2)
            {
                throw new Exception("Requires at least pipeName and guid");
            }

            var pipeName = p[0];
            var iid      = new Guid(p[1]);

            _client     = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, pipeName);
            messagePump = Task.Factory.StartNew(() => {
                try {
                    BuildMessage msg;

                    while (!stop || _messages.Count > 0)
                    {
                        if (_messages.TryDequeue(out msg))
                        {
                            var result = _client.Execute(msg.ToByteArray());
                            if (result.Length > 0 && result[1] == 0x01)
                            {
                                // we've been asked to kill ourselves.
                                stop = true;
                            }
                            continue;
                        }
                        Thread.Sleep(5);
                    }
                }
                finally {
                    stop = true;
                }
            }, TaskCreationOptions.LongRunning);

            eventSource.BuildFinished     += eventSource_BuildFinished;
            eventSource.BuildStarted      += eventSource_BuildStarted;
            eventSource.CustomEventRaised += eventSource_CustomEventRaised;
            eventSource.ErrorRaised       += eventSource_ErrorRaised;
            eventSource.MessageRaised     += eventSource_MessageRaised;
            eventSource.ProjectFinished   += eventSource_ProjectFinished;
            eventSource.ProjectStarted    += eventSource_ProjectStarted;
            //eventSource.StatusEventRaised += eventSource_StatusEventRaised;
            eventSource.TargetFinished += eventSource_TargetFinished;
            eventSource.TargetStarted  += eventSource_TargetStarted;
            eventSource.TaskFinished   += eventSource_TaskFinished;
            eventSource.TaskStarted    += eventSource_TaskStarted;
            eventSource.WarningRaised  += eventSource_WarningRaised;
        }
예제 #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            RpcLibrary.Log.VerboseEnabled = true;
            var iid    = new Guid("{78323803-786f-4f7b-908d-b2e89c41d45f}");
            var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "11111");

            client.AuthenticateAs(RpcClientApi.Self);

            byte[] response = client.Execute(new byte[] { 1 });
        }
예제 #16
0
        static void Test()
        {
            //An id to identify the endpoint interface
              Guid iid = Guid.Parse("430436ab-8786-4b19-905f-2e5cc11edda2");

              //For the client, we specify the protocol, endpoint, and interface id to connect
              using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "4747"))
              {
            client.AuthenticateAs(RpcClientApi.Self);

            byte[] response = client.Execute(new byte[0]);
              }
        }
        private static void Main(string[] args)
        {
            // The client and server must agree on the interface id to use:
            var iid = new Guid("{1B617C4B-BF68-4B8C-AE2B-A77E6A3ECEC5}");

            bool attempt = true;

            while (attempt)
            {
                attempt = false;

                // Open the connection based on the endpoint information and interface IID
                using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "RpcExampleClientServer"))
                //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
                {
                    // Provide authentication information (not nessessary for LRPC)
                    client.AuthenticateAs(RpcClientApi.Self);

                    try
                    {
                        var response = client.Execute(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetings" : args[0]));

                        Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));
                    }
                    catch (RpcException rx)
                    {
                        if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                        {
                            // HINT: Use a wait handle if your on the same box...
                            Console.Error.WriteLine("Waiting for server...");
                            System.Threading.Thread.Sleep(1000);
                            attempt = true;
                        }
                        else
                        {
                            Console.Error.WriteLine(rx);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Error.WriteLine(ex);
                        Console.ResetColor();
                    }
                }
            }

            Console.WriteLine("Client is done. Press [Enter] to exit.");
            Console.ReadLine();
        }
예제 #18
0
 public static AppMessage Send(AppMessage message)
 {
     try
     {
         Guid iid = new Guid(Constants.ACWatchDogInteropId);
         using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, Constants.ACWatchDogInteropEndpoint))
         //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
         {
             // Provide authentication information (not nessessary for LRPC)
             client.AuthenticateAs(RpcClientApi.Self);
             // Send the request and get a response
             return(AppMessage.FromBytes(client.Execute(message.ToBytes())));
         }
     }
     catch (Exception) { return(null); }
 }
        public void TestClientOnAnonymousPipe()
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_NONE);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Assert.AreEqual(0, arg.Length);
                    Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
                    Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_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);
                };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Anonymous);
                    client.Execute(new byte[0]);
                }
            }
        }
        static void ReversePingTest(RpcProtseq protocol, string[] hostNames, string endpoint, RpcAuthentication auth)
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Array.Reverse(arg);
                    return(arg);
                };

                server.AddProtocol(protocol, endpoint, 5);
                server.AddAuthentication(auth);
                server.StartListening();

                byte[] input  = Encoding.ASCII.GetBytes("abc");
                byte[] expect = Encoding.ASCII.GetBytes("cba");

                foreach (string hostName in hostNames)
                {
                    using (RpcClientApi client = new RpcClientApi(iid, protocol, hostName, endpoint))
                    {
                        client.AuthenticateAs(null, auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcClientApi.Anonymous
                                                      : RpcClientApi.Self,
                                              auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE
                                                      : RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
                                              auth);

                        Assert.AreEqual(expect, client.Execute(input));
                    }
                }
            }
        }
        public void TestClientOnNamedPipe()
        {
            Guid iid = Guid.NewGuid();

            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                {
                    Assert.AreEqual(0, arg.Length);
                    Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_WINNT, client.AuthenticationLevel);
                    Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_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);
                };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
예제 #22
0
 public void TestClientCannotConnect()
 {
     using (RpcClientApi client = new RpcClientApi(Guid.NewGuid(), RpcProtseq.ncalrpc, null, "lrpc-endpoint-doesnt-exist"))
         client.Execute(new byte[0]);
 }
 protected override Stream Execute(byte[] requestBytes)
 {
     return(new MemoryStream(_client.Execute(requestBytes), false));
 }
예제 #24
0
        static void ReversePingTest(RpcProtseq protocol, string[] hostNames, string endpoint, RpcAuthentication auth)
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.OnExecute += 
                    delegate(IRpcClientInfo client, byte[] arg)
                    {
                        Array.Reverse(arg);
                        return arg;
                    };

                server.AddProtocol(protocol, endpoint, 5);
                server.AddAuthentication(auth);
                server.StartListening();

                byte[] input = Encoding.ASCII.GetBytes("abc");
                byte[] expect = Encoding.ASCII.GetBytes("cba");

                foreach (string hostName in hostNames)
                {
                    using (RpcClientApi client = new RpcClientApi(iid, protocol, hostName, endpoint))
                    {
                        client.AuthenticateAs(null, auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcClientApi.Anonymous
                                                      : RpcClientApi.Self, 
                                                  auth == RpcAuthentication.RPC_C_AUTHN_NONE
                                                      ? RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE
                                                      : RpcProtectionLevel.RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
                                                  auth);

                        Assert.AreEqual(expect, client.Execute(input));
                    }
                }
            }
        }
예제 #25
0
 public IEnumerable <byte> Execute(byte[] input)
 {
     return(_client.Execute(input));
 }
        public void TestNestedClientImpersonate()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo 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;
                    };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Self);
                    client.Execute(new byte[0]);
                }
            }
        }
        public void TestClientOnAnonymousPipe()
        {
            Guid iid = Guid.NewGuid();
            using (RpcServerApi server = new RpcServerApi(iid))
            {
                server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
                server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_NONE);
                server.StartListening();
                server.OnExecute +=
                    delegate(IRpcClientInfo client, byte[] arg)
                    {
                        Assert.AreEqual(0, arg.Length);
                        Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
                        Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_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;
                    };

                using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
                {
                    client.AuthenticateAs(RpcClientApi.Anonymous);
                    client.Execute(new byte[0]);
                }
            }
        }
 public void TestClientCannotConnect()
 {
     using (RpcClientApi client = new RpcClientApi(Guid.NewGuid(), RpcProtseq.ncalrpc, null, "lrpc-endpoint-doesnt-exist"))
         client.Execute(new byte[0]);
 }
        public void demo1()
        {
            Thread.Sleep(3000);

            // The client and server must agree on the interface id to use:
            var iid = new Guid("{1B617C4B-BF68-4B8C-AE2B-A77E6A3ECEC5}");

            bool attempt = true;

            while (attempt)
            {
                attempt = false;
                // Open the connection based on the endpoint information and interface IID
                //using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "RpcExampleClientServer"))
                using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
                {
                    // Provide authentication information (not nessessary for LRPC)
                    client.AuthenticateAs(RpcClientApi.Self);

                    client.Execute(new byte[1] {
                        0xEC
                    });

                    // Send the request and get a response
                    try
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            var response = client.Execute(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
                            Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));
                        }

                        //client.Execute(new byte[0]);

                        //byte[] bytes = new byte[1 * 1024 * 1024]; //1mb in/out
                        //new Random().NextBytes(bytes);

                        //Stopwatch stopWatch = new Stopwatch();
                        //stopWatch.Start();

                        //for (int i = 0; i < 2; i++)
                        //    client.Execute(bytes);

                        //stopWatch.Stop();
                        //TimeSpan ts = stopWatch.Elapsed;
                        //string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
                        //Console.WriteLine(elapsedTime + " ncalrpc-large-timming");
                    }
                    catch (RpcException rx)
                    {
                        if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                        {
                            //Use a wait handle if your on the same box...
                            Console.Error.WriteLine("Waiting for server...");
                            System.Threading.Thread.Sleep(1000);
                            attempt = true;
                        }
                        else
                        {
                            Console.Error.WriteLine(rx);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                    }
                }
            }
        }