- Added support for ADD/MODIFY/DELETE functionalities for Keyring and

Kwallet stores in A-Dlib.
.....................................................................
This commit is contained in:
smanojna
2006-01-06 11:57:25 +00:00
parent b8aedf332e
commit f610a50037
12 changed files with 231 additions and 204 deletions

View File

@@ -160,21 +160,26 @@ namespace Novell.CASA.DataEngines
return doc.ChildNodes[0];
}
public int SetSecret(XmlNode secret)
public int SetSecret(XmlNode secret)
{
return (int)KeyringResultExtended.GNOME_KEYRING_RESULT_ERROR_UNKNOWN;
}
public int SetSecret(XmlNode secret, int opnType)
{
string password = null;
int retValue;
try
{
Console.WriteLine("In SetSecret Name = "+ secret.Name);
int itemid = ExtractSecretId(secret);
string keyringname = ExtractKeyringName(secret);
NameValueCollection newNVC = new System.Collections.Specialized.NameValueCollection();
NameValueCollection newNVC = new System.Collections.Specialized.NameValueCollection();
XmlNodeList keylist = secret.SelectNodes("descendant::Key");
Console.WriteLine("In SetSecret");
foreach (XmlNode tuple in keylist)
{
//Get the Key
@@ -190,36 +195,42 @@ namespace Novell.CASA.DataEngines
newNVC.Add(keyname, tuple.ChildNodes[0].InnerText);
}
}
if (itemid == -2) //Add Item Opn
if (opnType == ConstStrings.OPERATION_ADD_SECRET ) //Add Item Opn
{
string strItemType = ExtractItemType(secret);
string secretName = ExtractSecretName(secret);
string secretName = ExtractSecretName(secret, opnType);
return(GnomeKeyring.CreateSecret(keyringname, strItemType, secretName, password, newNVC));
}
//Modify secret Opn
if ( password != null)
{
retValue = GnomeKeyring.SetPassword(keyringname, itemid, password);
if (retValue != 0)
{
return retValue;
}
}
if (newNVC.Count != 0)
{
return (GnomeKeyring.SetAttributes( keyringname, itemid, newNVC));
}
return 0;
}
catch(NullReferenceException n)
{
Console.WriteLine("Exception in SetSecret = "+n.ToString());
//Console.WriteLine("Exception in SetSecret = "+n.ToString());
return (int)KeyringResultExtended.GNOME_KEYRING_RESULT_MALFORMED_XML;
}
catch(Exception e)
{
Console.WriteLine("Exception in SetSecret = "+e.ToString());
//Console.WriteLine("Exception in SetSecret = "+e.ToString());
return (int)KeyringResultExtended.GNOME_KEYRING_RESULT_ERROR_UNKNOWN;
}
}
@@ -228,6 +239,7 @@ namespace Novell.CASA.DataEngines
{
return ConstStrings.CASA_SUCCESS;
}
public int Remove(XmlNode secret)
{
try
@@ -238,13 +250,13 @@ namespace Novell.CASA.DataEngines
}
catch(NullReferenceException n)
{
Console.WriteLine("Exception in Remove = "+n.ToString());
//Console.WriteLine("Exception in Remove = "+n.ToString());
return (int)KeyringResultExtended.GNOME_KEYRING_RESULT_MALFORMED_XML;
}
catch(Exception e)
{
Console.WriteLine("Exception in Remove = "+e.ToString());
//Console.WriteLine("Exception in Remove = "+e.ToString());
return (int)KeyringResultExtended.GNOME_KEYRING_RESULT_ERROR_UNKNOWN;
}
}
@@ -253,13 +265,12 @@ namespace Novell.CASA.DataEngines
{
XmlAttributeCollection atcol = secret.Attributes;
String secretid = atcol["ID"].InnerXml;
Console.WriteLine("In Extract Secret Id");
//Check if itemId is present
if (secretid.EndsWith(":"))
/*if (secretid.EndsWith(":"))
{
Console.WriteLine("In Extract Secret Id : Add Opn");
return -2;
}
*/
int itemIdx = secretid.LastIndexOf(":");
if (itemIdx == -1)
{
@@ -269,14 +280,18 @@ namespace Novell.CASA.DataEngines
return itemid;
}
string ExtractSecretName(XmlNode secret)
string ExtractSecretName(XmlNode secret, int opnType)
{
XmlAttributeCollection atcol = secret.Attributes;
String secretid = atcol["ID"].InnerXml;
Console.WriteLine("In Extract Secret name");
if (opnType == ConstStrings.OPERATION_ADD_SECRET)
{
return secretid; //Not expecting an item Id
}
int itemIdx = secretid.LastIndexOf(":");
Console.WriteLine("Extracting Secret Name Last Index Of : = " + itemIdx);
//Check if itemId is present
//Return substring without itemId
return(secretid.Substring(0,itemIdx));
}
@@ -284,7 +299,6 @@ namespace Novell.CASA.DataEngines
{
XmlAttributeCollection atcol;
XmlNode parentNode = secret.ParentNode;
Console.WriteLine("In Extract Keyring Name");
atcol = parentNode.Attributes;
String keyringname = atcol["ID"].InnerXml;
return keyringname;
@@ -295,7 +309,6 @@ namespace Novell.CASA.DataEngines
{
XmlAttributeCollection atcol = secret.Attributes;
String itemType = atcol[ConstStrings.CCF_TYPE].InnerXml;
Console.WriteLine("In ExtractItemType");
return(itemType);
}
@@ -306,16 +319,17 @@ namespace Novell.CASA.DataEngines
{
Console.WriteLine("Hello there");
GKEngine gk = new GKEngine();
Console.WriteLine();
Console.WriteLine("********** Menu ***********");
Console.WriteLine("* 1. Set secret *");
Console.WriteLine("* 2. Remove secret *");
Console.WriteLine("* 3. Refresh *");
Console.WriteLine("* 4. Quit *");
Console.WriteLine("* 1. Add secret *");
Console.WriteLine("* 2. Modify secret *");
Console.WriteLine("* 3. Set secret *");
Console.WriteLine("* 4. Remove secret *");
Console.WriteLine("* 5. Refresh *");
Console.WriteLine("* 6. Quit *");
Console.WriteLine("***************************");
Console.WriteLine("For all options the input is the file /root/gktest.xml");
@@ -328,9 +342,9 @@ namespace Novell.CASA.DataEngines
char[] c = line.Substring(0, 1).ToCharArray();
if (c.Length > 0)
{
if (c[0].Equals('4'))
if (c[0].Equals('6'))
return;
if (c[0].Equals('3'))
if (c[0].Equals('5'))
{
XmlNode node = gk.Aggregate ();
XmlDocument doc = node.OwnerDocument;
@@ -351,22 +365,17 @@ namespace Novell.CASA.DataEngines
{
Console.WriteLine("Root is null");
}
Console.WriteLine("Root is not null\n");
Console.WriteLine("Root Name \n" + root.Name);
Console.WriteLine("Keyring Name \n" + root.ChildNodes[0].Name);
Console.WriteLine("Secret Name \n" + root.ChildNodes[0].ChildNodes[0].Name);
XmlNode secret = root.ChildNodes[0].ChildNodes[0];
Console.WriteLine("secret Name \n" + secret.Name);
if (c[0].Equals('2'))
if (c[0].Equals('4'))
res =gk.Remove(secret);
else if (c[0].Equals('1'))
res = gk.SetSecret(secret, ConstStrings.OPERATION_ADD_SECRET);
else if (c[0].Equals('2'))
res = gk.SetSecret(secret, ConstStrings.OPERATION_MODIFY_SECRET);
else if (c[0].Equals('3'))
res = gk.SetSecret(secret);
}
}
}