/// <summary> /// GetADFSAccounts method implmentation /// </summary> private static bool GetADFSAccounts(ref SIDsParametersRecord rec) { RegistryVersion reg = new RegistryVersion(); ADFSAdminPolicies pol = new ADFSAdminPolicies(); try { rec.ADFSAccountSID = GetADFSAccountSID(); rec.ADFSAccountName = GetADFSAccountName(); rec.ADFSServiceAccountSID = GetADFSServiceSID(); rec.ADFSServiceAccountName = GetADFSServiceName(); if (!reg.IsWindows2012R2) { rec.ADFSAdministrationGroupName = GetADFSAdminsGroupName(ref pol); rec.ADFSAdministrationGroupSID = GetADFSAdminsGroupSID(rec.ADFSAdministrationGroupName); rec.ADFSDelegateServiceAdministrationAllowed = pol.DelegateServiceAdministrationAllowed; rec.ADFSLocalAdminServiceAdministrationAllowed = pol.LocalAdminsServiceAdministrationAllowed; rec.ADFSSystemServiceAdministrationAllowed = pol.SystemServiceAdministrationAllowed; } else { rec.ADFSAdministrationGroupName = string.Empty; rec.ADFSAdministrationGroupSID = string.Empty; rec.ADFSDelegateServiceAdministrationAllowed = false; rec.ADFSLocalAdminServiceAdministrationAllowed = true; rec.ADFSSystemServiceAdministrationAllowed = true; } return(true); } catch (Exception) { return(false); } }
/// <summary> /// LoadFromCache method implementation /// </summary> private static SIDsParametersRecord LoadFromCache() { SIDsParametersRecord config = null; if (!File.Exists(SystemUtilities.SystemCacheFile)) { return(null); } DataContractSerializer serializer = new DataContractSerializer(typeof(SIDsParametersRecord)); using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Open, FileAccess.Read)) { byte[] bytes = new byte[fs.Length]; int n = fs.Read(bytes, 0, (int)fs.Length); fs.Close(); byte[] byt = null; using (AESSystemEncryption aes = new AESSystemEncryption()) { byt = aes.Decrypt(bytes); } using (MemoryStream ms = new MemoryStream(byt)) { using (StreamReader reader = new StreamReader(ms)) { config = (SIDsParametersRecord)serializer.ReadObject(ms); } } } return(config); }
/// <summary> /// WriteToCache method implementation /// </summary> private static void WriteToCache(SIDsParametersRecord config) { if (config.ADFSDelegateServiceAdministrationAllowed) { StoreDelegatedGroupStatus(config.ADFSAdministrationGroupName); } else { StoreDelegatedGroupStatus(null); } DataContractSerializer serializer = new DataContractSerializer(typeof(SIDsParametersRecord)); MemoryStream stm = new MemoryStream(); using (StreamReader reader = new StreamReader(stm)) { serializer.WriteObject(stm, config); stm.Position = 0; byte[] byt = null; using (AESSystemEncryption aes = new AESSystemEncryption()) { byt = aes.Encrypt(stm.ToArray()); } using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite)) { fs.Write(byt, 0, byt.Length); fs.Close(); } return; } }
/// <summary> /// GetADFSAccounts method implmentation /// </summary> private static bool GetADFSAccounts(ref SIDsParametersRecord rec) { RegistryVersion reg = new RegistryVersion(); ADFSAdminPolicies pol = new ADFSAdminPolicies(); try { rec.ADFSAccountSID = GetADFSAccountSID(); rec.ADFSAccountName = GetADFSAccountName(); rec.ADFSServiceAccountSID = GetADFSServiceSID(); rec.ADFSServiceAccountName = GetADFSServiceName(); if (!reg.IsWindows2012R2) { rec.ADFSAdministrationGroupName = GetADFSAdminsGroupName(ref pol); rec.ADFSAdministrationGroupSID = GetADFSAdminsGroupSID(rec.ADFSAdministrationGroupName); rec.ADFSDelegateServiceAdministrationAllowed = pol.DelegateServiceAdministrationAllowed; rec.ADFSLocalAdminServiceAdministrationAllowed = pol.LocalAdminsServiceAdministrationAllowed; rec.ADFSSystemServiceAdministrationAllowed = pol.SystemServiceAdministrationAllowed; } else { rec.ADFSAdministrationGroupName = string.Empty; rec.ADFSAdministrationGroupSID = string.Empty; rec.ADFSDelegateServiceAdministrationAllowed = false; rec.ADFSLocalAdminServiceAdministrationAllowed = true; rec.ADFSSystemServiceAdministrationAllowed = true; } return(true); } catch (Exception ex) { Log.WriteEntry("Error loading SIDs informations : \r" + ex.Message, EventLogEntryType.Error, 666); return(false); } }
/// <summary> /// PushSIDsInformations method implmentation /// </summary> public void PushSIDsInformations(SIDsParametersRecord rec) { try { _manager.PushSIDsInformations(rec); } catch (Exception e) { _log.WriteEntry(string.Format("Error on WebAdminService Service GetSIDsInformations method : {0}.", e.Message), EventLogEntryType.Error, 2010); throw e; } }
/// <summary> /// RequestSIDsInformations method implementation /// </summary> public SIDsParametersRecord RequestSIDsInformations() { try { return(_manager.RequestSIDsInformations()); } catch (Exception e) { _log.WriteEntry(string.Format("Error on WebAdminService Service GetSIDsInformations method : {0}.", e.Message), EventLogEntryType.Error, 2010); SIDsParametersRecord rec = new SIDsParametersRecord(); rec.Loaded = false; return(rec); } }
/// <summary> /// Assign method implmentation /// </summary> internal static void Assign(SIDsParametersRecord rec) { ADFSAccountSID = rec.ADFSAccountSID; ADFSAccountName = rec.ADFSAccountName; ADFSServiceSID = rec.ADFSServiceAccountSID; ADFSServiceName = rec.ADFSServiceAccountName; ADFSAdminGroupSID = rec.ADFSAdministrationGroupSID; ADFSAdminGroupName = rec.ADFSAdministrationGroupName; ADFSDelegateServiceAdministrationAllowed = rec.ADFSDelegateServiceAdministrationAllowed; ADFSLocalAdminServiceAdministrationAllowed = rec.ADFSLocalAdminServiceAdministrationAllowed; ADFSSystemServiceAdministrationAllowed = rec.ADFSSystemServiceAdministrationAllowed; WriteToCache(rec); Loaded = rec.Loaded; }
/// <summary> /// GetRemoteSIDsInformations method implmentation /// </summary> private SIDsParametersRecord GetRemoteSIDsInformations(Dictionary <string, bool> servers) { SIDsParametersRecord retvalue = null; try { retvalue = SIDs.GetSIDs(); if (retvalue == null) { string fqdn = Dns.GetHostEntry("localhost").HostName; foreach (var srv in servers) { if (srv.Key.ToLower().Equals(fqdn.ToLower()) || (!srv.Value)) { continue; } WebAdminClient manager = new WebAdminClient(); manager.Initialize(srv.Key); try { IWebAdminServices client = manager.Open(); try { retvalue = client.RequestSIDsInformations(); SIDs.Assign(retvalue); break; // Break on first primary server; } finally { manager.Close(client); } } catch (Exception e) { _log.WriteEntry(string.Format("Error on WebAdminService Service GetRemoteSIDsInformations method : {0} / {1}.", srv, e.Message), EventLogEntryType.Error, 2010); } finally { manager.UnInitialize(); } } } } catch (Exception e) { _log.WriteEntry(string.Format("Error on WebAdminService Service GetLocalSIDsInformations method : {0}.", e.Message), EventLogEntryType.Error, 2010); throw e; } return(retvalue); }
/// <summary> /// RequestSIDsInformations method implementation /// </summary> public SIDsParametersRecord RequestSIDsInformations() { SIDsParametersRecord retvalue = null; try { retvalue = SIDs.Initialize(); } catch (Exception e) { _log.WriteEntry(string.Format("Error on WebAdminService Service RequestSIDsInformations method : {0}.", e.Message), EventLogEntryType.Error, 2010); throw e; } return(retvalue); }
/// <summary> /// WriteToCache method implementation /// </summary> private static void WriteToCache(SIDsParametersRecord config) { XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(SIDsParametersRecord)); MemoryStream stm = new MemoryStream(); using (StreamReader reader = new StreamReader(stm)) { xmlserializer.Serialize(stm, config); stm.Position = 0; byte[] byt = null; using (AESSystemEncryption aes = new AESSystemEncryption()) { byt = aes.Encrypt(stm.ToArray()); } using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite)) { fs.Write(byt, 0, byt.Length); fs.Close(); } return; } }
/// <summary> /// GetSIDs method implementation /// </summary> /// <returns></returns> internal static SIDsParametersRecord GetSIDs() { SIDsParametersRecord rec = new SIDsParametersRecord() { Loaded = false }; if (!Loaded) { return(null); } rec.ADFSAccountSID = ADFSAccountSID; rec.ADFSAccountName = ADFSAccountName; rec.ADFSServiceAccountSID = ADFSServiceSID; rec.ADFSServiceAccountName = ADFSServiceName; rec.ADFSAdministrationGroupSID = ADFSAdminGroupSID; rec.ADFSAdministrationGroupName = ADFSAdminGroupName; rec.ADFSDelegateServiceAdministrationAllowed = ADFSDelegateServiceAdministrationAllowed; rec.ADFSLocalAdminServiceAdministrationAllowed = ADFSLocalAdminServiceAdministrationAllowed; rec.ADFSSystemServiceAdministrationAllowed = ADFSSystemServiceAdministrationAllowed; rec.Loaded = true; return(rec); }
/// <summary> /// Initialize method implmentation /// </summary> internal static SIDsParametersRecord Initialize() { SIDsParametersRecord rec = new SIDsParametersRecord(); if (!Loaded) { try { if (!File.Exists(SystemUtilities.SystemCacheFile)) { rec.Loaded = GetADFSAccounts(ref rec); ADFSAccountSID = rec.ADFSAccountSID; ADFSAccountName = rec.ADFSAccountName; ADFSServiceSID = rec.ADFSServiceAccountSID; ADFSServiceName = rec.ADFSServiceAccountName; ADFSAdminGroupSID = rec.ADFSAdministrationGroupSID; ADFSAdminGroupName = rec.ADFSAdministrationGroupName; ADFSDelegateServiceAdministrationAllowed = rec.ADFSDelegateServiceAdministrationAllowed; ADFSLocalAdminServiceAdministrationAllowed = rec.ADFSLocalAdminServiceAdministrationAllowed; ADFSSystemServiceAdministrationAllowed = rec.ADFSSystemServiceAdministrationAllowed; WriteToCache(rec); Loaded = true; } else { SIDsParametersRecord data = LoadFromCache(); if (data != null) { rec.ADFSAccountSID = data.ADFSAccountSID; rec.ADFSAccountName = data.ADFSAccountName; rec.ADFSServiceAccountSID = data.ADFSServiceAccountSID; rec.ADFSServiceAccountName = data.ADFSServiceAccountName; rec.ADFSAdministrationGroupSID = data.ADFSAdministrationGroupSID; rec.ADFSAdministrationGroupName = data.ADFSAdministrationGroupName; rec.ADFSDelegateServiceAdministrationAllowed = data.ADFSDelegateServiceAdministrationAllowed; rec.ADFSLocalAdminServiceAdministrationAllowed = data.ADFSLocalAdminServiceAdministrationAllowed; rec.ADFSSystemServiceAdministrationAllowed = data.ADFSSystemServiceAdministrationAllowed; rec.Loaded = true; ADFSAccountSID = data.ADFSAccountSID; ADFSAccountName = data.ADFSAccountName; ADFSServiceSID = data.ADFSServiceAccountSID; ADFSServiceName = data.ADFSServiceAccountName; ADFSAdminGroupSID = data.ADFSAdministrationGroupSID; ADFSAdminGroupName = data.ADFSAdministrationGroupName; ADFSDelegateServiceAdministrationAllowed = data.ADFSDelegateServiceAdministrationAllowed; ADFSLocalAdminServiceAdministrationAllowed = data.ADFSLocalAdminServiceAdministrationAllowed; ADFSSystemServiceAdministrationAllowed = data.ADFSSystemServiceAdministrationAllowed; Loaded = true; } else { Loaded = false; } } } catch (Exception) { Loaded = false; } } else { try { if (!File.Exists(SystemUtilities.SystemCacheFile)) { rec.Loaded = GetADFSAccounts(ref rec); ADFSAccountSID = rec.ADFSAccountSID; ADFSAccountName = rec.ADFSAccountName; ADFSServiceSID = rec.ADFSServiceAccountSID; ADFSServiceName = rec.ADFSServiceAccountName; ADFSAdminGroupSID = rec.ADFSAdministrationGroupSID; ADFSAdminGroupName = rec.ADFSAdministrationGroupName; ADFSDelegateServiceAdministrationAllowed = rec.ADFSDelegateServiceAdministrationAllowed; ADFSLocalAdminServiceAdministrationAllowed = rec.ADFSLocalAdminServiceAdministrationAllowed; ADFSSystemServiceAdministrationAllowed = rec.ADFSSystemServiceAdministrationAllowed; WriteToCache(rec); Loaded = true; } else { rec.ADFSAccountSID = ADFSAccountSID; rec.ADFSAccountName = ADFSAccountName; rec.ADFSServiceAccountSID = ADFSServiceSID; rec.ADFSServiceAccountName = ADFSServiceName; rec.ADFSAdministrationGroupSID = ADFSAdminGroupSID; rec.ADFSAdministrationGroupName = ADFSAdminGroupName; rec.ADFSDelegateServiceAdministrationAllowed = ADFSDelegateServiceAdministrationAllowed; rec.ADFSLocalAdminServiceAdministrationAllowed = ADFSLocalAdminServiceAdministrationAllowed; rec.ADFSSystemServiceAdministrationAllowed = ADFSSystemServiceAdministrationAllowed; rec.Loaded = true; } } catch (Exception) { Loaded = true; } } return(rec); }
/// <summary> /// PushSIDsInformations method implementation /// </summary> public void PushSIDsInformations(SIDsParametersRecord rec) { SIDs.Assign(rec); }