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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/mkvtoolnix-gui
profile mkvtoolnix-gui @{exec_path} {
  include <abstractions/base>
  include <abstractions/dri-enumerate>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/fonts>
  include <abstractions/freedesktop.org>
  include <abstractions/gtk>
  include <abstractions/mesa>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5>
  include <abstractions/qt5-compose-cache-write>
  include <abstractions/qt5-settings-write>
  include <abstractions/ssl_certs>
  include <abstractions/user-download-strict>
  include <abstractions/X>

  signal (send) set=(term, kill) peer=mkvmerge,

  @{exec_path} mr,

  @{bin}/mkvmerge      rPx,
  @{bin}/mediainfo-gui rPx,

  /usr/share/hwdata/pnp.ids r,

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

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

  owner @{user_config_dirs}/bunkus.org/ rw,
  owner @{user_config_dirs}/bunkus.org/mkvtoolnix-gui/ rw,
  owner @{user_config_dirs}/bunkus.org/mkvtoolnix-gui/** rwkl -> @{user_config_dirs}/bunkus.org/mkvtoolnix-gui/#@{int},

  owner @{user_cache_dirs}/ rw,
  owner @{user_cache_dirs}/bunkus.org/ rw,
  owner @{user_cache_dirs}/bunkus.org/mkvtoolnix-gui/ rw,
  owner @{user_cache_dirs}/bunkus.org/mkvtoolnix-gui/**/ rw,
  owner @{user_cache_dirs}/bunkus.org/mkvtoolnix-gui/**/@{hex} rw,

  owner @{tmp}/#@{int} rw,
  owner @{tmp}/MKVToolNix-GUI-MuxConfig-* rwl -> /tmp/#@{int},
  owner @{tmp}/MKVToolNix-process-*.json rwl -> /tmp/#@{int},
  owner @{tmp}/MKVToolNix-GUI-MuxJob-*.json rwl -> /tmp/#@{int},
  owner @{tmp}/MKVToolNix-GUI-Instance-Communicator-* rw,
  owner /dev/shm/#@{int} rw,

  deny owner @{PROC}/@{pid}/cmdline r,
  deny       @{PROC}/sys/kernel/random/boot_id r,
             @{PROC}/@{pid}/mountinfo r,
             @{PROC}/@{pid}/mounts r,

  owner /dev/tty@{int} rw,

  include if exists <local/mkvtoolnix-gui>
}

# vim:syntax=apparmor
