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

Contents of /eclass/pam.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations) (download)
Wed Feb 20 00:00:01 2008 UTC (6 years, 10 months ago) by flameeyes
Branch: MAIN
Changes since 1.14: +16 -6 lines
Replace pamd_mimic_system with a pamd_mimic function that takes as an
argument the stack that it should mime. pamd_mimic_system is now a
wrapper, which I should deprecated once I'm done with pambase.

1 flameeyes 1.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 flameeyes 1.15 # $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.14 2007/11/04 15:00:27 flameeyes Exp $
5 flameeyes 1.1 #
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 vapier 1.11 ( # dont want to pollute calling env
22     insinto /etc/pam.d
23     insopts -m 0644
24     doins "$@"
25     ) || die "failed to install $@"
26 flameeyes 1.9 cleanpamd "$@"
27 flameeyes 1.1 }
28    
29     # newpamd <old name> <new name>
30     #
31     # Install pam file <old name> as <new name> in /etc/pam.d
32     newpamd() {
33     [[ $# -ne 2 ]] && die "newpamd requires two arguments"
34    
35     if hasq pam ${IUSE} && ! use pam; then
36     return 0;
37     fi
38    
39 vapier 1.11 ( # dont want to pollute calling env
40     insinto /etc/pam.d
41     insopts -m 0644
42     newins "$1" "$2"
43     ) || die "failed to install $1 as $2"
44 flameeyes 1.9 cleanpamd $2
45 flameeyes 1.1 }
46    
47     # dopamsecurity <section> <file> [more files]
48     #
49     # Installs the config files in /etc/security/<section>/
50     dopamsecurity() {
51     [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments"
52    
53     if hasq pam ${IUSE} && ! use pam; then
54 vapier 1.11 return 0
55 flameeyes 1.1 fi
56    
57 vapier 1.11 ( # dont want to pollute calling env
58     insinto /etc/security/$1
59     insopts -m 0644
60     doins "${@:2}"
61     ) || die "failed to install ${@:2}"
62 flameeyes 1.1 }
63    
64     # newpamsecurity <section> <old name> <new name>
65     #
66     # Installs the config file <old name> as <new name> in /etc/security/<section>/
67     newpamsecurity() {
68     [[ $# -ne 3 ]] && die "newpamsecurity requires three arguments"
69    
70     if hasq pam ${IUSE} && ! use pam; then
71     return 0;
72     fi
73    
74 vapier 1.11 ( # dont want to pollute calling env
75     insinto /etc/security/$1
76     insopts -m 0644
77     newins "$2" "$3"
78     ) || die "failed to install $2 as $3"
79 flameeyes 1.1 }
80    
81     # getpam_mod_dir
82     #
83     # Returns the pam modules' directory for current implementation
84     getpam_mod_dir() {
85 flameeyes 1.4 if has_version sys-libs/pam || has_version sys-libs/openpam; then
86 flameeyes 1.1 PAM_MOD_DIR=/$(get_libdir)/security
87 flameeyes 1.4 elif use ppc-macos; then
88     # OSX looks there for pam modules
89     PAM_MOD_DIR=/usr/lib/pam
90 flameeyes 1.1 else
91     # Unable to find PAM implementation... defaulting
92     PAM_MOD_DIR=/$(get_libdir)/security
93     fi
94    
95     echo ${PAM_MOD_DIR}
96     }
97    
98     # dopammod <file> [more files]
99     #
100     # Install pam module file in the pam modules' dir for current implementation
101     dopammod() {
102     [[ -z $1 ]] && die "dopammod requires at least one argument"
103    
104     if hasq pam ${IUSE} && ! use pam; then
105     return 0;
106     fi
107    
108     exeinto $(getpam_mod_dir)
109     doexe "$@" || die "failed to install $@"
110     }
111    
112     # newpammod <old name> <new name>
113     #
114     # Install pam module file <old name> as <new name> in the pam
115     # modules' dir for current implementation
116     newpammod() {
117     [[ $# -ne 2 ]] && die "newpammod requires two arguements"
118    
119     if hasq pam ${IUSE} && ! use pam; then
120     return 0;
121     fi
122    
123     exeinto $(getpam_mod_dir)
124     newexe "$1" "$2" || die "failed to install $1 as $2"
125     }
126    
127     # pamd_mimic_system <pamd file> [auth levels]
128     #
129     # This function creates a pamd file which mimics system-auth file
130     # for the given levels in the /etc/pam.d directory.
131     pamd_mimic_system() {
132     [[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments"
133 flameeyes 1.15 pamd_mimic system-auth "$@"
134     }
135    
136     # pamd_mimic <stack> <pamd file> [auth levels]
137     #
138     # This function creates a pamd file which mimics the given stack
139     # for the given levels in the /etc/pam.d directory.
140     pamd_mimic() {
141     [[ $# -lt 3 ]] && die "pamd_mimic requires at least three argments"
142 flameeyes 1.1
143     if hasq pam ${IUSE} && ! use pam; then
144     return 0;
145     fi
146    
147     dodir /etc/pam.d
148 flameeyes 1.15 pamdfile=${D}/etc/pam.d/$2
149     echo -e "# File autogenerated by pamd_mimic in pam eclass\n\n" >> \
150 flameeyes 1.1 $pamdfile
151 flameeyes 1.4
152 flameeyes 1.15 originalstack=$1
153 flameeyes 1.1 authlevels="auth account password session"
154    
155 flameeyes 1.6 if has_version '<sys-libs/pam-0.78'; then
156 flameeyes 1.15 mimic="\trequired\t\tpam_stack.so service=${originalstack}"
157 flameeyes 1.6 else
158 flameeyes 1.15 mimic="\tinclude\t\t${originalstack}"
159 flameeyes 1.6 fi
160    
161 flameeyes 1.15 shift; shift
162 flameeyes 1.1
163     while [[ -n $1 ]]; do
164     hasq $1 ${authlevels} || die "unknown level type"
165    
166 flameeyes 1.6 echo -e "$1${mimic}" >> ${pamdfile}
167 flameeyes 1.1
168     shift
169     done
170     }
171 flameeyes 1.9
172     # cleanpamd <pamd file>
173     #
174     # Cleans a pam.d file from modules that might not be present on the system
175     # where it's going to be installed
176     cleanpamd() {
177     while [[ -n $1 ]]; do
178     if ! has_version sys-libs/pam; then
179     sed -i -e '/pam_shells\|pam_console/s:^:#:' ${D}/etc/pam.d/$1
180     fi
181    
182     shift
183     done
184     }
185 flameeyes 1.12
186     pam_epam_expand() {
187 flameeyes 1.13 sed -n -e 's|#%EPAM-\([[:alpha:]-]\+\):\([-+<>=/.![:alnum:]]\+\)%#.*|\1 \2|p' \
188 flameeyes 1.12 "$@" | sort -u | while read condition parameter; do
189    
190 flameeyes 1.14 disable="yes"
191 flameeyes 1.12
192     case "$condition" in
193     If-Has)
194     message="This can be used only if you have ${parameter} installed"
195 flameeyes 1.14 has_version "$parameter" && disable="no"
196 flameeyes 1.12 ;;
197     Use-Flag)
198     message="This can be used only if you enabled the ${parameter} USE flag"
199 flameeyes 1.14 use "$parameter" && disable="no"
200 flameeyes 1.12 ;;
201     *)
202     eerror "Unknown EPAM condition '${condition}' ('${parameter}')"
203     die "Unknown EPAM condition '${condition}' ('${parameter}')"
204     ;;
205     esac
206    
207 flameeyes 1.14 if [ "${disable}" = "yes" ]; then
208     sed -i -e "/#%EPAM-${condition}:${parameter/\//\\/}%#/d" "$@"
209     else
210     sed -i -e "s|#%EPAM-${condition}:${parameter}%#||" "$@"
211     fi
212    
213 flameeyes 1.12 done
214     }
215    
216 flameeyes 1.14 # Think about it before uncommenting this one, for now run it by hand
217 flameeyes 1.12 # pam_pkg_preinst() {
218     # local shopts=$-
219     # set -o noglob # so that bash doen't expand "*"
220     #
221     # pam_epam_expand "${D}"/etc/pam.d/*
222     #
223     # set +o noglob; set -$shopts # reset old shell opts
224     # }

  ViewVC Help
Powered by ViewVC 1.1.20