static void
install_mime_types_ready_cb (GObject      *source,
                             GAsyncResult *res,
                             gpointer      user_data)
{
  GtkAppChooserOnlinePk *self = user_data;
  GDBusProxy *proxy = G_DBUS_PROXY (source);
  GError *error = NULL;
  GVariant *variant;

  variant = g_dbus_proxy_call_finish (proxy, res, &error);

  if (variant == NULL)
    {
      /* don't show errors if the user cancelled the installation explicitely
       * or if PK wasn't able to find any apps
       */
      if (g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Cancelled") != 0 &&
          g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.NoPackagesFound") != 0)
        g_simple_async_result_set_from_error (self->priv->result, error);

      g_error_free (error);
    }

  g_simple_async_result_complete (self->priv->result);
  g_clear_object (&self->priv->result);
}
Exemple #2
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);
}
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);
}
Exemple #4
0
static void
set_gnome_env (const char *name,
	       const char *value)
{
  GDBusConnection *session_bus;
  GError *error = NULL;

  setenv (name, value, TRUE);

  session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
  g_assert (session_bus);

  g_dbus_connection_call_sync (session_bus,
			       "org.gnome.SessionManager",
			       "/org/gnome/SessionManager",
			       "org.gnome.SessionManager",
			       "Setenv",
			       g_variant_new ("(ss)", name, value),
			       NULL,
			       G_DBUS_CALL_FLAGS_NO_AUTO_START,
			       -1, NULL, &error);
  if (error)
    {
      if (g_strcmp0 (g_dbus_error_get_remote_error (error), "org.gnome.SessionManager.NotInInitialization") != 0)
        meta_warning ("Failed to set environment variable %s for gnome-session: %s\n", name, error->message);

      g_error_free (error);
    }
}
static void
delete_user_done (GObject        *proxy,
                  GAsyncResult   *r,
                  gpointer        user_data)
{
        AsyncUserOpData *data = user_data;
        GSimpleAsyncResult *res;
        GVariant *result;
        GError *error = NULL;

        res = g_simple_async_result_new (G_OBJECT (data->manager),
                                         data->callback,
                                         data->data,
                                         um_user_manager_delete_user);
        result = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), r, &error);
        if (!result) {
                if (g_dbus_error_is_remote_error (error) &&
                    strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.PermissionDenied") == 0) {
                        g_simple_async_result_set_error (res,
                                                         UM_USER_MANAGER_ERROR,
                                                         UM_USER_MANAGER_ERROR_PERMISSION_DENIED,
                                                         "Not authorized");
                }
                else if (g_dbus_error_is_remote_error (error) &&
                    strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.UserExists") == 0) {
                        g_simple_async_result_set_error (res,
                                                         UM_USER_MANAGER_ERROR,
                                                         UM_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST,
                                                         _("This user does not exist."));
                }
                else {
                        g_simple_async_result_set_from_error (res, error);
                        g_error_free (error);
                }
        }
        else
                g_variant_unref (result);

        data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data);
        async_user_op_data_free (data);
        g_object_unref (res);
}
static void
emit_error_helper (NMSupplicantInterface *self, GError *error)
{
	char *name = NULL;

	if (g_dbus_error_is_remote_error (error))
		name = g_dbus_error_get_remote_error (error);

	g_signal_emit (self, signals[CONNECTION_ERROR], 0, name, error->message);
	g_free (name);
}
gboolean
set_fingerprint_label (GtkWidget *label1,
                       GtkWidget *label2)
{
        GDBusProxy *device;
        GVariant *result;
        GVariantIter *fingers;
        GError *error = NULL;

        if (manager == NULL) {
                create_manager ();
                if (manager == NULL) {
                        return FALSE;
                }
        }

        device = get_first_device ();
        if (device == NULL)
                return FALSE;

        result = g_dbus_proxy_call_sync (device, "ListEnrolledFingers", g_variant_new ("(s)", ""), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
        if (!result) {
                if (!g_dbus_error_is_remote_error (error) ||
                    strcmp (g_dbus_error_get_remote_error(error), "net.reactivated.Fprint.Error.NoEnrolledPrints") != 0) {
                        g_object_unref (device);
                        return FALSE;
                }
        }

        if (result && g_variant_is_of_type (result, G_VARIANT_TYPE ("(as)")))
                g_variant_get (result, "(as)", &fingers);
        else
                fingers = NULL;

        if (fingers == NULL || g_variant_iter_n_children (fingers) == 0) {
                is_disable = FALSE;
                gtk_label_set_text (GTK_LABEL (label1), _("Disabled"));
                gtk_label_set_text (GTK_LABEL (label2), _("Disabled"));
        } else {
                is_disable = TRUE;
                gtk_label_set_text (GTK_LABEL (label1), _("Enabled"));
                gtk_label_set_text (GTK_LABEL (label2), _("Enabled"));
        }

        if (result != NULL)
                g_variant_unref (result);
        if (fingers != NULL)
                g_variant_iter_free (fingers);
        g_object_unref (device);

        return TRUE;
}
Exemple #8
0
gboolean
um_realm_join_finish (UmRealmObject *realm,
                      GAsyncResult *result,
                      GError **error)
{
        UmRealmKerberosMembership *membership;
        GError *call_error = NULL;
        gchar *dbus_error;
        GAsyncResult *async;

        g_return_val_if_fail (UM_REALM_IS_OBJECT (realm), FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

        membership = um_realm_object_get_kerberos_membership (realm);
        g_return_val_if_fail (membership != NULL, FALSE);

        async = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
        um_realm_kerberos_membership_call_join_finish (membership, async, &call_error);
        g_object_unref (membership);

        if (call_error == NULL)
                return TRUE;

        dbus_error = g_dbus_error_get_remote_error (call_error);
        if (dbus_error == NULL) {
                g_debug ("Join() failed because of %s", call_error->message);
                g_propagate_error (error, call_error);
                return FALSE;
        }

        g_dbus_error_strip_remote_error (call_error);

        if (g_str_equal (dbus_error, "org.freedesktop.realmd.Error.AuthenticationFailed")) {
                g_debug ("Join() failed because of invalid/insufficient credentials");
                g_set_error (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_LOGIN,
                             "%s", call_error->message);
                g_error_free (call_error);
        } else if (g_str_equal (dbus_error, "org.freedesktop.realmd.Error.BadHostname")) {
                g_debug ("Join() failed because of invalid/conflicting host name");
                g_set_error (error, UM_REALM_ERROR, UM_REALM_ERROR_BAD_HOSTNAME,
                             "%s", call_error->message);
                g_error_free (call_error);
        } else {
                g_debug ("Join() failed because of %s", call_error->message);
                g_propagate_error (error, call_error);
        }

        g_free (dbus_error);
        return FALSE;
}
/**
 * _nm_dbus_error_has_name:
 * @error: (allow-none): a #GError, or %NULL
 * @dbus_error_name: a D-Bus error name
 *
 * Checks if @error is set and corresponds to the D-Bus error @dbus_error_name.
 *
 * This should only be used for "foreign" D-Bus errors (eg, errors
 * from BlueZ or wpa_supplicant). All NetworkManager D-Bus errors
 * should be properly mapped by gdbus to one of the domains/codes in
 * nm-errors.h.
 *
 * Returns: %TRUE or %FALSE
 */
gboolean
_nm_dbus_error_has_name (GError     *error,
                         const char *dbus_error_name)
{
	gboolean has_name = FALSE;

	if (error && g_dbus_error_is_remote_error (error)) {
		char *error_name;

		error_name = g_dbus_error_get_remote_error (error);
		has_name = !g_strcmp0 (error_name, dbus_error_name);
		g_free (error_name);
	}

	return has_name;
}
void
realm_handle_error (GError *error,
                    const gchar *format,
                    ...)
{
	static gboolean diag_hint = TRUE;
	GString *message;
	gchar *remote;
	va_list va;

	if (realm_cancelled &&
	    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
		g_error_free (error);
		return;
	}

#ifdef WITH_JOURNAL
	remote = error ? g_dbus_error_get_remote_error (error) : NULL;
	if (diag_hint && realm_operation_id && !realm_verbose &&
	    g_strcmp0 (remote, REALM_DBUS_ERROR_NOT_AUTHORIZED) != 0) {
		g_printerr ("See: journalctl REALMD_OPERATION=%s\n",
		            realm_operation_id);
		diag_hint = FALSE;
	}
	g_free (remote);
#endif

	message = g_string_new ("");
	g_string_append_printf (message, "%s: ", g_get_prgname ());

	if (format) {
		va_start (va, format);
		g_string_append_vprintf (message, format, va);
		va_end (va);
	}

	if (error) {
		g_dbus_error_strip_remote_error (error);
		if (format)
			g_string_append (message, ": ");
		g_string_append (message, error->message);
		g_error_free (error);
	}

	g_printerr ("%s\n", message->str);
	g_string_free (message, TRUE);
}
Exemple #11
0
/**
 * cd_profile_fixup_dbus_error:
 **/
static void
cd_profile_fixup_dbus_error (GError *error)
{
	g_autofree gchar *name = NULL;

	g_return_if_fail (error != NULL);

	/* is a remote error? */
	if (!g_dbus_error_is_remote_error (error))
		return;

	/* parse the remote error */
	name = g_dbus_error_get_remote_error (error);
	error->domain = CD_PROFILE_ERROR;
	error->code = cd_profile_error_from_string (name);
	g_dbus_error_strip_remote_error (error);
}
Exemple #12
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);
      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);
}
Exemple #13
0
static void
end_invocation_take_gerror (Realms *realms,
                            GError *error)
{
  gchar *remote_error = g_dbus_error_get_remote_error (error);
  if (remote_error)
    {
      if (strcmp (remote_error, "org.freedesktop.realmd.Error.AuthenticationFailed") == 0
          || strcmp (remote_error, "org.freedesktop.DBus.Error.NotSupported") == 0)
        {
          g_dbus_method_invocation_return_error (realms->op_invocation,
                                                 COCKPIT_ERROR,
                                                 COCKPIT_ERROR_AUTHENTICATION_FAILED,
                                                 "Authentication failed");
        }
      else if (strcmp (remote_error, "org.freedesktop.realmd.Error.Cancelled") == 0)
        {
          g_dbus_method_invocation_return_error (realms->op_invocation,
                                                 COCKPIT_ERROR,
                                                 COCKPIT_ERROR_CANCELLED,
                                                 "Operation was cancelled");
        }
      else
        {
          g_dbus_error_strip_remote_error (error);
          g_dbus_method_invocation_return_error (realms->op_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 (realms->op_invocation, error);
  clear_invocation (realms);
}
Exemple #14
0
static void
on_poke_introspected (GObject *source_object,
                      GAsyncResult *result,
                      gpointer user_data)
{
  PokeContext *poke = user_data;
  CockpitFakeManager *self = poke->manager;
  GError *error = NULL;
  GDBusNodeInfo *node;
  gboolean expected;
  const gchar *xml;
  GVariant *retval;
  gchar *remote;

  retval = g_dbus_connection_call_finish (self->connection, result, &error);

  /* Bail fast if cancelled */
  if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
    {
      poke_context_finish (self, poke);
      g_error_free (error);
      return;
    }

  if (retval)
    {
      g_variant_get (retval, "(&s)", &xml);
      node = g_dbus_node_info_new_for_xml (xml, &error);
      process_introspect_node (self, poke, node);
      g_dbus_node_info_unref (node);
      g_variant_unref (retval);
    }

  if (error)
    {
      /*
       * Note that many DBus implementations don't return errors when
       * an unknown object path is introspected. They just return empty
       * introspect data. GDBus is one of these.
       */

      expected = FALSE;
      remote = g_dbus_error_get_remote_error (error);
      if (remote)
        {
          /*
           * DBus used to only have the UnknownMethod error. It didn't have
           * specific errors for UnknownObject and UnknownInterface. So we're
           * pretty liberal on what we treat as an expected error here.
           *
           * HACK: GDBus also doesn't understand the newer error codes :S
           *
           * https://bugzilla.gnome.org/show_bug.cgi?id=727900
           */
          expected = (g_str_equal (remote, "org.freedesktop.DBus.Error.UnknownMethod") ||
                      g_str_equal (remote, "org.freedesktop.DBus.Error.UnknownObject") ||
                      g_str_equal (remote, "org.freedesktop.DBus.Error.UnknownInterface"));
          g_free (remote);
        }

      if (!expected)
        {
          g_warning ("Couldn't look up introspection data on %s at %s: %s",
                     self->bus_name, poke->object_path, error->message);
        }
      g_error_free (error);
      poke_remove_object_and_finish (self, poke);
      return;
    }
}
/* Callback when GeoClue name appears on the bus */
static void
on_name_appeared(GDBusConnection *conn, const gchar *name,
		 const gchar *name_owner, gpointer user_data)
{
	location_geoclue2_state_t *state = user_data;

	/* Obtain GeoClue Manager */
	GError *error = NULL;
	GDBusProxy *geoclue_manager = g_dbus_proxy_new_sync(
		conn,
		G_DBUS_PROXY_FLAGS_NONE,
		NULL,
		"org.freedesktop.GeoClue2",
		"/org/freedesktop/GeoClue2/Manager",
		"org.freedesktop.GeoClue2.Manager",
		NULL, &error);
	if (geoclue_manager == NULL) {
		g_printerr(_("Unable to obtain GeoClue Manager: %s.\n"),
			   error->message);
		g_error_free(error);
		mark_error(state);
		return;
	}

	/* Obtain GeoClue Client path */
	error = NULL;
	GVariant *client_path_v =
		g_dbus_proxy_call_sync(geoclue_manager,
				       "GetClient",
				       NULL,
				       G_DBUS_CALL_FLAGS_NONE,
				       -1, NULL, &error);
	if (client_path_v == NULL) {
		g_printerr(_("Unable to obtain GeoClue client path: %s.\n"),
			   error->message);
		g_error_free(error);
		g_object_unref(geoclue_manager);
		mark_error(state);
		return;
	}

	const gchar *client_path;
	g_variant_get(client_path_v, "(&o)", &client_path);

	/* Obtain GeoClue client */
	error = NULL;
	GDBusProxy *geoclue_client = g_dbus_proxy_new_sync(
		conn,
		G_DBUS_PROXY_FLAGS_NONE,
		NULL,
		"org.freedesktop.GeoClue2",
		client_path,
		"org.freedesktop.GeoClue2.Client",
		NULL, &error);
	if (geoclue_client == NULL) {
		g_printerr(_("Unable to obtain GeoClue Client: %s.\n"),
			   error->message);
		g_error_free(error);
		g_variant_unref(client_path_v);
		g_object_unref(geoclue_manager);
		mark_error(state);
		return;
	}

	g_variant_unref(client_path_v);

	/* Set desktop id (basename of the .desktop file) */
	error = NULL;
	GVariant *ret_v = g_dbus_proxy_call_sync(
		geoclue_client,
		"org.freedesktop.DBus.Properties.Set",
		g_variant_new("(ssv)",
		"org.freedesktop.GeoClue2.Client",
		"DesktopId",
		g_variant_new("s", "redshift")),
		G_DBUS_CALL_FLAGS_NONE,
		-1, NULL, &error);
	if (ret_v == NULL) {
		/* Ignore this error for now. The property is not available
		   in early versions of GeoClue2. */
	} else {
		g_variant_unref(ret_v);
	}

	/* Set distance threshold */
	error = NULL;
	ret_v = g_dbus_proxy_call_sync(
		geoclue_client,
		"org.freedesktop.DBus.Properties.Set",
		g_variant_new("(ssv)",
		"org.freedesktop.GeoClue2.Client",
		"DistanceThreshold",
		g_variant_new("u", 50000)),
		G_DBUS_CALL_FLAGS_NONE,
		-1, NULL, &error);
	if (ret_v == NULL) {
		g_printerr(_("Unable to set distance threshold: %s.\n"),
			   error->message);
		g_error_free(error);
		g_object_unref(geoclue_client);
		g_object_unref(geoclue_manager);
		mark_error(state);
		return;
	}

	g_variant_unref(ret_v);

	/* Attach signal callback to client */
	g_signal_connect(geoclue_client, "g-signal",
			 G_CALLBACK(geoclue_client_signal_cb),
			 user_data);

	/* Start GeoClue client */
	error = NULL;
	ret_v = g_dbus_proxy_call_sync(geoclue_client,
				       "Start",
				       NULL,
				       G_DBUS_CALL_FLAGS_NONE,
				       -1, NULL, &error);
	if (ret_v == NULL) {
		g_printerr(_("Unable to start GeoClue client: %s.\n"),
			   error->message);
		if (g_dbus_error_is_remote_error(error)) {
			gchar *dbus_error = g_dbus_error_get_remote_error(
				error);
			if (g_strcmp0(dbus_error, DBUS_ACCESS_ERROR) == 0) {
				print_denial_message();
			}
			g_free(dbus_error);
		}
		g_error_free(error);
		g_object_unref(geoclue_client);
		g_object_unref(geoclue_manager);
		mark_error(state);
		return;
	}

	g_variant_unref(ret_v);
}
int
main (int argc, char *argv[])
{
	gs_unref_object GDBusConnection *connection = NULL;
	gs_free_error GError *error = NULL;
	gs_unref_variant GVariant *parameters = NULL;
	gs_unref_variant GVariant *result = NULL;
	gboolean success = FALSE;
	guint try_count = 0;
	gint64 time_end;

	nm_g_type_init ();

	/* FIXME: g_dbus_connection_new_for_address_sync() tries to connect to the socket in
	 * non-blocking mode, which can easily fail with EAGAIN, causing the creation of the
	 * socket to fail with "Could not connect: Resource temporarily unavailable".
	 *
	 * We should instead create the GIOStream ourself and block on connecting to
	 * the socket. */
	connection = g_dbus_connection_new_for_address_sync ("unix:path=" NMRUNDIR "/private-dhcp",
	                                                     G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
	                                                     NULL, NULL, &error);
	if (!connection) {
		g_dbus_error_strip_remote_error (error);
		_LOGE ("could not connect to NetworkManager D-Bus socket: %s",
		       error->message);
		goto out;
	}

	parameters = build_signal_parameters ();

	time_end = g_get_monotonic_time () + (200 * 1000L); /* retry for at most 200 milliseconds */

do_notify:
	try_count++;
	result = g_dbus_connection_call_sync (connection,
	                                      NULL,
	                                      NM_DHCP_HELPER_SERVER_OBJECT_PATH,
	                                      NM_DHCP_HELPER_SERVER_INTERFACE_NAME,
	                                      NM_DHCP_HELPER_SERVER_METHOD_NOTIFY,
	                                      parameters,
	                                      NULL,
	                                      G_DBUS_CALL_FLAGS_NONE,
	                                      1000,
	                                      NULL,
	                                      &error);

	if (!result) {
		gs_free char *s_err = NULL;

		s_err = g_dbus_error_get_remote_error (error);
		if (NM_IN_STRSET (s_err, "org.freedesktop.DBus.Error.UnknownMethod")) {
			gint64 remaining_time = time_end - g_get_monotonic_time ();

			/* I am not sure that a race can actually happen, as we register the object
			 * on the server side during GDBusServer:new-connection signal.
			 *
			 * However, there was also a race for subscribing to an event, so let's just
			 * do some retry. */
			if (remaining_time > 0) {
				_LOGi ("failure to call notify: %s (retry %u)", error->message, try_count);
				g_usleep (NM_MIN (NM_CLAMP ((gint64) (100L * (1L << try_count)), 5000, 25000), remaining_time));
				g_clear_error (&error);
				goto do_notify;
			}
		}
		_LOGW ("failure to call notify: %s (try signal via Event)", error->message);
		g_clear_error (&error);

		/* for backward compatibilty, try to emit the signal. There is no stable
		 * API between the dhcp-helper and NetworkManager. However, while upgrading
		 * the NetworkManager package, a newer helper might want to notify an
		 * older server, which still uses the "Event". */
		if (!g_dbus_connection_emit_signal (connection,
		                                    NULL,
		                                    "/",
		                                    NM_DHCP_CLIENT_DBUS_IFACE,
		                                    "Event",
		                                    parameters,
		                                    &error)) {
			g_dbus_error_strip_remote_error (error);
			_LOGE ("could not send DHCP Event signal: %s", error->message);
			goto out;
		}
		/* We were able to send the asynchronous Event. Consider that a success. */
		success = TRUE;
	} else
		success = TRUE;

	if (!g_dbus_connection_flush_sync (connection, NULL, &error)) {
		g_dbus_error_strip_remote_error (error);
		_LOGE ("could not flush D-Bus connection: %s", error->message);
		success = FALSE;
		goto out;
	}

out:
	if (!success)
		kill_pid ();
	return success ? EXIT_SUCCESS : EXIT_FAILURE;
}
void
ce_page_complete_init (CEPage *self,
                       const char *setting_name,
                       GVariant *secrets,
                       GError *error)
{
	GError *update_error = NULL;
	GVariant *setting_dict;
	char *dbus_err;
	gboolean ignore_error = FALSE;

	g_return_if_fail (self != NULL);
	g_return_if_fail (CE_IS_PAGE (self));

	if (error) {
		dbus_err = g_dbus_error_get_remote_error (error);
		ignore_error =    !g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.Settings.InvalidSetting")
		               || !g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.Settings.Connection.SettingNotFound")
		               || !g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.AgentManager.NoSecrets");
		g_free (dbus_err);
	}

	/* Ignore missing settings errors */
	if (error && !ignore_error) {
		emit_initialized (self, error);
		return;
	} else if (!setting_name || !secrets || g_variant_n_children (secrets) == 0) {
		/* Success, no secrets */
		emit_initialized (self, NULL);
		return;
	}

	g_assert (setting_name);
	g_assert (secrets);

	setting_dict = g_variant_lookup_value (secrets, setting_name, NM_VARIANT_TYPE_SETTING);
	if (!setting_dict) {
		/* Success, no secrets */
		emit_initialized (self, NULL);
		return;
	}
	g_variant_unref (setting_dict);

	/* Update the connection with the new secrets */
	if (nm_connection_update_secrets (self->connection,
	                                  setting_name,
	                                  secrets,
	                                  &update_error)) {
		/* Success */
		emit_initialized (self, NULL);
		return;
	}

	if (!update_error) {
		g_set_error_literal (&update_error, NMA_ERROR, NMA_ERROR_GENERIC,
		                     _("Failed to update connection secrets due to an unknown error."));
	}

	emit_initialized (self, update_error);
	g_clear_error (&update_error);
}
/* Used for both create_user and cache_user */
static void
user_call_done (GObject        *proxy,
                GAsyncResult   *r,
                gpointer        user_data)
{
        AsyncUserOpData *data = user_data;
        GSimpleAsyncResult *res;
        GVariant *result;
        GError *error = NULL;
        gchar *remote;

        res = g_simple_async_result_new (G_OBJECT (data->manager),
                                         data->callback,
                                         data->data,
                                         um_user_manager_create_user);
        result = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), r, &error);
        if (!result) {
                /* dbus-glib fail:
                 * We have to translate the errors manually here, since
                 * calling dbus_g_error_has_name on the error returned in
                 * um_user_manager_create_user_finish doesn't work.
                 */
                remote = g_dbus_error_get_remote_error (error);
                if (g_dbus_error_is_remote_error (error) &&
                    strcmp (remote, "org.freedesktop.Accounts.Error.PermissionDenied") == 0) {
                        g_simple_async_result_set_error (res,
                                                         UM_USER_MANAGER_ERROR,
                                                         UM_USER_MANAGER_ERROR_PERMISSION_DENIED,
                                                         "Not authorized");
                }
                if (g_dbus_error_is_remote_error (error) &&
                    strcmp (remote, "org.freedesktop.Accounts.Error.UserExists") == 0) {
                        g_simple_async_result_set_error (res,
                                                         UM_USER_MANAGER_ERROR,
                                                         UM_USER_MANAGER_ERROR_USER_EXISTS,
                                                         _("A user with name '%s' already exists."),
                                                         data->user_name);
                } else if (g_dbus_error_is_remote_error (error) &&
                    strcmp (remote, "org.freedesktop.Accounts.Error.UserDoesNotExist") == 0) {
                        g_simple_async_result_set_error (res,
                                                         UM_USER_MANAGER_ERROR,
                                                         UM_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST,
                                                         _("No user with the name '%s' exists."),
                                                         data->user_name);
                }
                else {
                        g_simple_async_result_set_from_error (res, error);
                }
                g_error_free (error);
                g_free (remote);
        }
        else {
                if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(o)"))) {
                        gchar *path;
                        g_variant_get (result, "(o)", &path);
                        g_simple_async_result_set_op_res_gpointer (res, path, g_free);
                }
                else
                        g_simple_async_result_set_error (res,
                                                         UM_USER_MANAGER_ERROR,
                                                         UM_USER_MANAGER_ERROR_FAILED,
                                                         "Got invalid response from AccountsService");
                g_variant_unref (result);
        }

        data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data);
        async_user_op_data_free (data);
        g_object_unref (res);
}
Exemple #19
0
static enum _GetResult
ol_config_proxy_get (OlConfigProxy *config,
                     const gchar *method,
                     const gchar *key,
                     const gchar *format_string,
                     gpointer retval)
{
  ol_assert_ret (OL_IS_CONFIG_PROXY (config), GET_RESULT_FAILED);
  ol_assert_ret (key != NULL, GET_RESULT_FAILED);
  enum _GetResult ret = GET_RESULT_OK;
  GError *error = NULL;
  GVariant *value = NULL;
  OlConfigProxyPrivate *priv = OL_CONFIG_PROXY_GET_PRIVATE (config);
  if (key[0] == '.')
  {
    value = g_hash_table_lookup (priv->temp_values, key);
    if (value)
      g_variant_ref (value);
  }
  else
  {
    value = g_dbus_proxy_call_sync (G_DBUS_PROXY (config),
                                    method,
                                    g_variant_new ("(s)", key),
                                    G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                    -1,   /* timeout_secs */
                                    NULL, /* cancellable */
                                    &error);
  }
  if (!value)
  {
    if (g_dbus_error_is_remote_error (error))
    {
      gchar *error_name = g_dbus_error_get_remote_error (error);
      if (strcmp (error_name, OL_ERROR_VALUE_NOT_EXIST) == 0)
      {
        ol_debugf ("Key %s not exists, use default value\n", key);
        ret = GET_RESULT_MISSING;
      }
      else
      {
        ol_errorf ("Failed to get config %s: %s\n", key, error->message);
        ret = GET_RESULT_FAILED;
      }
      g_free (error_name);
    }
    else
    {
      ol_errorf ("%s failed. Cannot get value %s from config: %s\n",
                 method, key, error->message);
      ret = GET_RESULT_FAILED;
    }
    g_error_free (error);
  }
  else
  {
    g_variant_get (value, format_string, retval);
    g_variant_unref (value);
  }
  return ret;
}