Ejemplo n.º 1
0
        /// <summary>
        /// DoClearConfigurationCache method implmentation
        /// </summary>
        public bool DoClearConfigurationCache(string requestor)
        {
            try
            {
                if (OnDecrypt == null)
                {
                    OnDecrypt += PipeClientOnDecrypt;
                }
                if (OnEncrypt == null)
                {
                    OnEncrypt += PipeClientOnEncrypt;
                }
                if (OnDecryptBytes == null)
                {
                    OnDecryptBytes += PipeClientOnDecryptBytes;
                }
                if (OnEncryptBytes == null)
                {
                    OnEncryptBytes += PipeClientOnEncryptBytes;
                }

                Task <bool>[] taskArray = new Task <bool> [_servers.Count];

                for (int i = 0; i < taskArray.Length; i++)
                {
                    string servername = _servers[i];
                    taskArray[i] = Task <bool> .Factory.StartNew((svr) =>
                    {
                        NamedPipeClientStream ClientStream = new NamedPipeClientStream(svr.ToString(), "adfsmfaconfig", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation);
                        try
                        {
                            ClientStream.Connect(3000);
                            PipeStreamData ss = new PipeStreamData(ClientStream);
                            ss.WriteString(OnEncrypt(Proofkey));
                            if (OnDecrypt(ss.ReadString()) == Proofkey)
                            {
                                NamedPipeClearConfigRecord xdata = new NamedPipeClearConfigRecord(requestor);
                                ss.WriteData(OnEncryptBytes(ObjectToByteArray(xdata)));
                                return(ByteArrayToObject <bool>(OnDecryptBytes(ss.ReadData())));
                            }
                        }
                        catch (IOException e)
                        {
                            LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8810);
                            return(false);
                        }
                        catch (TimeoutException e)
                        {
                            LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8811);
                            return(false);
                        }
                        finally
                        {
                            ClientStream.Close();
                        }
                        return(false);
                    }, servername);
                }
                Task.WaitAll(taskArray);
                for (int i = 0; i < taskArray.Length; i++)
                {
                    Task <bool> tsk = taskArray[i];
                    if (tsk == null)
                    {
                        return(false);
                    }
                    if (!tsk.Result)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8889);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// PipeServerConfigThread method implmentation
        /// </summary>
        private void PipeServerConfigThread()
        {
            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>(OnDecryptBytes(ss.ReadData()));

                            if (obj is NamedPipeReloadConfigRecord)
                            {
                                NamedPipeReloadConfigRecord encrypted = (NamedPipeReloadConfigRecord)obj;
                                bool b = false;
                                if (OnReloadConfiguration != null)
                                {
                                    b = OnReloadConfiguration(encrypted.Requestor, encrypted.Message);
                                    ss.WriteData(OnEncryptBytes(ObjectToByteArray <bool>(b)));
                                }
                            }
                            if (obj is NamedPipeClearConfigRecord)
                            {
                                NamedPipeClearConfigRecord encrypted = (NamedPipeClearConfigRecord)obj;
                                bool b = false;
                                if (OnClearConfigurationCache != null)
                                {
                                    b = OnClearConfigurationCache(encrypted.Requestor);
                                    ss.WriteData(OnEncryptBytes(ObjectToByteArray <bool>(b)));
                                }
                            }
                            else if (obj is NamedPipeServerConfigRecord)
                            {
                                NamedPipeServerConfigRecord encrypted = (NamedPipeServerConfigRecord)obj;
                                NamedPipeRegistryRecord     reg;
                                if (OnRequestServerConfiguration != null)
                                {
                                    reg = OnRequestServerConfiguration(encrypted.Requestor);
                                    ss.WriteData(OnEncryptBytes(ObjectToByteArray <NamedPipeRegistryRecord>(reg)));
                                }
                            }
                            else if (obj is NamedPipeNotificationReplayRecord)
                            {
                                if (OnCheckForReplay != null)
                                {
                                    NamedPipeNotificationReplayRecord encrypted = (NamedPipeNotificationReplayRecord)obj;
                                    bool b = OnCheckForReplay(encrypted);
                                    if ((b) && (encrypted.MustDispatch))
                                    {
                                        bool c = false;
                                        if (OnCheckForRemoteReplay != null)
                                        {
                                            c = OnCheckForRemoteReplay(encrypted);
                                            ss.WriteData(OnEncryptBytes(ObjectToByteArray <bool>(c)));
                                        }
                                        else
                                        {
                                            ss.WriteData(OnEncryptBytes(ObjectToByteArray <bool>(b)));
                                        }
                                    }
                                    else if ((b) && (!encrypted.MustDispatch))
                                    {
                                        ss.WriteData(OnEncryptBytes(ObjectToByteArray <bool>(true)));
                                    }
                                    else
                                    {
                                        ss.WriteData(OnEncryptBytes(ObjectToByteArray <bool>(false)));
                                    }
                                }
                            }
                        }
                    }
                    catch (IOException e)
                    {
                        LogForSlots.WriteEntry("PipeServer Error : " + e.Message, EventLogEntryType.Error, 8880);
                        ConfigPipeServer.Close();
                    }
                    finally
                    {
                        ConfigPipeServer.WaitForPipeDrain();
                        ConfigPipeServer.Disconnect();
                    }
                }
            }
            finally
            {
                ConfigPipeServer.Close();
            }
        }