# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2017-2021 Mikhail Morfikov
# 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}/lightdm
profile lightdm @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/authentication>
  include <abstractions/desktop>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/nameservice-strict>
  include <abstractions/wutmp>

  capability audit_write,
  capability chown,
  capability dac_override,
  capability dac_read_search,
  capability fowner,
  capability fsetid,
  capability kill,
  capability net_admin,
  capability setgid,
  capability setuid,
  capability sys_resource,
  capability sys_tty_config,

  network netlink raw,

  signal (receive) set=(usr1) peer=xorg,
  signal (send) set=(term) peer=lightdm-*-greeter,
  signal (send) set=(term) peer=xfce-session,
  signal (send) set=(term) peer=xorg,

  @{exec_path} mrix,

  @{bin}/rm     rix,

  @{bin}/lightdm-*-greeter    rPUx,
  @{bin}/startx                rPx,
  @{bin}/Xorg                  rPx,
  @{bin}/plymouth              rPx,
  @{bin}/gnome-keyring-daemon  rPx,

  @{lib}/security-misc/*       rPx, #aa:only whonix
  @{lib}/{,at-spi2{,-core}/}at-spi-bus-launcher rPx,

  /etc/lightdm/Xsession        rPx,
  /etc/X11/Xsession            rPx,

  /usr/share/lightdm/{,**} r,
  /usr/share/wayland-sessions/{,*.desktop} r,
  /usr/share/xgreeters/{,**} r,

  /etc/default/locale r,
  /etc/environment r,
  /etc/lightdm/{,**} r,
  /etc/machine-id r,
  /etc/security/limits.d/{,*} r,
  /etc/shells r,

  /var/cache/lightdm/dmrc/*.dmrc* rw,
  /var/lib/lightdm/{,**} rw,
  /var/lib/lightdm-data/{,**} rw,
  /var/log/lightdm/{,**} rw,

  owner @{HOME}/.dmrc r,

        @{run}/faillock/ rw,
        @{run}/faillock/@{user} rwk,
        @{run}/lightdm.pid rw,
        @{run}/lightdm/{,**} rw,
  owner @{run}/systemd/sessions/*.ref rw,

        @{PROC}/1/limits r,
        @{PROC}/cmdline r,
  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/loginuid rw,
  owner @{PROC}/@{pid}/uid_map r,

  /dev/tty@{int} r,

  include if exists <local/lightdm>
}

# vim:syntax=apparmor
