Beispiel #1
0
/* runs in thread dedicated to handling the method call so may block */
static gboolean
handle_set_hostname (CockpitManager *_manager,
                     GDBusMethodInvocation *invocation,
                     const gchar *arg_pretty_hostname,
                     const gchar *arg_hostname,
                     GVariant *arg_options)
{
  Manager *manager = MANAGER (_manager);
  GError *error;

  if (!auth_check_sender_role (invocation, COCKPIT_ROLE_ADMIN))
    return TRUE;

  /* TODO: validate that passed @arg_hostname is not malformed (e.g. only ASCII etc.) */

  if (strlen (arg_pretty_hostname) > 0)
    {
      error = NULL;
      if (!g_dbus_proxy_call_sync (manager->hostname1_proxy,
                                   "SetPrettyHostname",
                                   g_variant_new ("(sb)", arg_pretty_hostname, FALSE),
                                   G_DBUS_CALL_FLAGS_NONE,
                                   -1, /* timeout_msec */
                                   NULL, /* GCancellable* */
                                   &error))
        {
          g_dbus_error_strip_remote_error (error);
          g_dbus_method_invocation_take_error (invocation, error);
          goto out;
        }
    }

  if (strlen (arg_hostname) > 0)
    {
      error = NULL;
      if (!g_dbus_proxy_call_sync (manager->hostname1_proxy,
                                   "SetHostname",
                                   g_variant_new ("(sb)", arg_hostname, FALSE),
                                   G_DBUS_CALL_FLAGS_NONE,
                                   -1, /* timeout_msec */
                                   NULL, /* GCancellable* */
                                   &error))
        {
          g_dbus_error_strip_remote_error (error);
          g_dbus_method_invocation_take_error (invocation, error);
          goto out;
        }
    }

  cockpit_manager_complete_set_hostname (COCKPIT_MANAGER (manager), invocation);

out:
  return TRUE; /* Means we handled the invocation */
}
static void
interface_add_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;
	gs_free_error GError *error = NULL;
	gs_unref_variant GVariant *variant = NULL;
	const char *path;

	variant = _nm_dbus_proxy_call_finish (proxy, result,
	                                      G_VARIANT_TYPE ("(o)"),
	                                      &error);
	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
		return;

	self = NM_SUPPLICANT_INTERFACE (user_data);
	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	if (variant) {
		g_variant_get (variant, "(&o)", &path);
		interface_add_done (self, path);
	} else if (_nm_dbus_error_has_name (error, WPAS_ERROR_EXISTS_ERROR)) {
		/* Interface already added, just get its object path */
		g_dbus_proxy_call (priv->wpas_proxy,
		                   "GetInterface",
		                   g_variant_new ("(s)", priv->dev),
		                   G_DBUS_CALL_FLAGS_NONE,
		                   -1,
		                   priv->init_cancellable,
		                   (GAsyncReadyCallback) interface_get_cb,
		                   self);
	} else if (   g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_EXEC_FAILED)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FORK_FAILED)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FAILED)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMEOUT)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMED_OUT)
	           || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) {
		/* Supplicant wasn't running and could not be launched via service
		 * activation.  Wait for it to start by moving back to the INIT
		 * state.
		 */
		g_dbus_error_strip_remote_error (error);
		nm_log_dbg (LOGD_SUPPLICANT, "(%s): failed to activate supplicant: %s",
		            priv->dev, error->message);
		set_state (self, NM_SUPPLICANT_INTERFACE_STATE_INIT);
	} else {
		g_dbus_error_strip_remote_error (error);
		nm_log_err (LOGD_SUPPLICANT, "(%s): error adding interface: %s", priv->dev, error->message);
		set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN);
	}
}
static void
join_show_prompt (GisAccountPageEnterprise *page,
                  GError *error)
{
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  UmRealmKerberosMembership *membership;
  UmRealmKerberos *kerberos;
  gchar hostname[128];
  const gchar *name;

  gtk_entry_set_text (GTK_ENTRY (priv->join_password), "");
  gtk_widget_grab_focus (GTK_WIDGET (priv->join_password));

  kerberos = um_realm_object_get_kerberos (priv->realm);
  membership = um_realm_object_get_kerberos_membership (priv->realm);

  gtk_label_set_text (GTK_LABEL (priv->join_domain),
                      um_realm_kerberos_get_domain_name (kerberos));

  if (gethostname (hostname, sizeof (hostname)) == 0)
    gtk_entry_set_text (GTK_ENTRY (priv->join_computer), hostname);

  clear_entry_validation_error (GTK_ENTRY (priv->join_name));
  clear_entry_validation_error (GTK_ENTRY (priv->join_password));

  if (!priv->join_prompted) {
    name = um_realm_kerberos_membership_get_suggested_administrator (membership);
    if (name && !g_str_equal (name, "")) {
      g_debug ("Suggesting admin user: %s", name);
      gtk_entry_set_text (GTK_ENTRY (priv->join_name), name);
    } else {
      gtk_widget_grab_focus (GTK_WIDGET (priv->join_name));
    }

  } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_HOSTNAME)) {
    g_debug ("Bad host name: %s", error->message);
    set_entry_validation_error (GTK_ENTRY (priv->join_computer), error->message);

  } else if (g_error_matches (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_PASSWORD)) {
    g_debug ("Bad admin password: %s", error->message);
    set_entry_validation_error (GTK_ENTRY (priv->join_password), error->message);

  } else {
    g_debug ("Admin login failure: %s", error->message);
    g_dbus_error_strip_remote_error (error);
    set_entry_validation_error (GTK_ENTRY (priv->join_name), error->message);
  }

  g_debug ("Showing admin password dialog");
  gtk_window_set_transient_for (GTK_WINDOW (priv->join_dialog),
                                GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (page))));
  gtk_window_set_modal (GTK_WINDOW (priv->join_dialog), TRUE);
  gtk_window_present (GTK_WINDOW (priv->join_dialog));

  priv->join_prompted = TRUE;
  g_object_unref (kerberos);
  g_object_unref (membership);

  /* And now we wait for on_join_response() */
}
static gboolean
handle_deactivate (CockpitStorageLogicalVolume *object,
                   GDBusMethodInvocation *invocation)
{
  StorageLogicalVolume *volume = STORAGE_LOGICAL_VOLUME(object);
  GError *error = NULL;

  if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN))
    return TRUE;

  if (!lvm_logical_volume_call_deactivate_sync (volume->lvm_logical_volume,
                                                null_asv (),
                                                NULL,
                                                &error))
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_error_free (error);
    }
  else
    cockpit_storage_logical_volume_complete_deactivate (object, invocation);

  return TRUE;
}
static void
show_error_dialog (GisAccountPageEnterprise *page,
                   const gchar *message,
                   GError *error)
{
  GtkWidget *dialog;

  if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
    return;

  dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (page))),
                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                   GTK_MESSAGE_ERROR,
                                   GTK_BUTTONS_CLOSE,
                                   "%s", message);

  if (error != NULL) {
    g_dbus_error_strip_remote_error (error);
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                              "%s", error->message);
  }

  g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
  gtk_window_present (GTK_WINDOW (dialog));
}
static void
interface_get_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;
	gs_unref_variant GVariant *variant = NULL;
	gs_free_error GError *error = NULL;
	const char *path;

	variant = _nm_dbus_proxy_call_finish (proxy, result,
	                                      G_VARIANT_TYPE ("(o)"),
	                                      &error);
	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
		return;

	self = NM_SUPPLICANT_INTERFACE (user_data);
	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	if (variant) {
		g_variant_get (variant, "(&o)", &path);
		interface_add_done (self, path);
	} else {
		g_dbus_error_strip_remote_error (error);
		nm_log_err (LOGD_SUPPLICANT, "(%s): error getting interface: %s", priv->dev, error->message);
		set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN);
	}
}
Beispiel #7
0
static gboolean
handle_delete (CockpitStorageMDRaid *object,
               GDBusMethodInvocation *invocation)
{
  StorageMDRaid *mdraid = STORAGE_MDRAID(object);
  StorageProvider *provider = storage_object_get_provider (mdraid->object);
  UDisksClient *udisks_client = storage_provider_get_udisks_client (provider);
  gs_unref_object UDisksBlock *block = NULL;
  GList *members = NULL;
  GError *error = NULL;

  /* Delete is Stop followed by wiping of all member devices.
   */

  block = udisks_client_get_block_for_mdraid (udisks_client, mdraid->udisks_mdraid);
  if (block)
    {
      if (!storage_cleanup_block (provider, block, &error))
        goto out;
    }

  GVariantBuilder options;
  g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}"));

  if (!udisks_mdraid_call_stop_sync (mdraid->udisks_mdraid,
                                     g_variant_builder_end (&options),
                                     NULL,
                                     &error))
    goto out;

  members = udisks_client_get_members_for_mdraid (udisks_client,
                                                  mdraid->udisks_mdraid);
  for (GList *m = members; m; m = m->next)
    {
      UDisksBlock *block = m->data;
      GVariantBuilder options;
      g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}"));
      udisks_block_call_format_sync (block,
                                     "empty",
                                     g_variant_builder_end (&options),
                                     NULL,
                                     error ? NULL : &error);
    }

out:
  if (error)
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
    }
  else
    cockpit_storage_mdraid_complete_stop (object, invocation);

  g_list_free_full (members, g_object_unref);
  g_clear_error (&error);
  return TRUE;
}
static void
send_dbus_reply (CockpitDBusJson1 *self, const gchar *cookie, GVariant *result, GError *error)
{
  cleanup_unref_object JsonBuilder *builder = NULL;
  builder = prepare_builder ("call-reply");

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "cookie");
  json_builder_add_string_value (builder, cookie);

  if (result == NULL)
    {
      gchar *error_name;
      error_name = g_dbus_error_get_remote_error (error);
      g_dbus_error_strip_remote_error (error);

      json_builder_set_member_name (builder, "error_name");
      json_builder_add_string_value (builder, error_name != NULL ? error_name : "");

      json_builder_set_member_name (builder, "error_message");
      json_builder_add_string_value (builder, error->message);

      g_free (error_name);
    }
  else
    {
      json_builder_set_member_name (builder, "result");
      _json_builder_add_gvariant (builder, result);
    }
  json_builder_end_object (builder);

  write_builder (self, builder);
}
static void
set_ap_scan_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;
	gs_unref_variant GVariant *reply = NULL;
	gs_free_error GError *error = NULL;

	reply = g_dbus_proxy_call_finish (proxy, result, &error);
	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
		return;

	self = NM_SUPPLICANT_INTERFACE (user_data);
	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	if (!reply) {
		g_dbus_error_strip_remote_error (error);
		nm_log_warn (LOGD_SUPPLICANT, "Couldn't send AP scan mode to the supplicant interface: %s.",
		             error->message);
		emit_error_helper (self, error);
		return;
	}

	nm_log_info (LOGD_SUPPLICANT, "Config: set interface ap_scan to %d",
	             nm_supplicant_config_get_ap_scan (priv->cfg));

	g_dbus_proxy_call (priv->iface_proxy,
	                   "AddNetwork",
	                   g_variant_new ("(@a{sv})", nm_supplicant_config_to_variant (priv->cfg)),
	                   G_DBUS_CALL_FLAGS_NONE,
	                   -1,
	                   priv->assoc_cancellable,
	                   (GAsyncReadyCallback) add_network_cb,
	                   self);
}
static gboolean
handle_set_bitmap_location (CockpitStorageMDRaid *object,
                            GDBusMethodInvocation *invocation,
                            const gchar *arg_value)
{
    StorageMDRaid *mdraid = STORAGE_MDRAID(object);
    GError *error = NULL;

    if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN))
        return TRUE;

    GVariantBuilder options;
    g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}"));

    if (!udisks_mdraid_call_set_bitmap_location_sync (mdraid->udisks_mdraid,
            arg_value,
            g_variant_builder_end (&options),
            NULL,
            &error))
    {
        g_dbus_error_strip_remote_error (error);
        g_dbus_method_invocation_return_error (invocation,
                                               COCKPIT_ERROR,
                                               COCKPIT_ERROR_FAILED,
                                               "%s", error->message);
        g_error_free (error);
    }
    else
        cockpit_storage_mdraid_complete_set_bitmap_location (object, invocation);

    return TRUE;
}
static void
list_connections (GDBusProxy *proxy)
{
	int i;
	GError *error = NULL;
	GVariant *ret;
	char **paths;

	/* Call ListConnections D-Bus method */
	ret = g_dbus_proxy_call_sync (proxy,
	                              "ListConnections",
	                              NULL,
	                              G_DBUS_CALL_FLAGS_NONE, -1,
	                              NULL, &error);
	if (!ret) {
		g_dbus_error_strip_remote_error (error);
		g_print ("ListConnections failed: %s\n", error->message);
		g_error_free (error);
		return;
	}

	g_variant_get (ret, "(^ao)", &paths);
	g_variant_unref (ret);

	for (i = 0; paths[i]; i++)
		g_print ("%s\n", paths[i]);
	g_strfreev (paths);
}
Beispiel #12
0
static void
on_discover_done (GObject *object,
                  GAsyncResult *res,
                  gpointer user_data)
{
  struct DiscoverData *data = (struct DiscoverData *)user_data;

  GError *error = NULL;
  gs_unref_variant GVariant *discover_result = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error);
  if (error)
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (data->invocation,
                                             COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_free (data);
      g_error_free (error);
      return;
    }

  g_variant_builder_init (&(data->all_details), G_VARIANT_TYPE ("aa{sv}"));
  g_variant_get (discover_result, "(iao)", NULL, &(data->object_paths));

  data->cur_proxy = NULL;

  get_next_discover_info (data);
}
Beispiel #13
0
/**
 * fu_util_clear_results:
 **/
static gboolean
fu_util_clear_results (FuUtilPrivate *priv, gchar **values, GError **error)
{
	if (g_strv_length (values) != 1) {
		g_set_error_literal (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INTERNAL,
				     "Invalid arguments: expected 'id'");
		return FALSE;
	}

	/* clear results, and wait for reply */
	g_dbus_proxy_call (priv->proxy,
			   "ClearResults",
			   g_variant_new ("(s)", values[0]),
			   G_DBUS_CALL_FLAGS_NONE,
			   -1,
			   NULL,
			   fu_util_get_devices_cb, priv);
	g_main_loop_run (priv->loop);
	if (priv->val == NULL) {
		g_dbus_error_strip_remote_error (priv->error);
		g_propagate_error (error, priv->error);
		return FALSE;
	}
	return TRUE;
}
static void
dispatcher_done_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
	DispatchInfo *info = user_data;
	GVariant *ret;
	GVariantIter *results;
	GError *error = NULL;

	ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result,
	                                  G_VARIANT_TYPE ("(a(sus))"),
	                                  &error);
	if (ret) {
		g_variant_get (ret, "(a(sus))", &results);
		dispatcher_results_process (info->request_id, info->action, results);
		g_variant_iter_free (results);
		g_variant_unref (ret);
	} else {
		if (_nm_dbus_error_has_name (error, "org.freedesktop.systemd1.LoadFailed")) {
			g_dbus_error_strip_remote_error (error);
			_LOGW ("(%u) failed to call dispatcher scripts: %s",
			       info->request_id, error->message);
		} else {
			_LOGD ("(%u) failed to call dispatcher scripts: %s",
			       info->request_id, error->message);
		}
		g_clear_error (&error);
	}

	if (info->callback)
		info->callback (info->request_id, info->user_data);

	dispatcher_info_cleanup (info);
}
static void
on_realm_discover_input (GObject *source,
                         GAsyncResult *result,
                         gpointer user_data)
{
        UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
        GError *error = NULL;
        GList *realms;

        realms = um_realm_manager_discover_finish (self->realm_manager,
                                                   result, &error);

        /* Found a realm, log user into domain */
        if (error == NULL) {
                g_assert (realms != NULL);
                self->selected_realm = g_object_ref (realms->data);
                enterprise_check_login (self);
                g_list_free_full (realms, g_object_unref);

        /* The domain is likely invalid*/
        } else {
                finish_action (self);
                g_message ("Couldn't discover domain: %s", error->message);
                gtk_widget_grab_focus (GTK_WIDGET (self->enterprise_domain_entry));
                g_dbus_error_strip_remote_error (error);
                set_entry_validation_error (self->enterprise_domain_entry,
                                            error->message);
                g_error_free (error);
        }

        g_object_unref (self);
}
int
main (int argc, char *argv[])
{
	GDBusProxy *proxy;
	GError *error = NULL;

#if !GLIB_CHECK_VERSION (2, 35, 0)
	/* Initialize GType system */
	g_type_init ();
#endif

	/* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
	                                       G_DBUS_PROXY_FLAGS_NONE,
	                                       NULL,
	                                       NM_DBUS_SERVICE,
	                                       NM_DBUS_PATH_SETTINGS,
	                                       NM_DBUS_INTERFACE_SETTINGS,
	                                       NULL, &error);
	if (!proxy) {
		g_dbus_error_strip_remote_error (error);
		g_print ("Could not create NetworkManager D-Bus proxy: %s\n", error->message);
		g_error_free (error);
		return 1;
	}

	/* Add a connection */
	add_connection (proxy, "__Test connection__");

	g_object_unref (proxy);

	return 0;
}
static void
on_realm_discover_input (GObject *source,
                         GAsyncResult *result,
                         gpointer user_data)
{
  GisAccountPageEnterprise *page = user_data;
  GisAccountPageEnterprisePrivate *priv = gis_account_page_enterprise_get_instance_private (page);
  GError *error = NULL;
  GList *realms;

  realms = um_realm_manager_discover_finish (priv->realm_manager,
                                             result, &error);

  /* Found a realm, log user into domain */
  if (error == NULL) {
    g_assert (realms != NULL);
    priv->realm = g_object_ref (realms->data);
    enterprise_check_login (page);
    g_list_free_full (realms, g_object_unref);

  } else {
    /* The domain is likely invalid */
    g_dbus_error_strip_remote_error (error);
    g_message ("Couldn't discover domain: %s", error->message);
    gtk_widget_grab_focus (priv->domain_entry);
    set_entry_validation_error (GTK_ENTRY (priv->domain_entry), error->message);
    apply_complete (page, FALSE);
    g_error_free (error);
  }
}
Beispiel #18
0
void
_g_propagate_error_stripped (GError **dest, GError *src)
{
    g_propagate_error (dest, src);
    if (dest && *dest)
        g_dbus_error_strip_remote_error (*dest);
}
static void
dialog_sim_send_puk_ready (MMSim *sim,
                           GAsyncResult *res,
                           BroadbandDeviceInfo *info)
{
	GError *error = NULL;

	if (!mm_sim_send_puk_finish (sim, res, &error)) {
		const gchar *msg;

		if (g_error_matches (error,
		                     MM_MOBILE_EQUIPMENT_ERROR,
		                     MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD))
			msg = _("Wrong PUK code; please contact your provider.");
		else {
			g_dbus_error_strip_remote_error (error);
			msg = error ? error->message : NULL;
		}

		applet_mobile_pin_dialog_stop_spinner (info->dialog, msg);

		g_warning ("Failed to send PUK to devid: '%s' simid: '%s' : %s",
		           mm_modem_get_device_identifier (info->mm_modem),
		           mm_sim_get_identifier (info->mm_sim),
		           error->message);

		g_error_free (error);
		return;
	}

	/* Good */
	unlock_dialog_destroy (info);
}
Beispiel #20
0
void
_g_simple_async_result_take_error_stripped (GSimpleAsyncResult *simple,
        GError *error)
{
    g_dbus_error_strip_remote_error (error);
    g_simple_async_result_take_error (simple, error);
}
static void
default_adapter_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
	NMBluez4Manager *self = NM_BLUEZ4_MANAGER (user_data);
	NMBluez4ManagerPrivate *priv = NM_BLUEZ4_MANAGER_GET_PRIVATE (self);
	GVariant *ret;
	GError *err = NULL;

	ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result,
	                                  G_VARIANT_TYPE ("(o)"), &err);
	if (ret) {
		const char *default_adapter;

		g_variant_get (ret, "(&o)", &default_adapter);
		default_adapter_changed (priv->proxy, default_adapter, self);
		g_variant_unref (ret);
	} else {
		/* Ignore "No such adapter" errors; just means bluetooth isn't active */
		if (   !_nm_dbus_error_has_name (err, "org.bluez.Error.NoSuchAdapter")
		    && !_nm_dbus_error_has_name (err, "org.freedesktop.systemd1.LoadFailed")
		    && !g_error_matches (err, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) {
			g_dbus_error_strip_remote_error (err);
			nm_log_warn (LOGD_BT, "bluez error getting default adapter: %s",
			             err->message);
		}
		g_error_free (err);
	}
}
static void
inhibit_done (GObject      *source,
              GAsyncResult *result,
              gpointer      user_data)
{
    GDBusProxy *sd_proxy = G_DBUS_PROXY (source);
    NMSleepMonitor *self = user_data;
    GError *error = NULL;
    GVariant *res;
    GUnixFDList *fd_list;

    res = g_dbus_proxy_call_with_unix_fd_list_finish (sd_proxy, &fd_list, result, &error);
    if (!res) {
        g_dbus_error_strip_remote_error (error);
        nm_log_warn (LOGD_SUSPEND, "Inhibit failed: %s", error->message);
        g_error_free (error);
    } else {
        if (!fd_list || g_unix_fd_list_get_length (fd_list) != 1)
            nm_log_warn (LOGD_SUSPEND, "Didn't get a single fd back");

        self->inhibit_fd = g_unix_fd_list_get (fd_list, 0, NULL);

        nm_log_dbg (LOGD_SUSPEND, "Inhibitor fd is %d", self->inhibit_fd);
        g_object_unref (fd_list);
        g_variant_unref (res);
    }
}
gboolean
nm_supplicant_interface_credentials_reply (NMSupplicantInterface *self,
                                           const char *field,
                                           const char *value,
                                           GError **error)
{
	NMSupplicantInterfacePrivate *priv;
	gs_unref_variant GVariant *reply = NULL;

	g_return_val_if_fail (NM_IS_SUPPLICANT_INTERFACE (self), FALSE);
	g_return_val_if_fail (field != NULL, FALSE);
	g_return_val_if_fail (value != NULL, FALSE);

	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
	g_return_val_if_fail (priv->has_credreq == TRUE, FALSE);

	/* Need a network block object path */
	g_return_val_if_fail (priv->net_path, FALSE);
	reply = g_dbus_proxy_call_sync (priv->iface_proxy,
	                                "NetworkReply",
	                                g_variant_new ("(oss)",
	                                               priv->net_path,
	                                               field,
	                                               value),
	                                G_DBUS_CALL_FLAGS_NONE,
	                                5000,
	                                NULL,
	                                error);
	if (error && *error)
		g_dbus_error_strip_remote_error (*error);

	return !!reply;
}
Beispiel #24
0
static void finish_auth_check(GObject *source_object, GAsyncResult *res, gpointer user_data) {
	GError *error = NULL;
	GVariant *result;
	gboolean authorized;
	struct auth_check *auth_check = user_data;

	if (auth_check->cancel_id)
		g_source_remove(auth_check->cancel_id);
	g_free(auth_check->cancel_string);

	result = g_dbus_proxy_call_finish(polkit_proxy, res, &error);
	if (!result) {
		g_dbus_error_strip_remote_error(error);
		g_printerr("Failed to check authorization: %s\n", error->message);
		g_error_free(error);
		authorized = FALSE;
	} else {
		g_variant_get(result, "((bba{ss}))", &authorized, NULL, NULL);
		g_variant_unref(result);
	}

	if (authorized) {
		(auth_check->handler)(auth_check->invocation, auth_check->handler_data);
	} else {
		return_error(auth_check->invocation, G_DBUS_ERROR_AUTH_FAILED, "Not authorized");
	}

	g_object_unref(auth_check->cancellable);
	g_free(auth_check->handler_data);
	g_free(auth_check);

	g_assert(running_auth_checks);
	running_auth_checks--;
}
Beispiel #25
0
static gboolean
handle_delete (CockpitStorageVolumeGroup *object,
               GDBusMethodInvocation *invocation)
{
  StorageVolumeGroup *group = STORAGE_VOLUME_GROUP(object);
  StorageProvider *provider = storage_object_get_provider (group->object);
  GError *error = NULL;

  if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN))
    return TRUE;

  if (!storage_cleanup_volume_group (provider,
                                     group->lvm_volume_group,
                                     &error)
      || !lvm_volume_group_call_delete_sync (group->lvm_volume_group,
                                             TRUE,
                                             null_asv (),
                                             NULL,
                                             &error))
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_error_free (error);
    }
  else
    cockpit_storage_volume_group_complete_delete (object, invocation);

  return TRUE;
}
Beispiel #26
0
static gboolean
handle_start (CockpitStorageMDRaid *object,
              GDBusMethodInvocation *invocation)
{
  StorageMDRaid *mdraid = STORAGE_MDRAID(object);
  GError *error = NULL;

  GVariantBuilder options;
  g_variant_builder_init (&options, G_VARIANT_TYPE("a{sv}"));
  g_variant_builder_add (&options, "{sv}", "start-degraded", g_variant_new_boolean (TRUE));

  if (!udisks_mdraid_call_start_sync (mdraid->udisks_mdraid,
                                      g_variant_builder_end (&options),
                                      NULL,
                                      &error))
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_error_free (error);
    }
  else
    cockpit_storage_mdraid_complete_start (object, invocation);

  return TRUE;
}
Beispiel #27
0
static gboolean
handle_set_crypto_options (CockpitStorageBlock *object,
                           GDBusMethodInvocation *invocation,
                           const gchar *arg_passphrase,
                           const gchar *arg_options)
{
  StorageBlock *block = STORAGE_BLOCK(object);
  GError *error = NULL;

  if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN))
    return TRUE;

  if (!(storage_remove_crypto_config (block->udisks_block,
                                      &error)
        && set_crypto_config (block->udisks_block,
                              arg_passphrase,
                              arg_options,
                              &error)))
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_error_free (error);
      return TRUE;
    }

  cockpit_storage_block_complete_set_crypto_options (object, invocation);
  return TRUE;
}
Beispiel #28
0
static gboolean
handle_create_thin_pool_volume (CockpitStorageVolumeGroup *object,
                                GDBusMethodInvocation *invocation,
                                const gchar *arg_name,
                                guint64 arg_size)
{
  StorageVolumeGroup *group = STORAGE_VOLUME_GROUP(object);
  GError *error = NULL;
  gs_free gchar *result = NULL;

  if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN))
    return TRUE;

  if (!lvm_volume_group_call_create_thin_pool_volume_sync (group->lvm_volume_group,
                                                           arg_name,
                                                           arg_size,
                                                           null_asv (),
                                                           &result,
                                                           NULL,
                                                           &error))
    {
      g_dbus_error_strip_remote_error (error);
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_error_free (error);
    }
  else
    cockpit_storage_volume_group_complete_create_thin_pool_volume (object, invocation);

  return TRUE;
}
Beispiel #29
0
static void
end_invocation_take_gerror (GDBusMethodInvocation *invocation,
                            GError *error)
{
  gchar *remote_error = g_dbus_error_get_remote_error (error);
  if (remote_error)
    {
      g_dbus_error_strip_remote_error (error);
      if (strcmp (remote_error, "org.freedesktop.DBus.Error.AccessDenied") == 0)
        {
          g_dbus_method_invocation_return_error (invocation,
                                                 COCKPIT_ERROR,
                                                 COCKPIT_ERROR_FAILED,
                                                 "You are not authorized for this operation.");
        }
      else
        {
          g_dbus_method_invocation_return_error (invocation,
                                                 COCKPIT_ERROR,
                                                 COCKPIT_ERROR_FAILED,
                                                 "%s (%s)", error->message, remote_error);
        }
      g_free (remote_error);
      g_error_free (error);
    }
  else
    g_dbus_method_invocation_take_error (invocation, error);
}
Beispiel #30
0
static void
async_got_connection_cb (GDBusConnection *connection,
                         GError *io_error,
                         gpointer callback_data)
{
  AsyncPathCall *data = callback_data;
  
  if (connection == NULL)
    {
      g_dbus_error_strip_remote_error (io_error);
      g_simple_async_result_set_from_error (data->result, io_error);
      _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
      async_path_call_free (data);
      return;
    }
  
  data->connection = g_object_ref (connection);
  gvfs_dbus_mount_proxy_new (connection,
                             G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                             data->mount_info->dbus_id,
                             data->mount_info->object_path,
                             data->cancellable,
                             async_proxy_new_cb,
                             data);
}