Пример #1
0
static gboolean
check_authorization_no_polkit (UDisksDaemon          *daemon,
                               UDisksObject          *object,
                               const gchar           *action_id,
                               GVariant              *options,
                               const gchar           *message,
                               GDBusMethodInvocation *invocation)
{
  gboolean ret = FALSE;
  uid_t caller_uid = -1;
  GError *error = NULL;

  if (!udisks_daemon_util_get_caller_uid_sync (daemon,
                                               invocation,
                                               NULL,         /* GCancellable* */
                                               &caller_uid,
                                               NULL,         /* gid_t *out_gid */
                                               NULL,         /* gchar **out_user_name */
                                               &error))
    {
      g_dbus_method_invocation_return_error (invocation,
                                             UDISKS_ERROR,
                                             UDISKS_ERROR_FAILED,
                                             "Error getting uid for caller with bus name %s: %s (%s, %d)",
                                             g_dbus_method_invocation_get_sender (invocation),
                                             error->message, g_quark_to_string (error->domain), error->code);
      g_clear_error (&error);
      goto out;
    }

  /* only allow root */
  if (caller_uid == 0)
    {
      ret = TRUE;
    }
  else
    {
      g_dbus_method_invocation_return_error_literal (invocation,
                                                     UDISKS_ERROR,
                                                     UDISKS_ERROR_NOT_AUTHORIZED,
                                                     "Not authorized to perform operation (polkit authority not available and caller is not uid 0)");
    }

 out:
  return ret;
}
Пример #2
0
static gboolean
common_setup (UDisksLinuxLogicalVolume           *volume,
              GDBusMethodInvocation              *invocation,
              GVariant                           *options,
              const gchar                        *auth_err_msg,
              UDisksLinuxLogicalVolumeObject    **object,
              UDisksDaemon                      **daemon,
              uid_t                              *out_uid,
              gid_t                              *out_gid)
{
  gboolean rc = FALSE;
  GError *error = NULL;

  *object = udisks_daemon_util_dup_object (volume, &error);
  if (*object == NULL)
    {
      g_dbus_method_invocation_take_error (invocation, error);
      goto out;
    }

  *daemon = udisks_linux_logical_volume_object_get_daemon (*object);

  if (!udisks_daemon_util_get_caller_uid_sync (*daemon,
                                               invocation,
                                               NULL /* GCancellable */,
                                               out_uid,
                                               out_gid,
                                               NULL,
                                               &error))
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      g_clear_error (&error);
      goto out;
    }

  /* Policy check. */
  UDISKS_DAEMON_CHECK_AUTHORIZATION (*daemon,
                                     UDISKS_OBJECT (*object),
                                     lvm2_policy_action_id,
                                     options,
                                     auth_err_msg,
                                     invocation);
  rc = TRUE;
 out:
  return rc;
}