# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2018-2021 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/xdg-open
profile xdg-open @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/app-launcher-user>
  include <abstractions/consoles>

  @{exec_path} r,

  @{sh_path}          rix,
  @{bin}/{,e}grep     rix,
  @{bin}/sed          rix,
  @{bin}/cut          rix,
  @{bin}/which{,.debianutils}        rix,
  @{bin}/cat          rix,
  @{bin}/uname        rix,

  @{bin}/xprop        rPx,
  @{bin}/xdg-mime     rPx,

  @{bin}/exo-open     rPx,
  @{bin}/gio          rPx,
  #@{bin}/kde-open5  rPUx,
  @{bin}/ktraderclient5 rPUx,

  @{bin}/dbus-launch  rCx -> dbus,
  @{bin}/dbus-send    rCx -> dbus,

        /** r,
  owner /** rw,

  # freedesktop.org-strict
  owner @{user_share_dirs}/applications/ r,
  /usr/share/applications/*.desktop r,

  /dev/tty rw,

  profile dbus {
    include <abstractions/base>
    include <abstractions/nameservice-strict>

    @{bin}/dbus-launch   mr,
    @{bin}/dbus-send     mr,
    @{bin}/dbus-daemon  rPx,

    # for dbus-launch
    owner @{HOME}/.dbus/session-bus/@{hex}-[0-9] w,

    @{HOME}/.Xauthority r,
  }

  include if exists <local/xdg-open>
}
