# 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}/anyremote
profile anyremote /{,usr/}{,s}bin/anyremote flags=(complain) {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>

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

  network inet stream,
  network inet6 stream,

  @{exec_path} mr,

  @{sh_path}        rix,
  @{bin}/cat        rix,
  @{bin}/rm         rix,
  @{bin}/{,e}grep   rix,
  @{bin}/cut        rix,
  @{bin}/id         rix,
  @{bin}/mv         rix,
  @{bin}/expr       rix,
  @{bin}/which{,.debianutils}      rix,
  @{bin}/head       rix,
  @{bin}/wc         rix,
  @{bin}/tr         rix,
  @{bin}/mkdir      rix,
  @{bin}/tail       rix,
  @{bin}/{m,g,}awk  rix,
  @{bin}/sed        rix,
  @{bin}/md5sum     rix,
  @{bin}/basename   rix,
  @{bin}/sleep      rix,
  @{bin}/find       rix,

  @{bin}/convert-im6.q16 rCx -> imagemagic,
  @{bin}/killall         rCx -> killall,
  @{bin}/pgrep           rCx -> pgrep,
  @{lib}/qt5/bin/qdbus   rCx -> qdbus,
  @{bin}/curl            rCx -> curl,

  @{bin}/pacmd           rPx,
  @{bin}/pactl           rPx,
  @{bin}/wmctrl          rPx,
  @{bin}/qtchooser       rPx,
  @{bin}/ps              rPx,

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

  owner /tmp/amarok_covers/ rw,
  owner /tmp/*.png rw,

  # For shell pwd
  owner @{HOME}/ r,

  owner @{HOME}/.anyRemote/{,**} rw,
  owner @{HOME}/.anyRemote/imdb-mf.sh rix,

  /usr/share/anyremote/{,**} r,
  /usr/share/anyremote/cfg-data/Utils/*.sh rix,

  deny @{PROC}/sys/kernel/osrelease r,

  owner @{HOME}/.Xauthority r,


  profile imagemagic flags=(complain) {
    include <abstractions/base>

    @{bin}/convert-im6.q16 mr,

    /usr/share/ImageMagick-[0-9]/*.xml rw,
    /etc/ImageMagick-[0-9]/*.xml r,

    /usr/share/anyremote/cfg-data/Icons/common/*.png r,
    owner @{HOME}/.anyRemote/*.png rw,

    owner @{HOME}/.kde/share/apps/amarok/albumcovers/cache/* r,

          /tmp/ r,
    owner /tmp/*.png rw,
    owner /tmp/amarok_covers/* rw,
    owner /tmp/magick-* rw,

  }

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

    capability sys_ptrace,

    signal (send) set=(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,

    # file_inherit
    owner @{HOME}/.anyRemote/anyremote.stdout w,

  }

  profile pgrep flags=(complain) {
    include <abstractions/base>
    include <abstractions/consoles>

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

    @{bin}/pgrep mr,

    # The /proc/ dir and the cmdline have to be radable to avoid pgrep segfault.
         @{PROC}/ r,
         @{PROC}/@{pids}/cmdline r,
    deny @{PROC}/sys/kernel/osrelease r,

    # file_inherit
    owner @{HOME}/.anyRemote/anyremote.stdout w,

  }

  profile curl flags=(complain) {
    include <abstractions/base>
    include <abstractions/nameservice-strict>
    include <abstractions/ssl_certs>

    @{bin}/curl mr,

  }

    profile qdbus flags=(complain) {
    include <abstractions/base>

    @{lib}/qt5/bin/qdbus mr,

  }

  include if exists <local/anyremote>
}
