Alpha code for Secret Persistence Policy. In Progress.

This commit is contained in:
Jim Norman 2006-09-15 20:36:52 +00:00
parent 13cdbb2448
commit d41f5b42c3
6 changed files with 1393 additions and 338 deletions

View File

@ -235,6 +235,16 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "PersistentPolicyDialog.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "PolicyDialog.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "SingleApplication.cs"
SubType = "Code"

View File

@ -102,7 +102,9 @@ namespace Novell.CASA.GUI
checkbuttonGnomeKeyring,
checkbuttonKdeWallet,
checkbuttonCloseMessage,
checkbuttonRunInTray;
checkbuttonRunInTray,
checkbuttonSaveSecrets,
checkbuttonDecrypt;
[Glade.Widget]
Gtk.Label label88,
@ -829,6 +831,7 @@ namespace Novell.CASA.GUI
}
}
public void on_entryFirefoxMP_activate(object obj, EventArgs args)
{
on_buttonFirefoxMPok_clicked(obj, args);
@ -1707,6 +1710,22 @@ namespace Novell.CASA.GUI
config.WriteConfig();
}
public void on_checkbuttonSaveSecrets_toggled(object obj, EventArgs args)
{
if (checkbuttonSaveSecrets.Active)
{
entryStorageDirectory.Sensitive = true;
buttonChooseDirectory.Sensitive = true;
checkbuttonDecrypt.Sensitive = true;
}
else
{
entryStorageDirectory.Sensitive = false;
buttonChooseDirectory.Sensitive = false;
checkbuttonDecrypt.Sensitive = false;
}
}
public void okbuttonPreferences_clicked(object abj, EventArgs args)
{
Logger.DbgLog("GUI:CasaMain.okbuttonPreferences_clicked() - BEGIN");
@ -2133,7 +2152,7 @@ namespace Novell.CASA.GUI
{
//Choose directory for persistent storage
FileChooser fc = new FileChooser(FileChooser.ACTION_CHOOSE_DIR);
string sDirectory = fc.GetFile(entryStorageDirectory.Text, null);
string sDirectory = fc.GetFile(entryStorageDirectory.Text, null, "*.casa");
// show the user the directory choosen
if (sDirectory != null)
@ -2190,6 +2209,18 @@ namespace Novell.CASA.GUI
return false;
}
public void on_policies_activate(object obj, EventArgs args)
{
//Console.WriteLine("policy Activate");
//PolicyDialog pd = new PolicyDialog();
//pd.ShowDialog();
PersistentPolicyDialog ppd = new PersistentPolicyDialog();
ppd.ShowDialog();
}
/// <summary>
/// ********************************************************************
/// private void HandleQuit()
@ -2249,7 +2280,7 @@ namespace Novell.CASA.GUI
{
DbgFileChooser dbf = new DbgFileChooser();
dbf.Run();
}
}
}
}

View File

@ -0,0 +1,309 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using Gtk;
using Glade;
using Novell.CASA;
using Novell.CASA.CASAPolicy;
namespace Novell.CASA.GUI
{
/// <summary>
/// Summary description for PolicyDialog.
/// </summary>
public class PersistentPolicyDialog
{
private TreeStore tsPersistentList = new TreeStore(typeof(string));
private TreeStore tsNonPersistentList = new TreeStore(typeof(string));
private PersistencePol policy = null;
private bool bChanged = false;
#region Glade Widgets
[Glade.Widget]
Gtk.TreeView tvPersistentList,
tvNonPersistentList;
[Glade.Widget]
Gtk.Dialog dialogPersistentPolicy;
[Glade.Widget]
Gtk.Button applybuttonPersistent,
buttonMakeNonPersistent,
buttonMakePersistent;
#endregion
public PersistentPolicyDialog()
{
//
// TODO: Add constructor logic here
//
}
public void ShowDialog()
{
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogPersistentPolicy", null);
gxmlTemp.Autoconnect(this);
activateMoveButtons(false, false);
applybuttonPersistent.Sensitive = false;
// load store
SecretStore ss = SecretStore.getInstance();
StringCollection sc = ss.enumerateSecretIDs();
StringEnumerator senum = sc.GetEnumerator();
// load policy
policy = (PersistencePol)ICASAPol.GetPolicy(CASAPolType.PERSISTENCE_POL);
if (policy == null)
{
policy = new PersistencePol("Platform", "PersistentPath_NOT USED", 10);
}
while (senum.MoveNext())
{
string sSecretID = senum.Current;
if (policy.GetSecretPolicy(sSecretID, "Persistent", true))
{
tsPersistentList.AppendValues(sSecretID);
}
else
{
//tsNonPersistentList.AppendValues(sSecretID);
}
}
// display non-persistent IDs
ArrayList al = policy.GetNonpersistentSecretIDs();
for (int i=0; i<al.Count; i++)
{
tsNonPersistentList.AppendValues((string)al[i]);
}
// set sortable
tsPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
tsNonPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
// add Columnts
tvPersistentList.AppendColumn("Persistent Secrets", new CellRendererText(), "text", 0);
tvPersistentList.Columns[0].Clickable = true;
tvPersistentList.Columns[0].Clicked +=new EventHandler(PersistentPolicyDialog_Clicked);
tvPersistentList.RowActivated +=new RowActivatedHandler(tvPersistentList_RowActivated);
tvPersistentList.ButtonReleaseEvent += new ButtonReleaseEventHandler(tvPersistentList_ButtonReleaseEvent);
tvNonPersistentList.AppendColumn("Non-Persistent Secrets", new CellRendererText(), "text", 0);
tvNonPersistentList.Columns[0].Clickable = true;
tvNonPersistentList.Columns[0].Clicked +=new EventHandler(NonPersistentPolicyDialog_Clicked);
tvNonPersistentList.RowActivated +=new RowActivatedHandler(tvNonPeristentList_RowActivated);
tvNonPersistentList.ButtonReleaseEvent +=new ButtonReleaseEventHandler(tvNonPersistentList_ButtonReleaseEvent);
// hook up the model
tvPersistentList.Model = tsPersistentList;
tvNonPersistentList.Model = tsNonPersistentList;
}
public void on_applybuttonPersistent_clicked(object obj, EventArgs args)
{
if (bChanged)
{
// enumerate ts, setting the policy for each secret
TreeIter iter;
if(tsPersistentList.GetIterFirst(out iter))
{
do
{
string secretID = (string)tsPersistentList.GetValue(iter,0);
// set policy
if (policy != null)
{
policy.SetSecretPolicy(secretID, "Persistent", "True", "True");
}
}
while( tsPersistentList.IterNext(ref iter) );
}
if(tsNonPersistentList.GetIterFirst(out iter))
{
do
{
string secretID = (string)tsNonPersistentList.GetValue(iter,0);
// set policy
if (policy != null)
{
policy.SetSecretPolicy(secretID, "Persistent", "False", "True");
}
}
while( tsNonPersistentList.IterNext(ref iter) );
}
// save policy now
ICASAPol.SetPolicy(policy);
bChanged = false;
applybuttonPersistent.Sensitive = false;
activateMoveButtons(false, false);
}
}
public void on_okbutton_clicked(object obj, EventArgs args)
{
if (bChanged)
{
on_applybuttonPersistent_clicked(obj, args);
}
closeDialog();
}
public void on_cancelbutton_clicked(object obj, EventArgs args)
{
closeDialog();
}
private void closeDialog()
{
if (dialogPersistentPolicy != null)
{
dialogPersistentPolicy.Destroy();
}
}
private void tvPersistentList_RowActivated(object o, RowActivatedArgs args)
{
MakeNonPersistent();
}
private void MakeNonPersistent()
{
TreeModel model;
TreeIter iter;
String selected;
if( tvPersistentList.Selection.GetSelected (out model, out iter) )
{
selected = (string) model.GetValue (iter, 0);
tsNonPersistentList.AppendValues(selected);
tsPersistentList.Remove(ref iter);
bChanged = true;
applybuttonPersistent.Sensitive = true;
}
}
public void on_buttonMakeNonPersistent_clicked(object o, EventArgs args)
{
MakeNonPersistent();
}
public void on_buttonMakePersistent_clicked(object o, EventArgs args)
{
MakePersistent();
}
private void tvNonPeristentList_RowActivated(object o, RowActivatedArgs args)
{
MakePersistent();
}
private void MakePersistent()
{
TreeModel model;
TreeIter iter;
String selected;
if( tvNonPersistentList.Selection.GetSelected (out model, out iter) )
{
selected = (string) model.GetValue (iter, 0);
tsPersistentList.AppendValues(selected);
tsNonPersistentList.Remove(ref iter);
bChanged = true;
applybuttonPersistent.Sensitive = true;
}
}
private void PersistentPolicyDialog_Clicked(object sender, EventArgs e)
{
int iColID = 0;
Gtk.SortType sortType = Gtk.SortType.Ascending;
bool bReturn = tsPersistentList.GetSortColumnId(out iColID, out sortType);
if (bReturn)
{
if (sortType == Gtk.SortType.Ascending)
{
tsPersistentList.SetSortColumnId(0, Gtk.SortType.Descending);
}
else
{
tsPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
}
}
}
private void NonPersistentPolicyDialog_Clicked(object sender, EventArgs e)
{
int iColID = 0;
Gtk.SortType sortType = Gtk.SortType.Ascending;
bool bReturn = tsNonPersistentList.GetSortColumnId(out iColID, out sortType);
if (bReturn)
{
if (sortType == Gtk.SortType.Ascending)
{
tsNonPersistentList.SetSortColumnId(0, Gtk.SortType.Descending);
}
else
{
tsNonPersistentList.SetSortColumnId(0, Gtk.SortType.Ascending);
}
}
}
private void tvPersistentList_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
{
activateMoveButtons(true, false);
}
private void tvNonPersistentList_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
{
activateMoveButtons(false, true);
}
private void activateMoveButtons(bool bMakeNonPersist, bool bMakePersist)
{
if (bMakeNonPersist)
{
buttonMakeNonPersistent.Sensitive = true;
}
else
{
buttonMakeNonPersistent.Sensitive = false;
}
if (bMakePersist)
{
buttonMakePersistent.Sensitive = true;
}
else
{
buttonMakePersistent.Sensitive = false;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,8 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Xml.Serialization;
@ -54,13 +56,91 @@ public class PersistencePol : CASAPol
}
}
public PersistencePol(string osName,string path, int time)
public PersistencePol(string osName,string path, int time)
{
policyType = CASAPolType.PERSISTENCE_POL;
os = osName;
filePath = path;
pollInterval = time;
}
public PersistencePol(string osName,string path, int time, Hashtable htPolicies)
{
policyType = CASAPolType.PERSISTENCE_POL;
os = osName;
filePath = path;
pollInterval = time;
htSecretPolicys = htPolicies;
}
private Hashtable htSecretPolicys; // = new Hashtable();
public void SetSecretPolicy(string sSecretID, string sPolicyAttribID, string sPolicyAttribValue, string sDefaultValue)
{
if (htSecretPolicys == null)
{
htSecretPolicys = new Hashtable();
}
// find policys for given secretID
NameValueCollection nvc = (NameValueCollection)htSecretPolicys[sSecretID];
if (nvc == null)
{
nvc = new NameValueCollection();
htSecretPolicys.Add(sSecretID, nvc);
}
if (sPolicyAttribValue.Equals(sDefaultValue))
{
nvc.Remove(sPolicyAttribID);
}
else
{
nvc.Set(sPolicyAttribID, sPolicyAttribValue);
}
}
public bool GetSecretPolicy(string sSecretID, string sPolicyAttribID, bool bDefaultValue)
{
string sReturn = GetSecretPolicy(sSecretID, sPolicyAttribID, bDefaultValue.ToString());
return bool.Parse(sReturn);
}
public string GetSecretPolicy(string sSecretID, string sPolicyAttribID, string sDefaultValue)
{
if (htSecretPolicys != null)
{
NameValueCollection nvc = (NameValueCollection)htSecretPolicys[sSecretID];
if (nvc != null)
{
try
{
return nvc.GetValues(sPolicyAttribID)[0];
}
catch
{
}
}
}
return sDefaultValue;
}
public ArrayList GetNonpersistentSecretIDs()
{
ArrayList al = new ArrayList();
//enumerate all secrets loaded
IDictionaryEnumerator idEnum = htSecretPolicys.GetEnumerator();
while (idEnum.MoveNext())
{
string sSecretID = (string)idEnum.Key;
al.Add(sSecretID);
}
return al;
}
public override void DumpPol()
{
@ -95,10 +175,40 @@ public class PersistencePol : CASAPol
elem.InnerText = pollInterval.ToString();
persistPolElem.AppendChild(elem);
// write out policy for secrets
// write out NameValueCollection
XmlElement configElem = doc.CreateElement("SecretPolicies");
persistPolElem.AppendChild(configElem);
IDictionaryEnumerator ienum = htSecretPolicys.GetEnumerator();
while (ienum.MoveNext())
{
// get the collection for current SecretID
string sCurrentID = ienum.Key.ToString();
NameValueCollection nvc = (NameValueCollection)htSecretPolicys[sCurrentID];
// if no attributes exist, skip it
if (nvc.Count == 0) continue;
// create a policy element
XmlElement policyElement = doc.CreateElement("Secret");
policyElement.SetAttribute("id", sCurrentID);
// add all attributes
for (int i=0; i<nvc.Count; i++)
{
policyElement.SetAttribute(nvc.GetKey(i), nvc.GetValues(i)[0]);
}
configElem.AppendChild(policyElement);
}
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
Console.WriteLine(e.ToString());
}
}
}

View File

@ -22,6 +22,8 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
@ -179,7 +181,49 @@ public class ICASAPol
XmlNode pollIntervalNode = persistenceNode.SelectSingleNode(xpath);
int pollInterval = Convert.ToInt32(pollIntervalNode.InnerText);
PersistencePol persistencePol = new PersistencePol(os,storeFileLocation, pollInterval);
// load SecretPolices
xpath = "//SecretPolicies";
XmlNode policyNode = persistenceNode.SelectSingleNode(xpath);
Hashtable htSecretPolicies = new Hashtable();
if (policyNode != null)
{
XmlNodeList secretNodes = policyNode.ChildNodes;
IEnumerator ienum = secretNodes.GetEnumerator();
while (ienum.MoveNext())
{
XmlNode node = (XmlNode)ienum.Current;
// get the id
XmlAttributeCollection coll = node.Attributes;
XmlNode idNode = coll.GetNamedItem("id");
// get the rest of the attributes
IEnumerator enumAttribs = coll.GetEnumerator();
NameValueCollection nvc = new NameValueCollection();
while (enumAttribs.MoveNext())
{
XmlAttribute attrib = (XmlAttribute)enumAttribs.Current;
if (!attrib.Name.Equals("id"))
{
nvc.Add(attrib.Name, attrib.Value);
}
}
// add this one
try
{
htSecretPolicies.Add(idNode.Value, nvc);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
PersistencePol persistencePol = new PersistencePol(os,storeFileLocation, pollInterval, htSecretPolicies);
return persistencePol;
}
}