/// <summary> /// DoRequestServerConfiguration method implementation /// </summary> public NamedPipeRegistryRecord DoRequestServerConfiguration(string requestor) { try { if (OnDecrypt == null) { OnDecrypt += PipeClientOnDecrypt; } if (OnEncrypt == null) { OnEncrypt += PipeClientOnEncrypt; } Task <NamedPipeRegistryRecord> task = null; NamedPipeClientStream ClientStream = new NamedPipeClientStream(_servers[0], "adfsmfaconfig", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation); task = Task <NamedPipeRegistryRecord> .Factory.StartNew(() => { try { ClientStream.Connect(); PipeStreamData ss = new PipeStreamData(ClientStream); ss.WriteString(OnEncrypt(Proofkey)); if (OnDecrypt(ss.ReadString()) == Proofkey) { NamedPipeServerConfigRecord xdata = new NamedPipeServerConfigRecord(requestor); ss.WriteData(ObjectToByteArray(xdata)); return(ByteArrayToObject <NamedPipeRegistryRecord>(ss.ReadData())); } } catch (IOException e) { LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8888); ClientStream.Close(); } finally { ClientStream.Close(); } return(default(NamedPipeRegistryRecord)); }); task.Wait(); return(task.Result); } catch (Exception e) { LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8888); return(default(NamedPipeRegistryRecord)); } }
/// <summary> /// PipeServerConfigThread method implmentation /// </summary> private void PipeServerConfigThread(object data) { int threadId = Thread.CurrentThread.ManagedThreadId; try { while (!MustExit) { ConfigPipeServer.WaitForConnection(); try { PipeStreamData ss = new PipeStreamData(ConfigPipeServer); if (OnDecrypt(ss.ReadString()) == this.Proofkey) { ss.WriteString(this.OnEncrypt(Proofkey)); object obj = ByteArrayToObject <object>(ss.ReadData()); if (obj is NamedPipeReloadConfigRecord) { NamedPipeReloadConfigRecord encrypted = (NamedPipeReloadConfigRecord)obj; bool b = false; if (OnReloadConfiguration != null) { b = OnReloadConfiguration(encrypted.Requestor, OnDecrypt(encrypted.Message)); ss.WriteData(ObjectToByteArray <bool>(b)); } } else if (obj is NamedPipeServerConfigRecord) { NamedPipeServerConfigRecord encrypted = (NamedPipeServerConfigRecord)obj; NamedPipeRegistryRecord reg; if (OnRequestServerConfiguration != null) { reg = OnRequestServerConfiguration(encrypted.Requestor); ss.WriteData(ObjectToByteArray <NamedPipeRegistryRecord>(reg)); } } else if (obj is NamedPipeNotificationReplayRecord) { NamedPipeNotificationReplayRecord encrypted = (NamedPipeNotificationReplayRecord)obj; bool b = false; if (OnCheckForReplay != null) { b = OnCheckForReplay(encrypted); if ((b) && (encrypted.MustDispatch)) { bool c = false; if (OnCheckForRemoteReplay != null) { c = OnCheckForRemoteReplay(encrypted); ss.WriteData(ObjectToByteArray <bool>(c)); } else { ss.WriteData(ObjectToByteArray <bool>(b)); } } else if ((b) && (!encrypted.MustDispatch)) { ss.WriteData(ObjectToByteArray <bool>(true)); } else { ss.WriteData(ObjectToByteArray <bool>(false)); } } } } } catch (IOException e) { LogForSlots.WriteEntry("PipeServer Error : " + e.Message, EventLogEntryType.Error, 8888); ConfigPipeServer.Close(); } finally { ConfigPipeServer.WaitForPipeDrain(); ConfigPipeServer.Disconnect(); } } } finally { ConfigPipeServer.Close(); } }