Пример #1
0
static gboolean
service_method_lock (GkdExportedService *skeleton,
		     GDBusMethodInvocation *invocation,
		     gchar **objpaths,
		     GkdSecretService *self)
{
	const char *caller;
	GckObject *collection;
	int i;
	char **locked;
	GPtrArray *array;

	caller = g_dbus_method_invocation_get_sender (invocation);
	array = g_ptr_array_new ();
	for (i = 0; objpaths[i] != NULL; ++i) {
		collection = gkd_secret_objects_lookup_collection (self->objects, caller, objpaths[i]);
		if (collection != NULL) {
			if (gkd_secret_lock (collection, NULL)) {
				g_ptr_array_add (array, objpaths[i]);
				gkd_secret_objects_emit_collection_locked (self->objects,
									   collection);
			}
			g_object_unref (collection);
		}
	}

	g_ptr_array_add (array, NULL);

	locked = (gchar **) g_ptr_array_free (array, FALSE);
	gkd_exported_service_complete_lock (skeleton, invocation,
					    (const gchar **) locked, "/");

	return TRUE;
}
Пример #2
0
static DBusMessage*
service_method_unlock_with_master_password (GkdSecretService *self, DBusMessage *message)
{
	DBusError derr = DBUS_ERROR_INIT;
	GkdSecretSecret *master;
	GError *error = NULL;
	GckObject *collection;
	DBusMessageIter iter;
	DBusMessage *reply;
	const gchar *path;

	/* Parse the incoming message */
	if (!dbus_message_has_signature (message, "o(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);
	master = gkd_secret_secret_parse (self, message, &iter, &derr);
	if (master == NULL)
		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_unlock_with_secret (collection, master, &error)) {
		reply = dbus_message_new_method_return (message);
		gkd_secret_objects_emit_collection_locked (self->objects, collection);

	/* Failure */
	} else {
		reply = gkd_secret_propagate_error (message, "Couldn't unlock collection", error);
	}

	gkd_secret_secret_free (master);

	if (collection)
		g_object_unref (collection);

	return reply;
}
Пример #3
0
static gboolean
service_method_unlock_with_master_password (GkdExportedInternal *skeleton,
					    GDBusMethodInvocation *invocation,
					    gchar *path,
					    GVariant *master_variant,
					    GkdSecretService *self)
{
	GkdSecretSecret *master;
	GError *error = NULL;
	GckObject *collection;
	const gchar *sender;

	sender = g_dbus_method_invocation_get_sender (invocation);

	/* Parse the incoming message */
	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_unlock_with_secret (collection, master, &error)) {
		gkd_secret_objects_emit_collection_locked (self->objects, collection);
		gkd_exported_internal_complete_unlock_with_master_password
			(skeleton, invocation);

	/* Failure */
	} else {
		gkd_secret_propagate_error (invocation, "Couldn't unlock collection", error);
	}

	gkd_secret_secret_free (master);

	if (collection)
		g_object_unref (collection);

	return TRUE;
}
Пример #4
0
static DBusMessage*
service_method_lock (GkdSecretService *self, DBusMessage *message)
{
	DBusMessage *reply;
	const char *caller;
	const gchar *prompt;
	GckObject *collection;
	int n_objpaths, i;
	char **objpaths;
	GPtrArray *array;

	if (!dbus_message_get_args (message, NULL,
	                            DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &objpaths, &n_objpaths,
	                            DBUS_TYPE_INVALID))
		return NULL;

	caller = dbus_message_get_sender (message);
	array = g_ptr_array_new ();
	for (i = 0; i < n_objpaths; ++i) {
		collection = gkd_secret_objects_lookup_collection (self->objects, caller, objpaths[i]);
		if (collection != NULL) {
			if (gkd_secret_lock (collection, NULL)) {
				g_ptr_array_add (array, objpaths[i]);
				gkd_secret_objects_emit_collection_locked (self->objects,
				                                           collection);
			}
			g_object_unref (collection);
		}
	}

	prompt = "/";
	reply = dbus_message_new_method_return (message);
	dbus_message_append_args (reply,
	                          DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &array->pdata, array->len,
	                          DBUS_TYPE_OBJECT_PATH, &prompt,
	                          DBUS_TYPE_INVALID);

	dbus_free_string_array (objpaths);
	return reply;
}