# 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/4.0>,

include <tunables/global>

@{exec_path} = @{lib}/tracker-miner-fs-{,control-,rss-}3
profile tracker-miner @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.UPower>
  include <abstractions/bus/org.gtk.Private.RemoteVolumeMonitor>
  include <abstractions/bus/org.gtk.vfs.Daemon>
  include <abstractions/bus/org.gtk.vfs.MountTracker>
  include <abstractions/dconf-write>
  include <abstractions/deny-sensitive-home>
  include <abstractions/disks-read>
  include <abstractions/gnome-strict>
  include <abstractions/gstreamer>
  include <abstractions/nameservice-strict>

  network netlink raw,

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

  #aa:dbus own bus=session name=org.freedesktop.Tracker3.Miner.Files
  #aa:dbus own bus=session name=org.freedesktop.Tracker3.Miner.RSS

  dbus receive bus=session path=/org/freedesktop/Tracker3/Endpoint
       interface=org.freedesktop.DBus.Peer
       member=Ping
       peer=(name=:*, label=nautilus),
  dbus receive bus=session path=/org/freedesktop/Tracker3/Endpoint
       interface=org.freedesktop.Tracker3.Endpoint
       member=Query
       peer=(name=:*, label=nautilus),

  @{exec_path} mr,

  @{lib}/tracker-extract-3 rix,

  /usr/share/dconf/profile/gdm r,
  /usr/share/gdm/greeter/applications/{,mimeinfo.cache,*.list} r,
  /usr/share/gvfs/remote-volume-monitors/{,*.monitor} r,
  /usr/share/ladspa/rdf/{,**} r,
  /usr/share/osinfo/{,**} r,
  /usr/share/poppler/{,**} r,
  /usr/share/tracker3-miners/{,**} r,
  /usr/share/tracker3/{,**} r,

  /etc/fstab r,
  /etc/blkid.conf r,
  /etc/timezone r,

  owner @{GDM_HOME}/ r,
  owner @{GDM_HOME}/greeter-dconf-defaults r,
  owner @{gdm_cache_dirs}/gstreamer-*/registry.*.bin r,
  owner @{gdm_cache_dirs}/tracker3/{,tracker3/}files/{,**} rwk,
  owner @{gdm_config_dirs}/dconf/user r,
  owner @{gdm_share_dirs}/applications/ r,

  owner /var/tmp/etilqs_@{hex15} rw,
  owner /var/tmp/etilqs_@{hex16} rw,
  owner @{tmp}/etilqs_@{hex15} rw,
  owner @{tmp}/etilqs_@{hex16} rw,

  # Allow to search user files
  owner @{HOME}/{,**} r,
  owner @{MOUNTS}/{,**} r,
  owner @{tmp}/*/{,**} r,

  owner @{user_cache_dirs}/tracker3/ rw,
  owner @{user_cache_dirs}/tracker3/files/{,**} rwk,
  owner @{user_config_dirs}/tracker3/{,**} rwk,

  @{run}/blkid/blkid.tab r,
  @{run}/mount/utab r,

  @{run}/udev/data/c@{dynamic}:@{int} r,  # For dynamic assignment range 234 to 254, 384 to 511

        @{PROC}/@{pid}/cmdline r,
        @{PROC}/sys/fs/fanotify/max_user_marks r,
        @{PROC}/sys/fs/inotify/max_user_watches r,
        @{PROC}/sys/vm/mmap_min_addr r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,
  owner @{PROC}/@{pid}/task/@{tid}/comm rw,

        /dev/media@{int} rw,
        /dev/video@{int} rw,
  owner /dev/tty@{int} rw,

  include if exists <local/tracker-miner>
}

# vim:syntax=apparmor
