# 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}/apt-listchanges
profile apt-listchanges @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/python>
  include <abstractions/nameservice-strict>

  #capability sys_tty_config,

  @{exec_path} r,
  @{bin}/python3.@{int} r,

  @{bin}/ r,
  @{sh_path}            rix,
  @{bin}/tar            rix,

  # Do not strip env to avoid errors like the following:
  #  ERROR: ld.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded (cannot open
  #  shared object file): ignored.
  @{bin}/dpkg-deb       rpx,
  #
  @{bin}/sensible-pager rCx -> pager,
  # Send results using email
  @{bin}/exim4         rPx,

  /usr/share/apt-listchanges/{,**} r,

  /etc/apt/listchanges.conf r,
  /etc/apt/listchanges.conf.d/{,*} r,

  /etc/apt/apt.conf r,
  /etc/apt/apt.conf.d/{,*} r,

  /usr/share/dpkg/cputable r,
  /usr/share/dpkg/tupletable r,

  /var/lib/dpkg/status r,

  /var/lib/apt/listchanges{,-new}.db rw,
  /var/lib/apt/listchanges-old.db rwl -> /var/lib/apt/listchanges.db,

  /var/cache/apt/archives/ r,

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

        /tmp/ r,
  owner @{tmp}/* rw,
  owner @{tmp}/apt-listchanges*/ rw,
  owner @{tmp}/apt-listchanges*/**/ rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/changelog.gz rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/changelog.Debian*.gz rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/NEWS.Debian.gz rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/*/changelog.gz rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/*/changelog/changelog_to_file rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/*/changelog/simple_changelog rw,
  owner @{tmp}/apt-listchanges*/*/*/*/*/*/*-local/debian/changelog rw,

  # The following is needed when apt-listchanges uses debcconf GUI frontends.
  include <abstractions/gtk>
  include <abstractions/fonts>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/freedesktop.org>
  capability dac_read_search,
  @{bin}/lsb_release rPx -> lsb_release,
  @{bin}/hostname    rix,
  owner @{PROC}/@{pid}/mounts r,
  @{HOME}/.Xauthority r,


  profile pager {
    include <abstractions/base>
    include <abstractions/consoles>

    capability dac_read_search,
    #capability sys_tty_config,

    @{bin}/sensible-pager mr,

    @{bin}/           r,
    @{sh_path}        rix,
    @{bin}/which{,.debianutils}      rix,
    @{bin}/less       rix,

    owner @{HOME}/.less* rw,

    # For shell pwd
    /root/ r,

          /tmp/ r,
    owner @{tmp}/apt-listchanges-tmp*.txt r,

  }

  include if exists <local/apt-listchanges>
}

# vim:syntax=apparmor
