# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-2022 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} = @{bin}/passwd
profile passwd @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/authentication>
  include <abstractions/nameservice-strict>
  include <abstractions/wutmp>

  capability audit_write,
  capability chown,
  capability fsetid,
  capability net_admin,
  capability setuid,

  signal (receive) set=(term, kill) peer=gnome-control-center,

  network netlink raw,

  @{exec_path} mr,

  /etc/nshadow rw,
  /etc/shadow rw,
  /etc/shadow- rw,
  /etc/shadow.@{int} rw,
  /etc/shadow.lock rwl,
  /etc/shadow+ rw,

  # A process first uses lckpwdf() to lock the lock file, thereby gaining exclusive rights to
  # modify the /etc/passwd or /etc/shadow password database.
  /etc/.pwd.lock rwk,

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

  include if exists <local/passwd>
}
