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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/totem
profile totem @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/bus/org.freedesktop.ScreenSaver>
  include <abstractions/bus/org.gnome.SessionManager>
  include <abstractions/common/gnome>
  include <abstractions/gstreamer>
  include <abstractions/user-download-strict>

  network netlink raw,

  signal (send) set=(kill) peer=totem//bwrap,

  #aa:dbus own bus=session name=org.mpris.MediaPlayer2.totem
  #aa:dbus talk bus=session name=org.gnome.Nautilus label=nautilus
  #aa:dbus talk bus=session name=org.gnome.OnlineAccounts label=goa-daemon
  #aa:dbus talk bus=session name=org.gtk.vfs label="gvfsd{,-*}"

  @{exec_path} mr,

  @{bin}/bwrap rCx -> bwrap,
  @{open_path}  rPx -> child-open-help,

  /usr/share/xml/iso-codes/{,**} r,
  /usr/share/grilo-plugins/{,**} r,
  /usr/share/thumbnailers/{,**} r,

  owner @{HOME}/ r,
  owner @{MOUNTS}/ r,

  owner @{user_music_dirs}/{,**} rw,
  owner @{user_pictures_dirs}/{,**} rw,
  owner @{user_torrents_dirs}/{,**} rw,
  owner @{user_videos_dirs}/{,**} rw,

  owner @{user_cache_dirs}/gnome-desktop-thumbnailer/gstreamer-1.0/{,**} r,
  owner @{user_share_dirs}/grilo-plugins/ rw,
  owner @{user_share_dirs}/grilo-plugins/** rwlk,

  owner @{tmp}/flatpak-seccomp-@{rand6} rw,
  owner @{tmp}/gnome-desktop-thumbnailer-@{rand6}/{,**} rw,

  owner @{run}/user/@{uid}/gvfs/smb-share:server=*,share=**/ r,
  owner @{run}/user/@{uid}/gvfs/smb-share:server=*,share=** r,

  @{run}/mount/utab r,

  owner @{PROC}/@{pid}/mountinfo r,

  deny @{user_share_dirs}/gvfs-metadata/* r,

  profile bwrap flags=(attach_disconnected) {
    include <abstractions/base>
    include <abstractions/common/bwrap>
    include <abstractions/fonts>
    include <abstractions/freedesktop.org>
    include <abstractions/graphics>
    include <abstractions/gstreamer>

    capability dac_override,

    @{bin}/bwrap mr,
    @{bin}/totem-video-thumbnailer rix,

    /usr/share/ladspa/rdf/{,*} r,

    owner @{user_cache_dirs}/gnome-desktop-thumbnailer/{,**} rw,

    owner @{tmp}/flatpak-seccomp-@{rand6} rw,
    owner @{tmp}/gnome-desktop-file-to-thumbnail.* rw,
    owner @{tmp}/gnome-desktop-thumbnailer-@{rand6}/{,**} rw,

          @{PROC}/sys/vm/mmap_min_addr r,
    owner @{PROC}/@{pid}/task/@{tid}/comm w,

    /dev/ r,

    include if exists <local/totem_bwrap>
  }

  include if exists <local/totem>
}

# vim:syntax=apparmor
