# 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}/systemsettings
profile systemsettings @{exec_path} {
  include <abstractions/base>
  include <abstractions/graphics>
  include <abstractions/kde-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5-shader-cache>

  network netlink raw,

  @{exec_path} mr,

  @{bin}/kcminit rPx,

  /usr/share/kcm_networkmanagement/{,**} r,
  /usr/share/kinfocenter/{,**} r,
  /usr/share/kpackage/{,**} r,
  /usr/share/kservices{5,6}/{,**} r,
  /usr/share/kservicetypes5/{,**} r,
  /usr/share/kxmlgui5/systemsettings/systemsettingsui.rc r,
  /usr/share/plasma/{,**} r,
  /usr/share/sddm/themes/{,**} r,
  /usr/share/systemsettings/{,**} r,

  /etc/fstab r,
  /etc/machine-id r,
  /etc/xdg/menus/ r,
  /etc/xdg/ui/ui_standards.rc r,
  /var/lib/dbus/machine-id r,

  owner @{user_cache_dirs}/#@{int} rw,
  owner @{user_cache_dirs}/icon-cache.kcache rw,
  owner @{user_cache_dirs}/kinfocenter/{,**} rwl,
  owner @{user_cache_dirs}/ksvg-elements rw,
  owner @{user_cache_dirs}/ksvg-elements.@{rand6} rwlk -> @{user_cache_dirs}/#@{int},
  owner @{user_cache_dirs}/ksvg-elements.lock rwlk,
  owner @{user_cache_dirs}/ksycoca{5,6}_* r,
  owner @{user_cache_dirs}/plasma_theme_*.kcache rw,
  owner @{user_cache_dirs}/systemsettings/ rw,
  owner @{user_cache_dirs}/systemsettings/** rwlk -> @{user_cache_dirs}/systemsettings/**,

  owner @{user_config_dirs}/#@{int} rw,
  owner @{user_config_dirs}/kde.org/{,**} rwlk,
  owner @{user_config_dirs}/kdedefaults/plasmarc r,
  owner @{user_config_dirs}/kinfocenterrc* rwlk,
  owner @{user_config_dirs}/systemsettingsrc.lock rwk,
  owner @{user_config_dirs}/systemsettingsrc{,.@{rand6}} rwl -> @{user_config_dirs}/#@{int},

  owner @{user_share_dirs}/kactivitymanagerd/resources/database rk,
  owner @{user_share_dirs}/kactivitymanagerd/resources/database-shm rwk,
  owner @{user_share_dirs}/kactivitymanagerd/resources/database-wal rw,

  owner @{user_share_dirs}/systemsettings/ rw,
  owner @{user_share_dirs}/systemsettings/** rwlk,

  @{sys}/bus/ r,
  @{sys}/bus/cpu/devices/ r,
  @{sys}/class/ r,

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

  /dev/tty r,

  include if exists <local/systemsettings>
}