#!/bin/sh
# userdel(8) drop-in of libgss-opaque: before shadow's userdel deletes an
# account, remove the account's OPAQUE record, so an account created later
# under the same name does not accept the deleted account's password
# (RFC 9807 §8: a credential identifier MUST NOT be used for several clients).
#
# shadow runs every file of /etc/shadow-maint/userdel-pre.d with ACTION=userdel
# and SUBJECT=<user name> before it deletes the account, and does not delete it
# when one of them exits non-zero. An account without a record exits 0; a record
# that cannot be removed stops the deletion, so no record outlives its account.
set -eu

[ "${ACTION:-}" = userdel ] || exit 0
[ -n "${SUBJECT:-}" ] || exit 0
[ -e "/etc/opaque/records/$SUBJECT" ] || exit 0
exec "/usr/sbin/opaque-keytab" remove -u "$SUBJECT"
