eclass/pam: Sync with Gentoo

It's from Gentoo commit 9ee970fd6afc45d0ea99f3bab90b40c8ce6b40c5.
This commit is contained in:
Flatcar Buildbot 2023-08-07 07:12:35 +00:00 committed by Krzesimir Nowak
parent 68488e7c2d
commit fbcbdb052c

View File

@ -6,14 +6,14 @@
# base-system@gentoo.org # base-system@gentoo.org
# @AUTHOR: # @AUTHOR:
# Diego Pettenò <flameeyes@gentoo.org> # Diego Pettenò <flameeyes@gentoo.org>
# @SUPPORTED_EAPIS: 6 7 8 # @SUPPORTED_EAPIS: 7 8
# @BLURB: Handles pam related tasks # @BLURB: Handles pam related tasks
# @DESCRIPTION: # @DESCRIPTION:
# This eclass contains functions to install pamd configuration files and # This eclass contains functions to install pamd configuration files and
# pam modules. # pam modules.
case ${EAPI:-0} in case ${EAPI} in
[678]) ;; 7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac esac
@ -22,6 +22,14 @@ _PAM_ECLASS=1
inherit flag-o-matic inherit flag-o-matic
# @FUNCTION: _pam_flag_disabled
# @INTERNAL
# @DESCRIPTION:
# Check whether pam support is disabled.
_pam_flag_disabled() {
in_iuse pam && ! use pam
}
# @FUNCTION: dopamd # @FUNCTION: dopamd
# @USAGE: <file> [more files] # @USAGE: <file> [more files]
# @DESCRIPTION: # @DESCRIPTION:
@ -29,15 +37,13 @@ inherit flag-o-matic
dopamd() { dopamd() {
[[ -z $1 ]] && die "dopamd requires at least one argument" [[ -z $1 ]] && die "dopamd requires at least one argument"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0;
fi
( # dont want to pollute calling env ( # dont want to pollute calling env
insinto /etc/pam.d insinto /etc/pam.d
insopts -m 0644 insopts -m 0644
doins "$@" doins "$@"
) || die "failed to install $@" )
cleanpamd "$@" cleanpamd "$@"
} }
@ -48,15 +54,13 @@ dopamd() {
newpamd() { newpamd() {
[[ $# -ne 2 ]] && die "newpamd requires two arguments" [[ $# -ne 2 ]] && die "newpamd requires two arguments"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0;
fi
( # dont want to pollute calling env ( # dont want to pollute calling env
insinto /etc/pam.d insinto /etc/pam.d
insopts -m 0644 insopts -m 0644
newins "$1" "$2" newins "$1" "$2"
) || die "failed to install $1 as $2" )
cleanpamd $2 cleanpamd $2
} }
@ -67,15 +71,13 @@ newpamd() {
dopamsecurity() { dopamsecurity() {
[[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments" [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0
fi
( # dont want to pollute calling env ( # dont want to pollute calling env
insinto /etc/security/$1 insinto /etc/security/$1
insopts -m 0644 insopts -m 0644
doins "${@:2}" doins "${@:2}"
) || die "failed to install ${@:2}" )
} }
# @FUNCTION: newpamsecurity # @FUNCTION: newpamsecurity
@ -85,15 +87,13 @@ dopamsecurity() {
newpamsecurity() { newpamsecurity() {
[[ $# -ne 3 ]] && die "newpamsecurity requires three arguments" [[ $# -ne 3 ]] && die "newpamsecurity requires three arguments"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0;
fi
( # dont want to pollute calling env ( # dont want to pollute calling env
insinto /etc/security/$1 insinto /etc/security/$1
insopts -m 0644 insopts -m 0644
newins "$2" "$3" newins "$2" "$3"
) || die "failed to install $2 as $3" )
} }
# @FUNCTION: getpam_mod_dir # @FUNCTION: getpam_mod_dir
@ -129,12 +129,10 @@ EOF
dopammod() { dopammod() {
[[ -z $1 ]] && die "dopammod requires at least one argument" [[ -z $1 ]] && die "dopammod requires at least one argument"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0;
fi
exeinto $(getpam_mod_dir) exeinto $(getpam_mod_dir)
doexe "$@" || die "failed to install $@" doexe "$@"
} }
# @FUNCTION: newpammod # @FUNCTION: newpammod
@ -145,12 +143,10 @@ dopammod() {
newpammod() { newpammod() {
[[ $# -ne 2 ]] && die "newpammod requires two arguments" [[ $# -ne 2 ]] && die "newpammod requires two arguments"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0;
fi
exeinto $(getpam_mod_dir) exeinto $(getpam_mod_dir)
newexe "$1" "$2" || die "failed to install $1 as $2" newexe "$1" "$2"
} }
# @FUNCTION: pamd_mimic_system # @FUNCTION: pamd_mimic_system
@ -171,26 +167,23 @@ pamd_mimic_system() {
pamd_mimic() { pamd_mimic() {
[[ $# -lt 3 ]] && die "pamd_mimic requires at least three arguments" [[ $# -lt 3 ]] && die "pamd_mimic requires at least three arguments"
if has pam ${IUSE} && ! use pam; then _pam_flag_disabled && return 0
return 0;
fi
dodir /etc/pam.d dodir /etc/pam.d
pamdfile=${D}/etc/pam.d/$2 local pamdfile="${ED}/etc/pam.d/$2"
echo -e "# File autogenerated by pamd_mimic in pam eclass\n\n" >> \ echo -e "# File autogenerated by pamd_mimic in pam eclass\n\n" \
$pamdfile >> "${pamdfile}" || die
originalstack=$1 local authlevels="auth account password session"
authlevels="auth account password session"
mimic="\tsubstack\t\t${originalstack}" local mimic="\tsubstack\t\t$1"
shift; shift shift; shift
while [[ -n $1 ]]; do while [[ -n $1 ]]; do
has $1 ${authlevels} || die "unknown level type" has $1 ${authlevels} || die "unknown level type"
echo -e "$1${mimic}" >> ${pamdfile} echo -e "$1${mimic}" >> "${pamdfile}" || die
shift shift
done done
@ -204,7 +197,7 @@ pamd_mimic() {
cleanpamd() { cleanpamd() {
while [[ -n $1 ]]; do while [[ -n $1 ]]; do
if ! has_version sys-libs/pam; then if ! has_version sys-libs/pam; then
sed -i -e '/pam_shells\|pam_console/s:^:#:' "${D}/etc/pam.d/$1" || die sed -i -e '/pam_shells\|pam_console/s:^:#:' "${ED}/etc/pam.d/$1" || die
fi fi
shift shift