859
859
return gkr_operation_block (op);
862
typedef struct _create_keyring_args {
862
typedef struct _create_keyring_password_args {
863
863
gchar *keyring_name;
865
} create_keyring_args;
865
} create_keyring_password_args;
868
create_keyring_free (gpointer data)
868
create_keyring_password_free (gpointer data)
870
create_keyring_args *args = data;
870
create_keyring_password_args *args = data;
871
871
g_free (args->keyring_name);
872
872
egg_secure_strfree (args->password);
873
g_slice_free (create_keyring_args, args);
873
g_slice_free (create_keyring_password_args, args);
939
939
gkr_operation_prompt (op, prompt);
943
create_keyring_check_reply (GkrOperation *op, DBusMessage *reply, gpointer user_data)
945
create_keyring_args *args = user_data;
946
DBusMessageIter iter;
949
/* If no such object, then no such keyring exists and we're good to go. */
950
if (!dbus_message_is_error (reply, ERROR_NO_SUCH_OBJECT)) {
951
/* Success means 'already exists' */
952
if (!gkr_operation_handle_errors (op, reply))
953
gkr_operation_complete (op, GNOME_KEYRING_RESULT_ALREADY_EXISTS);
957
/* With a password requires a session, so get on that */
958
if (args->password) {
959
gkr_operation_push (op, create_keyring_password_reply, GKR_CALLBACK_OP_SESSION, args, NULL);
960
gkr_session_negotiate (op);
962
/* Otherwiswe just create the collection */
964
req = dbus_message_new_method_call (gkr_service_name (), SERVICE_PATH,
965
SERVICE_INTERFACE, "CreateCollection");
966
dbus_message_iter_init_append (req, &iter);
967
create_keyring_encode_properties (&iter, args->keyring_name);
968
gkr_operation_push (op, create_keyring_reply, GKR_CALLBACK_OP_MSG, NULL, NULL);
969
gkr_operation_request (op, req);
970
dbus_message_unref (req);
975
943
* gnome_keyring_create:
976
944
* @keyring_name: The new keyring name. Must not be %NULL.
995
963
GDestroyNotify destroy_data)
997
create_keyring_args *args;
965
create_keyring_password_args *args;
966
DBusMessageIter iter;
998
967
DBusMessage *req;
999
968
GkrOperation *op;
1002
970
g_return_val_if_fail (callback, NULL);
1004
972
op = gkr_operation_new (callback, GKR_CALLBACK_RES, data, destroy_data);
1006
args = g_slice_new0 (create_keyring_args);
1007
args->keyring_name = g_strdup (keyring_name);
1008
args->password = egg_secure_strdup (password);
1011
* The secrets API has a significantly different model with creating of
1012
* keyrings, where we never get an 'already exists' error. However this
1013
* breaks certain strange uses of gnome_keyring_create ().
1015
* So we simulate 'already exists' in a fairly good, but 'racy' manner.
1018
path = gkr_encode_keyring_name (keyring_name);
1019
req = prepare_property_get (path, COLLECTION_INTERFACE, "Label");
1020
gkr_operation_push (op, create_keyring_check_reply, GKR_CALLBACK_OP_MSG,
1021
args, create_keyring_free);
1022
gkr_operation_request (op, req);
1023
dbus_message_unref (req);
974
/* With and without password are completely different */
977
args = g_slice_new0 (create_keyring_password_args);
978
args->keyring_name = g_strdup (keyring_name);
979
args->password = egg_secure_strdup (password);
980
gkr_operation_push (op, create_keyring_password_reply, GKR_CALLBACK_OP_SESSION,
981
args, create_keyring_password_free);
982
gkr_session_negotiate (op);
985
req = dbus_message_new_method_call (gkr_service_name (), SERVICE_PATH,
986
SERVICE_INTERFACE, "CreateCollection");
987
dbus_message_iter_init_append (req, &iter);
988
create_keyring_encode_properties (&iter, keyring_name);
989
gkr_operation_push (op, create_keyring_reply, GKR_CALLBACK_OP_MSG, NULL, NULL);
990
gkr_operation_request (op, req);
991
dbus_message_unref (req);
1026
994
gkr_operation_unref (op);
4548
4516
/* All done, complete the operation here */
4549
4517
if (path == NULL) {
4550
4518
cb = gkr_operation_pop (op);
4551
gkr_callback_invoke_ok_string (cb, NULL);
4519
gkr_callback_invoke_res (cb, GNOME_KEYRING_RESULT_NO_MATCH);
4553
4521
/* We need a session to get the secret for this item */