# 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/4.0>,

include <tunables/global>

@{exec_path}  = @{bin}/baloo_file @{lib}/{,kf6/}baloo_file
@{exec_path} += @{lib}/@{multiarch}/{,libexec/}baloo_file
profile baloo @{exec_path} {
  include <abstractions/base>
  include <abstractions/deny-sensitive-home>
  include <abstractions/disks-read>
  include <abstractions/fontconfig-cache-write>
  include <abstractions/graphics>
  include <abstractions/kde-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/private-files-strict>

  network netlink raw,

  @{exec_path} mr,

  @{lib}/{,kf6/}baloo_file_extractor rix,

  /usr/share/poppler/{,**} r,

  /etc/fstab r,
  /etc/machine-id r,

  # Allow to search user files
  owner @{HOME}/{,**} r,
  owner @{MOUNTS}/{,**} r,
  owner @{tmp}/*/{,**} r,

  owner @{user_cache_dirs}/kcrash-metadata/ w,

  owner @{user_config_dirs}/#@{int} rw,
  owner @{user_config_dirs}/baloofilerc rwl,
  owner @{user_config_dirs}/baloofilerc.lock rwkl,

  owner @{user_share_dirs}/baloo/{,**} rwk,

  @{run}/udev/data/+acpi:* r,             # for acpi
  @{run}/udev/data/+backlight:* r,
  @{run}/udev/data/+bluetooth:* r,
  @{run}/udev/data/+dmi:* r,              # For motherboard info
  @{run}/udev/data/+input:input@{int} r,  # for mouse, keyboard, touchpad
  @{run}/udev/data/+leds:* r,
  @{run}/udev/data/+pci:* r,              # Identifies all PCI devices (CPU, GPU, Network, Disks, USB, etc.)
  @{run}/udev/data/+platform:* r,
  @{run}/udev/data/+power_supply* r,
  @{run}/udev/data/+rfkill:* r,
  @{run}/udev/data/+sound:card@{int} r,   # for sound card

  @{run}/udev/data/c1:@{int} r,           # For RAM disk
  @{run}/udev/data/c4:@{int} r,           # For TTY devices
  @{run}/udev/data/c7:@{int} r,           # For Virtual console capture devices
  @{run}/udev/data/c10:@{int} r,          # For non-serial mice, misc features
  @{run}/udev/data/c13:@{int}  r,         # For /dev/input/*
  @{run}/udev/data/c29:@{int} r,          # For /dev/fb[0-9]*
  @{run}/udev/data/c89:@{int} r,          # For I2C bus interface
  @{run}/udev/data/c116:@{int} r,         # For ALSA
  @{run}/udev/data/c202:@{int} r,         # CPU model-specific registers
  @{run}/udev/data/c226:@{int} r,         # For /dev/dri/card[0-9]*
  @{run}/udev/data/c@{dynamic}:@{int} r,  # For dynamic assignment range 234 to 254, 384 to 511

  @{sys}/bus/ r,
  @{sys}/bus/*/devices/ r,
  @{sys}/class/*/ r,
  @{sys}/devices/**/uevent r,

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

  /dev/tty r,

  include if exists <local/baloo>
}

# vim:syntax=apparmor
