# 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} = @{lib}/{,kf6/}kauth/{,libexec/}backlighthelper
@{att} = ""
profile kauth-backlighthelper /{,usr/}lib{,exec,32,64}/{,kf6/}kauth/{,libexec/}backlighthelper flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.PolicyKit1>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5>

  capability net_admin,

  include <abstractions/bus/system/own>

  dbus bind bus=system name=org.kde.powerdevil.backlighthelper{,.*},
  dbus receive bus=system path=/org/kde/powerdevil/backlighthelper{,/**}
       interface=org.kde.powerdevil.backlighthelper{,.*}
       peer=(name="@{busname}"),
  dbus send bus=system path=/org/kde/powerdevil/backlighthelper{,/**}
       interface=org.kde.powerdevil.backlighthelper{,.*}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus (send receive) bus=system path=/org/kde/powerdevil/backlighthelper{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus receive bus=system path=/org/kde/powerdevil/backlighthelper{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="@{busname}"),
  dbus receive bus=system path=/org/kde/powerdevil/backlighthelper{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.kde.powerdevil.backlighthelper{,.*}}"),
  dbus send bus=system path=/org/kde/powerdevil/backlighthelper{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.DBus}"),

  @{exec_path} mr,

  /usr/share/icu/@{int}.@{int}/*.dat r,

  @{sys}/class/backlight/ r,
  @{sys}/class/leds/ r,
  @{sys}/devices/@{pci}/*_backlight/{,max_,actual_}brightness rw,
  @{sys}/devices/@{pci}/*_backlight/{uevent,type,enabled} r,
  @{sys}/devices/@{pci}/backlight/**/{,max_,actual_}brightness rw,
  @{sys}/devices/@{pci}/backlight/**/{uevent,type,enabled} r,
  @{sys}/devices/@{pci}/backlight/**/brightness rw,
  @{sys}/devices/@{pci}/drm/card@{int}/**/{,max_,actual_}brightness rw,
  @{sys}/devices/@{pci}/drm/card@{int}/**/{uevent,type,enabled} r,
  @{sys}/devices/@{pci}/drm/card@{int}/**/brightness rw,

  /dev/tty r,

  include if exists <local/kauth-backlighthelper>
}

# vim:syntax=apparmor
