# 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/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/synaptic @{bin}/synaptic-pkexec
profile synaptic @{exec_path} {
  include <abstractions/base>
  include <abstractions/common/apt>
  include <abstractions/consoles>
  include <abstractions/desktop>
  include <abstractions/nameservice-strict>

  capability chown,
  capability dac_override,
  capability dac_read_search,
  capability fowner,
  capability fsetid,
  capability kill,
  capability net_admin,
  capability setgid,
  capability setuid,
  capability sys_nice,

  signal send peer=apt-methods-*,

  @{exec_path} mr,

  @{sh_path}        rix,
  @{bin}/{,e,f}grep rix,
  @{bin}/echo       rix,
  @{bin}/ionice     rix,
  @{bin}/nice       rix,
  @{bin}/test       rix,

  @{bin}/adequate           rPx,
  @{bin}/appstreamcli       rPx,
  @{bin}/apt-listbugs       rPx,
  @{bin}/apt-listchanges    rPx,
  @{bin}/apt-show-versions  rPx,
  @{bin}/deborphan          rPx,
  @{bin}/debtags            rPx,
  @{bin}/dpkg               rPx,
  @{bin}/dpkg-preconfigure  rPx,
  @{bin}/localepurge        rPx,
  @{bin}/lsb_release        rPx -> lsb_release,
  @{bin}/pkexec             rCx -> pkexec,
  @{bin}/ps                 rPx,
  @{bin}/software-properties-gtk rPx,
  @{bin}/tasksel            rPx,
  @{bin}/update-apt-xapian-index       rPx,
  @{bin}/update-command-not-found      rPx,
  /usr/share/command-not-found/cnf-update-db rPx,

  # Methods to use to download packages from the net
  @{lib}/apt/methods/*      rPx,

  /usr/share/synaptic/{,**} r,

  /etc/apt/apt.conf.d/99synaptic rw,

  # For editing the sources.list file
  /etc/apt/sources.list rwk,
  /etc/apt/sources.list.d/ r,
  /etc/apt/sources.list.d/*.list rw,

  /etc/fstab r,
  /etc/machine-id r,
  /var/lib/dbus/machine-id r,

  /var/log/apt/eipp.log.xz w,
  /var/log/apt/{term,history}.log w,

  /var/cache/apt/ r,
  /var/cache/apt/** rwk,
  /var/cache/apt-xapian-index/index.[0-9]/*.glass r,
  /var/cache/apt-xapian-index/index.[0-9]/iamglass r,

  /var/lib/apt-xapian-index/index r,
  /var/lib/dpkg/** r,
  /var/lib/dpkg/lock{,-frontend} rwk,
  /var/lib/apt/lists/** rw,
  /var/lib/apt/lists/lock rwk,
  /var/lib/apt/extended_states{,.*} rw,

  # For package building
  @{user_build_dirs}/** rwkl -> @{user_build_dirs}/**,

  owner @{HOME}/.synaptic/ rw,
  owner @{HOME}/.synaptic/** rwk,

        /tmp/ r,
  owner @{tmp}/apt-dpkg-install-*/ rw,
  owner @{tmp}/apt-dpkg-install-*/@{int}-*.deb w,

  @{run}/synaptic.socket w,

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

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

  deny @{bin}/dbus-launch x,
  deny @{bin}/dbus-send x,
  deny @{bin}/gdbus x,
  deny @{user_share_dirs}/gvfs-metadata/{*,} r,

  profile pkexec {
    include <abstractions/base>
    include <abstractions/app/pkexec>

    include if exists <local/synaptic_pkexec>
  }

  include if exists <local/synaptic>
}

# vim:syntax=apparmor
