/[gentoo-x86]/eclass/pam.eclass
Gentoo

Diff of /eclass/pam.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.9 Revision 1.18
1# Copyright 2004 Gentoo Foundation 1# Copyright 2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License, v2 or later 2# Distributed under the terms of the GNU General Public License, v2 or later
3# Author Diego Pettenò <flameeyes@gentoo.org> 3# Author Diego Pettenò <flameeyes@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.9 2005/09/09 10:31:35 flameeyes Exp $ 4# $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.18 2009/12/11 20:33:11 vapier Exp $
5# 5#
6# This eclass contains functions to install pamd configuration files and 6# This eclass contains functions to install pamd configuration files and
7# pam modules. 7# pam modules.
8 8
9inherit multilib 9inherit multilib
16 16
17 if hasq pam ${IUSE} && ! use pam; then 17 if hasq pam ${IUSE} && ! use pam; then
18 return 0; 18 return 0;
19 fi 19 fi
20 20
21 INSDESTTREE=/etc/pam.d \ 21 ( # dont want to pollute calling env
22 insinto /etc/pam.d
23 insopts -m 0644
24 doins "$@"
22 doins "$@" || die "failed to install $@" 25 ) || die "failed to install $@"
23 cleanpamd "$@" 26 cleanpamd "$@"
24} 27}
25 28
26# newpamd <old name> <new name> 29# newpamd <old name> <new name>
27# 30#
31 34
32 if hasq pam ${IUSE} && ! use pam; then 35 if hasq pam ${IUSE} && ! use pam; then
33 return 0; 36 return 0;
34 fi 37 fi
35 38
36 INSDESTTREE=/etc/pam.d \ 39 ( # dont want to pollute calling env
40 insinto /etc/pam.d
41 insopts -m 0644
42 newins "$1" "$2"
37 newins "$1" "$2" || die "failed to install $1 as $2" 43 ) || die "failed to install $1 as $2"
38 cleanpamd $2 44 cleanpamd $2
39} 45}
40 46
41# dopamsecurity <section> <file> [more files] 47# dopamsecurity <section> <file> [more files]
42# 48#
43# Installs the config files in /etc/security/<section>/ 49# Installs the config files in /etc/security/<section>/
44dopamsecurity() { 50dopamsecurity() {
45 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments" 51 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments"
46 52
47 if hasq pam ${IUSE} && ! use pam; then 53 if hasq pam ${IUSE} && ! use pam; then
48 return 0; 54 return 0
49 fi 55 fi
50 56
51 INSDESTTREE=/etc/security/$1 \ 57 ( # dont want to pollute calling env
52 doins "${@:2}" || die "failed to install ${@:2}" 58 insinto /etc/security/$1
59 insopts -m 0644
60 doins "${@:2}"
61 ) || die "failed to install ${@:2}"
53} 62}
54 63
55# newpamsecurity <section> <old name> <new name> 64# newpamsecurity <section> <old name> <new name>
56# 65#
57# Installs the config file <old name> as <new name> in /etc/security/<section>/ 66# Installs the config file <old name> as <new name> in /etc/security/<section>/
60 69
61 if hasq pam ${IUSE} && ! use pam; then 70 if hasq pam ${IUSE} && ! use pam; then
62 return 0; 71 return 0;
63 fi 72 fi
64 73
65 INSDESTTREE=/etc/security/$1 \ 74 ( # dont want to pollute calling env
75 insinto /etc/security/$1
76 insopts -m 0644
77 newins "$2" "$3"
66 newins "$2" "$3" || die "failed to install $2 as $3" 78 ) || die "failed to install $2 as $3"
67} 79}
68 80
69# getpam_mod_dir 81# getpam_mod_dir
70# 82#
71# Returns the pam modules' directory for current implementation 83# Returns the pam modules' directory for current implementation
72getpam_mod_dir() { 84getpam_mod_dir() {
73 if has_version sys-libs/pam || has_version sys-libs/openpam; then 85 if has_version sys-libs/pam || has_version sys-libs/openpam; then
74 PAM_MOD_DIR=/$(get_libdir)/security 86 PAM_MOD_DIR=/$(get_libdir)/security
75 elif use ppc-macos; then
76 # OSX looks there for pam modules
77 PAM_MOD_DIR=/usr/lib/pam
78 else 87 else
79 # Unable to find PAM implementation... defaulting 88 # Unable to find PAM implementation... defaulting
80 PAM_MOD_DIR=/$(get_libdir)/security 89 PAM_MOD_DIR=/$(get_libdir)/security
81 fi 90 fi
82 91
116# 125#
117# This function creates a pamd file which mimics system-auth file 126# This function creates a pamd file which mimics system-auth file
118# for the given levels in the /etc/pam.d directory. 127# for the given levels in the /etc/pam.d directory.
119pamd_mimic_system() { 128pamd_mimic_system() {
120 [[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments" 129 [[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments"
130 pamd_mimic system-auth "$@"
131}
132
133# pamd_mimic <stack> <pamd file> [auth levels]
134#
135# This function creates a pamd file which mimics the given stack
136# for the given levels in the /etc/pam.d directory.
137pamd_mimic() {
138 [[ $# -lt 3 ]] && die "pamd_mimic requires at least three argments"
121 139
122 if hasq pam ${IUSE} && ! use pam; then 140 if hasq pam ${IUSE} && ! use pam; then
123 return 0; 141 return 0;
124 fi 142 fi
125 143
126 dodir /etc/pam.d 144 dodir /etc/pam.d
127 pamdfile=${D}/etc/pam.d/$1 145 pamdfile=${D}/etc/pam.d/$2
128 echo -e "# File autogenerated by pamd_mimic_system in pam eclass\n\n" >> \ 146 echo -e "# File autogenerated by pamd_mimic in pam eclass\n\n" >> \
129 $pamdfile 147 $pamdfile
130 148
149 originalstack=$1
131 authlevels="auth account password session" 150 authlevels="auth account password session"
132 151
133 if has_version '<sys-libs/pam-0.78'; then 152 if has_version '<sys-libs/pam-0.78'; then
134 mimic="\trequired\t\tpam_stack.so service=system-auth" 153 mimic="\trequired\t\tpam_stack.so service=${originalstack}"
135 else 154 else
136 mimic="\tinclude\t\tsystem-auth" 155 mimic="\tinclude\t\t${originalstack}"
137 fi 156 fi
138 157
139 shift 158 shift; shift
140 159
141 while [[ -n $1 ]]; do 160 while [[ -n $1 ]]; do
142 hasq $1 ${authlevels} || die "unknown level type" 161 hasq $1 ${authlevels} || die "unknown level type"
143 162
144 echo -e "$1${mimic}" >> ${pamdfile} 163 echo -e "$1${mimic}" >> ${pamdfile}
152# Cleans a pam.d file from modules that might not be present on the system 171# Cleans a pam.d file from modules that might not be present on the system
153# where it's going to be installed 172# where it's going to be installed
154cleanpamd() { 173cleanpamd() {
155 while [[ -n $1 ]]; do 174 while [[ -n $1 ]]; do
156 if ! has_version sys-libs/pam; then 175 if ! has_version sys-libs/pam; then
157 sed -i -e '/pam_shells\|pam_console/s:^:#:' ${D}/etc/pam.d/$1 176 sed -i -e '/pam_shells\|pam_console/s:^:#:' "${D}/etc/pam.d/$1"
158 fi 177 fi
159 178
160 shift 179 shift
161 done 180 done
162} 181}
182
183pam_epam_expand() {
184 sed -n -e 's|#%EPAM-\([[:alpha:]-]\+\):\([-+<>=/.![:alnum:]]\+\)%#.*|\1 \2|p' \
185 "$@" | sort -u | while read condition parameter; do
186
187 disable="yes"
188
189 case "$condition" in
190 If-Has)
191 message="This can be used only if you have ${parameter} installed"
192 has_version "$parameter" && disable="no"
193 ;;
194 Use-Flag)
195 message="This can be used only if you enabled the ${parameter} USE flag"
196 use "$parameter" && disable="no"
197 ;;
198 *)
199 eerror "Unknown EPAM condition '${condition}' ('${parameter}')"
200 die "Unknown EPAM condition '${condition}' ('${parameter}')"
201 ;;
202 esac
203
204 if [ "${disable}" = "yes" ]; then
205 sed -i -e "/#%EPAM-${condition}:${parameter/\//\\/}%#/d" "$@"
206 else
207 sed -i -e "s|#%EPAM-${condition}:${parameter}%#||" "$@"
208 fi
209
210 done
211}
212
213# Think about it before uncommenting this one, for now run it by hand
214# pam_pkg_preinst() {
215# eshopts_push -o noglob # so that bash doen't expand "*"
216#
217# pam_epam_expand "${D}"/etc/pam.d/*
218#
219# eshopts_pop # reset old shell opts
220# }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.20