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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/lxappearance
profile lxappearance @{exec_path} {
  include <abstractions/base>
  include <abstractions/gtk>
  include <abstractions/fonts>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/freedesktop.org>

  @{exec_path} mr,

  # When lxappearance is run as root, it wants to exec dbus-launch, and hence it creates the two
  # following root processes:
  #  dbus-launch --autolaunch e0a30ad97cd6421c85247839ccef9db2 --binary-syntax --close-stderr
  #  /usr/bin/dbus-daemon --syslog-only --fork --print-pid 5 --print-address 7 --session
  #
  # Should this be allowed? Lxappearance works fine without this.
  #@{bin}/dbus-launch        rCx -> dbus,
  #@{bin}/dbus-send          rCx -> dbus,
  deny @{bin}/dbus-launch rx,
  deny @{bin}/dbus-send   rx,

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

  owner @{HOME}/.themes/{,**} r,
  owner @{HOME}/.icons/{,**} rw,

  owner @{HOME}/.gtkrc-2.0{,.*} rw,
  owner @{user_config_dirs}/gtk-3.0/settings.ini{,.*} rw,

  /etc/X11/cursors/*.theme r,

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

  /etc/fstab r,

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

  # file_inherit
  owner /dev/tty@{int} rw,


  profile dbus {
    include <abstractions/base>
    include <abstractions/nameservice-strict>

    @{bin}/dbus-launch   mr,
    @{bin}/dbus-send     mr,
    @{bin}/dbus-daemon rPUx,

    # for dbus-launch
    owner @{HOME}/.dbus/session-bus/@{hex}-[0-9] w,

    @{HOME}/.Xauthority r,
  }

  include if exists <local/lxappearance>
}
