Checked in for changes in ADLib for Add-Modify-Delete for KWallet and
Keyring
This commit is contained in:
@@ -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