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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{lib}/{,cups-pk-helper/}cups-pk-helper-mechanism
@{exec_path} += @{lib}/@{multiarch}/cups-pk-helper-mechanism
profile cups-pk-helper-mechanism /{{,usr/}lib{,exec,32,64}/{,cups-pk-helper/}cups-pk-helper-mechanism,{,usr/}lib{,exec,32,64}/*-linux-gnu*/cups-pk-helper-mechanism} flags=(complain) {
  include <abstractions/base>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.PolicyKit1>
  include <abstractions/nameservice-strict>

  capability dac_read_search,
  capability sys_nice,

  network inet stream,
  network inet6 stream,

  dbus bind bus=system name=org.opensuse.CupsPkHelper.Mechanism{,.*},
  dbus receive bus=system path=/
       interface=org.opensuse.CupsPkHelper.Mechanism{,.*}
       peer=(name=":1.@{int}"),
  dbus receive bus=system path=/
       interface=org.freedesktop.DBus.Properties
       peer=(name=":1.@{int}"),
  dbus receive bus=system path=/
       interface=org.freedesktop.DBus.ObjectManager
       peer=(name=":1.@{int}"),
  dbus send bus=system path=/
       interface=org.opensuse.CupsPkHelper.Mechanism{,.*}
       peer=(name="{:1.@{int},org.freedesktop.DBus}"),
  dbus send bus=system path=/
       interface=org.freedesktop.DBus.Properties
       peer=(name="{:1.@{int},org.freedesktop.DBus}"),
  dbus send bus=system path=/
       interface=org.freedesktop.DBus.ObjectManager
       peer=(name="{:1.@{int},org.freedesktop.DBus}"),
  dbus receive bus=system path=/
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name=":1.@{int}"),

  @{exec_path} mr,

  /etc/cups/ppd/*.ppd r,

  owner /tmp/[a-z0-9]* rw,

  @{run}/cups/cups.sock rw,

  include if exists <local/cups-pk-helper-mechanism>
}