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

Diff of /eclass/pam.eclass

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

Revision 1.7 Revision 1.14
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.7 2005/07/06 20:20:04 agriffis Exp $ 4# $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.14 2007/11/04 15:00:27 flameeyes 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
10INHERITED="$INHERITED $ECLASS"
11 10
12# dopamd <file> [more files] 11# dopamd <file> [more files]
13# 12#
14# Install pam auth config file in /etc/pam.d 13# Install pam auth config file in /etc/pam.d
15dopamd() { 14dopamd() {
17 16
18 if hasq pam ${IUSE} && ! use pam; then 17 if hasq pam ${IUSE} && ! use pam; then
19 return 0; 18 return 0;
20 fi 19 fi
21 20
22 INSDESTTREE=/etc/pam.d \ 21 ( # dont want to pollute calling env
22 insinto /etc/pam.d
23 insopts -m 0644
24 doins "$@"
23 doins "$@" || die "failed to install $@" 25 ) || die "failed to install $@"
26 cleanpamd "$@"
24} 27}
25 28
26# newpamd <old name> <new name> 29# newpamd <old name> <new name>
27# 30#
28# Install pam file <old name> as <new name> in /etc/pam.d 31# Install pam file <old name> as <new name> in /etc/pam.d
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"
44 cleanpamd $2
38} 45}
39 46
40# dopamsecurity <section> <file> [more files] 47# dopamsecurity <section> <file> [more files]
41# 48#
42# Installs the config files in /etc/security/<section>/ 49# Installs the config files in /etc/security/<section>/
43dopamsecurity() { 50dopamsecurity() {
44 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments" 51 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments"
45 52
46 if hasq pam ${IUSE} && ! use pam; then 53 if hasq pam ${IUSE} && ! use pam; then
47 return 0; 54 return 0
48 fi 55 fi
49 56
50 INSDESTTREE=/etc/security/$1 \ 57 ( # dont want to pollute calling env
51 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}"
52} 62}
53 63
54# newpamsecurity <section> <old name> <new name> 64# newpamsecurity <section> <old name> <new name>
55# 65#
56# 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>/
59 69
60 if hasq pam ${IUSE} && ! use pam; then 70 if hasq pam ${IUSE} && ! use pam; then
61 return 0; 71 return 0;
62 fi 72 fi
63 73
64 INSDESTTREE=/etc/security/$1 \ 74 ( # dont want to pollute calling env
75 insinto /etc/security/$1
76 insopts -m 0644
77 newins "$2" "$3"
65 newins "$2" "$3" || die "failed to install $2 as $3" 78 ) || die "failed to install $2 as $3"
66} 79}
67 80
68# getpam_mod_dir 81# getpam_mod_dir
69# 82#
70# Returns the pam modules' directory for current implementation 83# Returns the pam modules' directory for current implementation
143 echo -e "$1${mimic}" >> ${pamdfile} 156 echo -e "$1${mimic}" >> ${pamdfile}
144 157
145 shift 158 shift
146 done 159 done
147} 160}
161
162# cleanpamd <pamd file>
163#
164# Cleans a pam.d file from modules that might not be present on the system
165# where it's going to be installed
166cleanpamd() {
167 while [[ -n $1 ]]; do
168 if ! has_version sys-libs/pam; then
169 sed -i -e '/pam_shells\|pam_console/s:^:#:' ${D}/etc/pam.d/$1
170 fi
171
172 shift
173 done
174}
175
176pam_epam_expand() {
177 sed -n -e 's|#%EPAM-\([[:alpha:]-]\+\):\([-+<>=/.![:alnum:]]\+\)%#.*|\1 \2|p' \
178 "$@" | sort -u | while read condition parameter; do
179
180 disable="yes"
181
182 case "$condition" in
183 If-Has)
184 message="This can be used only if you have ${parameter} installed"
185 has_version "$parameter" && disable="no"
186 ;;
187 Use-Flag)
188 message="This can be used only if you enabled the ${parameter} USE flag"
189 use "$parameter" && disable="no"
190 ;;
191 *)
192 eerror "Unknown EPAM condition '${condition}' ('${parameter}')"
193 die "Unknown EPAM condition '${condition}' ('${parameter}')"
194 ;;
195 esac
196
197 if [ "${disable}" = "yes" ]; then
198 sed -i -e "/#%EPAM-${condition}:${parameter/\//\\/}%#/d" "$@"
199 else
200 sed -i -e "s|#%EPAM-${condition}:${parameter}%#||" "$@"
201 fi
202
203 done
204}
205
206# Think about it before uncommenting this one, for now run it by hand
207# pam_pkg_preinst() {
208# local shopts=$-
209# set -o noglob # so that bash doen't expand "*"
210#
211# pam_epam_expand "${D}"/etc/pam.d/*
212#
213# set +o noglob; set -$shopts # reset old shell opts
214# }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.20