- Added Modify and Delete functionalities for Firefox Password

Manager Secrets into CASAManager.
This commit is contained in:
lsreevatsa
2006-03-15 15:56:11 +00:00
parent 49d966cf50
commit b6ff2610b2
8 changed files with 275 additions and 13 deletions

View File

@@ -130,7 +130,52 @@ namespace Novell.CASA.DataEngines
public int SetSecret(XmlNode secret, int opnType)
{
return (int)FireFoxResultExtended.FIREFOX_RESULT_ERROR_UNKNOWN;
string ProfileName=null,secretName=null;
int retVal=0;
ProfileName = ExtractProfileName(secret);
//Console.WriteLine("FfEngine.cs : ProfileName : " + ProfileName);
secretName = ExtractSecretName(secret, opnType);
Host newHost = new Host();
HostElement nh1 = null;
try
{
newHost.hostName = Marshal.StringToHGlobalAnsi(secretName);
//Console.WriteLine("FFEngine.cs : SecretName " + secretName);
}catch(Exception e)
{
Console.WriteLine("Unable to Marshal the SecretName" + e.ToString());
}
XmlNodeList keylist = secret.SelectNodes("descendant::Key");
try
{
IntPtr next = IntPtr.Zero;
for (int i=keylist.Count-1;i>=0;i--)
{
//Get the Key
HostElement nh = new HostElement();
XmlAttributeCollection at = keylist.Item(i).Attributes;
String keyname = (at["ID"]).InnerText;
String passwordstatus = (at["PasswordStatus"]).InnerText;
//Console.WriteLine("FFEngine.cs : Keyname : " + keyname);
//Console.WriteLine("FFEngine.cs : Value : " + keylist.Item(i).ChildNodes[0].InnerText );
nh.name = Marshal.StringToHGlobalAnsi(keyname);
nh.value = Marshal.StringToHGlobalAnsi(keylist.Item(i).ChildNodes[0].InnerText);
nh.isPassword = Convert.ToInt32(passwordstatus);
nh.next = next;
next = Marshal.AllocHGlobal(Marshal.SizeOf(nh));
Marshal.StructureToPtr(nh,next,false);
}
newHost.hostElement = next;
retVal = FireFox.Modify_Host(ProfileName,newHost,1);
}
catch(Exception e)
{
Console.WriteLine("Unable to Marshal the Key/Value Pairs" + e.ToString());
}
return retVal;
}
public int GetSecret(XmlNode secret)
@@ -140,7 +185,11 @@ namespace Novell.CASA.DataEngines
public int Remove(XmlNode secret)
{
return (int)FireFoxResultExtended.FIREFOX_RESULT_ERROR_UNKNOWN;
string ProfileName = ExtractProfileName(secret);
string secretName = ExtractSecretName(secret, ConstStrings.OPERATION_DELETE_SECRET);
int retVal = FireFox.Remove_Host(ProfileName,secretName);
//return (int)FireFoxResultExtended.FIREFOX_RESULT_ERROR_UNKNOWN;
return retVal;
}
//--------------------------------------------------------------
@@ -253,6 +302,7 @@ namespace Novell.CASA.DataEngines
XmlElement xmlKeyElement = null;
XmlAttribute keyIdAttr = null;
XmlAttribute keyPasswdStatusAttr = null;
XmlElement xmlValueElement = null;
name = (String)Marshal.PtrToStringAnsi(hostElementList.name);
@@ -267,6 +317,13 @@ namespace Novell.CASA.DataEngines
keyIdAttr.Value = name;
xmlKeyElement.SetAttributeNode(keyIdAttr);
keyPasswdStatusAttr = doc.CreateAttribute(ConstStrings.CCF_PASSWDSTATUS); //<Key>-ID
if(isPassword == 1)
keyPasswdStatusAttr.Value = "1";
else
keyPasswdStatusAttr.Value = "0";
xmlKeyElement.SetAttributeNode(keyPasswdStatusAttr);
xmlValueElement = doc.CreateElement(ConstStrings.CCF_VALUE); //<value>
xmlValueElement.InnerText = value;
xmlKeyElement.AppendChild(xmlValueElement); //</value>
@@ -326,6 +383,33 @@ namespace Novell.CASA.DataEngines
}
}
string ExtractSecretName(XmlNode secret, int opnType)
{
XmlAttributeCollection atcol = secret.Attributes;
String secretid = atcol["ID"].InnerXml;
//Console.WriteLine("FFEngine.cs: SecretId : " + secretid);
if (opnType == ConstStrings.OPERATION_ADD_SECRET)
{
return secretid; //Not expecting an item Id
}
return secretid;
//int itemIdx = secretid.LastIndexOf("]");
//Return substring without itemId
//return(secretid.Substring(0,itemIdx));
}
string ExtractProfileName(XmlNode secret)
{
XmlAttributeCollection atcol;
XmlNode parentNode = secret.ParentNode;
atcol = parentNode.Attributes;
String profilename = atcol["ID"].InnerXml;
return profilename;
}
//#if TEST
public static void Main()
{