Impersonation with IPCChannel
-
Hi, I am trying to connect to IPCChannel using an impersonated user and had encountered an Access Denied exception. Have anyone encountered this? Please help. Please see some code snippets below: Server: BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; System.Collections.IDictionary props = new System.Collections.Hashtable(); props["portName"] = "TestRemoteObject"; props["name"] = "TestRemoteObject"; props["authorizedGroup"] = "Everyone"; props["impersonate"] = true; props["secure"] = true; serverChannel = new IpcServerChannel(props, serverProvider); ChannelServices.RegisterChannel(serverChannel, true); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "TestRemoteObject", WellKnownObjectMode.Singleton); Client: BinaryClientFormatterSinkProvider clientSink = new BinaryClientFormatterSinkProvider(); System.Collections.IDictionary clientProps = new System.Collections.Hashtable(); clientProps["secure"] = true; clientProps["tokenImpersonationLevel"] = TokenImpersonationLevel.Delegation; IpcClientChannel clientChannel = new IpcClientChannel(clientProps, clientSink); ChannelServices.RegisterChannel(clientChannel, true); // Impersonate user to use Administrator IntPtr token; bool result = LogonUser( "Administrator", "MyMachine", "MyPassword", LogonTypes.Network, LogonProviders.Default, out token); if (result) { WindowsIdentity identity = new WindowsIdentity(token); using (WindowsImpersonationContext imp = identity.Impersonate()) { try { RemoteObject remote = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "ipc://TestRemoteObject/TestRemoteObject"); message = remote.Echo("Test"); } catch (Exception exc) { message = exc.ToString(); } imp.Undo(); }
-
Hi, I am trying to connect to IPCChannel using an impersonated user and had encountered an Access Denied exception. Have anyone encountered this? Please help. Please see some code snippets below: Server: BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider(); serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; System.Collections.IDictionary props = new System.Collections.Hashtable(); props["portName"] = "TestRemoteObject"; props["name"] = "TestRemoteObject"; props["authorizedGroup"] = "Everyone"; props["impersonate"] = true; props["secure"] = true; serverChannel = new IpcServerChannel(props, serverProvider); ChannelServices.RegisterChannel(serverChannel, true); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "TestRemoteObject", WellKnownObjectMode.Singleton); Client: BinaryClientFormatterSinkProvider clientSink = new BinaryClientFormatterSinkProvider(); System.Collections.IDictionary clientProps = new System.Collections.Hashtable(); clientProps["secure"] = true; clientProps["tokenImpersonationLevel"] = TokenImpersonationLevel.Delegation; IpcClientChannel clientChannel = new IpcClientChannel(clientProps, clientSink); ChannelServices.RegisterChannel(clientChannel, true); // Impersonate user to use Administrator IntPtr token; bool result = LogonUser( "Administrator", "MyMachine", "MyPassword", LogonTypes.Network, LogonProviders.Default, out token); if (result) { WindowsIdentity identity = new WindowsIdentity(token); using (WindowsImpersonationContext imp = identity.Impersonate()) { try { RemoteObject remote = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "ipc://TestRemoteObject/TestRemoteObject"); message = remote.Echo("Test"); } catch (Exception exc) { message = exc.ToString(); } imp.Undo(); }
-
You are running the server and client on the same machine, right?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)