| 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.3 2005/05/20 15:54:34 flameeyes Exp $ |
4 | # $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.10 2005/11/03 21:27:02 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 | |
| 9 | inherit multilib |
9 | inherit multilib |
| 10 | ECLASS="pam" |
|
|
| 11 | INHERITED="$INHERITED $ECLASS" |
|
|
| 12 | |
10 | |
| 13 | # dopamd <file> [more files] |
11 | # dopamd <file> [more files] |
| 14 | # |
12 | # |
| 15 | # Install pam auth config file in /etc/pam.d |
13 | # Install pam auth config file in /etc/pam.d |
| 16 | dopamd() { |
14 | dopamd() { |
| … | |
… | |
| 19 | if hasq pam ${IUSE} && ! use pam; then |
17 | if hasq pam ${IUSE} && ! use pam; then |
| 20 | return 0; |
18 | return 0; |
| 21 | fi |
19 | fi |
| 22 | |
20 | |
| 23 | INSDESTTREE=/etc/pam.d \ |
21 | INSDESTTREE=/etc/pam.d \ |
|
|
22 | INSOPTIONS="-m 0644" \ |
| 24 | doins "$@" || die "failed to install $@" |
23 | doins "$@" || die "failed to install $@" |
|
|
24 | cleanpamd "$@" |
| 25 | } |
25 | } |
| 26 | |
26 | |
| 27 | # newpamd <old name> <new name> |
27 | # newpamd <old name> <new name> |
| 28 | # |
28 | # |
| 29 | # Install pam file <old name> as <new name> in /etc/pam.d |
29 | # Install pam file <old name> as <new name> in /etc/pam.d |
| … | |
… | |
| 33 | if hasq pam ${IUSE} && ! use pam; then |
33 | if hasq pam ${IUSE} && ! use pam; then |
| 34 | return 0; |
34 | return 0; |
| 35 | fi |
35 | fi |
| 36 | |
36 | |
| 37 | INSDESTTREE=/etc/pam.d \ |
37 | INSDESTTREE=/etc/pam.d \ |
|
|
38 | INSOPTIONS="-m 0644" \ |
| 38 | newins "$1" "$2" || die "failed to install $1 as $2" |
39 | newins "$1" "$2" || die "failed to install $1 as $2" |
|
|
40 | cleanpamd $2 |
| 39 | } |
41 | } |
| 40 | |
42 | |
| 41 | # dopamsecurity <section> <file> [more files] |
43 | # dopamsecurity <section> <file> [more files] |
| 42 | # |
44 | # |
| 43 | # Installs the config files in /etc/security/<section>/ |
45 | # Installs the config files in /etc/security/<section>/ |
| … | |
… | |
| 47 | if hasq pam ${IUSE} && ! use pam; then |
49 | if hasq pam ${IUSE} && ! use pam; then |
| 48 | return 0; |
50 | return 0; |
| 49 | fi |
51 | fi |
| 50 | |
52 | |
| 51 | INSDESTTREE=/etc/security/$1 \ |
53 | INSDESTTREE=/etc/security/$1 \ |
| 52 | shift |
54 | INSOPTIONS="-m 0644" \ |
| 53 | doins "$@" || die "failed to install $@" |
55 | doins "${@:2}" || die "failed to install ${@:2}" |
| 54 | } |
56 | } |
| 55 | |
57 | |
| 56 | # newpamsecurity <section> <old name> <new name> |
58 | # newpamsecurity <section> <old name> <new name> |
| 57 | # |
59 | # |
| 58 | # Installs the config file <old name> as <new name> in /etc/security/<section>/ |
60 | # Installs the config file <old name> as <new name> in /etc/security/<section>/ |
| … | |
… | |
| 62 | if hasq pam ${IUSE} && ! use pam; then |
64 | if hasq pam ${IUSE} && ! use pam; then |
| 63 | return 0; |
65 | return 0; |
| 64 | fi |
66 | fi |
| 65 | |
67 | |
| 66 | INSDESTTREE=/etc/security/$1 \ |
68 | INSDESTTREE=/etc/security/$1 \ |
|
|
69 | INSOPTIONS="-m 0644" \ |
| 67 | newins "$2" "$3" || die "failed to install $2 as $3" |
70 | newins "$2" "$3" || die "failed to install $2 as $3" |
| 68 | } |
71 | } |
| 69 | |
72 | |
| 70 | # getpam_mod_dir |
73 | # getpam_mod_dir |
| 71 | # |
74 | # |
| 72 | # Returns the pam modules' directory for current implementation |
75 | # Returns the pam modules' directory for current implementation |
| 73 | getpam_mod_dir() { |
76 | getpam_mod_dir() { |
| 74 | if has_version sys-libs/pam; then |
77 | if has_version sys-libs/pam || has_version sys-libs/openpam; then |
| 75 | PAM_MOD_DIR=/$(get_libdir)/security |
78 | PAM_MOD_DIR=/$(get_libdir)/security |
| 76 | elif has_version sys-libs/openpam; then |
79 | elif use ppc-macos; then |
|
|
80 | # OSX looks there for pam modules |
| 77 | PAM_MOD_DIR=/usr/$(get_libdir) |
81 | PAM_MOD_DIR=/usr/lib/pam |
| 78 | else |
82 | else |
| 79 | # Unable to find PAM implementation... defaulting |
83 | # Unable to find PAM implementation... defaulting |
| 80 | PAM_MOD_DIR=/$(get_libdir)/security |
84 | PAM_MOD_DIR=/$(get_libdir)/security |
| 81 | fi |
85 | fi |
| 82 | |
86 | |
| … | |
… | |
| 125 | |
129 | |
| 126 | dodir /etc/pam.d |
130 | dodir /etc/pam.d |
| 127 | pamdfile=${D}/etc/pam.d/$1 |
131 | pamdfile=${D}/etc/pam.d/$1 |
| 128 | echo -e "# File autogenerated by pamd_mimic_system in pam eclass\n\n" >> \ |
132 | echo -e "# File autogenerated by pamd_mimic_system in pam eclass\n\n" >> \ |
| 129 | $pamdfile |
133 | $pamdfile |
| 130 | |
134 | |
| 131 | authlevels="auth account password session" |
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 |
| 132 | |
142 | |
| 133 | shift |
143 | shift |
| 134 | |
144 | |
| 135 | while [[ -n $1 ]]; do |
145 | while [[ -n $1 ]]; do |
| 136 | hasq $1 ${authlevels} || die "unknown level type" |
146 | hasq $1 ${authlevels} || die "unknown level type" |
| 137 | |
147 | |
| 138 | echo -e "$1\tinclude\t\tsystem-auth" >> ${pamdfile} |
148 | echo -e "$1${mimic}" >> ${pamdfile} |
| 139 | |
149 | |
| 140 | shift |
150 | shift |
| 141 | done |
151 | done |
| 142 | } |
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 | } |