# 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}/kwin_wayland
profile kwin_wayland @{exec_path} flags=(attach_disconnected mediate_deleted) {
  include <abstractions/base>
  include <abstractions/app-launcher-user>
  include <abstractions/fontconfig-cache-write>
  include <abstractions/graphics>
  include <abstractions/kde-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5-shader-cache>

  capability sys_nice,
  capability sys_ptrace,

  ptrace (read),

  signal (receive) set=term peer=sddm,
  signal (receive) set=(kill, term) peer=kwin_wayland_wrapper,
  signal (send) set=(kill, term) peer=xwayland,

  network netlink raw,

  @{exec_path} mr,

  #aa:exec kscreenlocker_greet

  /usr/share/color-schemes/*.colors r,
  /usr/share/desktop-base/kf5-settings/{,**} r,
  /usr/share/desktop-directories/*.directory r,
  /usr/share/kglobalaccel/{,**} r,
  /usr/share/knotifications{5,6}/ksmserver.notifyrc r,
  /usr/share/kservices{5,6}/{,**} r,
  /usr/share/kservicetypes5/{,*.desktop} r,
  /usr/share/kwin/{,**} r,
  /usr/share/libinput-*/{,**} r,
  /usr/share/libinput/{,**} r,
  /usr/share/pipewire/client.conf r,
  /usr/share/plasma/desktoptheme/** r,

  /etc/pipewire/client.conf.d/ r,
  /etc/xdg/kscreenlockerrc r,
  /etc/xdg/menus/{,applications.menu} r,
  /etc/xdg/menus/applications-merged/ r,
  /etc/xdg/plasmarc r,

  /etc/machine-id r,
  /var/lib/dbus/machine-id r,

  / r,
  owner @{HOME}/ r,

  owner @{sddm_cache_dirs}/#@{int} rwk,
  owner @{sddm_cache_dirs}/fontconfig/* rwk,
  owner @{sddm_cache_dirs}/fontconfig/*-le64.cache-@{int}.LCK l -> @{sddm_cache_dirs}/fontconfig/*-le64.cache-@{int}.TMP-@{rand6},
  owner @{sddm_cache_dirs}/fontconfig/*-le64.cache-@{int}{,TMP-@{rand6},NEW,LCK} w,
  owner @{sddm_cache_dirs}/ksycoca{5,6}_* rwkl  -> @{sddm_cache_dirs}/#@{int},

  owner @{sddm_config_dirs}/#@{int} rw,
  owner @{sddm_config_dirs}/kcminputrc r,
  owner @{sddm_config_dirs}/kdeglobals r,
  owner @{sddm_config_dirs}/kglobalshortcutsrc.lock rwk,
  owner @{sddm_config_dirs}/kglobalshortcutsrc{,.@{rand6}} rwl -> @{sddm_config_dirs}/#@{int},
  owner @{sddm_config_dirs}/kwinrc.lock rwk,
  owner @{sddm_config_dirs}/kwinrc{,.@{rand6}} rwl -> @{sddm_config_dirs}/#@{int},

  owner @{user_cache_dirs}/ r,
  owner @{user_cache_dirs}/#@{int} rw,
  owner @{user_cache_dirs}/ksvg-elements r,
  owner @{user_cache_dirs}/icon-cache.kcache rw,
  owner @{user_cache_dirs}/ksycoca{5,6}_* r,
  owner @{user_cache_dirs}/ksycoca{5,6}_* rwkl -> @{user_cache_dirs}/#@{int},
  owner @{user_cache_dirs}/kwin/ rw,
  owner @{user_cache_dirs}/kwin/** rwkl -> @{user_cache_dirs}/kwin/**,
  owner @{user_cache_dirs}/plasma_theme_*.kcache rw,
  owner @{user_cache_dirs}/plasma-svgelements rw,
  owner @{user_cache_dirs}/plasma-svgelements.@{rand6} rwl -> @{user_cache_dirs}/#@{int},
  owner @{user_cache_dirs}/plasma-svgelements.lock rwk,

  owner @{user_config_dirs}/#@{int} rwl,
  owner @{user_config_dirs}/breezerc r,
  owner @{user_config_dirs}/kcminputrc r,
  owner @{user_config_dirs}/kdedefaults/* r,
  owner @{user_config_dirs}/kglobalshortcutsrc.lock rwk,
  owner @{user_config_dirs}/kglobalshortcutsrc{,.@{rand6}} rwl -> @{user_config_dirs}/#@{int},
  owner @{user_config_dirs}/klaunchrc r,
  owner @{user_config_dirs}/kscreenlockerrc r,
  owner @{user_config_dirs}/kwinoutputconfig.json rw,
  owner @{user_config_dirs}/kwinrc.lock rwk,
  owner @{user_config_dirs}/kwinrc{,.@{rand6}} rwl -> @{user_config_dirs}/#@{int},
  owner @{user_config_dirs}/kwinrulesrc r,
  owner @{user_config_dirs}/kxkbrc r,
  owner @{user_config_dirs}/menus/{,applications-merged/} r,
  owner @{user_config_dirs}/plasmarc r,
  owner @{user_config_dirs}/session/* r, 

  owner @{user_share_dirs}/kscreen/* r,
  owner @{user_share_dirs}/kwin/scripts/{,**} r,

  @{run}/systemd/inhibit/*.ref rw,

  @{sys}/bus/ r,
  @{sys}/class/ r,
  @{sys}/class/drm/ r,
  @{sys}/class/input/ r,
  @{sys}/devices/**/uevent r,

  @{run}/udev/data/+acpi:* r,             # for ACPI
  @{run}/udev/data/+dmi:* r,              # for motherboard info
  @{run}/udev/data/+hid:* r,              # for HID subsystem
  @{run}/udev/data/+input:input@{int} r,  # for mouse, keyboard, touchpad
  @{run}/udev/data/+pci:* r,              # Identifies all PCI devices (CPU, GPU, Network, Disks, USB, etc.)
  @{run}/udev/data/+platform:* r,         # for ?
  @{run}/udev/data/+sound:card@{int} r,   # for sound card
  @{run}/udev/data/+usb:* r,

  @{run}/udev/data/c10:@{int} r,          # for non-serial mice, misc features
  @{run}/udev/data/c13:@{int}  r,         # for /dev/input/*
  @{run}/udev/data/c189:@{int} r,         # for /dev/bus/usb/**
  @{run}/udev/data/c226:@{int} r,         # for /dev/dri/card*

  @{PROC}/@{pid}/task/@{tid}/comm rw,

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

  include if exists <local/kwin_wayland>
}

# vim:syntax=apparmor
