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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{lib}/xdg-permission-store
profile xdg-permission-store @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-session>

  capability sys_nice,

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

  #aa:dbus own bus=session name=org.freedesktop.impl.portal.PermissionStore

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

  @{exec_path} mr,

  @{HOME}/@{XDG_DATA_DIR}/flatpak/db/gnome rw,

  owner @{user_share_dirs}/flatpak/ w,
  owner @{user_share_dirs}/flatpak/db/ rw,
  owner @{user_share_dirs}/flatpak/db/.goutputstream-@{rand6} rw,
  owner @{user_share_dirs}/flatpak/db/background rw,
  owner @{user_share_dirs}/flatpak/db/devices r,
  owner @{user_share_dirs}/flatpak/db/notifications rw,

  /dev/tty@{int} rw,

  include if exists <local/xdg-permission-store>
}
