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

abi <abi/3.0>,

include <tunables/global>

@{exec_path}  = /usr/share/command-not-found/cnf-update-db
@{exec_path} += @{bin}/update-command-not-found
@{exec_path} += @{lib}/cnf-update-db
profile update-command-not-found @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>
  include <abstractions/python>

  capability dac_read_search,

  @{exec_path} r,

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

  @{bin}/dpkg            rPx -> child-dpkg,
  @{lib}/apt/apt-helper  rix,

  /usr/share/dpkg/cputable r,
  /usr/share/dpkg/tupletable r,
  /usr/share/command-not-found/{,**} r,

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

  /var/lib/command-not-found/ r,
  /var/lib/command-not-found/commands.db* rwk,

  /var/lib/apt/lists/ r,
  /var/lib/apt/lists/*_Contents-* r,
  /var/lib/apt/lists/*_Commands-* r,

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

  # file_inherit
  /var/log/cron-apt/temp w,

  include if exists <local/update-command-not-found>
}
