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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "ad_gk.h"
|
||||
|
||||
GMainLoop *loop = NULL;
|
||||
|
||||
void ListKeyringsCb (GnomeKeyringResult result,
|
||||
GList *keyrings,
|
||||
gpointer data)
|
||||
@@ -235,3 +237,151 @@ int FreeAttributeList(GList *attrList)
|
||||
g_list_free(attrList);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
OperationCompletedCb (GnomeKeyringResult result,
|
||||
gpointer data)
|
||||
{
|
||||
OperationCompleted *cbData = (OperationCompleted *)data;
|
||||
g_print ("ad_gk.c : Operation %s Completed %d\n", cbData->OperationName, result);
|
||||
cbData->result = result;
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
CreateItemCb (GnomeKeyringResult result,
|
||||
guint32 id,
|
||||
gpointer data)
|
||||
{
|
||||
OperationCompleted *cbData = (OperationCompleted *)data;
|
||||
g_print ("ad_gk.c : CreateItemCb : created item: res: %d id: %d\n", result, id);
|
||||
if (result != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
g_print ("ad_gk.c : CreateItemCb : Unable to create item : %d\n", result);
|
||||
}
|
||||
cbData->result = result;
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
SetItemAttributes (char *keyring, guint32 itemid, Attribute **attrs, int length)
|
||||
{
|
||||
GnomeKeyringAttributeList *attributes;
|
||||
GnomeKeyringAttribute attribute;
|
||||
OperationCompleted cbData;
|
||||
int i;
|
||||
printf("ad_gk.c : In SetItemAttributes\n");
|
||||
printf("ad_gk.c : Keyring %s, itemid %d\n",keyring,itemid);
|
||||
cbData.OperationName = "Set Item Attributes";
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
attributes = gnome_keyring_attribute_list_new ();
|
||||
for (i=0; i< length; i++)
|
||||
{
|
||||
printf("ad_gk.c : In key %s \n", attrs[i]->key);
|
||||
attribute.name = g_strdup (attrs[i]->key);
|
||||
attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
|
||||
attribute.value.string = g_strdup (attrs[i]->value);
|
||||
g_array_append_val (attributes, attribute);
|
||||
}
|
||||
gnome_keyring_item_set_attributes (keyring, itemid, attributes,
|
||||
OperationCompletedCb, &cbData, NULL);
|
||||
gnome_keyring_attribute_list_free (attributes);
|
||||
g_main_loop_run (loop);
|
||||
return cbData.result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
RemoveItem (char *keyring, guint32 itemid)
|
||||
{
|
||||
OperationCompleted cbData;
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
cbData.OperationName = "Remove Item";
|
||||
gnome_keyring_item_delete (keyring, itemid,
|
||||
OperationCompletedCb, &cbData, NULL);
|
||||
g_main_loop_run (loop);
|
||||
return cbData.result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SetPassword (char *keyring, guint32 itemid, char *secret)
|
||||
{
|
||||
GnomeKeyringItemInfo *info;
|
||||
OperationCompleted cbData;
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
cbData.OperationName = "Set Item Secret";
|
||||
info = gnome_keyring_item_info_new ();
|
||||
gnome_keyring_item_info_set_secret (info, secret);
|
||||
gnome_keyring_item_set_info (keyring, itemid, info,
|
||||
OperationCompletedCb, &cbData, NULL);
|
||||
gnome_keyring_item_info_free (info);
|
||||
g_main_loop_run (loop);
|
||||
return cbData.result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
CreateItem(char *keyring, int32_t itemType, char *display_name, char *secret, Attribute **attrs, int attrcnt)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateItemInKeyring(keyring,itemType,display_name,secret,attrs,attrcnt);
|
||||
if (ret == 4)
|
||||
{
|
||||
ret = CreateKeyring(keyring);
|
||||
if (ret != 0)
|
||||
{
|
||||
return GNOME_KEYRING_RESULT_CANNOT_CREATE_KEYRING ;
|
||||
}
|
||||
ret = CreateItemInKeyring(keyring,itemType,display_name ,secret,attrs,attrcnt);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
CreateItemInKeyring(char *keyring, int32_t itemType, char *display_name, char *secret, Attribute **attrs, int attrcnt)
|
||||
{
|
||||
GnomeKeyringAttributeList *attributes;
|
||||
GnomeKeyringAttribute attribute;
|
||||
OperationCompleted cbData;
|
||||
int i;
|
||||
printf("ad:gk.c :In CreateItemInKeyring\n");
|
||||
printf("ad.gk.c : CreateItemInKeyring : Keyring %s, itemType %d displayname %s, secret %s \n",keyring,itemType, display_name,secret);
|
||||
cbData.OperationName = "Create Item";
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
attributes = gnome_keyring_attribute_list_new ();
|
||||
for (i=0; i< attrcnt; i++)
|
||||
{
|
||||
printf("as.gk.c : CreateItemInKeyring : In key %s \n", attrs[i]->key);
|
||||
attribute.name = g_strdup (attrs[i]->key);
|
||||
attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
|
||||
attribute.value.string = g_strdup (attrs[i]->value);
|
||||
g_array_append_val (attributes, attribute);
|
||||
}
|
||||
|
||||
gnome_keyring_item_create(keyring,itemType,display_name,attributes,secret,FALSE,CreateItemCb,&cbData,NULL);
|
||||
gnome_keyring_attribute_list_free (attributes);
|
||||
g_main_loop_run (loop);
|
||||
return cbData.result;
|
||||
}
|
||||
|
||||
static int
|
||||
CreateKeyring(char *keyring)
|
||||
{
|
||||
|
||||
OperationCompleted cbData;
|
||||
cbData.OperationName = "Create Keyring";
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
gnome_keyring_create(keyring,NULL,OperationCompletedCb,&cbData,NULL);
|
||||
g_main_loop_run(loop);
|
||||
return cbData.result;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
#define KEY_SIZE 128
|
||||
#define VAL_SIZE 128
|
||||
|
||||
|
||||
enum KeyringResultExtended { GNOME_KEYRING_RESULT_NO_SUCH_ITEM = 128,
|
||||
GNOME_KEYRING_RESULT_CANNOT_DELETE_SECRET_VALUE,
|
||||
GNOME_KEYRING_RESULT_MALFORMED_XML,
|
||||
GNOME_KEYRING_RESULT_CANNOT_CREATE_KEYRING
|
||||
};
|
||||
|
||||
typedef struct _KeyringInfo
|
||||
{
|
||||
int32_t lockOnIdle;
|
||||
@@ -44,6 +51,19 @@ int GetItemInfo(char *keyring, int itemId, ItemInfo *info);
|
||||
int GetAttributeList(char *keyring, int itemId, GList **);
|
||||
int FreeAttributeList(GList *attrList);
|
||||
|
||||
int
|
||||
SetItemAttributes (char *keyring, guint32 item_id, Attribute **attrs, int length);
|
||||
int
|
||||
CreateItem(char *keyring, int32_t itemType, char *display_name, char *secret, Attribute **attrs, int attrcnt);
|
||||
int
|
||||
RemoveItem (char *keyring, guint32 itemid);
|
||||
int
|
||||
SetPassword (char *keyring, guint32 itemid, char *secret);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct _GetKeyringsCbData
|
||||
{
|
||||
GList **keyringList;
|
||||
@@ -73,4 +93,13 @@ typedef struct _GetAttributeListCbData
|
||||
GList **attrList;
|
||||
GMainLoop *loop;
|
||||
}GetAttributeListCbData;
|
||||
typedef struct _OperationCompleted
|
||||
{
|
||||
char *OperationName;
|
||||
GnomeKeyringResult result;
|
||||
|
||||
}OperationCompleted;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user