- Added support for ADD/MODIFY/DELETE functionalities for Keyring and
Kwallet stores in A-Dlib. .....................................................................
This commit is contained in:
@@ -188,9 +188,10 @@ namespace Novell.CASA.DataEngines
|
||||
idattr.Value = secid;
|
||||
Secret.SetAttributeNode(idattr);
|
||||
|
||||
XmlAttribute typeAttr = doc.CreateAttribute(ConstStrings.CCF_TYPE);
|
||||
/*XmlAttribute typeAttr = doc.CreateAttribute(ConstStrings.CCF_TYPE);
|
||||
typeAttr.Value = entryType;
|
||||
Secret.SetAttributeNode(typeAttr);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -290,77 +291,62 @@ namespace Novell.CASA.DataEngines
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
SetSecret will modify the Value(s) of a Key(s) for an existing secret
|
||||
SetSecret will also add new secrets
|
||||
|
||||
|
||||
Parameters
|
||||
|
||||
secret : Secrets XMLNode
|
||||
1. If a Key node of a secret is missing then that key will be deleted
|
||||
2. For Gnome keyring, Key having Id "GkPassword" cannot be deleted as
|
||||
Gnome Api's do not allow it.
|
||||
|
||||
3. All Time nodes for a Secret need not be passed as they cannot be set.
|
||||
4. Keyring attributes have a fixed datatype of Int and String. Currently we support only String types.
|
||||
To support int types CCF needs to be modified accordingly.
|
||||
5. To signify that a GnomeKeyring secret should be added, append the secret's ID with a ":".
|
||||
|
||||
|
||||
StoreID : int value
|
||||
Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET;
|
||||
|
||||
Returns
|
||||
An Error code or 0 if operation is successfull.
|
||||
***************************************************************************************/
|
||||
|
||||
|
||||
public int SetSecret(XmlNode secret)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
string walletName = ExtractWalletName(secret);
|
||||
string folderName = ExtractFolderName(secret);
|
||||
string keyName = ExtractKeyName(secret);
|
||||
int secretType = ExtractSecretType(secret);
|
||||
if (secretType != 3) //Type not Map
|
||||
|
||||
if (secretType != 3) //Type not Map
|
||||
{
|
||||
|
||||
string value = secret.ChildNodes[0].ChildNodes[0].InnerText; //Secret.Key.Value
|
||||
|
||||
return(kwallet.SetSecret(walletName, folderName, secretType, keyName, value, value.Length));
|
||||
}
|
||||
else //If type is Map
|
||||
{
|
||||
|
||||
NameValueCollection nvc = new NameValueCollection();
|
||||
|
||||
for (int i =0; i< secret.ChildNodes.Count; i++)
|
||||
{
|
||||
|
||||
XmlNode key = secret.ChildNodes[i];
|
||||
XmlAttributeCollection atcol;
|
||||
atcol = key.Attributes;
|
||||
String keyMapName = atcol["ID"].InnerXml;
|
||||
Console.WriteLine("Map Ele KeyName = " + keyMapName);
|
||||
|
||||
string value = key.ChildNodes[0].InnerText; //Secret.Key.Value
|
||||
Console.WriteLine("Map Ele Value = " + value);
|
||||
nvc.Add(keyMapName,value);
|
||||
|
||||
nvc.Add(keyMapName,value);
|
||||
}
|
||||
|
||||
|
||||
return(kwallet.SetSecret(walletName, folderName,keyName,nvc));
|
||||
}
|
||||
}
|
||||
catch(NullReferenceException n)
|
||||
{
|
||||
Console.WriteLine("Exception in Set Secret Cause :" + n.ToString());
|
||||
//Console.WriteLine("Exception in Set Secret Cause :" + n.ToString());
|
||||
return (int)KWalletResult.KWALLET_RESULT_MALFORMED_XML;
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Exception in Set Secret Cause :" + e.ToString());
|
||||
//Console.WriteLine("Exception in Set Secret Cause :" + e.ToString());
|
||||
return (int)KWalletResult.KWALLET_RESULT_UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SetSecret(XmlNode secret, int opnType)
|
||||
{
|
||||
return SetSecret(secret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -369,25 +355,6 @@ namespace Novell.CASA.DataEngines
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
/**************************************************************************************
|
||||
Remove will delete a Secret.
|
||||
|
||||
Parameters
|
||||
|
||||
secret : Secrets XmlNode
|
||||
1. This node will be deleted from its parent.
|
||||
|
||||
|
||||
StoreID : int value
|
||||
Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET;
|
||||
|
||||
|
||||
Returns
|
||||
An Error code or 0 if operation is successfull. Error code is same as above
|
||||
|
||||
**************************************************************************************/
|
||||
|
||||
|
||||
public int Remove(XmlNode secret)
|
||||
{
|
||||
try
|
||||
@@ -395,7 +362,6 @@ namespace Novell.CASA.DataEngines
|
||||
string walletName = ExtractWalletName(secret);
|
||||
string folderName = ExtractFolderName(secret);
|
||||
string keyName = ExtractKeyName(secret);
|
||||
int secretType = ExtractSecretType(secret);
|
||||
int res = kwallet.DeleteSecret(walletName, folderName, keyName);
|
||||
if (res == 0)
|
||||
{
|
||||
@@ -406,13 +372,13 @@ namespace Novell.CASA.DataEngines
|
||||
}
|
||||
catch(NullReferenceException n)
|
||||
{
|
||||
Console.WriteLine("Exception in Set Secret Cause :" + n.ToString());
|
||||
//Console.WriteLine("Exception in Set Secret Cause :" + n.ToString());
|
||||
return (int)KWalletResult.KWALLET_RESULT_MALFORMED_XML;
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Exception in Set Secret Cause :" + e.ToString());
|
||||
//Console.WriteLine("Exception in Set Secret Cause :" + e.ToString());
|
||||
return (int)KWalletResult.KWALLET_RESULT_UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -421,10 +387,8 @@ namespace Novell.CASA.DataEngines
|
||||
{
|
||||
XmlAttributeCollection atcol;
|
||||
XmlNode parentNode = secret.ParentNode.ParentNode.ParentNode;
|
||||
Console.WriteLine("In Extract Wallet Name ");
|
||||
atcol = parentNode.Attributes;
|
||||
String walletname = atcol["ID"].InnerXml;
|
||||
Console.WriteLine("In Extract Wallet Name Wallet Name = " + walletname);
|
||||
return walletname;
|
||||
}
|
||||
|
||||
@@ -432,20 +396,16 @@ namespace Novell.CASA.DataEngines
|
||||
{
|
||||
XmlAttributeCollection atcol;
|
||||
XmlNode parentNode = secret.ParentNode.ParentNode; //Folder.Type.Secret
|
||||
Console.WriteLine("In Extract Folder Name ");
|
||||
atcol = parentNode.Attributes;
|
||||
String foldername = atcol["Name"].InnerXml;
|
||||
Console.WriteLine("In Extract Folder Name Folder Name = " + foldername);
|
||||
return foldername;
|
||||
}
|
||||
|
||||
string ExtractKeyName(XmlNode secret)
|
||||
{
|
||||
XmlAttributeCollection atcol;
|
||||
Console.WriteLine("In Extract Key Name ");
|
||||
atcol = secret.Attributes;
|
||||
String keyname = atcol["ID"].InnerXml;
|
||||
Console.WriteLine("In Extract Key Name Key Name = " + keyname);
|
||||
return keyname;
|
||||
}
|
||||
|
||||
@@ -453,10 +413,8 @@ namespace Novell.CASA.DataEngines
|
||||
{
|
||||
XmlAttributeCollection atcol;
|
||||
XmlNode parentNode = secret.ParentNode; //Type.Secret
|
||||
Console.WriteLine("In Extract Entry Type ");
|
||||
atcol = parentNode.Attributes;
|
||||
String entryType = atcol["ID"].InnerXml;
|
||||
Console.WriteLine("In Extract Entry Type = " + entryType);
|
||||
if (entryType.CompareTo("Passwords")== 0)
|
||||
{
|
||||
return 1;
|
||||
@@ -473,19 +431,20 @@ namespace Novell.CASA.DataEngines
|
||||
}
|
||||
|
||||
|
||||
#if TEST
|
||||
#if TEST
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("Hello there");
|
||||
KWalletEngine kw = new KWalletEngine();
|
||||
|
||||
|
||||
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/kwtest.xml");
|
||||
|
||||
@@ -500,9 +459,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'))
|
||||
kw.Aggregate ();
|
||||
else
|
||||
{
|
||||
@@ -516,17 +475,15 @@ 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("Wallet Name \n" + root.ChildNodes[0].Name);
|
||||
Console.WriteLine("Folder Name \n" + root.ChildNodes[0].ChildNodes[0].Name);
|
||||
Console.WriteLine("Type Name \n" + root.ChildNodes[0].ChildNodes[0].ChildNodes[0].Name);
|
||||
Console.WriteLine("Secret Name \n" + root.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].Name);
|
||||
XmlNode secret = root.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0];
|
||||
|
||||
if (c[0].Equals('2'))
|
||||
if (c[0].Equals('4'))
|
||||
res =kw.Remove(secret);
|
||||
else if (c[0].Equals('1'))
|
||||
res = kw.SetSecret(secret,ConstStrings.OPERATION_ADD_SECRET);
|
||||
else if (c[0].Equals('2'))
|
||||
res = kw.SetSecret(secret,ConstStrings.OPERATION_MODIFY_SECRET);
|
||||
else if (c[0].Equals('3'))
|
||||
res = kw.SetSecret(secret);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user