# apparmor.d - Full set of apparmor profiles
# 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}/dolphin
profile dolphin @{exec_path} {
  include <abstractions/base>
  include <abstractions/app-launcher-user>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.UDisks2>
  include <abstractions/deny-sensitive-home>
  include <abstractions/devices-usb>
  include <abstractions/disks-read>
  include <abstractions/graphics>
  include <abstractions/kde-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/recent-documents-write>

  network netlink raw,

  signal (send) set=(term) peer=kioworker,

  @{exec_path} mr,

  @{bin}/ldd            rix,
  @{thunderbird_path}   rPx,
  #aa:exec kioworker

  /usr/share/kf5/kmoretools/{,**} r,
  /usr/share/kio/{,**} r,
  /usr/share/kservices{5,6}/{,**} r,
  /usr/share/kservicetypes5/{,**} r,

  /etc/fstab r,
  /etc/machine-id r,
  /etc/xdg/arkrc r,
  /etc/xdg/dolphinrc r,
  /etc/xdg/menus/ r,
  /etc/xdg/menus/applications-merged/ r,
  /etc/xdg/ui/ui_standards.rc r,

  # Full access to user's data
  / r,
  /*/ r,
  @{bin}/ r,
  @{lib}/ r,
  @{MOUNTDIRS}/ r,
  @{MOUNTS}/ r,
  @{MOUNTS}/** rw,
  owner @{HOME}/{,**} rw,
  owner @{run}/user/@{uid}/{,**} rw,
  owner @{tmp}/{,**} rw,

  # Silence non user's data
  deny /boot/{,**} r,
  deny /opt/{,**} r,
  deny /root/{,**} r,
  deny /tmp/.* rw,
  deny /tmp/.*/{,**} rw,

  owner @{user_share_dirs}/dolphin/ rw,
  owner @{user_share_dirs}/dolphin/** rwkl -> @{user_share_dirs}/dolphin/#@{int},
  owner @{user_share_dirs}/recently-used.xbel{,.*} rwlk,

  owner @{user_config_dirs}/#@{int} rw,
  owner @{user_config_dirs}/dolphinrc rwl -> @{user_config_dirs}/#@{int},
  owner @{user_config_dirs}/dolphinrc.@{rand6} rwl -> @{user_config_dirs}/#@{int},
  owner @{user_config_dirs}/dolphinrc.lock rwk,
  owner @{user_config_dirs}/kde.org/#@{int} rw,
  owner @{user_config_dirs}/kde.org/UserFeedback.org.kde.dolphin.conf{,.*} rwlk -> @{user_config_dirs}/kde.org/#@{int},
  owner @{user_config_dirs}/kde.org/UserFeedback.org.kde.dolphin.conf.lock rwk,

  owner @{user_config_dirs}/session/ rw,
  owner @{user_config_dirs}/session/#@{int} rw,
  owner @{user_config_dirs}/session/dolphin_* rwlk -> @{user_config_dirs}/session/#@{int},

  owner @{user_cache_dirs}/ksplash/qmlcache/*.qmlc rwl -> @{user_cache_dirs}/dolphin/qmlcache/#@{int},
  owner @{user_cache_dirs}/ksplash/qmlcache/*.qmlc.@{rand6} rwl -> @{user_cache_dirs}/dolphin/qmlcache/#@{int},

        @{run}/mount/utab r,
  owner @{run}/user/@{uid}/dolphin@{rand6}.@{int}.kioworker.socket rwl -> @{run}/user/@{uid}/#@{int},
  owner @{run}/user/@{uid}/#@{int} rw,

        @{PROC}/sys/kernel/core_pattern r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,

  @{sys}/devices/virtual/block/dm-@{int}/uevent r,

  /dev/tty r,

  include if exists <local/dolphin>
}
