/// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig cfg  = ManagementAdminService.ADFSManager.Config;
            SendMail  mail = cfg.SendMail;

            cfg.IsDirty   = IsDirty;
            mail.From     = From;
            mail.UserName = UserName;
            mail.Password = Password;
            mail.Host     = Host;
            mail.Port     = Port;
            mail.UseSSL   = UseSSL;
            mail.Company  = Company;
            mail.MailOTPContent.Clear();
            foreach (MMCConfigMailFileName itm in MailOTPContent)
            {
                mail.MailOTPContent.Add((SendMailFileName)itm);
            }
            mail.MailAdminContent.Clear();
            foreach (MMCConfigMailFileName itm in MailAdminContent)
            {
                mail.MailAdminContent.Add((SendMailFileName)itm);
            }
            mail.MailKeyContent.Clear();
            foreach (MMCConfigMailFileName itm in MailKeyContent)
            {
                mail.MailKeyContent.Add((SendMailFileName)itm);
            }
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// UpgradeServersConfig method implementation (Client)
        /// </summary>
        private void UpgradeServersConfig(NamedPipeRegistryRecord reg)
        {
            NamedPipeRegistryRecord rec = FarmUtilities.InitServerNodeConfiguration(reg);

            MFAConfig      cfg = CFGUtilities.ReadConfiguration(null);
            ADFSServerHost svr = null;

            if (cfg.Hosts.ADFSFarm.Servers.Exists(s => s.FQDN.ToLower().Equals(rec.FQDN.ToLower())))
            {
                svr = cfg.Hosts.ADFSFarm.Servers.Find(s => s.FQDN.ToLower().Equals(rec.FQDN.ToLower()));
                cfg.Hosts.ADFSFarm.Servers.Remove(svr);
            }
            svr                           = new ADFSServerHost();
            svr.FQDN                      = rec.FQDN;
            svr.CurrentVersion            = rec.CurrentVersion;
            svr.CurrentBuild              = rec.CurrentBuild;
            svr.CurrentMajorVersionNumber = rec.CurrentMajorVersionNumber;
            svr.CurrentMinorVersionNumber = rec.CurrentMinorVersionNumber;
            svr.InstallationType          = rec.InstallationType;
            svr.ProductName               = rec.ProductName;
            svr.NodeType                  = rec.NodeType;
            svr.BehaviorLevel             = rec.BehaviorLevel;
            svr.HeartbeatTmeStamp         = rec.HeartbeatTimestamp;
            cfg.Hosts.ADFSFarm.Servers.Add(svr);
            CFGUtilities.WriteConfiguration(null, cfg);

            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.Text = Environment.MachineName;
                mailslot.SendNotification(NotificationsKind.ConfigurationReload);
            }
        }
        /// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig cfg = ManagementAdminService.ADFSManager.Config;

            cfg.AdminContact         = AdminContact;
            cfg.IsDirty              = IsDirty;
            cfg.RefreshScan          = RefreshScan;
            cfg.DeliveryWindow       = DeliveryWindow;
            cfg.TOTPShadows          = TOTPShadows;
            cfg.MailEnabled          = MailEnabled;
            cfg.SMSEnabled           = SMSEnabled;
            cfg.AppsEnabled          = AppsEnabled;
            cfg.Algorithm            = Algorithm;
            cfg.Issuer               = Issuer;
            cfg.UseActiveDirectory   = UseActiveDirectory;
            cfg.CustomUpdatePassword = CustomUpdatePassword;
            cfg.DefaultCountryCode   = DefaultCountryCode;
            cfg.AdminContact         = AdminContact;
            cfg.UserFeatures         = UserFeatures;
            cfg.AdvertisingDays      = AdvertisingDays;
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig cfg  = ManagementAdminService.ADFSManager.Config;
            ADDSHost  adds = cfg.Hosts.ActiveDirectoryHost;

            cfg.IsDirty                   = IsDirty;
            adds.Account                  = Account;
            adds.Password                 = adds.Password;
            adds.DomainAddress            = adds.DomainAddress;
            adds.keyAttribute             = KeyAttribute;
            adds.mailAttribute            = MailAttribute;
            adds.methodAttribute          = MethodAttribute;
            adds.notifcheckdateattribute  = NotifCheckDateAttribute;
            adds.notifcreatedateAttribute = NotifCreateDateAttribute;
            adds.notifvalidityAttribute   = NotifValidityAttribute;
            adds.phoneAttribute           = PhoneAttribute;
            adds.totpAttribute            = TOTPAttribute;
            adds.totpEnabledAttribute     = TOTPEnabledAttribute;
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig     cfg = ManagementAdminService.ADFSManager.Config;
            SQLServerHost sql = cfg.Hosts.SQLServerHost;

            cfg.IsDirty          = IsDirty;
            sql.ConnectionString = ConnectionString;
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig     cfg = ManagementAdminService.ADFSManager.Config;
            MFAKeysConfig otp = cfg.KeysConfig;

            otp.ExternalKeyManager.FullQualifiedImplementation = this.FullQualifiedImplementation;
            otp.ExternalKeyManager.Parameters = this.Parameters;
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
Example #7
0
        /// <summary>
        /// SetBLOBPayloadCache method implmentation
        /// </summary>
        public void SetBLOBPayloadCache(BLOBPayloadInformations infos)
        {
            RegistryKey ek = Registry.LocalMachine.OpenSubKey("Software\\MFA", true);

            ek.SetValue("BlobNumber", Convert.ToString(infos.Number), RegistryValueKind.String);
            ek.SetValue("BlobNextUpdate", infos.NextUpdate.ToString("yyyy-MM-dd"), RegistryValueKind.String);
            ek.SetValue("BlobDownload", Convert.ToInt32(infos.CanDownload), RegistryValueKind.DWord);
            File.WriteAllText(SystemUtilities.PayloadCacheFile, infos.BLOB);
            using (MailSlotClient mailslot = new MailSlotClient("BDC"))
            {
                mailslot.Text = Environment.MachineName;
                mailslot.SendNotification(NotificationsKind.ConfigurationReload);
            }
        }
 /// <summary>
 /// PushNotification method implementation
 /// </summary>
 internal void PushNotification(NotificationsKind kind, string message, string appname)
 {
     using (MailSlotClient mailslot = new MailSlotClient(appname))
     {
         if (string.IsNullOrEmpty(message))
         {
             mailslot.Text = Environment.MachineName;
         }
         else
         {
             mailslot.Text = message;
         }
         mailslot.SendNotification(kind);
     }
 }
 /// <summary>
 /// private bool DoOnReceiveClearConfiguration(string requestor) method implementation (Server)
 /// </summary>
 private bool DoOnReceiveClearConfiguration(string requestor)
 {
     try
     {
         File.Delete(CFGUtilities.configcachedir);
         using (MailSlotClient mailslot = new MailSlotClient())
         {
             mailslot.Text = requestor;
             mailslot.SendNotification(NotificationsKind.ConfigurationReload);
         }
     }
     catch (Exception ex)
     {
         this.EventLog.WriteEntry("Error when writing Confoguration cache ! " + ex.Message, EventLogEntryType.Error, 10000);
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig           cfg = ManagementAdminService.ADFSManager.Config;
            ExternalOTPProvider otp = cfg.ExternalOTPProvider;

            cfg.IsDirty = true;
            otp.Company = this.Company;
            otp.FullQualifiedImplementation = this.FullQualifiedImplementation;
            otp.IsTwoWay   = this.IsTwoWay;
            otp.Sha1Salt   = this.Sha1Salt;
            otp.Timeout    = this.Timeout;
            otp.Parameters = this.Parameters;
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// Update method implmentation
        /// </summary>
        public void Update(PSHost host)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig     cfg  = ManagementAdminService.ADFSManager.Config;
            MFAKeysConfig keys = cfg.KeysConfig;

            cfg.IsDirty = true;
            keys.CertificateThumbprint = this.CertificateThumbprint;
            keys.CertificateValidity   = this.CertificateValidity;
            keys.KeyFormat             = this.KeyFormat;
            keys.KeyGenerator          = this.KeyGenerator;
            keys.KeySize            = this.KeySize;
            keys.ExternalKeyManager = (MFAExternalKeyManager)this.ExternalKeyManager;
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// internalStopService method implementation
        /// </summary>
        private void StopADFSService()
        {
            ServiceController ADFSController = null;

            try
            {
                ADFSController = new ServiceController("adfssrv");
                using (MailSlotClient mailslot = new MailSlotClient("MGT"))
                {
                    mailslot.Text = Environment.MachineName;
                    mailslot.SendNotification(0x12);
                }
                if (ADFSController.Status != ServiceControllerStatus.Stopped)
                {
                    ADFSController.Stop();
                }
                ADFSController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 1, 0));
                using (MailSlotClient mailslot = new MailSlotClient("MGT"))
                {
                    mailslot.Text = Environment.MachineName;
                    mailslot.SendNotification(0x11);
                }
            }
            catch (Exception e)
            {
                using (MailSlotClient mailslot = new MailSlotClient("MGT"))
                {
                    mailslot.Text = Environment.MachineName;
                    mailslot.SendNotification(0x19);
                }
                this.EventLog.WriteEntry("Error Stopping ADFS Service \r" + e.Message, EventLogEntryType.Error, 3);
                return;
            }
            finally
            {
                ADFSController.Close();
            }
        }
        /// <summary>
        /// SetTemplate method implmentation
        /// </summary>
        public void SetTemplate(PSHost host, MMCTemplateMode mode)
        {
            ManagementAdminService.Initialize(true);
            MFAConfig cfg = ManagementAdminService.ADFSManager.Config;

            switch (mode)
            {
            case MMCTemplateMode.Free:
                cfg.UserFeatures = (UserFeaturesOptions.BypassDisabled | UserFeaturesOptions.BypassUnRegistered | UserFeaturesOptions.AllowManageOptions | UserFeaturesOptions.AllowChangePassword);
                break;

            case MMCTemplateMode.Open:
                cfg.UserFeatures = (UserFeaturesOptions.BypassDisabled | UserFeaturesOptions.AllowUnRegistered | UserFeaturesOptions.AllowManageOptions | UserFeaturesOptions.AllowChangePassword);
                break;

            case MMCTemplateMode.Default:
                cfg.UserFeatures = (UserFeaturesOptions.AllowDisabled | UserFeaturesOptions.AllowUnRegistered | UserFeaturesOptions.AllowManageOptions | UserFeaturesOptions.AllowChangePassword);
                break;

            case MMCTemplateMode.Managed:
                cfg.UserFeatures = (UserFeaturesOptions.AllowDisabled | UserFeaturesOptions.AllowUnRegistered | UserFeaturesOptions.AllowProvideInformations | UserFeaturesOptions.AllowChangePassword);
                break;

            case MMCTemplateMode.Strict:
                cfg.UserFeatures = (UserFeaturesOptions.AllowProvideInformations);
                break;

            case MMCTemplateMode.Administrative:
                cfg.UserFeatures = (UserFeaturesOptions.AdministrativeMode);
                break;
            }
            ManagementAdminService.ADFSManager.WriteConfiguration(host);
            using (MailSlotClient mailslot = new MailSlotClient())
            {
                mailslot.SendNotification(0xAA);
            }
        }
        /// <summary>
        /// MailSlotMessageArrived implementation
        /// </summary>
        private void MailSlotMessageArrived(MailSlotServer maislotserver, MailSlotMessage message)
        {
            if (message.ApplicationName == "CP1")
            {
                switch (message.Operation)
                {
                case 0x10:
                    if (IsLocalMessage(message))
                    {
                        this.EventLog.WriteEntry(string.Format("Server Information REQUEST To {0}", message.Text), EventLogEntryType.SuccessAudit, 10000);
                        using (MailSlotClient mailslot = new MailSlotClient("CP1"))
                        {
                            mailslot.Text = Dns.GetHostEntry(message.Text).HostName.ToLower();
                            mailslot.SendNotification(0x11);
                        }
                    }
                    break;

                case 0x11:
                    if (!IsLocalMessage(message))
                    {
                        string localname = Dns.GetHostEntry("localhost").HostName.ToLower();
                        if (localname.ToLower().Equals(message.Text.ToLower()))
                        {
                            this.EventLog.WriteEntry(string.Format("Server Information RECEIVED for {0}", message.Text), EventLogEntryType.SuccessAudit, 10000);
                            using (MailSlotClient mailslot = new MailSlotClient("CP1"))
                            {
                                FarmUtilities reg = new FarmUtilities();
                                mailslot.Text = reg.InitServerNodeConfiguration();
                                mailslot.SendNotification(0x12);
                            }
                        }
                    }
                    break;

                case 0x12:
                    if (!IsLocalMessage(message))
                    {
                        FarmUtilities  reg  = new FarmUtilities();
                        ADFSServerHost host = reg.UnPackServerNodeConfiguration(message.Text);

                        ManagementService.EnsureService();
                        int i = ManagementService.ADFSManager.ADFSFarm.Servers.FindIndex(c => c.FQDN.ToLower() == host.FQDN.ToLower());
                        if (i < 0)
                        {
                            ManagementService.ADFSManager.ADFSFarm.Servers.Add(host);
                        }
                        else
                        {
                            ManagementService.ADFSManager.ADFSFarm.Servers[i] = host;
                        }

                        ManagementService.ADFSManager.SetDirty(true);
                        ManagementService.ADFSManager.WriteConfiguration(null);

                        this.EventLog.WriteEntry(string.Format("Server Information RESPONSE : {0}", message.Text), EventLogEntryType.SuccessAudit, 10000);
                    }
                    break;
                }
            }
        }