# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2025 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/whoopsie-preferences
@{att} = ""
profile whoopsie-preferences /{,usr/}bin/whoopsie-preferences flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/bus-system>
  include <abstractions/nameservice-strict>

  include <abstractions/bus/system/own>

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

  @{exec_path} mr,

  @{bin}/systemctl cx -> systemctl,

  /etc/whoopsie w,
  /etc/whoopsie.@{rand6} rw,

  profile systemctl flags=(complain) {
    include <abstractions/base-strict>
    include <abstractions/app/systemctl>

    include if exists <local/whoopsie-preferences_systemctl>
  }

  include if exists <local/whoopsie-preferences>
}

# vim:syntax=apparmor
