static gboolean service_method_change_with_master_password (GkdExportedInternal *skeleton, GDBusMethodInvocation *invocation, gchar *path, GVariant *original_variant, GVariant *master_variant, GkdSecretService *self) { GkdSecretSecret *original, *master; GckObject *collection; GError *error = NULL; const gchar *sender; sender = g_dbus_method_invocation_get_sender (invocation); /* Parse the incoming message */ original = gkd_secret_secret_parse (self, sender, original_variant, &error); if (original == NULL) { g_dbus_method_invocation_take_error (invocation, error); return TRUE; } master = gkd_secret_secret_parse (self, sender, master_variant, &error); if (master == NULL) { g_dbus_method_invocation_take_error (invocation, error); return TRUE; } /* Make sure we have such a collection */ collection = gkd_secret_objects_lookup_collection (self->objects, sender, path); /* No such collection */ if (collection == NULL) { g_dbus_method_invocation_return_error_literal (invocation, GKD_SECRET_ERROR, GKD_SECRET_ERROR_NO_SUCH_OBJECT, "The collection does not exist"); } /* Success */ else if (gkd_secret_change_with_secrets (collection, NULL, original, master, &error)) gkd_exported_internal_complete_change_with_master_password (skeleton, invocation); /* Failure */ else gkd_secret_propagate_error (invocation, "Couldn't change collection password", error); gkd_secret_secret_free (original); gkd_secret_secret_free (master); if (collection) g_object_unref (collection); return TRUE; }
static DBusMessage* service_method_change_with_master_password (GkdSecretService *self, DBusMessage *message) { DBusError derr = DBUS_ERROR_INIT; GkdSecretSecret *original, *master; GckObject *collection; DBusMessageIter iter; DBusMessage *reply; GError *error = NULL; const gchar *path; /* Parse the incoming message */ if (!dbus_message_has_signature (message, "o(oayays)(oayays)")) return NULL; if (!dbus_message_iter_init (message, &iter)) g_return_val_if_reached (NULL); dbus_message_iter_get_basic (&iter, &path); dbus_message_iter_next (&iter); original = gkd_secret_secret_parse (self, message, &iter, &derr); if (original == NULL) return gkd_secret_error_to_reply (message, &derr); dbus_message_iter_next (&iter); master = gkd_secret_secret_parse (self, message, &iter, &derr); if (master == NULL) { gkd_secret_secret_free (original); return gkd_secret_error_to_reply (message, &derr); } /* Make sure we have such a collection */ collection = gkd_secret_objects_lookup_collection (self->objects, dbus_message_get_sender (message), path); /* No such collection */ if (collection == NULL) reply = dbus_message_new_error (message, SECRET_ERROR_NO_SUCH_OBJECT, "The collection does not exist"); /* Success */ else if (gkd_secret_change_with_secrets (collection, NULL, original, master, &error)) reply = dbus_message_new_method_return (message); /* Failure */ else reply = gkd_secret_propagate_error (message, "Couldn't change collection password", error); gkd_secret_secret_free (original); gkd_secret_secret_free (master); if (collection) g_object_unref (collection); return reply; }
static gboolean service_method_create_with_master_password (GkdExportedInternal *skeleton, GDBusMethodInvocation *invocation, GVariant *attributes, GVariant *master, GkdSecretService *self) { GckBuilder builder = GCK_BUILDER_INIT; GkdSecretSecret *secret = NULL; GckAttributes *attrs = NULL; GError *error = NULL; gchar *path; const gchar *caller; if (!gkd_secret_property_parse_all (attributes, SECRET_COLLECTION_INTERFACE, &builder)) { gck_builder_clear (&builder); g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid properties argument"); return TRUE; } caller = g_dbus_method_invocation_get_sender (invocation); secret = gkd_secret_secret_parse (self, caller, master, &error); if (secret == NULL) { gck_builder_clear (&builder); g_dbus_method_invocation_take_error (invocation, error); return TRUE; } gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE); attrs = gck_attributes_ref_sink (gck_builder_end (&builder)); path = gkd_secret_create_with_secret (attrs, secret, &error); gck_attributes_unref (attrs); gkd_secret_secret_free (secret); if (path == NULL) { gkd_secret_propagate_error (invocation, "Couldn't create collection", error); return TRUE; } /* Notify the callers that a collection was created */ g_message ("emit collection_Created"); gkd_secret_service_emit_collection_created (self, path); gkd_exported_internal_complete_create_with_master_password (skeleton, invocation, path); g_free (path); return TRUE; }
static DBusMessage* service_method_create_with_master_password (GkdSecretService *self, DBusMessage *message) { GckBuilder builder = GCK_BUILDER_INIT; DBusError derr = DBUS_ERROR_INIT; DBusMessageIter iter, array; DBusMessage *reply = NULL; GkdSecretSecret *secret = NULL; GckAttributes *attrs = NULL; GError *error = NULL; gchar *path; /* Parse the incoming message */ if (!dbus_message_has_signature (message, "a{sv}(oayays)")) return NULL; if (!dbus_message_iter_init (message, &iter)) g_return_val_if_reached (NULL); dbus_message_iter_recurse (&iter, &array); if (!gkd_secret_property_parse_all (&array, SECRET_COLLECTION_INTERFACE, &builder)) { gck_builder_clear (&builder); return dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, "Invalid properties argument"); } dbus_message_iter_next (&iter); secret = gkd_secret_secret_parse (self, message, &iter, &derr); if (secret == NULL) { gck_builder_clear (&builder); return gkd_secret_error_to_reply (message, &derr); } gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE); attrs = gck_attributes_ref_sink (gck_builder_end (&builder)); path = gkd_secret_create_with_secret (attrs, secret, &error); gck_attributes_unref (attrs); gkd_secret_secret_free (secret); if (path == NULL) return gkd_secret_propagate_error (message, "Couldn't create collection", error); /* Notify the callers that a collection was created */ gkd_secret_service_emit_collection_created (self, path); reply = dbus_message_new_method_return (message); dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); g_free (path); return reply; }