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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{lib}/mozilla/kmozillahelper
profile firefox-kmozillahelper @{exec_path} {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/desktop>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5-settings-write>
  include <abstractions/recent-documents-write>
  include <abstractions/thumbnails-cache-read>

  ptrace (read) peer=firefox,

  @{exec_path} mr,

  @{lib}/libheif/            r,
  @{lib}/libheif/*.so*      rm,

  /usr/share/hwdata/*.ids r,
  /usr/share/icu/@{int}.@{int}/*.dat r,
  /usr/share/knotifications{5,6}/*.notifyrc r,
  /usr/share/kservices{5,6}/{,**} r,

  /etc/xdg/kdeglobals r,
  /etc/xdg/kwinrc r,
  /etc/xdg/menus/ r,
  /etc/xdg/menus/applications-merged/ r,

  owner @{HOME}/@{XDG_DESKTOP_DIR}/ r,
  owner @{HOME}/@{XDG_DESKTOP_DIR}/*.desktop r,

  owner @{user_cache_dirs}/icon-cache.kcache rw,
  owner @{user_cache_dirs}/ksycoca{5,6}_* r,

  owner @{user_config_dirs}/kdedefaults/kdeglobals r,
  owner @{user_config_dirs}/kdedefaults/kwinrc r,
  owner @{user_config_dirs}/kdeglobals r,
  owner @{user_config_dirs}/kdeglobals.@{rand6} rwl,
  owner @{user_config_dirs}/kmozillahelperrc r,
  owner @{user_config_dirs}/kmozillahelperrc.@{rand6} rwl,
  owner @{user_config_dirs}/kwinrc r,

  owner @{run}/user/@{uid}/kmozillahelper@{rand6}.@{int}.kioworker.socket wl,
  owner @{run}/user/@{uid}/xauth_@{rand6} rl,

  @{run}/udev/data/+usb:* r,              # For /dev/bus/usb/**

  @{run}/udev/data/c189:@{int} r,     # for /dev/bus/usb/**

        @{PROC}/sys/kernel/core_pattern r,
  owner @{PROC}/@{pid}/mountinfo r,

  /dev/tty r,

  include if exists <local/firefox-kmozillahelper>
}
