Bug 369296. Zen/Security issue. Adding global config setting support.

This commit is contained in:
Jim Norman 2008-04-01 21:06:24 +00:00
parent e9c094ab27
commit 04fb478810
4 changed files with 547 additions and 375 deletions

View File

@ -40,79 +40,35 @@ namespace sscs.common
#if W32 #if W32
private static string CASA_REG_KEY = "SOFTWARE\\Novell\\CASA"; private static string CASA_REG_KEY = "SOFTWARE\\Novell\\CASA";
private static bool IsRegKeySet(string sPath, string sValue)
{
Microsoft.Win32.RegistryKey key;
try
{
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sPath);
int iValue = (int)key.GetValue(sValue);
key.Close();
if (iValue > 0)
{
return true;
}
}
catch (Exception e)
{
}
return false;
}
internal static void SetAllowDesktopAccess()
{
// create a reg key
System.Diagnostics.Trace.WriteLine("CASA installer: SetAllowDesktopAccess start");
try
{
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(CASA_REG_KEY);
key.SetValue("CacheDesktopPassword", 1, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.ToString());
}
System.Diagnostics.Trace.WriteLine("CASA installer: SetAllowDesktopAccess done");
}
internal static void RemoveGlobalCASASettings()
{
// Delete CASA settings
try
{
Microsoft.Win32.Registry.LocalMachine.DeleteSubKeyTree(CASA_REG_KEY);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
#endif #endif
public static bool StoreDesktopPasswordInCache() public static bool StoreDesktopPasswordInCache()
{ {
#if LINUX if (Config.GetGlobalConfigSetting("CacheDesktopPassword", "false").Equals("true"))
{
return true; return true;
#else }
return IsRegKeySet(CASA_REG_KEY, "CacheDesktopPassword"); else
#endif {
return false;
}
} }
public static bool UseMasterPassword() public static bool UseMasterPassword()
{ {
#if LINUX if (Config.GetGlobalConfigSetting("UserMasterPassword", "false").Equals("true"))
{
return true; return true;
#else }
//return false; else
return IsRegKeySet(CASA_REG_KEY, "UseMasterPassword"); {
#endif return false;
}
} }
public static bool IsFileOwnedByRoot(string filePath) public static bool IsFileOwnedByRoot(string filePath)

View File

@ -0,0 +1,216 @@
using System;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using sscs.constants;
namespace sscs.common
{
class Config
{
private static string CASA_REG_KEY = "SOFTWARE\\Novell\\CASA";
private static NameValueCollection m_nvc;
public Config()
{
LoadConfigSettings();
}
public static void SetGlobalConfigSetting(string sName, string sValue)
{
if (m_nvc == null)
{
m_nvc = new NameValueCollection();
}
m_nvc.Set(sName, sValue);
}
public static string GetGlobalConfigSetting(string sName)
{
return GetGlobalConfigSetting(sName, null);
}
public static string GetGlobalConfigSetting(string sName, string sDefaultValue)
{
string sValue = null;
if (m_nvc == null)
{
LoadConfigSettings();
}
if (m_nvc != null)
{
sValue = m_nvc.Get(sName);
}
if (sValue == null)
{
ReadRegSetting(sName);
sValue = sDefaultValue;
}
return sValue;
}
public static void WriteGlobalConfig()
{
#if LINUX
XmlDocument doc = new XmlDocument();
AppendToDoc(doc);
XmlTextWriter writer = new XmlTextWriter(GetGlobalConfPath(), null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
writer.Close();
#else
// Write to windows registry
for (int i = 0; i < m_nvc.Count; i++)
{
WriteRegSetting(m_nvc.GetKey(i), m_nvc.GetValues(i)[0]);
}
#endif
}
#if W32
internal static void SetAllowDesktopAccess()
{
// create a reg key
System.Diagnostics.Trace.WriteLine("CASA installer: SetAllowDesktopAccess start");
WriteRegSetting("CacheDesktopPassword", "true");
System.Diagnostics.Trace.WriteLine("CASA installer: SetAllowDesktopAccess done");
}
internal static void WriteRegSetting(string sSubKey, string sValue)
{
try
{
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(CASA_REG_KEY);
key.SetValue(sSubKey, sValue, Microsoft.Win32.RegistryValueKind.String);
key.Close();
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.ToString());
}
}
internal static string ReadRegSetting(string sSubKey)
{
string sValue = null;
try
{
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(CASA_REG_KEY);
if (key != null)
{
sValue = (string)key.GetValue(sSubKey);
}
key.Close();
}
catch
{
}
return sValue;
}
#endif
internal static void RemoveGlobalCASASettings()
{
#if W32
// Delete CASA settings
try
{
Microsoft.Win32.Registry.LocalMachine.DeleteSubKeyTree(CASA_REG_KEY);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
#endif
}
internal static string GetGlobalConfPath()
{
#if LINUX
// Does directory exist?
if (!Directory.Exists(ConstStrings.SSCS_LINUX_GLOBAL_CONF_PATH))
{
Directory.CreateDirectory(ConstStrings.SSCS_LINUX_GLOBAL_CONF_PATH);
}
return ConstStrings.SSCS_LINUX_GLOBAL_CONF_PATH + ConstStrings.SSCS_GLOBAL_CONF_FILE;
#else
return ConstStrings.SSCS_GLOBAL_CONF_FILE;
#endif
}
internal static void AppendToDoc(XmlDocument doc)
{
try{
XmlElement configElem = doc.CreateElement("ConfigSettings");
doc.AppendChild(configElem);
for (int i = 0; i < m_nvc.Count; i++)
{
XmlElement settingElem = doc.CreateElement("Setting");
configElem.AppendChild(settingElem);
XmlElement nameElem = doc.CreateElement("Name");
nameElem.InnerText = m_nvc.GetKey(i);
settingElem.AppendChild(nameElem);
XmlElement valueElem = doc.CreateElement("Value");
valueElem.InnerXml = m_nvc.GetValues(i)[0];
settingElem.AppendChild(valueElem);
}
}
catch (Exception)
{
//Console.WriteLine(e.ToString());
}
}
internal static void LoadConfigSettings()
{
string sGlobalConfPath = GetGlobalConfPath();
if (File.Exists(sGlobalConfPath))
{
XmlDocument doc = new XmlDocument();
doc.Load(sGlobalConfPath);
// Load config settings
System.Collections.Specialized.NameValueCollection nvc = new System.Collections.Specialized.NameValueCollection();
XmlNode configNode = doc.SelectSingleNode("//ConfigSettings");
if (configNode != null)
{
XmlNodeList nodeList = configNode.ChildNodes;
XmlNode setting;
for (int i = 0; i < nodeList.Count; i++)
{
setting = nodeList[i];
XmlNode nameNode = setting.SelectSingleNode("Name");
XmlNode valueNode = setting.SelectSingleNode("Value");
nvc.Add(nameNode.InnerText, valueNode.InnerText);
}
}
if (nvc.Count > 0)
{
m_nvc = nvc;
}
}
}
}
}

View File

@ -104,6 +104,8 @@ namespace sscs.constants
internal static string SSCS_LINUX_DEBUGLOG = "/var/log/micasad_debug.log"; internal static string SSCS_LINUX_DEBUGLOG = "/var/log/micasad_debug.log";
internal static string SSCS_LINUX_PIDFILE = "/var/run/micasad.pid"; internal static string SSCS_LINUX_PIDFILE = "/var/run/micasad.pid";
internal static string SSCS_LINUX_GLOBAL_CONF_PATH = "/etc/opt/novell/micasa/";
internal static string SSCS_GLOBAL_CONF_FILE = "micasad.conf.xml";
internal static bool STATUS = true; internal static bool STATUS = true;
internal static bool DEBUG = false; internal static bool DEBUG = false;

View File

@ -120,17 +120,15 @@ namespace sscs.init
stopService(); stopService();
uninstallService(); uninstallService();
CredMgr.Uninstall(); CredMgr.Uninstall();
CSSSUtils.RemoveGlobalCASASettings(); Config.RemoveGlobalCASASettings();
return; return;
} }
else if (opt != null && opt.ToLower() == "/allowdesktopaccess") else if (opt != null && opt.ToLower() == "/allowdesktopaccess")
{ {
CSSSUtils.SetAllowDesktopAccess(); Config.SetAllowDesktopAccess();
return; return;
} }
if (opt != null if (opt != null
&& (opt.ToLower() == "/standalone" || opt.ToLower() == "/s")) && (opt.ToLower() == "/standalone" || opt.ToLower() == "/s"))
{ {