Checked in for changes in ADLib for Add-Modify-Delete for KWallet and
Keyring
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections;
|
||||
using System.Threading;
|
||||
using Gtk;
|
||||
using GLib;
|
||||
|
||||
|
||||
namespace Novell.CASA.DataEngines.GK
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
@@ -54,6 +56,7 @@ namespace Novell.CASA.DataEngines.GK
|
||||
public IntPtr value;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class Attribute
|
||||
{
|
||||
public uint type;
|
||||
@@ -76,6 +79,15 @@ namespace Novell.CASA.DataEngines.GK
|
||||
public static extern int GetAttributeList(string keyring,int itemId, out IntPtr attrList);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int FreeAttributeList(IntPtr attrList);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int SetPassword (string keyring, int itemid, string password);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int RemoveItem (string keyring, int itemid);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int SetItemAttributes (string keyring, int itemid, IntPtr[] attrs, int length);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int CreateItem(string keyringName, int itemType, string displayName, string password, IntPtr[] arrptr, int attrCount);
|
||||
|
||||
|
||||
public static KeyringInfo GKGetKeyringInfo(string name)
|
||||
{
|
||||
@@ -282,5 +294,81 @@ namespace Novell.CASA.DataEngines.GK
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int SetAttributes(String keyringName, int itemId, NameValueCollection nvc)
|
||||
{
|
||||
IntPtr[] arrptr = new IntPtr[nvc.Count];
|
||||
for(int i=0; i < nvc.Count; i++)
|
||||
{
|
||||
string key = nvc.GetKey(i);
|
||||
string value = nvc.Get(key);
|
||||
Attribute attr = new Attribute();
|
||||
attr.type=0;
|
||||
attr.key=key;
|
||||
attr.value=value;
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(attr));
|
||||
Marshal.StructureToPtr(attr,ptr,false);
|
||||
arrptr[i] = ptr;
|
||||
}
|
||||
int ret = SetItemAttributes( keyringName,itemId,arrptr,nvc.Count);
|
||||
FreeIntPtrArray(arrptr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static int RemoveSecret(string keyringname, int itemid)
|
||||
{
|
||||
|
||||
return(RemoveItem(keyringname,itemid));
|
||||
}
|
||||
|
||||
public static int CreateSecret(String keyringName, string strItemType, string displayName, string password, NameValueCollection nvc)
|
||||
{
|
||||
Console.WriteLine("In CreateSecret ");
|
||||
int itemType = 3; //No Type
|
||||
IntPtr[] arrptr = new IntPtr[nvc.Count];
|
||||
if(strItemType.CompareTo("Generic Secret") == 0 )
|
||||
{
|
||||
itemType = 0;
|
||||
}
|
||||
else
|
||||
if(strItemType.CompareTo("Network Password") == 0 )
|
||||
{
|
||||
itemType = 1;
|
||||
}
|
||||
else
|
||||
if(strItemType.CompareTo("Note") == 0 )
|
||||
{
|
||||
itemType = 2;
|
||||
}
|
||||
Console.WriteLine("In CreateSecret ItemType = "+itemType);
|
||||
for(int i=0; i < nvc.Count; i++)
|
||||
{
|
||||
string key = nvc.GetKey(i);
|
||||
Console.WriteLine("In CreateSecret Key "+i + " = " + key);
|
||||
string value = nvc.Get(key);
|
||||
Console.WriteLine("In CreateSecret Value "+i + " = " + value);
|
||||
Attribute attr = new Attribute();
|
||||
attr.type=0;
|
||||
attr.key=key;
|
||||
attr.value=value;
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(attr));
|
||||
Marshal.StructureToPtr(attr,ptr,false);
|
||||
arrptr[i] = ptr;
|
||||
}
|
||||
Console.WriteLine("Calling Create item ");
|
||||
int ret = CreateItem(keyringName, itemType, displayName, password, arrptr, nvc.Count);
|
||||
FreeIntPtrArray(arrptr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void FreeIntPtrArray(IntPtr[] arrptr)
|
||||
{
|
||||
for(int i=0; i < arrptr.Length; i++)
|
||||
{
|
||||
Marshal.FreeHGlobal(arrptr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user