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

# Note: This profile does not specify an attachment path because it is
# intended to be used only via "Px -> child-pager" exec transitions from
# other profiles. We want to confine the pager(1) utility when it
# is invoked from other confined applications, but not when it is used
# in regular (unconfined) shell scripts or run directly by the user.

abi <abi/4.0>,

include <tunables/global>

profile child-pager flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/consoles>

  capability dac_override,
  capability dac_read_search,

  signal (receive) set=(stop, cont, term, kill),

  @{bin}/       r,
  @{pager_path} mr,

  @{system_share_dirs}/terminfo/{,**} r,
  /usr/share/file/misc/** r,
  /usr/share/nvim/{,**} r,

  @{HOME}/.lesshst r,

  owner @{HOME}/ r,
  owner @{HOME}/.lesshs* rw,
  owner @{HOME}/.terminfo/@{int}/* r,
  owner @{user_cache_dirs}/lesshs* rw,
  owner @{user_state_dirs}/ r,
  owner @{user_state_dirs}/lesshs* rw,

  /dev/tty@{int} rw,

  include if exists <local/child-pager>
}

# vim:syntax=apparmor
