Ejemplo n.º 1
0
static void
impl_ifcfgrh_get_ifcfg_details (SettingsPluginIfcfg *plugin,
                                GDBusMethodInvocation *context,
                                const char *in_ifcfg)
{
	NMIfcfgConnection *connection;
	NMSettingConnection *s_con;
	const char *uuid;
	const char *path;

	if (!g_path_is_absolute (in_ifcfg)) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_INVALID_CONNECTION,
		                                       "ifcfg path '%s' is not absolute", in_ifcfg);
		return;
	}

	connection = find_by_path (plugin, in_ifcfg);
	if (   !connection
	    || nm_ifcfg_connection_get_unmanaged_spec (connection)
	    || nm_ifcfg_connection_get_unrecognized_spec (connection)) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_INVALID_CONNECTION,
		                                       "ifcfg file '%s' unknown", in_ifcfg);
		return;
	}

	s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
	if (!s_con) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_FAILED,
		                                       "unable to retrieve the connection setting");
		return;
	}

	uuid = nm_setting_connection_get_uuid (s_con);
	if (!uuid) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_FAILED,
		                                       "unable to get the UUID");
		return;
	}

	path = nm_connection_get_path (NM_CONNECTION (connection));
	if (!path) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_FAILED,
		                                       "unable to get the connection D-Bus path");
		return;
	}

	g_dbus_method_invocation_return_value (context,
	                                       g_variant_new ("(so)", uuid, path));
}
Ejemplo n.º 2
0
static gboolean
meta_monitor_manager_handle_get_crtc_gamma  (MetaDBusDisplayConfig *skeleton,
                                             GDBusMethodInvocation *invocation,
                                             guint                  serial,
                                             guint                  crtc_id)
{
  MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
  MetaMonitorManagerClass *klass;
  MetaCRTC *crtc;
  gsize size;
  unsigned short *red;
  unsigned short *green;
  unsigned short *blue;
  GBytes *red_bytes, *green_bytes, *blue_bytes;
  GVariant *red_v, *green_v, *blue_v;

  if (serial != manager->serial)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_ACCESS_DENIED,
                                             "The requested configuration is based on stale information");
      return TRUE;
    }

  if (crtc_id >= manager->n_crtcs)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_INVALID_ARGS,
                                             "Invalid crtc id");
      return TRUE;
    }
  crtc = &manager->crtcs[crtc_id];

  klass = META_MONITOR_MANAGER_GET_CLASS (manager);
  if (klass->get_crtc_gamma)
    klass->get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
  else
    {
      size = 0;
      red = green = blue = NULL;
    }

  red_bytes = g_bytes_new_take (red, size * sizeof (unsigned short));
  green_bytes = g_bytes_new_take (green, size * sizeof (unsigned short));
  blue_bytes = g_bytes_new_take (blue, size * sizeof (unsigned short));

  red_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), red_bytes, TRUE);
  green_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), green_bytes, TRUE);
  blue_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), blue_bytes, TRUE);

  meta_dbus_display_config_complete_get_crtc_gamma (skeleton, invocation,
                                                    red_v, green_v, blue_v);

  g_bytes_unref (red_bytes);
  g_bytes_unref (green_bytes);
  g_bytes_unref (blue_bytes);

  return TRUE;
}
Ejemplo n.º 3
0
static gboolean
meta_monitor_manager_handle_set_crtc_gamma  (MetaDBusDisplayConfig *skeleton,
                                             GDBusMethodInvocation *invocation,
                                             guint                  serial,
                                             guint                  crtc_id,
                                             GVariant              *red_v,
                                             GVariant              *green_v,
                                             GVariant              *blue_v)
{
  MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
  MetaMonitorManagerClass *klass;
  MetaCRTC *crtc;
  gsize size, dummy;
  unsigned short *red;
  unsigned short *green;
  unsigned short *blue;
  GBytes *red_bytes, *green_bytes, *blue_bytes;

  if (serial != manager->serial)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_ACCESS_DENIED,
                                             "The requested configuration is based on stale information");
      return TRUE;
    }

  if (crtc_id >= manager->n_crtcs)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_INVALID_ARGS,
                                             "Invalid crtc id");
      return TRUE;
    }
  crtc = &manager->crtcs[crtc_id];

  red_bytes = g_variant_get_data_as_bytes (red_v);
  green_bytes = g_variant_get_data_as_bytes (green_v);
  blue_bytes = g_variant_get_data_as_bytes (blue_v);

  size = g_bytes_get_size (red_bytes) / sizeof (unsigned short);
  red = (unsigned short*) g_bytes_get_data (red_bytes, &dummy);
  green = (unsigned short*) g_bytes_get_data (green_bytes, &dummy);
  blue = (unsigned short*) g_bytes_get_data (blue_bytes, &dummy);

  klass = META_MONITOR_MANAGER_GET_CLASS (manager);
  if (klass->set_crtc_gamma)
    klass->set_crtc_gamma (manager, crtc, size, red, green, blue);

  meta_dbus_display_config_complete_set_crtc_gamma (skeleton, invocation);

  g_bytes_unref (red_bytes);
  g_bytes_unref (green_bytes);
  g_bytes_unref (blue_bytes);

  return TRUE;
}
Ejemplo n.º 4
0
static gboolean
handle_delete_partition (CockpitStorageBlock *object,
                         GDBusMethodInvocation *invocation)
{
  StorageBlock *block = STORAGE_BLOCK(object);
  StorageProvider *provider = storage_object_get_provider (block->object);

  GError *error = NULL;

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

  UDisksObject *udisks_object =
    (UDisksObject *) g_dbus_interface_get_object(G_DBUS_INTERFACE (block->udisks_block));
  if (udisks_object == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "No object!?");
      g_error_free (error);
      return TRUE;
    }

  UDisksPartition *part = udisks_object_peek_partition (udisks_object);
  if (part == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "Block device is not a partition");
      g_error_free (error);
      return TRUE;
    }

  if (!storage_cleanup_block (provider,
                              block->udisks_block,
                              &error)
      || !udisks_partition_call_delete_sync (part,
                                             g_variant_new ("a{sv}", NULL),
                                             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);
      return TRUE;
    }

  cockpit_storage_block_complete_delete_partition (object, invocation);
  return TRUE;
}
Ejemplo n.º 5
0
static gboolean
handle_unlock (CockpitStorageBlock *object,
               GDBusMethodInvocation *invocation,
               const gchar *arg_passphrase)
{
  StorageBlock *block = STORAGE_BLOCK(object);
  GError *error = NULL;

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

  UDisksObject *udisks_object =
    (UDisksObject *) g_dbus_interface_get_object(G_DBUS_INTERFACE (block->udisks_block));
  if (udisks_object == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "No object!?");
      g_error_free (error);
      return TRUE;
    }

  UDisksEncrypted *enc = udisks_object_peek_encrypted (udisks_object);
  if (enc == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "Block device is not encrypted");
      g_error_free (error);
      return TRUE;
    }

  if (!udisks_encrypted_call_unlock_sync (enc,
                                          arg_passphrase,
                                          g_variant_new ("a{sv}", NULL),
                                          NULL,
                                          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);
      return TRUE;
    }

  cockpit_storage_block_complete_unlock (object, invocation);
  return TRUE;
}
Ejemplo n.º 6
0
static void
portal_revoke_permissions (GDBusMethodInvocation *invocation,
                           GVariant *parameters,
                           const char *app_id)
{
  const char *target_app_id;
  const char *id;
  g_autofree const char **permissions = NULL;
  g_autoptr(XdgAppDbEntry) entry = NULL;
  XdpPermissionFlags perms;

  g_variant_get (parameters, "(&s&s^a&s)", &id, &target_app_id, &permissions);

  {
    AUTOLOCK(db);

    entry = xdg_app_db_lookup (db, id);
    if (entry == NULL)
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_FOUND,
                                               "No such document: %s", id);
        return;
      }

    if (!xdg_app_is_valid_name (target_app_id))
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_INVALID_ARGUMENT,
                                               "Invalid app name: %s", target_app_id);
        return;
      }

    perms = xdp_parse_permissions (permissions);

    /* Must have grant-permissions, or be itself */
    if (!xdp_entry_has_permissions (entry, app_id,
                                    XDP_PERMISSION_FLAGS_GRANT_PERMISSIONS) ||
        strcmp (app_id, target_app_id) == 0)
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_ALLOWED,
                                               "Not enough permissions");
        return;
      }

    do_set_permissions (entry, id, target_app_id,
                        ~perms & xdp_entry_get_permissions (entry, target_app_id));
  }

  /* Invalidate with lock dropped to avoid deadlock */
  xdp_fuse_invalidate_doc_app (id, target_app_id);

  g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
}
Ejemplo n.º 7
0
static gboolean
handle_mount (CockpitStorageBlock *object,
              GDBusMethodInvocation *invocation)
{
  StorageBlock *block = STORAGE_BLOCK(object);
  GError *error = NULL;

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

  UDisksObject *udisks_object =
    (UDisksObject *) g_dbus_interface_get_object(G_DBUS_INTERFACE (block->udisks_block));
  if (udisks_object == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "No object!?");
      g_error_free (error);
      return TRUE;
    }

  UDisksFilesystem *fsys = udisks_object_peek_filesystem (udisks_object);
  if (fsys == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "Block device is not a filesystem");
      g_error_free (error);
      return TRUE;
    }

  if (!udisks_filesystem_call_mount_sync (fsys,
                                          g_variant_new ("a{sv}", NULL),
                                          NULL,
                                          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);
      return TRUE;
    }

  cockpit_storage_block_complete_mount (object, invocation);
  return TRUE;
}
Ejemplo n.º 8
0
static void
content_chooser_done (GObject      *object,
                      GAsyncResult *result,
                      gpointer      user_data)
{
  g_autoptr(GSubprocess) subprocess = G_SUBPROCESS (object);
  ContentChooserData *data = user_data;
  g_autoptr(GBytes) stdout_buf = NULL;
  g_autoptr(GError) error = NULL;
  const char *uri = NULL;
  g_autoptr (GFile) file = NULL;
  g_autoptr(GDBusConnection) connection = NULL;

  if (!g_subprocess_communicate_finish (subprocess, result, &stdout_buf, NULL, &error))
    {
      g_dbus_method_invocation_return_error (data->invocation,
                                             XDP_ERROR, XDP_ERROR_FAILED,
                                             "Content chooser failed: %s", error->message);
      g_free (data);
      return;
    }

  if (!g_subprocess_get_if_exited (subprocess) ||
      g_subprocess_get_exit_status (subprocess) != 0)
    {
      g_dbus_method_invocation_return_error (data->invocation,
                                             XDP_ERROR, XDP_ERROR_FAILED,
                                             "Content chooser exit %d", g_subprocess_get_exit_status (subprocess));
      g_free (data);
      return;
    }

  uri = g_bytes_get_data (stdout_buf, NULL);
  file = g_file_new_for_uri (uri);
  data->basename = g_file_get_basename (file);

  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
  g_dbus_connection_call (connection,
                          "org.freedesktop.portal.Documents",
                          "/org/freedesktop/portal/documents",
                          "org.freedesktop.portal.Documents",
                          "Add",
                          g_variant_new ("(s)", uri),
                          G_VARIANT_TYPE ("(u)"),
                          G_DBUS_CALL_FLAGS_NONE,
                          30000,
                          NULL,
                          got_document_handle,
                          data);
}
Ejemplo n.º 9
0
static void
handle_root_method_call(GDBusConnection *connection,
			 const char *sender,
			 const char *object_path,
			 const char *interface_name,
			 const char *method_name,
			 GVariant *parameters,
			 GDBusMethodInvocation *invocation,
			 XmrMprisPlugin *plugin)
{
	XmrWindow *window = NULL;

	if (g_strcmp0(object_path, MPRIS_OBJECT_NAME) != 0 ||
	    g_strcmp0(interface_name, MPRIS_ROOT_INTERFACE) != 0)
	{
		g_dbus_method_invocation_return_error(invocation,
						       G_DBUS_ERROR,
						       G_DBUS_ERROR_NOT_SUPPORTED,
						       "Method %s.%s not supported",
						       interface_name,
						       method_name);
		return;
	}

	g_object_get(plugin, "object", &window, NULL);

	if (g_strcmp0(method_name, "Raise") == 0)
	{
		gtk_widget_show(GTK_WIDGET(window));
        gtk_window_present(GTK_WINDOW(window));

		g_dbus_method_invocation_return_value(invocation, NULL);
	}
	else if (g_strcmp0(method_name, "Quit") == 0)
	{
		xmr_window_quit(window);
		g_dbus_method_invocation_return_value(invocation, NULL);
	}
	else
	{
		g_dbus_method_invocation_return_error(invocation,
						       G_DBUS_ERROR,
						       G_DBUS_ERROR_NOT_SUPPORTED,
						       "Method %s.%s not supported",
						       interface_name,
						       method_name);
	}

	g_object_unref(window);
}
Ejemplo n.º 10
0
static gboolean
meta_monitor_manager_handle_change_backlight  (MetaDBusDisplayConfig *skeleton,
                                               GDBusMethodInvocation *invocation,
                                               guint                  serial,
                                               guint                  output_id,
                                               gint                   value)
{
  MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
  MetaOutput *output;

  if (serial != manager->serial)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_ACCESS_DENIED,
                                             "The requested configuration is based on stale information");
      return TRUE;
    }

  if (output_id >= manager->n_outputs)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_INVALID_ARGS,
                                             "Invalid output id");
      return TRUE;
    }
  output = &manager->outputs[output_id];

  if (value < 0 || value > 100)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_INVALID_ARGS,
                                             "Invalid backlight value");
      return TRUE;
    }

  if (output->backlight == -1 ||
      (output->backlight_min == 0 && output->backlight_max == 0))
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_INVALID_ARGS,
                                             "Output does not support changing backlight");
      return TRUE;
    }

  META_MONITOR_MANAGER_GET_CLASS (manager)->change_backlight (manager, output, value);

  meta_dbus_display_config_complete_change_backlight (skeleton, invocation, output->backlight);
  return TRUE;
}
Ejemplo n.º 11
0
static void
portal_delete (GDBusMethodInvocation *invocation,
               GVariant *parameters,
               const char *app_id)
{
  const char *id;
  g_autoptr(XdgAppDbEntry) entry = NULL;
  g_autofree const char **old_apps = NULL;
  int i;

  g_variant_get (parameters, "(s)", &id);

  {
    AUTOLOCK(db);

    entry = xdg_app_db_lookup (db, id);
    if (entry == NULL)
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_FOUND,
                                             "No such document: %s", id);
        return;
      }

    if (!xdp_entry_has_permissions (entry, app_id, XDP_PERMISSION_FLAGS_DELETE))
      {
        g_dbus_method_invocation_return_error (invocation, XDG_APP_PORTAL_ERROR, XDG_APP_PORTAL_ERROR_NOT_ALLOWED,
                                               "Not enough permissions");
        return;
      }

    g_debug ("delete %s", id);

    xdg_app_db_set_entry (db, id, NULL);

    if (persist_entry (entry))
      xdg_app_permission_store_call_delete (permission_store, TABLE_NAME,
                                            id, NULL, NULL, NULL);
  }

  /* All i/o is done now, so drop the lock so we can invalidate the fuse caches */
  old_apps = xdg_app_db_entry_list_apps (entry);
  for (i = 0; old_apps[i] != NULL; i++)
    xdp_fuse_invalidate_doc_app (id, old_apps[i]);
  xdp_fuse_invalidate_doc_app (id, NULL);

  /* Now fuse view is up-to-date, so we can return the call */
  g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
}
Ejemplo n.º 12
0
static void
handle_player_method_call(GDBusConnection *connection,
			const char *sender,
			const char *object_path,
			const char *interface_name,
			const char *method_name,
			GVariant *parameters,
			GDBusMethodInvocation *invocation,
			XmrMprisPlugin *plugin)

{
	if(g_strcmp0(object_path, MPRIS_OBJECT_NAME) != 0 ||
	    g_strcmp0(interface_name, MPRIS_PLAYER_INTERFACE) != 0)
	{
		g_dbus_method_invocation_return_error(invocation,
						       G_DBUS_ERROR,
						       G_DBUS_ERROR_NOT_SUPPORTED,
						       "Method %s.%s not supported",
						       interface_name,
						       method_name);
		return;
	}

	if (g_strcmp0(method_name, "Next") == 0)
	{
		xmr_window_play_next(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else if (g_strcmp0(method_name, "Pause") == 0)
	{
		xmr_window_pause(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else if (g_strcmp0 (method_name, "Play") == 0)
	{
		xmr_window_play(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else
	{
		g_dbus_method_invocation_return_error(invocation,
					G_DBUS_ERROR,
					G_DBUS_ERROR_NOT_SUPPORTED,
					"Method %s.%s not supported",
					interface_name,
					method_name);
	}
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
static void
create_account_done (ActUserManager *manager,
                     GAsyncResult *res,
                     CallData *data)
{
  CockpitAccounts *object = data->object;
  GDBusMethodInvocation *invocation = data->invocation;
  gs_free gchar *password = data->password;
  gboolean locked = data->locked;
  g_free (data);

  GError *error = NULL;
  ActUser *user = act_user_manager_create_user_finish (manager, res, &error);
  if (user == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                             "Failed to create user account: %s", error->message);
      g_error_free (error);
      return;
    }

  if (password && *password)
    {
      act_user_set_password_mode (user, ACT_USER_PASSWORD_MODE_REGULAR);
      act_user_set_password (user, password, "");
    }

  act_user_set_locked (user, locked);

  cockpit_accounts_complete_create_account (object, invocation);
}
Ejemplo n.º 16
0
/**
 * cd_sensor_unlock_cb:
 **/
static void
cd_sensor_unlock_cb (GObject *source_object,
		     GAsyncResult *res,
		     gpointer user_data)
{
	CdSensor *sensor = CD_SENSOR (source_object);
	gboolean ret;
	GDBusMethodInvocation *invocation = (GDBusMethodInvocation *) user_data;
	GError *error = NULL;

	/* get the result */
	if (sensor->priv->desc != NULL &&
	    sensor->priv->desc->unlock_finish != NULL) {
		ret = sensor->priv->desc->unlock_finish (sensor, res, &error);
		if (!ret) {
			g_dbus_method_invocation_return_error (invocation,
							       CD_SENSOR_ERROR,
							       CD_SENSOR_ERROR_NO_SUPPORT,
							       "failed to unlock: %s",
							       error->message);
			g_error_free (error);
			goto out;
		}
	}
	cd_sensor_set_locked (sensor, FALSE);
	g_dbus_method_invocation_return_value (invocation, NULL);
out:
	return;
}
Ejemplo n.º 17
0
/* org.nemomobile.MmsEngine.sendReadReport */
static
gboolean
mms_engine_handle_send_read_report(
    OrgNemomobileMmsEngine* proxy,
    GDBusMethodInvocation* call,
    int database_id,
    const char* imsi,
    const char* message_id,
    const char* to,
    int read_status, /*  0: Read  1: Deleted without reading */
    MMSEngine* engine)
{
    GError* error = NULL;
    char* id = g_strdup_printf("%d", database_id);
    MMS_DEBUG_("%s %s %s %s %d", id, imsi, message_id, to, read_status);
    if (mms_dispatcher_send_read_report(engine->dispatcher, id, imsi,
        message_id, to, (read_status == 1) ? MMS_READ_STATUS_DELETED :
        MMS_READ_STATUS_READ, &error)) {
        if (mms_dispatcher_start(engine->dispatcher)) {
            mms_engine_start_timeout_cancel(engine);
        }
        org_nemomobile_mms_engine_complete_send_read_report(proxy, call);
    } else {
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(error));
        g_error_free(error);
    }
    g_free(id);
    return TRUE;
}
Ejemplo n.º 18
0
static gboolean
handle_uninstall (FlatpakSystemHelper *object,
                  GDBusMethodInvocation *invocation,
                  guint arg_flags,
                  const gchar *arg_ref)
{
  g_autoptr(FlatpakDir) system = dir_get_system ();
  g_autoptr(GError) error = NULL;

  g_debug ("Uninstall %u %s", arg_flags, arg_ref);

  if ((arg_flags & ~FLATPAK_HELPER_UNINSTALL_FLAGS_ALL) != 0)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                                             "Unsupported flags enabled: 0x%x", (arg_flags & ~FLATPAK_HELPER_UNINSTALL_FLAGS_ALL));
      return TRUE;
    }

  if (!flatpak_dir_ensure_repo (system, NULL, &error))
    {
      g_dbus_method_invocation_return_gerror  (invocation, error);
      return TRUE;
    }

  if (!flatpak_dir_uninstall (system, arg_ref, arg_flags, NULL, &error))
    {
      g_dbus_method_invocation_return_gerror  (invocation, error);
      return TRUE;
    }

  flatpak_system_helper_complete_uninstall (object, invocation);

  return TRUE;
}
Ejemplo n.º 19
0
gboolean
daemon_get_sender_uid (Daemon *daemon,
                       GDBusMethodInvocation *invocation,
                       uid_t *uid)
{
  GError *error = NULL;
  const char *sender = g_dbus_method_invocation_get_sender (invocation);
  gs_unref_variant GVariant *reply = NULL;

  reply = g_dbus_proxy_call_sync (daemon->system_bus_proxy, "org.freedesktop.DBus.GetConnectionUnixUser",
                                  g_variant_new ("(s)", sender), 0, -1,
                                  NULL, &error);
  if (reply == NULL)
    {
      g_dbus_method_invocation_take_error (invocation, error);
      return FALSE;
    }

  if (g_variant_is_of_type (reply, G_VARIANT_TYPE("(u)")))
    g_variant_get (reply, "(u)", uid);
  else
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                             "DBus is broken");
      return FALSE;
    }

  return TRUE;
}
Ejemplo n.º 20
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;
}
Ejemplo n.º 21
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;
}
Ejemplo n.º 22
0
static gboolean
on_handle_delete_object (TestFrobber *object,
                         GDBusMethodInvocation *invocation,
                         const gchar *path,
                         gpointer user_data)
{
  MockData *data = user_data;
  GDBusObject *previous;

  previous = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (data->object_manager), path);
  if (previous != NULL)
    {
      g_warn_if_fail (g_dbus_object_manager_server_unexport (data->object_manager, path));
      test_frobber_complete_delete_object (object, invocation);
      g_object_unref (previous);
    }
  else
    {
      g_dbus_method_invocation_return_error (invocation,
                                             G_IO_ERROR, G_IO_ERROR_FAILED,
                                             "Sorry, there is no object at %s",
                                             path);
    }
  return TRUE;
}
Ejemplo n.º 23
0
static gboolean
on_account_handle_ensure_credentials (GoaAccount            *account,
                                      GDBusMethodInvocation *invocation,
                                      gpointer               user_data)
{
  GoaDaemon *daemon = GOA_DAEMON (user_data);
  GoaProvider *provider;
  GoaObject *object;

  object = GOA_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (account)));
  provider = goa_provider_get_for_provider_type (goa_account_get_provider_type (account));
  if (provider == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             GOA_ERROR,
                                             GOA_ERROR_FAILED,
                                             "Unsupported account type %s for id %s (no provider)",
                                             goa_account_get_provider_type (account),
                                             goa_account_get_id (account));
      goto out;
    }

  goa_provider_ensure_credentials (provider,
                                   object,
                                   NULL, /* GCancellable */
                                   (GAsyncReadyCallback) ensure_credentials_cb,
                                   ensure_data_new (daemon, object, invocation));

 out:
  return TRUE; /* invocation was handled */
}
Ejemplo n.º 24
0
static gboolean
korva_server_on_handle_get_device_info (KorvaController1      *iface,
                                        GDBusMethodInvocation *invocation,
                                        const char            *uid,
                                        gpointer               user_data)
{
    KorvaServer *self = KORVA_SERVER (user_data);
    KorvaDevice *device;

    korva_server_reset_timeout (self);

    device = korva_server_get_device (self, uid);

    if (device != NULL) {
        GVariant *result;

        result = korva_device_serialize (device);
        korva_controller1_complete_get_device_info (iface, invocation, result);
    } else {
        g_dbus_method_invocation_return_error (invocation,
                                               KORVA_CONTROLLER1_ERROR,
                                               KORVA_CONTROLLER1_ERROR_NO_SUCH_DEVICE,
                                               "Device '%s' does not exist",
                                               uid);
    }

    return TRUE;
}
Ejemplo n.º 25
0
static gboolean
set_invocation (Realms *realms,
                GDBusMethodInvocation *invocation,
                const gchar *op,
                const gchar *name,
                GVariant *creds,
                GVariant *options)
{
  if (realms->op_invocation == NULL)
    {
      realms->op_invocation = invocation;
      realms->op = op;
      realms->op_name = g_strdup (name);
      realms->op_creds = g_variant_ref (creds);
      realms->op_options = g_variant_ref (options);
      realms->op_id = g_strdup_printf ("cockpitd-%u", realms->next_op_id++);
      realms->op_cancelled = FALSE;
      cockpit_realms_set_busy (COCKPIT_REALMS (realms),
                               g_variant_new ("(ss)", op, name));
      g_string_assign (realms->diagnostics, "");
      return TRUE;
    }
  else
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "Busy");
      return FALSE;
    }
}
Ejemplo n.º 26
0
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;
}
Ejemplo n.º 27
0
/**
 * daemon_authorize_method:
 * @daemon: a #Daemon
 * @invocation: method invocation handle
 *
 * Global hook used to authorize DBus methods.  We restrict them to
 * root at the moment (but this forces the bridge to run as root).
 *
 * Possibly a better long term fix is that the bridge actually starts
 * cockpitd as root, opens a private socketpair between them to speak
 * DBus, then drops privileges.
 *
 * Returns: %TRUE if call should be authorized, %FALSE otherwise
 */
gboolean
daemon_authorize_method (Daemon *daemon,
                         GDBusMethodInvocation *invocation)
{
  GError *error = NULL;
  gboolean is_authorized = FALSE;

  if (!authorize_method (daemon, invocation, &is_authorized, NULL, &error))
    {
      g_warning ("Error while authorizing method %s.%s: %s",
                 g_dbus_method_invocation_get_interface_name (invocation),
                 g_dbus_method_invocation_get_method_name (invocation),
                 error->message);
      g_clear_error (&error);
      return FALSE;
    }
  if (!is_authorized)
    {
      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                             G_DBUS_ERROR_ACCESS_DENIED,
                                             "Method %s.%s cannot be invoked by non-root",
                                             g_dbus_method_invocation_get_interface_name (invocation),
                                             g_dbus_method_invocation_get_method_name (invocation));
    }
  return is_authorized;
}
Ejemplo n.º 28
0
static gboolean
handle_remove (GVfsMetadata *object,
               GDBusMethodInvocation *invocation,
               const gchar *arg_treefile,
               const gchar *arg_path,
               GVfsMetadata *daemon)
{
  TreeInfo *info;

  info = tree_info_lookup (arg_treefile);
  if (info == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             G_IO_ERROR,
                                             G_IO_ERROR_NOT_FOUND,
                                             _("Can't find metadata file %s"),
                                             arg_treefile);
      return TRUE;
    }

  if (!meta_tree_remove (info->tree, arg_path))
    {
      g_dbus_method_invocation_return_error_literal (invocation,
                                                     G_IO_ERROR,
                                                     G_IO_ERROR_FAILED,
                                                     _("Unable to remove metadata keys"));
      return TRUE;
    }

  tree_info_schedule_writeout (info);
  gvfs_metadata_complete_remove (object, invocation);
  
  return TRUE;
}
Ejemplo n.º 29
0
static gboolean
handle_list_services (CockpitServices *object,
                      GDBusMethodInvocation *invocation)
{
  Services *services = SERVICES (object);

  if (services->systemd == NULL)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                             "systemd not running");
      return TRUE;
    }

  ListServicesData *data = g_new0(ListServicesData, 1);
  data->services = services;
  data->invocation = invocation;

  g_dbus_proxy_call (services->systemd,
                     "ListUnits",
                     NULL,
                     G_DBUS_CALL_FLAGS_NONE,
                     G_MAXINT,
                     NULL,
                     on_list_units_done,
                     data);
  return TRUE;
}
Ejemplo n.º 30
0
/**
 * cd_sensor_unlock_cb:
 **/
static void
cd_sensor_unlock_cb (GObject *source_object,
		     GAsyncResult *res,
		     gpointer user_data)
{
	CdSensor *sensor = CD_SENSOR (source_object);
	CdSensorPrivate *priv = GET_PRIVATE (sensor);
	GDBusMethodInvocation *invocation = (GDBusMethodInvocation *) user_data;
	gboolean ret;
	g_autoptr(GError) error = NULL;

	/* set here to avoid every sensor doing this */
	cd_sensor_set_state (sensor, CD_SENSOR_STATE_IDLE);

	/* get the result */
	if (priv->desc != NULL &&
	    priv->desc->unlock_finish != NULL) {
		ret = priv->desc->unlock_finish (sensor, res, &error);
		if (!ret) {
			g_dbus_method_invocation_return_error (invocation,
							       CD_SENSOR_ERROR,
							       CD_SENSOR_ERROR_NO_SUPPORT,
							       "failed to unlock: %s",
							       error->message);
			return;
		}
	}
	cd_sensor_set_locked (sensor, FALSE);
	g_dbus_method_invocation_return_value (invocation, NULL);
}