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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{sbin}/groupadd
@{att} = /att/groupadd/
profile groupadd /{,usr/}{,s}bin/groupadd  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/attached/consoles>
  include <abstractions/nameservice-strict>

  capability audit_write,
  capability chown,
  capability dac_override,
  capability fsetid,

  network netlink raw,

  @{exec_path} mr,
  @{bin}/nscd rix,

  @{etc_ro}/login.defs r,

  /etc/{group,gshadow} rw,
  /etc/{group,gshadow}- w,
  /etc/{group,gshadow}.@{pid} w,
  /etc/{group,gshadow}+ rw,
  /etc/group.lock wl -> /etc/group.@{pid},
  /etc/gshadow.lock wl -> /etc/gshadow.@{pid},

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

  /var/lib/extrausers/group w,
  /var/lib/extrausers/group- w,
  /var/lib/extrausers/group.@{pid} w,
  /var/lib/extrausers/group.lock wl -> /var/lib/extrausers/group.@{pid},
  /var/lib/extrausers/group+ rw,
  /var/lib/extrausers/gshadow rw,
  /var/lib/extrausers/gshadow- w,
  /var/lib/extrausers/gshadow.lock wl -> /var/lib/extrausers/gshadow.@{pid},
  /var/lib/extrausers/gshadow+ rw,

  include if exists <local/groupadd>
}

# vim:syntax=apparmor
