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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{lib}/{,at-spi2{,-core}/}at-spi-bus-launcher
profile dbus-accessibility @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-accessibility>
  include <abstractions/bus-session>
  include <abstractions/bus/org.a11y>
  include <abstractions/bus/org.gnome.SessionManager>
  include <abstractions/dconf-write>
  include <abstractions/nameservice-strict>

  signal (receive) set=(term hup kill) peer=dbus-session,
  signal (receive) set=(term hup kill) peer=gdm{,-session-worker},

  dbus bus=accessibility,

  #aa:dbus own bus=session name=org.a11y.{B,b}us

  dbus receive bus=session
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name=:*, label=gnome-shell),

  @{exec_path} mrix,

  @{bin}/dbus-broker                           rix,
  @{bin}/dbus-broker-launch                    rix,
  @{bin}/dbus-daemon                           rix,
  @{lib}/at-spi2-registryd                     rPx,
  @{lib}/at-spi2{,-core}/at-spi2-registryd     rPx,

  /usr/share/dbus-1/accessibility-services/{,**} r,
  /usr/share/dconf/profile/gdm r,
  /usr/share/defaults/at-spi2/{,**} r,
  /usr/share/gdm/greeter-dconf-defaults r,
  /usr/share/glib-2.0/schemas/gschemas.compiled r,

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

  owner @{DESKTOP_HOME}/greeter-dconf-defaults r,
  owner @{desktop_config_dirs}/dconf/user r,

  owner @{HOME}/.Xauthority r,

        @{run}/systemd/users/@{uid} r,
  owner @{run}/user/@{uid}/gdm/Xauthority r,

  @{sys}/kernel/security/apparmor/.access rw,
  @{sys}/kernel/security/apparmor/features/dbus/mask r,
  @{sys}/module/apparmor/parameters/enabled r,

        @{PROC}/@{pid}/attr/apparmor/current r,
        @{PROC}/@{pid}/cgroup r,
        @{PROC}/@{pid}/cmdline r,
        @{PROC}/@{pid}/oom_score_adj r,
  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mounts r,

  owner /dev/tty@{int} rw,

  include if exists <local/dbus-accessibility>
}

# vim:syntax=apparmor
