# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2018-2021 Mikhail Morfikov
# 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}/sddm-greeter{,-qt6}
profile sddm-greeter @{exec_path} {
  include <abstractions/base>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.login1>
  include <abstractions/bus/org.freedesktop.UPower>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/graphics>
  include <abstractions/kde-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5-compose-cache-write>
  include <abstractions/qt5-shader-cache>

  network netlink raw,

  @{exec_path} mr,

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

  /usr/share/desktop-base/*-theme/login/*.svg r,
  /usr/share/plasma/desktoptheme/** r,
  /usr/share/sddm/{,**} r,
  /usr/share/wayland-sessions/{,*.desktop} r,
  /usr/share/xsessions/{,*.desktop} r,
  /usr/share/wallpapers/{,**} r,
  /usr/share/hunspell/** r,

  /etc/fstab r,
  /etc/os-release r,
  /etc/sddm.conf r,
  /etc/sddm.conf.d/{,*} r,
  /etc/xdg/plasmarc r,
  /var/lib/AccountsService/icons/* r,
  /var/lib/dbus/machine-id r,

        @{SDDM_HOME}/state.conf r,
  owner @{SDDM_HOME}/** rw,
  owner @{SDDM_HOME}/#@{int} mrw,
  owner @{sddm_cache_dirs}/** mrwkl -> @{sddm_cache_dirs}/**,

  owner @{user_cache_dirs}/ rw,
  owner @{user_cache_dirs}/icon-cache.kcache rw,
  owner @{user_cache_dirs}/plasma_theme_*.kcache rw,
  owner @{user_cache_dirs}/plasma-svgelements rw,
  owner @{user_cache_dirs}/plasma-svgelements.@{rand6} rw,
  owner @{user_cache_dirs}/plasma-svgelements.lock rwk,
  owner @{user_cache_dirs}/sddm-greeter/{,**} rwl,

  owner @{user_config_dirs}/plasmarc r,

  # If one is blocked, the others are probed.
  deny owner @{HOME}/#@{int} mrw,
       owner @{HOME}/.glvnd* mrw,

  owner @{tmp}/runtime-sddm/ rw,
  owner @{tmp}/sddm-:@{int}-@{rand6} rw,

  owner @{run}/sddm/{,*} rw,

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

  include if exists <local/sddm-greeter>
}
