~ubuntu-branches/ubuntu/precise/libgnome-keyring/precise-201110220705

« back to all changes in this revision

Viewing changes to library/gnome-keyring.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-03-31 10:24:59 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100331102459-j567owunjkeu0iu1
Tags: 2.30.0-0ubuntu1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
859
859
        return gkr_operation_block (op);
860
860
}
861
861
 
862
 
typedef struct _create_keyring_args {
 
862
typedef struct _create_keyring_password_args {
863
863
        gchar *keyring_name;
864
864
        gchar *password;
865
 
} create_keyring_args;
 
865
} create_keyring_password_args;
866
866
 
867
867
static void
868
 
create_keyring_free (gpointer data)
 
868
create_keyring_password_free (gpointer data)
869
869
{
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);
874
874
}
875
875
 
876
876
static void
892
892
static void
893
893
create_keyring_password_reply (GkrOperation *op, GkrSession *session, gpointer user_data)
894
894
{
895
 
        create_keyring_args *args = user_data;
 
895
        create_keyring_password_args *args = user_data;
896
896
        DBusMessageIter iter;
897
897
        DBusMessage *req;
898
898
 
939
939
                gkr_operation_prompt (op, prompt);
940
940
}
941
941
 
942
 
static void
943
 
create_keyring_check_reply (GkrOperation *op, DBusMessage *reply, gpointer user_data)
944
 
{
945
 
        create_keyring_args *args = user_data;
946
 
        DBusMessageIter iter;
947
 
        DBusMessage *req;
948
 
 
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);
954
 
                return;
955
 
        }
956
 
 
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);
961
 
 
962
 
        /* Otherwiswe just create the collection */
963
 
        } else {
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);
971
 
        }
972
 
}
973
 
 
974
942
/**
975
943
 * gnome_keyring_create:
976
944
 * @keyring_name: The new keyring name. Must not be %NULL.
994
962
                      gpointer                                     data,
995
963
                      GDestroyNotify                               destroy_data)
996
964
{
997
 
        create_keyring_args *args;
 
965
        create_keyring_password_args *args;
 
966
        DBusMessageIter iter;
998
967
        DBusMessage *req;
999
968
        GkrOperation *op;
1000
 
        gchar *path;
1001
969
 
1002
970
        g_return_val_if_fail (callback, NULL);
1003
971
 
1004
972
        op = gkr_operation_new (callback, GKR_CALLBACK_RES, data, destroy_data);
1005
973
 
1006
 
        args = g_slice_new0 (create_keyring_args);
1007
 
        args->keyring_name = g_strdup (keyring_name);
1008
 
        args->password = egg_secure_strdup (password);
1009
 
 
1010
 
        /*
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 ().
1014
 
         *
1015
 
         * So we simulate 'already exists' in a fairly good, but 'racy' manner.
1016
 
         */
1017
 
 
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);
1024
 
        g_free (path);
 
974
        /* With and without password are completely different */
 
975
 
 
976
        if (password) {
 
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);
 
983
 
 
984
        } else {
 
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);
 
992
        }
1025
993
 
1026
994
        gkr_operation_unref (op);
1027
995
        return 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);
4552
4520
 
4553
4521
        /* We need a session to get the secret for this item */
4554
4522
        } else {
4567
4535
        GkrOperation *op;
4568
4536
 
4569
4537
        g_assert (schema);
 
4538
        g_assert (va);
4570
4539
        g_assert (callback);
4571
4540
 
4572
4541
        attributes = schema_attribute_list_va (schema, va);
4694
4663
        GkrOperation *op;
4695
4664
 
4696
4665
        g_assert (schema);
 
4666
        g_assert (va);
4697
4667
        g_assert (callback);
4698
4668
 
4699
4669
        attributes = schema_attribute_list_va (schema, va);