# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2017-2021 Mikhail Morfikov
# 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} = @{bin}/mpsyt
profile mpsyt @{exec_path} {
  include <abstractions/base>
  include <abstractions/python>
  include <abstractions/user-download-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/ssl_certs>

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

  network inet dgram,
  network inet6 dgram,
  network inet stream,
  network inet6 stream,
  network netlink raw,

  @{exec_path} r,
  @{bin}/python3.@{int} r,

  @{bin}/ r,
  @{bin}/ldconfig  rix,
  @{bin}/tset      rix,
  @{bin}/uname     rix,

  @{bin}/mpv      rPUx,
  @{bin}/ffmpeg   rPUx,
  @{bin}/ffprobe  rPUx,

  # MPV config files
  /etc/mpv/* r,
  owner @{user_config_dirs}/mpv/* r,

  # mps-yt config files
  owner @{user_config_dirs}/mps-youtube/{,**} rw,

  # Cache files
  owner @{user_cache_dirs}/youtube-dl/youtube-sigfuncs/js_*.json{,.*.tmp} rw,

  /etc/inputrc r,
  /etc/mime.types r,

  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mounts r,

        /tmp/ r,
  owner @{tmp}/[a-z0-9]* rw,
  owner @{tmp}/mpsyt-input* rw,
  owner @{tmp}/mpsyt-mpv*.sock rw,

  include if exists <local/mpsyt>
}

# vim:syntax=apparmor
