# 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/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/kcminit
@{att} = ""
profile kcminit /{,usr/}bin/kcminit flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/bus-session>
  include <abstractions/bus/session/org.freedesktop.systemd1>
  include <abstractions/kde-strict>
  include <abstractions/ibus-strict>

  #aa/dbus own bus=session name=org.kde.{KCMI,kcmi}nit path=/kcminit
  include <abstractions/bus/session/own>
  dbus bind bus=session name=org.kde.{KCMI,kcmi}nit{,.*},
  dbus receive bus=session path=/kcminit
       interface=org.kde.{KCMI,kcmi}nit{,.*}
       peer=(name="@{busname}"),
  dbus send bus=session path=/kcminit
       interface=org.kde.{KCMI,kcmi}nit{,.*}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  # DBus.Properties: reply to properties request from anyone
  dbus (send receive) bus=session path=/kcminit
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  # DBus.Introspectable: allow clients to introspect the service
  dbus receive bus=session path=/kcminit
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="@{busname}"),
  # DBus.ObjectManager: allow clients to enumerate sources
  dbus receive bus=session path=/kcminit
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.kde.{KCMI,kcmi}nit{,.*}}"),
  dbus send bus=session path=/kcminit
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.DBus}"),


  #aa/dbus talk bus=session name=org.kde.KSplash path=/KSplash label=ksplashqml
  # Unix: allow connection to the profile
  unix type=stream peer=(label=ksplashqml),
  # org.kde.KSplash: send and receive anything to the interface on the specific peer label
  dbus (send receive) bus=session path=/KSplash
       interface=org.kde.KSplash{,.*}
       peer=(name="{@{busname},org.kde.KSplash{,.*},org.freedesktop.DBus}", label=ksplashqml),
  dbus send bus=session path=/KSplash
       interface=org.kde.KSplash{,.*}
       peer=(name="org.kde.KSplash{,.*}"),
  # DBus.Properties: read and send properties
  dbus (send receive) bus=session path=/KSplash
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.kde.KSplash{,.*},org.freedesktop.DBus}", label=ksplashqml),
  # DBus.Introspectable: allow service introspection
  dbus send bus=session path=/KSplash
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="{@{busname},org.kde.KSplash{,.*},org.freedesktop.DBus}", label=ksplashqml),
  # DBus.ObjectManager: allow clients to enumerate sources
  dbus send bus=session path=/KSplash
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.kde.KSplash{,.*},org.freedesktop.DBus}", label=ksplashqml),
  dbus receive bus=session path=/KSplash
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.kde.KSplash{,.*},org.freedesktop.DBus}", label=ksplashqml),

  #aa/dbus talk bus=session name=org.kde.KWin label=kwin_wayland
  # Unix: allow connection to the profile
  unix type=stream peer=(label=kwin_wayland),
  # org.kde.KWin: send and receive anything to the interface on the specific peer label
  dbus (send receive) bus=session path=/org/kde/KWin{,/**}
       interface=org.kde.KWin{,.*}
       peer=(name="{@{busname},org.kde.KWin{,.*},org.freedesktop.DBus}", label=kwin_wayland),
  dbus send bus=session path=/org/kde/KWin{,/**}
       interface=org.kde.KWin{,.*}
       peer=(name="org.kde.KWin{,.*}"),
  # DBus.Properties: read and send properties
  dbus (send receive) bus=session path=/org/kde/KWin{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.kde.KWin{,.*},org.freedesktop.DBus}", label=kwin_wayland),
  # DBus.Introspectable: allow service introspection
  dbus send bus=session path=/org/kde/KWin{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="{@{busname},org.kde.KWin{,.*},org.freedesktop.DBus}", label=kwin_wayland),
  # DBus.ObjectManager: allow clients to enumerate sources
  dbus send bus=session path=/org/kde/KWin{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.kde.KWin{,.*},org.freedesktop.DBus}", label=kwin_wayland),
  dbus receive bus=session path=/org/kde/KWin{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.kde.KWin{,.*},org.freedesktop.DBus}", label=kwin_wayland),


  @{exec_path} mr,

  @{bin}/xrdb      rpx,
  @{bin}/xsetroot  rpx,

  /etc/xdg/kcmdisplayrc r,
  /etc/X11/xorg.conf r,

  owner @{HOME}/.Xdefaults r,

  owner @{user_config_dirs}/gtkrc-2.0{,.@{rand6}} rwl,
  owner @{user_config_dirs}/gtkrc{,.@{rand6}} rwl,
  owner @{user_config_dirs}/kcmfonts r,
  owner @{user_config_dirs}/kcminputrc{,.@{rand6}} rwl,
  owner @{user_config_dirs}/kcminputrc.lock rwk,
  owner @{user_config_dirs}/kgammarc r,
  owner @{user_config_dirs}/touchpadrc r,
  owner @{user_config_dirs}/touchpadxlibinputrc r,
  owner @{user_config_dirs}/Trolltech.conf.lock rwk,
  owner @{user_config_dirs}/Trolltech.conf{,.@{rand6}} rwl,

  owner @{tmp}/#@{int} rw,
  owner @{tmp}/kcminit.@{rand6} rwl,

  owner @{tmp}/.touchpaddefaults wl,
  owner @{tmp}/.touchpaddefaults.lock rwk,

  @{run}/user/@{uid}/xauth_@{rand6} rl,

  @{PROC}/sys/kernel/random/boot_id r,

  /dev/tty r,

  include if exists <local/kcminit>
}

# vim:syntax=apparmor
