# 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} = @{bin}/startplasma-wayland @{bin}/startplasma-x11
profile startplasma @{exec_path} {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/kde-strict>
  include <abstractions/bus-session>

  signal (receive) set=(hup) peer=@{p_systemd},
  signal (receive) set=(term) peer=sddm,

  @{exec_path} mr,

  @{sh_path}                rix,
  @{bin}/env                rix,
  @{bin}/grep               rix,
  @{bin}/kapplymousetheme  rPUx,
  @{bin}/ksplashqml        rPUx,
  @{bin}/plasma_session     rPx,
  @{bin}/xrdb               rPx,
  @{bin}/xsetroot           rPx,

  @{lib}/@{multiarch}/libexec/plasma-sourceenv.sh r,

  /usr/share/color-schemes/{,**} r,
  /usr/share/desktop-directories/{,**} r,
  /usr/share/knotifications{5,6}/{,**} r,
  /usr/share/kservices{5,6}/{,**} r,
  /usr/share/kservicetypes5/{,**} r,
  /usr/share/plasma/{,**} r,

  /etc/locale.alias r,
  /etc/machine-id r,
  /etc/xdg/kcminputrc r,
  /etc/xdg/menus/{,**} r,
  /etc/xdg/plasma-workspace/env/{,*} r,

  /var/lib/flatpak/exports/share/mime/ r,

        @{user_cache_dirs}/ksycoca{5,6}_* rwkl -> @{user_cache_dirs}/#@{int},
  owner @{user_cache_dirs}/#@{int} rwk,
  owner @{user_cache_dirs}/kcrash-metadata/ rw,
  owner @{user_cache_dirs}/plasma-svgelements rw,

  owner @{user_config_dirs}/#@{int} rw,
  owner @{user_config_dirs}/gtkrc{,*} rwlk,
  owner @{user_config_dirs}/kcminputrc r,
  owner @{user_config_dirs}/kdedefaults/ rw,
  owner @{user_config_dirs}/kdedefaults/** rwkl -> @{user_config_dirs}/kdedefaults/**,
  owner @{user_config_dirs}/kdeglobals.lock rwk,
  owner @{user_config_dirs}/kdeglobals{,.@{rand6}} rwl -> @{user_config_dirs}/#@{int},
  owner @{user_config_dirs}/ksplashrc r,
  owner @{user_config_dirs}/kwinkdeglobalsrc.lock rwk,
  owner @{user_config_dirs}/menus/{,**} r,
  owner @{user_config_dirs}/plasma_workspace.notifyrc r,
  owner @{user_config_dirs}/plasma-localerc rwl,
  owner @{user_config_dirs}/plasma-localerc.lock rwk,
  owner @{user_config_dirs}/plasma-workspace/env/ r,
  owner @{user_config_dirs}/startkderc r,
  owner @{user_config_dirs}/Trolltech.conf.lock rwk,
  owner @{user_config_dirs}/Trolltech.conf{,.@{rand6}} rwl,

  owner @{user_share_dirs}/color-schemes/{,**} r,
  owner @{user_share_dirs}/kservices{5,6}/{,**} r,
  owner @{user_share_dirs}/sddm/wayland-session.log rw,
  owner @{user_share_dirs}/sddm/xorg-session.log rw,

  owner @{tmp}/#@{int} rw,
  owner @{tmp}/startplasma-{x11,wayland}.@{rand6} rwl -> /tmp/#@{int},

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

        @{PROC}/sys/kernel/random/boot_id r,
  owner @{PROC}/@{pid}/maps r,

  /dev/tty r,
  /dev/tty@{int} rw,

  include if exists <local/startplasma>
}

# vim:syntax=apparmor
