| 1 |
# Copyright 2004 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License, v2 or later |
| 3 |
# Author Diego Pettenò <flameeyes@gentoo.org> |
| 4 |
# $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.10 2005/11/03 21:27:02 flameeyes Exp $ |
| 5 |
# |
| 6 |
# This eclass contains functions to install pamd configuration files and |
| 7 |
# pam modules. |
| 8 |
|
| 9 |
inherit multilib |
| 10 |
|
| 11 |
# dopamd <file> [more files] |
| 12 |
# |
| 13 |
# Install pam auth config file in /etc/pam.d |
| 14 |
dopamd() { |
| 15 |
[[ -z $1 ]] && die "dopamd requires at least one argument" |
| 16 |
|
| 17 |
if hasq pam ${IUSE} && ! use pam; then |
| 18 |
return 0; |
| 19 |
fi |
| 20 |
|
| 21 |
INSDESTTREE=/etc/pam.d \ |
| 22 |
INSOPTIONS="-m 0644" \ |
| 23 |
doins "$@" || die "failed to install $@" |
| 24 |
cleanpamd "$@" |
| 25 |
} |
| 26 |
|
| 27 |
# newpamd <old name> <new name> |
| 28 |
# |
| 29 |
# Install pam file <old name> as <new name> in /etc/pam.d |
| 30 |
newpamd() { |
| 31 |
[[ $# -ne 2 ]] && die "newpamd requires two arguments" |
| 32 |
|
| 33 |
if hasq pam ${IUSE} && ! use pam; then |
| 34 |
return 0; |
| 35 |
fi |
| 36 |
|
| 37 |
INSDESTTREE=/etc/pam.d \ |
| 38 |
INSOPTIONS="-m 0644" \ |
| 39 |
newins "$1" "$2" || die "failed to install $1 as $2" |
| 40 |
cleanpamd $2 |
| 41 |
} |
| 42 |
|
| 43 |
# dopamsecurity <section> <file> [more files] |
| 44 |
# |
| 45 |
# Installs the config files in /etc/security/<section>/ |
| 46 |
dopamsecurity() { |
| 47 |
[[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments" |
| 48 |
|
| 49 |
if hasq pam ${IUSE} && ! use pam; then |
| 50 |
return 0; |
| 51 |
fi |
| 52 |
|
| 53 |
INSDESTTREE=/etc/security/$1 \ |
| 54 |
INSOPTIONS="-m 0644" \ |
| 55 |
doins "${@:2}" || die "failed to install ${@:2}" |
| 56 |
} |
| 57 |
|
| 58 |
# newpamsecurity <section> <old name> <new name> |
| 59 |
# |
| 60 |
# Installs the config file <old name> as <new name> in /etc/security/<section>/ |
| 61 |
newpamsecurity() { |
| 62 |
[[ $# -ne 3 ]] && die "newpamsecurity requires three arguments" |
| 63 |
|
| 64 |
if hasq pam ${IUSE} && ! use pam; then |
| 65 |
return 0; |
| 66 |
fi |
| 67 |
|
| 68 |
INSDESTTREE=/etc/security/$1 \ |
| 69 |
INSOPTIONS="-m 0644" \ |
| 70 |
newins "$2" "$3" || die "failed to install $2 as $3" |
| 71 |
} |
| 72 |
|
| 73 |
# getpam_mod_dir |
| 74 |
# |
| 75 |
# Returns the pam modules' directory for current implementation |
| 76 |
getpam_mod_dir() { |
| 77 |
if has_version sys-libs/pam || has_version sys-libs/openpam; then |
| 78 |
PAM_MOD_DIR=/$(get_libdir)/security |
| 79 |
elif use ppc-macos; then |
| 80 |
# OSX looks there for pam modules |
| 81 |
PAM_MOD_DIR=/usr/lib/pam |
| 82 |
else |
| 83 |
# Unable to find PAM implementation... defaulting |
| 84 |
PAM_MOD_DIR=/$(get_libdir)/security |
| 85 |
fi |
| 86 |
|
| 87 |
echo ${PAM_MOD_DIR} |
| 88 |
} |
| 89 |
|
| 90 |
# dopammod <file> [more files] |
| 91 |
# |
| 92 |
# Install pam module file in the pam modules' dir for current implementation |
| 93 |
dopammod() { |
| 94 |
[[ -z $1 ]] && die "dopammod requires at least one argument" |
| 95 |
|
| 96 |
if hasq pam ${IUSE} && ! use pam; then |
| 97 |
return 0; |
| 98 |
fi |
| 99 |
|
| 100 |
exeinto $(getpam_mod_dir) |
| 101 |
doexe "$@" || die "failed to install $@" |
| 102 |
} |
| 103 |
|
| 104 |
# newpammod <old name> <new name> |
| 105 |
# |
| 106 |
# Install pam module file <old name> as <new name> in the pam |
| 107 |
# modules' dir for current implementation |
| 108 |
newpammod() { |
| 109 |
[[ $# -ne 2 ]] && die "newpammod requires two arguements" |
| 110 |
|
| 111 |
if hasq pam ${IUSE} && ! use pam; then |
| 112 |
return 0; |
| 113 |
fi |
| 114 |
|
| 115 |
exeinto $(getpam_mod_dir) |
| 116 |
newexe "$1" "$2" || die "failed to install $1 as $2" |
| 117 |
} |
| 118 |
|
| 119 |
# pamd_mimic_system <pamd file> [auth levels] |
| 120 |
# |
| 121 |
# This function creates a pamd file which mimics system-auth file |
| 122 |
# for the given levels in the /etc/pam.d directory. |
| 123 |
pamd_mimic_system() { |
| 124 |
[[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments" |
| 125 |
|
| 126 |
if hasq pam ${IUSE} && ! use pam; then |
| 127 |
return 0; |
| 128 |
fi |
| 129 |
|
| 130 |
dodir /etc/pam.d |
| 131 |
pamdfile=${D}/etc/pam.d/$1 |
| 132 |
echo -e "# File autogenerated by pamd_mimic_system in pam eclass\n\n" >> \ |
| 133 |
$pamdfile |
| 134 |
|
| 135 |
authlevels="auth account password session" |
| 136 |
|
| 137 |
if has_version '<sys-libs/pam-0.78'; then |
| 138 |
mimic="\trequired\t\tpam_stack.so service=system-auth" |
| 139 |
else |
| 140 |
mimic="\tinclude\t\tsystem-auth" |
| 141 |
fi |
| 142 |
|
| 143 |
shift |
| 144 |
|
| 145 |
while [[ -n $1 ]]; do |
| 146 |
hasq $1 ${authlevels} || die "unknown level type" |
| 147 |
|
| 148 |
echo -e "$1${mimic}" >> ${pamdfile} |
| 149 |
|
| 150 |
shift |
| 151 |
done |
| 152 |
} |
| 153 |
|
| 154 |
# cleanpamd <pamd file> |
| 155 |
# |
| 156 |
# Cleans a pam.d file from modules that might not be present on the system |
| 157 |
# where it's going to be installed |
| 158 |
cleanpamd() { |
| 159 |
while [[ -n $1 ]]; do |
| 160 |
if ! has_version sys-libs/pam; then |
| 161 |
sed -i -e '/pam_shells\|pam_console/s:^:#:' ${D}/etc/pam.d/$1 |
| 162 |
fi |
| 163 |
|
| 164 |
shift |
| 165 |
done |
| 166 |
} |