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

abi <abi/4.0>,

include <tunables/global>

@{name} = proton-mail "Proton Mail"
@{domain} = org.chromium.Chromium
@{lib_dirs} = /opt/@{name}
@{config_dirs} = @{user_config_dirs}/@{name}
@{cache_dirs} = @{user_cache_dirs}/@{name}

@{exec_path} = @{bin}/proton-mail /opt/proton-mail/Proton*
@{att} = /att/protonmail/
profile protonmail /{{,usr/}bin/proton-mail,opt/proton-mail/Proton*}  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/common/electron>
  include <abstractions/secrets-service>

  network inet stream,
  network inet dgram,
  network inet6 dgram,
  network netlink raw,

  ptrace read peer=protonmail//&xdg-settings,

  @{exec_path} mrix,


  @{bin}/xdg-settings  rpx -> protonmail//&xdg-settings,
  @{open_path}          px -> child-open,

  owner @{user_config_dirs}/ibus/bus/ r,

  @{sys}/devices/@{pci}/boot_vga r,

  owner @{tmp}/gtkprint_ppd_@{rand6} rw,

  # Stacked profile: xdg-settings
  include <abstractions/consoles>
  include <abstractions/freedesktop.org>
  @{sh_path}        mr,
  @{bin}/{,e}grep  rix,
  @{bin}/basename  rix,
  @{bin}/cat        ix,
  @{bin}/cut       rix,
  @{bin}/head       ix,
  @{bin}/mkdir      ix,
  @{bin}/mktemp     ix,
  @{bin}/mv         ix,
  @{bin}/readlink   ix,
  @{bin}/realpath  rix,
  @{bin}/rm         ix,
  @{bin}/sed        ix,
  @{bin}/sleep      ix,
  @{bin}/sort       ix,
  @{bin}/touch      ix,
  @{bin}/tr         ix,
  @{bin}/uname      ix,
  @{bin}/wc         ix,
  # To set/get DE information
  @{bin}/gconftool{,-2}       ix,
  @{bin}/kde{,4}-config       ix,
  @{bin}/kwriteconfig{,5,6}   ix,
  @{bin}/qtxdg-mat            ix,
  @{bin}/dbus-send            Cx -> bus,
  @{bin}/kreadconfig{,5}      Px,
  @{bin}/xdg-mime             Px,
  @{bin}/xprop                Px,
  owner @{user_config_dirs}/xfce4/helpers.rc{,.@{rand6}} rw,
  owner @{user_share_dirs}/applications/{,**} rw,
  @{PROC}/version r,
  owner /dev/pts/@{int} rw,
  profile bus flags=(complain) {
    include <abstractions/app/bus>
    include <abstractions/bus-session>
    include if exists <local/xdg-settings_bus>
  }
  include if exists <local/xdg-settings>

  include if exists <local/protonmail>
}

# vim:syntax=apparmor
