/[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.23
1# Copyright 2004 Gentoo Foundation 1# Copyright 1999-2012 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>
4# $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.9 2005/09/09 10:31:35 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.23 2012/08/05 15:34:20 jlec Exp $
5# 4#
5
6# @ECLASS: pam.eclass
7# @MAINTAINER:
8# pam-bugs@gentoo.org
9# @AUTHOR:
10# Diego Pettenò <flameeyes@gentoo.org>
11# @BLURB: Handles pam related tasks
12# @DESCRIPTION:
6# This eclass contains functions to install pamd configuration files and 13# This eclass contains functions to install pamd configuration files and
7# pam modules. 14# pam modules.
8 15
9inherit multilib 16if [[ ${___ECLASS_ONCE_PAM} != "recur -_+^+_- spank" ]] ; then
17___ECLASS_ONCE_PAM="recur -_+^+_- spank"
10 18
19inherit flag-o-matic multilib
20
21# @FUNCTION: dopamd
11# dopamd <file> [more files] 22# @USAGE: <file> [more files]
12# 23# @DESCRIPTION:
13# Install pam auth config file in /etc/pam.d 24# Install pam auth config file in /etc/pam.d
14dopamd() { 25dopamd() {
15 [[ -z $1 ]] && die "dopamd requires at least one argument" 26 [[ -z $1 ]] && die "dopamd requires at least one argument"
16 27
17 if hasq pam ${IUSE} && ! use pam; then 28 if has pam ${IUSE} && ! use pam; then
18 return 0; 29 return 0;
19 fi 30 fi
20 31
21 INSDESTTREE=/etc/pam.d \ 32 ( # dont want to pollute calling env
33 insinto /etc/pam.d
34 insopts -m 0644
35 doins "$@"
22 doins "$@" || die "failed to install $@" 36 ) || die "failed to install $@"
23 cleanpamd "$@" 37 cleanpamd "$@"
24} 38}
25 39
40# @FUNCTION: newpamd
26# newpamd <old name> <new name> 41# @USAGE: <old name> <new name>
27# 42# @DESCRIPTION:
28# Install pam file <old name> as <new name> in /etc/pam.d 43# Install pam file <old name> as <new name> in /etc/pam.d
29newpamd() { 44newpamd() {
30 [[ $# -ne 2 ]] && die "newpamd requires two arguments" 45 [[ $# -ne 2 ]] && die "newpamd requires two arguments"
31 46
32 if hasq pam ${IUSE} && ! use pam; then 47 if has pam ${IUSE} && ! use pam; then
33 return 0; 48 return 0;
34 fi 49 fi
35 50
36 INSDESTTREE=/etc/pam.d \ 51 ( # dont want to pollute calling env
52 insinto /etc/pam.d
53 insopts -m 0644
54 newins "$1" "$2"
37 newins "$1" "$2" || die "failed to install $1 as $2" 55 ) || die "failed to install $1 as $2"
38 cleanpamd $2 56 cleanpamd $2
39} 57}
40 58
59# @FUNCTION: dopamsecurity
41# dopamsecurity <section> <file> [more files] 60# @USAGE: <section> <file> [more files]
42# 61# @DESCRIPTION:
43# Installs the config files in /etc/security/<section>/ 62# Installs the config files in /etc/security/<section>/
44dopamsecurity() { 63dopamsecurity() {
45 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments" 64 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments"
46 65
47 if hasq pam ${IUSE} && ! use pam; then 66 if has pam ${IUSE} && ! use pam; then
48 return 0; 67 return 0
49 fi 68 fi
50 69
51 INSDESTTREE=/etc/security/$1 \ 70 ( # dont want to pollute calling env
52 doins "${@:2}" || die "failed to install ${@:2}" 71 insinto /etc/security/$1
72 insopts -m 0644
73 doins "${@:2}"
74 ) || die "failed to install ${@:2}"
53} 75}
54 76
77# @FUNCTION: newpamsecurity
55# newpamsecurity <section> <old name> <new name> 78# @USAGE: <section> <old name> <new name>
56# 79# @DESCRIPTION:
57# Installs the config file <old name> as <new name> in /etc/security/<section>/ 80# Installs the config file <old name> as <new name> in /etc/security/<section>/
58newpamsecurity() { 81newpamsecurity() {
59 [[ $# -ne 3 ]] && die "newpamsecurity requires three arguments" 82 [[ $# -ne 3 ]] && die "newpamsecurity requires three arguments"
60 83
61 if hasq pam ${IUSE} && ! use pam; then 84 if has pam ${IUSE} && ! use pam; then
62 return 0; 85 return 0;
63 fi 86 fi
64 87
65 INSDESTTREE=/etc/security/$1 \ 88 ( # dont want to pollute calling env
89 insinto /etc/security/$1
90 insopts -m 0644
91 newins "$2" "$3"
66 newins "$2" "$3" || die "failed to install $2 as $3" 92 ) || die "failed to install $2 as $3"
67} 93}
68 94
69# getpam_mod_dir 95# @FUNCTION: getpam_mod_dir
70# 96# @DESCRIPTION:
71# Returns the pam modules' directory for current implementation 97# Returns the pam modules' directory for current implementation
72getpam_mod_dir() { 98getpam_mod_dir() {
73 if has_version sys-libs/pam || has_version sys-libs/openpam; then 99 if has_version sys-libs/pam || has_version sys-libs/openpam; then
74 PAM_MOD_DIR=/$(get_libdir)/security 100 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 101 else
79 # Unable to find PAM implementation... defaulting 102 # Unable to find PAM implementation... defaulting
80 PAM_MOD_DIR=/$(get_libdir)/security 103 PAM_MOD_DIR=/$(get_libdir)/security
81 fi 104 fi
82 105
83 echo ${PAM_MOD_DIR} 106 echo ${PAM_MOD_DIR}
84} 107}
85 108
86# dopammod <file> [more files] 109# @FUNCTION: pammod_hide_symbols
87# 110# @DESCRIPTION:
111# Hide all non-PAM-used symbols from the module; this function creates a
112# simple ld version script that hides all the symbols that are not
113# necessary for PAM to load the module, then uses append-flags to make
114# sure that it gets used.
115pammod_hide_symbols() {
116 cat - > "${T}"/pam-eclass-pam_symbols.ver <<EOF
117{
118 global: pam_sm_*;
119 local: *;
120};
121EOF
122
123 append-ldflags -Wl,--version-script="${T}"/pam-eclass-pam_symbols.ver
124}
125
126# @FUNCTION: dopammod
127# @USAGE: <file> [more files]
128# @DESCRIPTION:
88# Install pam module file in the pam modules' dir for current implementation 129# Install pam module file in the pam modules' dir for current implementation
89dopammod() { 130dopammod() {
90 [[ -z $1 ]] && die "dopammod requires at least one argument" 131 [[ -z $1 ]] && die "dopammod requires at least one argument"
91 132
92 if hasq pam ${IUSE} && ! use pam; then 133 if has pam ${IUSE} && ! use pam; then
93 return 0; 134 return 0;
94 fi 135 fi
95 136
96 exeinto $(getpam_mod_dir) 137 exeinto $(getpam_mod_dir)
97 doexe "$@" || die "failed to install $@" 138 doexe "$@" || die "failed to install $@"
98} 139}
99 140
141# @FUNCTION: newpammod
100# newpammod <old name> <new name> 142# @USAGE: <old name> <new name>
101# 143# @DESCRIPTION:
102# Install pam module file <old name> as <new name> in the pam 144# Install pam module file <old name> as <new name> in the pam
103# modules' dir for current implementation 145# modules' dir for current implementation
104newpammod() { 146newpammod() {
105 [[ $# -ne 2 ]] && die "newpammod requires two arguements" 147 [[ $# -ne 2 ]] && die "newpammod requires two arguements"
106 148
107 if hasq pam ${IUSE} && ! use pam; then 149 if has pam ${IUSE} && ! use pam; then
108 return 0; 150 return 0;
109 fi 151 fi
110 152
111 exeinto $(getpam_mod_dir) 153 exeinto $(getpam_mod_dir)
112 newexe "$1" "$2" || die "failed to install $1 as $2" 154 newexe "$1" "$2" || die "failed to install $1 as $2"
113} 155}
114 156
115# pamd_mimic_system <pamd file> [auth levels] 157# @FUNCTION: pamd_mimic_system
116# 158# @USAGE: <pamd file> [auth levels]
159# @DESCRIPTION:
117# This function creates a pamd file which mimics system-auth file 160# This function creates a pamd file which mimics system-auth file
118# for the given levels in the /etc/pam.d directory. 161# for the given levels in the /etc/pam.d directory.
119pamd_mimic_system() { 162pamd_mimic_system() {
120 [[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments" 163 [[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments"
164 pamd_mimic system-auth "$@"
165}
121 166
167# @FUNCTION: pamd_mimic
168# @USAGE: <stack> <pamd file> [auth levels]
169# @DESCRIPTION:
170# This function creates a pamd file which mimics the given stack
171# for the given levels in the /etc/pam.d directory.
172pamd_mimic() {
173 [[ $# -lt 3 ]] && die "pamd_mimic requires at least three argments"
174
122 if hasq pam ${IUSE} && ! use pam; then 175 if has pam ${IUSE} && ! use pam; then
123 return 0; 176 return 0;
124 fi 177 fi
125 178
126 dodir /etc/pam.d 179 dodir /etc/pam.d
127 pamdfile=${D}/etc/pam.d/$1 180 pamdfile=${D}/etc/pam.d/$2
128 echo -e "# File autogenerated by pamd_mimic_system in pam eclass\n\n" >> \ 181 echo -e "# File autogenerated by pamd_mimic in pam eclass\n\n" >> \
129 $pamdfile 182 $pamdfile
130 183
184 originalstack=$1
131 authlevels="auth account password session" 185 authlevels="auth account password session"
132 186
133 if has_version '<sys-libs/pam-0.78'; then 187 if has_version '<sys-libs/pam-0.78'; then
134 mimic="\trequired\t\tpam_stack.so service=system-auth" 188 mimic="\trequired\t\tpam_stack.so service=${originalstack}"
135 else 189 else
136 mimic="\tinclude\t\tsystem-auth" 190 mimic="\tinclude\t\t${originalstack}"
137 fi 191 fi
138 192
139 shift 193 shift; shift
140 194
141 while [[ -n $1 ]]; do 195 while [[ -n $1 ]]; do
142 hasq $1 ${authlevels} || die "unknown level type" 196 has $1 ${authlevels} || die "unknown level type"
143 197
144 echo -e "$1${mimic}" >> ${pamdfile} 198 echo -e "$1${mimic}" >> ${pamdfile}
145 199
146 shift 200 shift
147 done 201 done
148} 202}
149 203
150# cleanpamd <pamd file> 204# @FUNCTION: cleanpamd
151# 205# @USAGE: <pamd file>
206# @DESCRIPTION:
152# Cleans a pam.d file from modules that might not be present on the system 207# Cleans a pam.d file from modules that might not be present on the system
153# where it's going to be installed 208# where it's going to be installed
154cleanpamd() { 209cleanpamd() {
155 while [[ -n $1 ]]; do 210 while [[ -n $1 ]]; do
156 if ! has_version sys-libs/pam; then 211 if ! has_version sys-libs/pam; then
157 sed -i -e '/pam_shells\|pam_console/s:^:#:' ${D}/etc/pam.d/$1 212 sed -i -e '/pam_shells\|pam_console/s:^:#:' "${D}/etc/pam.d/$1"
158 fi 213 fi
159 214
160 shift 215 shift
161 done 216 done
162} 217}
218
219# @FUNCTION: pam_epam_expand
220# @USAGE: <pamd file>
221# @DESCRIPTION:
222# Steer clear, deprecated, don't use, bad experiment
223pam_epam_expand() {
224 sed -n -e 's|#%EPAM-\([[:alpha:]-]\+\):\([-+<>=/.![:alnum:]]\+\)%#.*|\1 \2|p' \
225 "$@" | sort -u | while read condition parameter; do
226
227 disable="yes"
228
229 case "$condition" in
230 If-Has)
231 message="This can be used only if you have ${parameter} installed"
232 has_version "$parameter" && disable="no"
233 ;;
234 Use-Flag)
235 message="This can be used only if you enabled the ${parameter} USE flag"
236 use "$parameter" && disable="no"
237 ;;
238 *)
239 eerror "Unknown EPAM condition '${condition}' ('${parameter}')"
240 die "Unknown EPAM condition '${condition}' ('${parameter}')"
241 ;;
242 esac
243
244 if [ "${disable}" = "yes" ]; then
245 sed -i -e "/#%EPAM-${condition}:${parameter/\//\\/}%#/d" "$@"
246 else
247 sed -i -e "s|#%EPAM-${condition}:${parameter}%#||" "$@"
248 fi
249
250 done
251}
252
253# Think about it before uncommenting this one, for now run it by hand
254# pam_pkg_preinst() {
255# eshopts_push -o noglob # so that bash doen't expand "*"
256#
257# pam_epam_expand "${D}"/etc/pam.d/*
258#
259# eshopts_pop # reset old shell opts
260# }
261
262fi

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

  ViewVC Help
Powered by ViewVC 1.1.20