# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2015-2020 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}/qbittorrent-nox
@{att} = ""
profile qbittorrent-nox /{,usr/}bin/qbittorrent-nox flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/freedesktop.org>
  include <abstractions/nameservice-strict>
  include <abstractions/ssl_certs>

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

  @{exec_path} mr,

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

  owner @{user_torrents_dirs}/ r,
  owner @{user_torrents_dirs}/** rw,

  owner @{user_cache_dirs}/ rw,
  owner @{user_cache_dirs}/#@{int} rw,
  owner @{user_cache_dirs}/qBittorrent/{,**} rw,

  owner @{user_config_dirs}/qBittorrent/ rw,
  owner @{user_config_dirs}/qBittorrent/** rwkl -> @{user_config_dirs}/qBittorrent/#@{int},
  owner @{user_share_dirs}/qBittorrent/ rw,
  owner @{user_share_dirs}/qBittorrent/** rwl -> @{user_share_dirs}/data/qBittorrent/**/#@{int},

  owner @{tmp}/.*/{,s} rw,
  owner @{tmp}/.qBittorrent/ rw,
  owner @{tmp}/.qBittorrent/* rwl -> /tmp/.qBittorrent/*,
  owner @{tmp}/*.torrent rw,
  owner @{tmp}/mozilla_*/*.torrent rw,
  owner @{tmp}/qtsingleapp-qBitto-* rw,
  owner @{tmp}/qtsingleapp-qBitto-*-lockfile rwk,

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

  /dev/disk/by-label/ r,
  /dev/shm/#@{int} rw,

  deny owner @{user_share_dirs}/data/qBittorrent/ rw,  # Old dir, not recommended to use

  include if exists <local/qbittorrent-nox>
}

# vim:syntax=apparmor
