Example #1
0
static gboolean
walk_block_parents (UDisksClient *client,
                    GDBusObjectManager  *objman,
                    UDisksBlock *block,
                    ObjectWalker *walker,
                    gpointer user_data,
                    GError **error)
{
  /* Parents are
     - of a block that is a logical volume, the logical volume object
     - of a clear text device, the encrypted device.

     XXX - support the whole tree.
  */

  while (block)
    {
      const gchar *path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (block));
      LvmLogicalVolumeBlock *lvm_block =
        LVM_LOGICAL_VOLUME_BLOCK (g_dbus_object_manager_get_interface (objman, path,
                                                                       "com.redhat.lvm2.LogicalVolumeBlock"));

      const gchar *logical_volume_path =
        (lvm_block ? lvm_logical_volume_block_get_logical_volume (lvm_block) : "/");
      const gchar *crypto_path = udisks_block_get_crypto_backing_device (block);

      if (g_strcmp0 (logical_volume_path, "/") != 0)
        {
          gs_unref_object LvmObject *logical_volume_object =
            LVM_OBJECT (g_dbus_object_manager_get_object (objman, logical_volume_path));

          if (logical_volume_object)
            {
              if (!walker (client, G_DBUS_OBJECT (logical_volume_object), user_data, error))
                return FALSE;
            }
          block = NULL;
        }
      else if (g_strcmp0 (crypto_path, "/") != 0)
        {
          UDisksObject *crypto_object = udisks_client_peek_object (client, crypto_path);
          if (crypto_object)
            {
              if (!walker (client, G_DBUS_OBJECT (crypto_object), user_data, error))
                return FALSE;
            }
          block = udisks_object_peek_block (crypto_object);
        }
      else
        block = NULL;
    }

  return TRUE;
}
static void
ensure_credentials_cb (GoaProvider   *provider,
                       GAsyncResult  *res,
                       gpointer       user_data)
{
  EnsureData *data = user_data;
  gint expires_in;
  GError *error;

  error= NULL;
  if (!goa_provider_ensure_credentials_finish (provider, &expires_in, res, &error))
    {
      /* Set AttentionNeeded only if the error is an authorization error */
      if (is_authorization_error (error))
        {
          GoaAccount *account;
          account = goa_object_peek_account (data->object);
          if (!goa_account_get_attention_needed (account))
            {
              goa_account_set_attention_needed (account, TRUE);
              g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (account));
              g_message ("%s: Setting AttentionNeeded to TRUE because EnsureCredentials() failed with: %s (%s, %d)",
                         g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object)),
                         error->message, g_quark_to_string (error->domain), error->code);
            }
        }
      g_dbus_method_invocation_return_gerror (data->invocation, error);
      g_error_free (error);
    }
  else
    {
      GoaAccount *account;
      account = goa_object_peek_account (data->object);

      /* Clear AttentionNeeded flag if set */
      if (goa_account_get_attention_needed (account))
        {
          goa_account_set_attention_needed (account, FALSE);
          g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (account));
          g_message ("%s: Setting AttentionNeeded to FALSE because EnsureCredentials() succeded\n",
                     g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object)));
        }
      goa_account_complete_ensure_credentials (goa_object_peek_account (data->object),
                                               data->invocation,
                                               expires_in);
    }
  ensure_data_unref (data);
}
Example #3
0
static void
remove_modem (MMManager *manager,
              MMBaseModem *modem)
{
    gchar *path;
    gchar *device;

    device = g_strdup (mm_base_modem_get_device (modem));
    path = g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (modem)));

    /* If we get DBus object path, modem was exported */
    if (path) {
        g_dbus_object_manager_server_unexport (manager->priv->object_manager, path);
        g_object_set (modem,
                      MM_BASE_MODEM_CONNECTION, NULL,
                      NULL);

        mm_dbg ("Unexported modem '%s' from path '%s'", device, path);
        g_free (path);
    } else {
        mm_dbg ("Removing modem '%s', which wasn't exported yet", device);
    }

    /* Run dispose before unref-ing, in order to cleanup the SIM object,
     * if any (which also holds a reference to the modem object) */
    g_object_run_dispose (G_OBJECT (modem));
    g_hash_table_remove (manager->priv->modems, device);
    g_free (device);
}
static void
g_dbus_object_manager_server_emit_interfaces_removed (GDBusObjectManagerServer *manager,
                                                      RegistrationData   *data,
                                                      const gchar *const *interfaces)
{
  GVariantBuilder array_builder;
  GError *error;
  guint n;
  const gchar *object_path;

  if (data->manager->priv->connection == NULL)
    goto out;

  g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("as"));
  for (n = 0; interfaces[n] != NULL; n++)
    g_variant_builder_add (&array_builder, "s", interfaces[n]);

  error = NULL;
  object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object));
  g_dbus_connection_emit_signal (data->manager->priv->connection,
                                 NULL, /* destination_bus_name */
                                 manager->priv->object_path,
                                 manager_interface_info.name,
                                 "InterfacesRemoved",
                                 g_variant_new ("(oas)",
                                                object_path,
                                                &array_builder),
                                 &error);
  g_assert_no_error (error);
 out:
  ;
}
static UDisksObject *
wait_for_logical_volume_block_object (UDisksDaemon *daemon,
                                      gpointer      user_data)
{
  UDisksLinuxLogicalVolumeObject *volume_object = user_data;
  const gchar *volume_objpath;
  GList *objects, *l;
  UDisksObject *ret = NULL;

  volume_objpath = g_dbus_object_get_object_path (G_DBUS_OBJECT (volume_object));

  objects = udisks_daemon_get_objects (daemon);
  for (l = objects; l != NULL; l = l->next)
    {
      UDisksObject *object = UDISKS_OBJECT (l->data);
      UDisksBlockLVM2 *block;

      block = udisks_object_peek_block_lvm2 (object);
      if (block == NULL)
        continue;

      if (g_strcmp0 (udisks_block_lvm2_get_logical_volume (block), volume_objpath) == 0)
        {
          ret = g_object_ref (object);
          goto out;
        }
    }

 out:
  g_list_free_full (objects, g_object_unref);
  return ret;
}
Example #6
0
static gboolean
cleanup_logical_volume_walker (GDBusObjectManager *objman,
                               LvmLogicalVolume *logical_volume,
                               gpointer user_data,
                               GError **error)
{
  StorageProvider *provider = user_data;
  UDisksBlock *block = lvm_util_peek_block_for_logical_volume (storage_provider_get_lvm_object_manager (provider),
                                                               storage_provider_get_udisks_client (provider),
                                                               logical_volume);
  if (block)
    {
      /* The logical volume is active, let's clean it up by walking
         the tree of block devices hanging off of it.
       */
      return cleanup_block (provider, block, error);
    }
  else
    {
      /* The logical volume is inactive, let's clean it up by removing
         the remembered configs from its children.
      */
      LvmObject *object = LVM_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (logical_volume)));
      GList *remembered_configs = storage_provider_get_and_forget_remembered_configs
        (provider, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
      for (GList *l = remembered_configs; l; l = l->next)
        {
          GVariant *config = l->data;
          storage_remove_config (provider, NULL, config);
        }
      g_list_free_full (remembered_configs, (GDestroyNotify)g_variant_unref);
      return TRUE;
    }
}
static void
update_block (StoragedLinuxBlockObject       *block_object,
              StoragedLinuxVolumeGroupObject *group_object,
              GHashTable                     *new_lvs,
              GHashTable                     *new_pvs)
{
    StoragedBlock *block;
    GVariant *pv_info;

    block = storaged_object_peek_block (STORAGED_OBJECT (block_object));
    if (block == NULL)
        return;

    // XXX - move this elsewhere?
    {
        StoragedLinuxDevice *device;
        StoragedLinuxLogicalVolumeObject *lv_object;
        const gchar *block_vg_name;
        const gchar *block_lv_name;

        device = storaged_linux_block_object_get_device (block_object);
        if (device)
        {
            block_vg_name = g_udev_device_get_property (device->udev_device, "DM_VG_NAME");
            block_lv_name = g_udev_device_get_property (device->udev_device, "DM_LV_NAME");

            if (g_strcmp0 (block_vg_name, storaged_linux_volume_group_object_get_name (group_object)) == 0
                    && (lv_object = g_hash_table_lookup (new_lvs, block_lv_name)))
            {
                block_object_update_lvm_iface (block_object, g_dbus_object_get_object_path (G_DBUS_OBJECT (lv_object)));
            }
        }
    }

    pv_info = g_hash_table_lookup (new_pvs, storaged_block_get_device (block));
    if (!pv_info)
    {
        const gchar *const *symlinks;
        int i;
        symlinks = storaged_block_get_symlinks (block);
        for (i = 0; symlinks[i]; i++)
        {
            pv_info = g_hash_table_lookup (new_pvs, symlinks[i]);
            if (pv_info)
                break;
        }
    }

    if (pv_info)
    {
        storaged_linux_block_object_update_lvm_pv (block_object, group_object, pv_info);
    }
    else
    {
        StoragedPhysicalVolume *pv = storaged_object_peek_physical_volume (STORAGED_OBJECT (block_object));
        if (pv && g_strcmp0 (storaged_physical_volume_get_volume_group (pv),
                             g_dbus_object_get_object_path (G_DBUS_OBJECT (group_object))) == 0)
            storaged_linux_block_object_update_lvm_pv (block_object, NULL, NULL);
    }
}
Example #8
0
static void
on_interface_proxy_properties_changed (GDBusObjectManager *manager,
                                       GDBusObjectProxy *object_proxy,
                                       GDBusProxy *interface_proxy,
                                       GVariant *changed_properties,
                                       const gchar * const *invalidated_properties,
                                       gpointer user_data)
{
  CockpitDBusJson1 *self = user_data;
  cleanup_unref_object JsonBuilder *builder = prepare_builder ("interface-properties-changed");

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "objpath");
  json_builder_add_string_value (builder, g_dbus_object_get_object_path (G_DBUS_OBJECT (object_proxy)));
  json_builder_set_member_name (builder, "iface_name");
  json_builder_add_string_value (builder, g_dbus_proxy_get_interface_name (interface_proxy));
  /* It's a bit of a waste to send all properties - would be cheaper to just
   * send @changed_properties and @invalidated_properties. But this is simpler.
   */
  json_builder_set_member_name (builder, "iface");
  json_builder_begin_object (builder);
  add_interface (builder, G_DBUS_INTERFACE (interface_proxy), changed_properties);
  json_builder_end_object (builder);
  json_builder_end_object (builder);

  write_builder (self, builder);
}
static void
enterprise_add_realm (GisAccountPageEnterprise *page,
                      UmRealmObject  *realm)
{
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GtkTreeIter iter;
  gchar *name;

  name = realm_get_name (realm);

  /*
   * Don't add a second realm if we already have one with this name.
   * Sometimes realmd returns two realms for the same name, if it has
   * different ways to use that realm. The first one that realmd
   * returns is the one it prefers.
   */

  if (!model_contains_realm (GTK_TREE_MODEL (priv->realms_model), name)) {
    gtk_list_store_append (GTK_LIST_STORE (priv->realms_model), &iter);
    gtk_list_store_set (GTK_LIST_STORE (priv->realms_model), &iter,
                        0, name,
                        1, realm,
                        -1);

    if (!priv->domain_chosen && um_realm_is_configured (realm))
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->domain), &iter);

    g_debug ("added realm to drop down: %s %s", name,
             g_dbus_object_get_object_path (G_DBUS_OBJECT (realm)));
  }

  g_free (name);
}
static void
handle_format_complete (gpointer user_data)
{
  struct FormatCompleteData *data = user_data;
  storaged_partition_table_complete_create_partition
    (data->table, data->invocation, g_dbus_object_get_object_path (G_DBUS_OBJECT (data->partition_object)));
}
Example #11
0
/* Runs in housekeeping thread - called without lock held */
static void
housekeeping_all_drives (UDisksLinuxProvider *provider,
                         guint                secs_since_last)
{
  GList *objects;
  GList *l;

  G_LOCK (provider_lock);
  objects = g_hash_table_get_values (provider->vpd_to_drive);
  g_list_foreach (objects, (GFunc) g_object_ref, NULL);
  G_UNLOCK (provider_lock);

  for (l = objects; l != NULL; l = l->next)
    {
      UDisksLinuxDriveObject *object = UDISKS_LINUX_DRIVE_OBJECT (l->data);
      GError *error;

      error = NULL;
      if (!udisks_linux_drive_object_housekeeping (object,
                                                   secs_since_last,
                                                   NULL, /* TODO: cancellable */
                                                   &error))
        {
          udisks_warning ("Error performing housekeeping for drive %s: %s (%s, %d)",
                          g_dbus_object_get_object_path (G_DBUS_OBJECT (object)),
                          error->message, g_quark_to_string (error->domain), error->code);
          g_error_free (error);
        }
    }

  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  g_list_free (objects);
}
/* runs in thread dedicated to handling @invocation */
static gboolean
handle_create_partition (StoragedPartitionTable   *table,
                         GDBusMethodInvocation    *invocation,
                         guint64                   offset,
                         guint64                   size,
                         const gchar              *type,
                         const gchar              *name,
                         GVariant                 *options)
{
  StoragedObject *partition_object =
    storaged_linux_partition_table_handle_create_partition (table,
                                                            invocation,
                                                            offset,
                                                            size,
                                                            type,
                                                            name,
                                                            options);

  if (partition_object)
    {
      storaged_partition_table_complete_create_partition
        (table, invocation, g_dbus_object_get_object_path (G_DBUS_OBJECT (partition_object)));
      g_object_unref (partition_object);
    }

  return TRUE; /* returning TRUE means that we handled the method invocation */
}
Example #13
0
void
storage_mdraid_update (StorageMDRaid *mdraid)
{
    UDisksMDRaid *udisks_mdraid = mdraid->udisks_mdraid;
    CockpitStorageMDRaid *iface = COCKPIT_STORAGE_MDRAID (mdraid);
    StorageProvider *provider = storage_object_get_provider (mdraid->object);
    UDisksClient *udisks_client = storage_provider_get_udisks_client (provider);

    cockpit_storage_mdraid_set_uuid (iface, udisks_mdraid_get_uuid (udisks_mdraid));
    cockpit_storage_mdraid_set_name (iface, udisks_mdraid_get_name (udisks_mdraid));
    cockpit_storage_mdraid_set_level (iface, udisks_mdraid_get_level (udisks_mdraid));
    cockpit_storage_mdraid_set_num_devices (iface, udisks_mdraid_get_num_devices (udisks_mdraid));
    cockpit_storage_mdraid_set_size (iface, udisks_mdraid_get_size (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_action (iface, udisks_mdraid_get_sync_action (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_completed (iface, udisks_mdraid_get_sync_completed (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_rate (iface, udisks_mdraid_get_sync_rate (udisks_mdraid));
    cockpit_storage_mdraid_set_sync_remaining_time (iface, udisks_mdraid_get_sync_remaining_time (udisks_mdraid));
    cockpit_storage_mdraid_set_degraded (iface, udisks_mdraid_get_degraded (udisks_mdraid));
    {
        gs_free gchar *loc = g_locale_to_utf8 (udisks_mdraid_get_bitmap_location (udisks_mdraid),
                                               -1, NULL, NULL, NULL);
        cockpit_storage_mdraid_set_bitmap_location (iface, loc);
    }
    cockpit_storage_mdraid_set_chunk_size (iface, udisks_mdraid_get_chunk_size (udisks_mdraid));

    GVariantBuilder devices;
    g_variant_builder_init (&devices, G_VARIANT_TYPE("a(oiast)"));

    GVariantIter iter;
    gint disk_slot;
    const gchar *disk_block_objpath;
    gs_unref_variant GVariant *disk_states = NULL;
    guint64 disk_num_errors;
    g_variant_iter_init (&iter, udisks_mdraid_get_active_devices (udisks_mdraid));
    while (g_variant_iter_next (&iter, "(&oi@asta{sv})",
                                &disk_block_objpath,
                                &disk_slot,
                                &disk_states,
                                &disk_num_errors,
                                NULL))
    {
        UDisksObject *udisks_object;
        UDisksBlock *udisks_block;
        StorageObject *object;

        if ((udisks_object = udisks_client_peek_object (udisks_client, disk_block_objpath))
                && (udisks_block = udisks_object_peek_block (udisks_object))
                && (object = storage_provider_lookup_for_udisks_block (provider, udisks_block)))
        {
            g_variant_builder_add (&devices, "(oi@ast)",
                                   g_dbus_object_get_object_path (G_DBUS_OBJECT(object)),
                                   disk_slot,
                                   disk_states,
                                   disk_num_errors);
        }
    }
    cockpit_storage_mdraid_set_active_devices (iface, g_variant_builder_end (&devices));
}
Example #14
0
void
storage_daemon_unpublish (StorageDaemon *self,
                          const gchar *path,
                          gpointer thing)
{
  GDBusObject *object;
  gboolean unexport = FALSE;
  GList *interfaces, *l;

  g_return_if_fail (STORAGE_IS_DAEMON (self));
  g_return_if_fail (path != NULL);

  object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), path);
  if (object == NULL)
    return;

  path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));

  if (G_IS_DBUS_INTERFACE (thing))
    {
      g_debug ("unpublishing interface: %s %s", path,
               g_dbus_interface_get_info(thing)->name);

      unexport = TRUE;

      interfaces = g_dbus_object_get_interfaces (object);
      for (l = interfaces; l != NULL; l = g_list_next (l))
        {
          if (G_DBUS_INTERFACE (l->data) != G_DBUS_INTERFACE (thing))
            unexport = FALSE;
        }
      g_list_free_full (interfaces, g_object_unref);

      /*
       * HACK: GDBusObjectManagerServer is broken ... and sends InterfaceRemoved
       * too many times, if you remove all interfaces manually, and then unexport
       * a GDBusObject. So only do it here if we're not unexporting the object.
       */
      if (!unexport)
        g_dbus_object_skeleton_remove_interface (G_DBUS_OBJECT_SKELETON (object), thing);
      else
        g_debug ("(unpublishing object, too)");

    }
  else if (thing == NULL)
    {
      unexport = TRUE;
    }
  else
    {
      g_critical ("Unsupported type to unpublish: %s", G_OBJECT_TYPE_NAME (thing));
    }

  if (unexport)
    g_dbus_object_manager_server_unexport (self->object_manager, path);

  g_object_unref (object);
}
Example #15
0
/**
 * storaged_object_get_volume_group:
 * @object: A #StoragedObject.
 *
 * Gets the #StoragedVolumeGroup instance for the D-Bus interface <link linkend="gdbus-interface-org-storaged-Storaged-VolumeGroup.top_of_page">org.storaged.Storaged.VolumeGroup</link> on @object, if any.
 *
 * Returns: (transfer full): A #StoragedVolumeGroup that must be freed with g_object_unref() or %NULL if @object does not implement the interface.
 */
StoragedVolumeGroup *
storaged_object_get_volume_group (StoragedObject *object)
{
  GDBusInterface *ret;
  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "org.storaged.Storaged.VolumeGroup");
  if (ret == NULL)
    return NULL;
  return STORAGED_VOLUME_GROUP (ret);
}
Example #16
0
/**
 * storaged_object_get_physical_volume:
 * @object: A #StoragedObject.
 *
 * Gets the #StoragedPhysicalVolume instance for the D-Bus interface <link linkend="gdbus-interface-org-storaged-Storaged-PhysicalVolume.top_of_page">org.storaged.Storaged.PhysicalVolume</link> on @object, if any.
 *
 * Returns: (transfer full): A #StoragedPhysicalVolume that must be freed with g_object_unref() or %NULL if @object does not implement the interface.
 */
StoragedPhysicalVolume *
storaged_object_get_physical_volume (StoragedObject *object)
{
  GDBusInterface *ret;
  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "org.storaged.Storaged.PhysicalVolume");
  if (ret == NULL)
    return NULL;
  return STORAGED_PHYSICAL_VOLUME (ret);
}
Example #17
0
/**
 * storaged_object_get_block_lvm2:
 * @object: A #StoragedObject.
 *
 * Gets the #StoragedBlockLVM2 instance for the D-Bus interface <link linkend="gdbus-interface-org-storaged-Storaged-Block-LVM2.top_of_page">org.storaged.Storaged.Block.LVM2</link> on @object, if any.
 *
 * Returns: (transfer full): A #StoragedBlockLVM2 that must be freed with g_object_unref() or %NULL if @object does not implement the interface.
 */
StoragedBlockLVM2 *
storaged_object_get_block_lvm2 (StoragedObject *object)
{
  GDBusInterface *ret;
  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "org.storaged.Storaged.Block.LVM2");
  if (ret == NULL)
    return NULL;
  return STORAGED_BLOCK_LVM2 (ret);
}
Example #18
0
void
storage_daemon_publish (StorageDaemon *self,
                        const gchar *path,
                        gboolean uniquely,
                        gpointer thing)
{
  GDBusInterface *prev;
  GDBusInterfaceInfo *info;
  GDBusObjectSkeleton *object;
  GQuark detail;

  g_return_if_fail (STORAGE_IS_DAEMON (self));
  g_return_if_fail (path != NULL);

  if (G_IS_DBUS_INTERFACE (thing))
    {
      g_debug ("%spublishing iface: %s %s", uniquely ? "uniquely " : "", path,
               g_dbus_interface_get_info(thing)->name);

      object = G_DBUS_OBJECT_SKELETON (g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), path));
      if (object != NULL)
        {
          if (uniquely)
            {
              info = g_dbus_interface_get_info (thing);
              prev = g_dbus_object_get_interface (G_DBUS_OBJECT (object), info->name);
              if (prev)
                {
                  g_object_unref (prev);
                  g_object_unref (object);
                  object = NULL;
                }
            }
        }

      if (object == NULL)
          object = g_dbus_object_skeleton_new (path);

      g_dbus_object_skeleton_add_interface (object, thing);
    }
  else
    {
      g_critical ("Unsupported type to publish: %s", G_OBJECT_TYPE_NAME (thing));
      return;
    }

  if (uniquely)
    g_dbus_object_manager_server_export_uniquely (self->object_manager, object);
  else
    g_dbus_object_manager_server_export (self->object_manager, object);

  detail = g_quark_from_static_string (G_OBJECT_TYPE_NAME (thing));
  g_signal_emit (self, signals[PUBLISHED], detail, thing);

  g_object_unref (object);
}
Example #19
0
/**
 * storaged_object_peek_logical_volume: (skip)
 * @object: A #StoragedObject.
 *
 * Like storaged_object_get_logical_volume() but doesn't increase the reference count on the returned object.
 *
 * <warning>It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running.</warning>
 *
 * Returns: (transfer none): A #StoragedLogicalVolume or %NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object.
 */
StoragedLogicalVolume *
storaged_object_peek_logical_volume (StoragedObject *object)
{
  GDBusInterface *ret;
  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "org.storaged.Storaged.LogicalVolume");
  if (ret == NULL)
    return NULL;
  g_object_unref (ret);
  return STORAGED_LOGICAL_VOLUME (ret);
}
static void
print_objects (GDBusObjectManager *manager)
{
    GList *objects;
    GList *l;

    g_print ("Object manager at %s\n", g_dbus_object_manager_get_object_path (manager));
    objects = g_dbus_object_manager_get_objects (manager);
    for (l = objects; l != NULL; l = l->next)
    {
        ExampleObject *object = EXAMPLE_OBJECT (l->data);
        GList *interfaces;
        GList *ll;
        g_print (" - Object at %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));

        interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object));
        for (ll = interfaces; ll != NULL; ll = ll->next)
        {
            GDBusInterface *interface = G_DBUS_INTERFACE (ll->data);
            g_print ("   - Interface %s\n", g_dbus_interface_get_info (interface)->name);

            /* Note that @interface is really a GDBusProxy instance - and additionally also
             * an ExampleAnimal or ExampleCat instance - either of these can be used to
             * invoke methods on the remote object. For example, the generated function
             *
             *  void example_animal_call_poke_sync (ExampleAnimal  *proxy,
             *                                      gboolean        make_sad,
             *                                      gboolean        make_happy,
             *                                      GCancellable   *cancellable,
             *                                      GError        **error);
             *
             * can be used to call the Poke() D-Bus method on the .Animal interface.
             * Additionally, the generated function
             *
             *  const gchar *example_animal_get_mood (ExampleAnimal *object);
             *
             * can be used to get the value of the :Mood property.
             */
        }
        g_list_free_full (interfaces, g_object_unref);
    }
    g_list_free_full (objects, g_object_unref);
}
static void
manager_method_call (GDBusConnection       *connection,
                     const gchar           *sender,
                     const gchar           *object_path,
                     const gchar           *interface_name,
                     const gchar           *method_name,
                     GVariant              *parameters,
                     GDBusMethodInvocation *invocation,
                     gpointer               user_data)
{
  GDBusObjectManagerServer *manager = G_DBUS_OBJECT_MANAGER_SERVER (user_data);
  GVariantBuilder array_builder;
  GHashTableIter object_iter;
  RegistrationData *data;

  if (g_strcmp0 (method_name, "GetManagedObjects") == 0)
    {
      g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a{oa{sa{sv}}}"));
      g_hash_table_iter_init (&object_iter, manager->priv->map_object_path_to_data);
      while (g_hash_table_iter_next (&object_iter, NULL, (gpointer) &data))
        {
          GVariantBuilder interfaces_builder;
          GHashTableIter interface_iter;
          GDBusInterfaceSkeleton *iface;
          const gchar *iter_object_path;

          g_variant_builder_init (&interfaces_builder, G_VARIANT_TYPE ("a{sa{sv}}"));
          g_hash_table_iter_init (&interface_iter, data->map_iface_name_to_iface);
          while (g_hash_table_iter_next (&interface_iter, NULL, (gpointer) &iface))
            {
              g_variant_builder_add_value (&interfaces_builder,
                                           g_variant_new ("{s@a{sv}}",
                                                          g_dbus_interface_skeleton_get_info (iface)->name,
                                                          g_dbus_interface_skeleton_get_properties (iface)));
            }
          iter_object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object));
          g_variant_builder_add (&array_builder,
                                 "{oa{sa{sv}}}",
                                 iter_object_path,
                                 &interfaces_builder);
        }

      g_dbus_method_invocation_return_value (invocation,
                                             g_variant_new ("(a{oa{sa{sv}}})",
                                                            &array_builder));
    }
  else
    {
      g_dbus_method_invocation_return_error (invocation,
                                             G_DBUS_ERROR,
                                             G_DBUS_ERROR_UNKNOWN_METHOD,
                                             "Unknown method %s - only GetManagedObjects() is supported",
                                             method_name);
    }
}
Example #22
0
static void
udisks_client_get_object_info_for_loop (UDisksClient     *client,
                                        UDisksLoop       *loop,
                                        UDisksBlock      *block,
                                        UDisksPartition  *partition,
                                        UDisksObjectInfo *info)
{
  guint64 size = 0;
  gchar *size_str = NULL;
  gchar *s;

  size = udisks_block_get_size (block);
  if (size > 0)
    size_str = udisks_client_get_size_for_display (client, size, FALSE, FALSE);

  info->icon = g_themed_icon_new_with_default_fallbacks ("drive-removable-media");
  info->icon_symbolic = g_themed_icon_new_with_default_fallbacks ("drive-removable-media-symbolic");
  info->name = udisks_loop_dup_backing_file (loop);
  if (size_str != NULL)
    {
      info->description = g_strdup_printf (_("%s Loop Device"), size_str);
    }
  else
    {
      info->description = g_strdup (_("Loop Device"));
    }

  if (partition != NULL)
    {
      /* Translators: Used to describe a partition of a loop device.
       *              The %d is the partition number.
       *              The %s is the description for the loop device (e.g. "5 GB Loop Device").
       */
      s = g_strdup_printf (C_("part-loop", "Partition %d of %s"),
                           udisks_partition_get_number (partition), info->description);
      g_free (info->description);
      info->description = s;
    }

  /* Translators: String used for one-liner description of a loop device.
   *              The first %s is the description of the object (e.g. "2 GB Loop Device").
   *              The second %s is the name of the backing file (e.g. "/home/davidz/file.iso").
   *              The third %s is the special device file (e.g. "/dev/loop2").
   */
  info->one_liner = g_strdup_printf (C_("one-liner-loop", "%s — %s (%s)"),
                                     info->description,
                                     info->name,
                                     udisks_block_get_preferred_device (block));

  info->sort_key = g_strdup_printf ("03_loop_%s_%d",
                                    last_segment (g_dbus_object_get_object_path (G_DBUS_OBJECT (info->object))),
                                    partition != NULL ? udisks_partition_get_number (partition) : 0);
}
Example #23
0
static void
manager_add_object (CockpitFakeManager *self,
                    CockpitObjectProxy *object)
{
  const gchar *object_path;

  object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));
  g_hash_table_insert (self->path_to_object, (gpointer)object_path,
                       g_object_ref (object));
  g_debug ("fakemanager: object-added: %s", object_path);
  g_signal_emit (self, sig_manager__object_added, 0, object);
}
static gboolean
have_partition_in_range (StoragedPartitionTable     *table,
                         StoragedObject             *object,
                         guint64                     start,
                         guint64                     end,
                         gboolean                    ignore_container)
{
  gboolean ret = FALSE;
  StoragedDaemon *daemon = NULL;
  GDBusObjectManager *object_manager = NULL;
  const gchar *table_object_path;
  GList *objects = NULL, *l;

  daemon = storaged_linux_block_object_get_daemon (STORAGED_LINUX_BLOCK_OBJECT (object));
  object_manager = G_DBUS_OBJECT_MANAGER (storaged_daemon_get_object_manager (daemon));

  table_object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));

  objects = g_dbus_object_manager_get_objects (object_manager);
  for (l = objects; l != NULL; l = l->next)
    {
      StoragedObject *i_object = STORAGED_OBJECT (l->data);
      StoragedPartition *i_partition = NULL;

      i_partition = storaged_object_get_partition (i_object);

      if (i_partition == NULL)
        goto cont;

      if (g_strcmp0 (storaged_partition_get_table (i_partition), table_object_path) != 0)
        goto cont;

      if (ignore_container && storaged_partition_get_is_container (i_partition))
        goto cont;

      if (!ranges_overlap (start, end - start,
                           storaged_partition_get_offset (i_partition), storaged_partition_get_size (i_partition)))
        goto cont;

      ret = TRUE;
      g_clear_object (&i_partition);
      goto out;

    cont:
      g_clear_object (&i_partition);
    }

 out:
  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  g_list_free (objects);
  return ret;
}
Example #25
0
const gchar *
storage_provider_translate_path (StorageProvider *provider,
                                 const gchar *udisks_or_lvm_path)
{
  StorageObject *object = NULL;

  if (udisks_or_lvm_path == NULL)
    udisks_or_lvm_path = "/";

  gs_unref_object UDisksObject *udisks_object = udisks_client_get_object (provider->udisks_client,
                                                                          udisks_or_lvm_path);
  if (udisks_object != NULL)
    {

      UDisksDrive *udisks_drive = udisks_object_peek_drive (udisks_object);
      if (udisks_drive != NULL)
        object = storage_provider_lookup_for_udisks_drive (provider, udisks_drive);

      UDisksBlock *udisks_block = udisks_object_peek_block (udisks_object);
      if (udisks_block != NULL)
        object = storage_provider_lookup_for_udisks_block (provider, udisks_block);

      UDisksMDRaid *udisks_raid = udisks_object_peek_mdraid (udisks_object);
      if (udisks_raid != NULL)
        object = storage_provider_lookup_for_udisks_mdraid (provider, udisks_raid);
    }

  gs_unref_object LvmObject *lvm_object = LVM_OBJECT (g_dbus_object_manager_get_object (provider->lvm_objman,
                                                                                        udisks_or_lvm_path));
  if (lvm_object)
    {
      LvmVolumeGroup *lvm_volume_group = lvm_object_peek_volume_group (lvm_object);
      if (lvm_volume_group != NULL)
        object = storage_provider_lookup_for_lvm_volume_group (provider, lvm_volume_group);

      LvmLogicalVolume *lvm_logical_volume = lvm_object_peek_logical_volume (lvm_object);
      if (lvm_logical_volume != NULL)
        object = storage_provider_lookup_for_lvm_logical_volume (provider, lvm_logical_volume);
    }

  if (object != NULL)
    {
      // g_debug ("%s -> %s", udisks_or_lvm_path, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
      return g_dbus_object_get_object_path (G_DBUS_OBJECT (object));
    }
  else
    {
      // g_debug ("%s -> nothing", udisks_or_lvm_path);
      return "/";
    }
}
void
storaged_linux_volume_group_object_destroy (StoragedLinuxVolumeGroupObject *object)
{
    GHashTableIter volume_iter;
    gpointer key, value;

    g_hash_table_iter_init (&volume_iter, object->logical_volumes);
    while (g_hash_table_iter_next (&volume_iter, &key, &value))
    {
        StoragedLinuxLogicalVolumeObject *volume = value;
        g_dbus_object_manager_server_unexport (storaged_daemon_get_object_manager (object->daemon),
                                               g_dbus_object_get_object_path (G_DBUS_OBJECT (volume)));
    }
}
static void
enterprise_add_realm (UmAccountDialog *self,
                      UmRealmObject *realm)
{
        GtkTreeModel *model;
        GtkTreeIter iter;
        UmRealmCommon *common;
        const gchar *realm_name;
        gboolean match;
        gboolean ret;
        gchar *name;

        common = um_realm_object_get_common (realm);
        realm_name = um_realm_common_get_name (common);

        /*
         * Don't add a second realm if we already have one with this name.
         * Sometimes realmd returns to realms for the same name, if it has
         * different ways to use that realm. The first one that realmd
         * returns is the one it prefers.
         */

        model = GTK_TREE_MODEL (self->enterprise_realms);
        ret = gtk_tree_model_get_iter_first (model, &iter);
        while (ret) {
                gtk_tree_model_get (model, &iter, 0, &name, -1);
                match = (g_strcmp0 (name, realm_name) == 0);
                g_free (name);
                if (match) {
                        g_debug ("ignoring duplicate realm: %s", realm_name);
                        return;
                }
                ret = gtk_tree_model_iter_next (model, &iter);
        }

        gtk_list_store_append (self->enterprise_realms, &iter);
        gtk_list_store_set (self->enterprise_realms, &iter,
                            0, realm_name,
                            1, realm,
                            -1);

        g_debug ("added realm to drop down: %s %s", realm_name,
                 g_dbus_object_get_object_path (G_DBUS_OBJECT (realm)));

        if (!self->enterprise_domain_chosen && um_realm_is_configured (realm))
                gtk_combo_box_set_active_iter (self->enterprise_domain, &iter);

        g_object_unref (common);
}
Example #28
0
static gboolean
cleanup_block_walker (UDisksClient *client,
                      UDisksBlock *block,
                      gboolean is_leaf,
                      gpointer user_data,
                      GError **error)
{
  StorageProvider *provider = user_data;
  UDisksObject *object = UDISKS_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (block)));
  UDisksEncrypted *enc = udisks_object_peek_encrypted (object);

  if (enc)
    {
      UDisksBlock *cleartext = udisks_client_get_cleartext_block (client, block);
      if (cleartext)
        {
          /* The crypto backing device is unlocked and the cleartext
             device has been cleaned up.  Lock the backing device so
             that we can format or wipe it later.
          */
          if (enc && !udisks_encrypted_call_lock_sync (enc,
                                                       g_variant_new ("a{sv}", NULL),
                                                       NULL,
                                                       error))
            return FALSE;
        }
      else
        {
          /* The crypto backing device is locked and the cleartext
             device has not been cleaned up (since it doesn't exist).
             Remove its remembered configs.
          */
          GList *remembered_configs = storage_provider_get_and_forget_remembered_configs
              (provider, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
          for (GList *l = remembered_configs; l; l = l->next)
            {
              GVariant *config = l->data;
              storage_remove_config (provider, block, config);
            }
          g_list_free_full (remembered_configs, (GDestroyNotify)g_variant_unref);
        }
    }

  storage_remove_config (provider, block, udisks_block_get_configuration (block));

  return TRUE;
}
Example #29
0
static void
screen_destroy_cb (GObject *screen,
                   gpointer user_data)
{
  GDBusObjectManagerServer *object_manager;
  GDBusObjectSkeleton *skeleton;
  const char *object_path;

  skeleton = g_object_get_data (screen, RECEIVER_IMPL_SKELETON_DATA_KEY);
  if (skeleton == NULL)
    return;

  object_manager = terminal_app_get_object_manager (terminal_app_get ());
  object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (skeleton));
  g_dbus_object_manager_server_unexport (object_manager, object_path);
  g_object_set_data (screen, RECEIVER_IMPL_SKELETON_DATA_KEY, NULL);
}
Example #30
0
/**
 * udisks_linux_drive_object_get_block:
 * @object: A #UDisksLinuxDriveObject.
 * @get_hw: If the drive is multipath, set to %TRUE to get a path device instead of the multipath device.
 *
 * Gets a #UDisksLinuxBlockObject representing a block device associated with @object.
 *
 * Returns: A #UDisksLinuxBlockObject or %NULL. The returned object
 * must be freed with g_object_unref().
 */
UDisksLinuxBlockObject *
udisks_linux_drive_object_get_block (UDisksLinuxDriveObject   *object,
                                     gboolean                  get_hw)
{
  GDBusObjectManagerServer *object_manager;
  UDisksLinuxBlockObject *ret;
  GList *objects;
  GList *l;

  /* TODO: actually look at @get_hw */

  ret = NULL;

  object_manager = udisks_daemon_get_object_manager (object->daemon);
  objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (object_manager));
  for (l = objects; l != NULL; l = l->next)
    {
      GDBusObjectSkeleton *iter_object = G_DBUS_OBJECT_SKELETON (l->data);
      UDisksBlock *block;
      UDisksLinuxDevice *device;
      gboolean is_disk;

      if (!UDISKS_IS_LINUX_BLOCK_OBJECT (iter_object))
        continue;

      device = udisks_linux_block_object_get_device (UDISKS_LINUX_BLOCK_OBJECT (iter_object));
      is_disk = (g_strcmp0 (g_udev_device_get_devtype (device->udev_device), "disk") == 0);
      g_object_unref (device);

      if (!is_disk)
        continue;

      block = udisks_object_peek_block (UDISKS_OBJECT (iter_object));
      if (g_strcmp0 (udisks_block_get_drive (block),
                     g_dbus_object_get_object_path (G_DBUS_OBJECT (object))) == 0)
        {
          ret = g_object_ref (iter_object);
          goto out;
        }
    }

 out:
  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  g_list_free (objects);
  return ret;
}