# apparmor.d - Full set of apparmor profiles
# 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} = /usr/share/libalpm/scripts/systemd-hook
profile pacman-hook-systemd @{exec_path} {
  include <abstractions/base>
  include <abstractions/nameservice-strict>

  capability dac_read_search,

  @{exec_path} mr,

  @{sh_path}   rix,
  @{bin}/touch rix,

  @{bin}/journalctl             rPx,
  @{bin}/systemctl              rCx -> systemctl,
  @{bin}/systemd-detect-virt    rPx,
  @{bin}/systemd-hwdb           rPx,
  @{bin}/systemd-notify         rPx,
  @{bin}/systemd-sysusers       rPx,
  @{bin}/systemd-tmpfiles       rPx,
  @{bin}/udevadm                rPx,
  @{lib}/systemd/systemd-binfmt rPx,
  @{lib}/systemd/systemd-sysctl rPx,

  /usr/ rw,

        /dev/tty rw,
        /dev/tty@{int} rw,
  owner /dev/pts/@{int} rw,

  # Inherit silencer
  deny network inet6 stream,
  deny network inet stream,

  profile systemctl flags=(attach_disconnected) {
    include <abstractions/base>
    include <abstractions/app/systemctl>

    capability net_admin,

    include if exists <local/pacman-hook-systemd_systemctl>
  }

  include if exists <local/pacman-hook-systemd>
}

# vim:syntax=apparmor
