# 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/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/orage
profile orage @{exec_path} {
  include <abstractions/base>
  include <abstractions/gtk>
  include <abstractions/fonts>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/freedesktop.org>
  include <abstractions/user-download-strict>
  include <abstractions/nameservice-strict>

  @{exec_path} mr,

  @{bin}/globaltime rPx,

  @{bin}/xdg-open   rCx -> open,
  @{bin}/exo-open   rCx -> open,
  @{lib}/@{multiarch}/glib-[0-9]*/gio-launch-desktop rCx -> open,

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

  owner @{user_share_dirs}/orage/ rw,
  owner @{user_share_dirs}/orage/* rwk,

  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,

  /etc/fstab r,

  # Allowed apps to open
  @{lib}/firefox/firefox rPUx,

  # file_inherit
  owner /dev/tty@{int} rw,


  profile open {
    include <abstractions/base>
    include <abstractions/xdg-open>

    @{bin}/xdg-open mr,

    @{sh_path}             rix,
    @{bin}/{m,g,}awk       rix,
    @{bin}/readlink        rix,
    @{bin}/basename        rix,

    owner @{HOME}/ r,

    owner @{run}/user/@{uid}/ r,

    # Allowed apps to open
    @{lib}/firefox/firefox rPUx,

    # file_inherit
    owner @{HOME}/.xsession-errors w,

  }

  include if exists <local/orage>
}
