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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/kanyremote
@{att} = ""
profile kanyremote /{,usr/}bin/kanyremote flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/consoles>
  include <abstractions/desktop>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>
  include <abstractions/python>
  include <abstractions/qt5-compose-cache-write>
  include <abstractions/qt5-settings-write>
  include <abstractions/user-download-strict>

  network inet stream,
  network inet6 stream,

  @{exec_path} r,
  @{sh_path}        rix,

  @{bin}/ r,
  @{bin}/rm         rix,
  @{bin}/{,e}grep   rix,
  @{bin}/cut        rix,
  @{bin}/id         rix,
  @{bin}/which{,.debianutils}  rix,
  @{bin}/tr         rix,
  @{bin}/{m,g,}awk  rix,
  @{bin}/head       rix,
  @{bin}/find       rix,

  @{bin}/anyremote  rpx,
  @{bin}/ps         rpx,

  @{bin}/killall    rcx -> killall,
  @{bin}/pgrep      rcx -> pgrep,

  @{bin}/pacmd      rpux,
  @{bin}/pactl      rpux,

  # Players
  @{bin}/amarok     rpux,
  @{bin}/mpv        rpux,
  @{bin}/smplayer   rpux,
  @{bin}/strawberry rpux,
  @{bin}/vlc        rpux,

  /usr/share/anyremote/{,**} r,

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

  owner @{HOME}/ r,
  owner @{HOME}/.anyRemote/{,**} rw,

  owner @{user_config_dirs}/anyRemote/{,**} rw,

  owner /dev/shm/#@{int} rw,

  owner @{PROC}/@{pid}/cmdline r,

  profile killall flags=(complain) {
    include <abstractions/base-strict>
    include <abstractions/consoles>

    capability sys_ptrace,

    signal (send) set=(int, term, kill),

    ptrace (read),

    @{bin}/killall mr,

    # The /proc/ dir is needed to avoid the following error:
    #  /proc: Permission denied
         @{PROC}/ r,
         @{PROC}/@{pids}/stat r,

    include if exists <local/kanyremote_killall>
  }

  profile pgrep flags=(complain) {
    include <abstractions/base-strict>
    include <abstractions/app/pgrep>

    /usr/share/anyremote/{,**} r,

    include if exists <local/kanyremote_pgrep>
  }

  include if exists <local/kanyremote>
}

# vim:syntax=apparmor
