# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2020-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}/kodi @{lib}/@{multiarch}/kodi/kodi.bin
profile kodi @{exec_path} {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>
  include <abstractions/python>
  include <abstractions/ssl_certs>
  include <abstractions/X-strict>

  @{exec_path} mr,

  @{lib}/@{multiarch}/kodi/kodi.bin   mrix,
  @{lib}/@{multiarch}/kodi/kodi-xrandr rPx,

  @{sh_path}         rix,
  @{bin}/basename    rix,
  @{bin}/cat         rix,
  @{bin}/cut         rix,
  @{bin}/date        rix,
  @{bin}/df          rix,
  @{bin}/dirname     rix,
  @{bin}/find        rix,
  @{bin}/ldconfig    rix,
  @{bin}/mv          rix,
  @{bin}/uname       rix,

  @{bin}/lsb_release rPx -> lsb_release,

  /usr/share/kodi/{,**} r,
  /usr/share/publicsuffix/* r,

  /etc/fstab r,
  /etc/machine-id r,
  /etc/timezone r,
  /var/lib/dbus/machine-id r,

  owner @{HOME}/.kodi/ rw,
  owner @{HOME}/.kodi/** rwk,

  owner @{HOME}/core w,
  owner @{HOME}/kodi_crashlog-@{int}_@{int}.log w,

  @{run}/udev/data/* r,

  @{sys}/**/ r,
  @{sys}/devices/@{pci}/usb@{int}/{bDeviceClass,idProduct,idVendor} r,
  @{sys}/devices/@{pci}/usb@{int}/**/{bDeviceClass,idProduct,idVendor} r,
  @{sys}/devices/**/uevent r,
  @{sys}/devices/system/cpu/cpufreq/policy@{int}/scaling_cur_freq r,
  @{sys}/devices/virtual/thermal/thermal_zone@{int}/temp r,

        @{PROC}/@{pid}/net/dev r,
        @{PROC}/@{pid}/net/route r,
        @{PROC}/sys/kernel/core_pattern r,
  owner @{PROC}/@{pid}/mounts r,
  owner @{PROC}/@{pid}/mountinfo r,

  include if exists <local/kodi>
}
