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

Contents of /eclass/pam.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Fri Sep 9 10:31:35 2005 UTC (8 years, 10 months ago) by flameeyes
Branch: MAIN
Changes since 1.8: +17 -1 lines
Added check for non-portable modules in pamd files, so that pamd files that get installed on OpenPAM systems works fine.

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 # $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.8 2005/07/06 20:23:20 agriffis Exp $
5 #
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 INSDESTTREE=/etc/pam.d \
22 doins "$@" || die "failed to install $@"
23 cleanpamd "$@"
24 }
25
26 # newpamd <old name> <new name>
27 #
28 # Install pam file <old name> as <new name> in /etc/pam.d
29 newpamd() {
30 [[ $# -ne 2 ]] && die "newpamd requires two arguments"
31
32 if hasq pam ${IUSE} && ! use pam; then
33 return 0;
34 fi
35
36 INSDESTTREE=/etc/pam.d \
37 newins "$1" "$2" || die "failed to install $1 as $2"
38 cleanpamd $2
39 }
40
41 # dopamsecurity <section> <file> [more files]
42 #
43 # Installs the config files in /etc/security/<section>/
44 dopamsecurity() {
45 [[ $# -lt 2 ]] && die "dopamsecurity requires at least two arguments"
46
47 if hasq pam ${IUSE} && ! use pam; then
48 return 0;
49 fi
50
51 INSDESTTREE=/etc/security/$1 \
52 doins "${@:2}" || die "failed to install ${@:2}"
53 }
54
55 # newpamsecurity <section> <old name> <new name>
56 #
57 # Installs the config file <old name> as <new name> in /etc/security/<section>/
58 newpamsecurity() {
59 [[ $# -ne 3 ]] && die "newpamsecurity requires three arguments"
60
61 if hasq pam ${IUSE} && ! use pam; then
62 return 0;
63 fi
64
65 INSDESTTREE=/etc/security/$1 \
66 newins "$2" "$3" || die "failed to install $2 as $3"
67 }
68
69 # getpam_mod_dir
70 #
71 # Returns the pam modules' directory for current implementation
72 getpam_mod_dir() {
73 if has_version sys-libs/pam || has_version sys-libs/openpam; then
74 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
79 # Unable to find PAM implementation... defaulting
80 PAM_MOD_DIR=/$(get_libdir)/security
81 fi
82
83 echo ${PAM_MOD_DIR}
84 }
85
86 # dopammod <file> [more files]
87 #
88 # Install pam module file in the pam modules' dir for current implementation
89 dopammod() {
90 [[ -z $1 ]] && die "dopammod requires at least one argument"
91
92 if hasq pam ${IUSE} && ! use pam; then
93 return 0;
94 fi
95
96 exeinto $(getpam_mod_dir)
97 doexe "$@" || die "failed to install $@"
98 }
99
100 # newpammod <old name> <new name>
101 #
102 # Install pam module file <old name> as <new name> in the pam
103 # modules' dir for current implementation
104 newpammod() {
105 [[ $# -ne 2 ]] && die "newpammod requires two arguements"
106
107 if hasq pam ${IUSE} && ! use pam; then
108 return 0;
109 fi
110
111 exeinto $(getpam_mod_dir)
112 newexe "$1" "$2" || die "failed to install $1 as $2"
113 }
114
115 # pamd_mimic_system <pamd file> [auth levels]
116 #
117 # This function creates a pamd file which mimics system-auth file
118 # for the given levels in the /etc/pam.d directory.
119 pamd_mimic_system() {
120 [[ $# -lt 2 ]] && die "pamd_mimic_system requires at least two argments"
121
122 if hasq pam ${IUSE} && ! use pam; then
123 return 0;
124 fi
125
126 dodir /etc/pam.d
127 pamdfile=${D}/etc/pam.d/$1
128 echo -e "# File autogenerated by pamd_mimic_system in pam eclass\n\n" >> \
129 $pamdfile
130
131 authlevels="auth account password session"
132
133 if has_version '<sys-libs/pam-0.78'; then
134 mimic="\trequired\t\tpam_stack.so service=system-auth"
135 else
136 mimic="\tinclude\t\tsystem-auth"
137 fi
138
139 shift
140
141 while [[ -n $1 ]]; do
142 hasq $1 ${authlevels} || die "unknown level type"
143
144 echo -e "$1${mimic}" >> ${pamdfile}
145
146 shift
147 done
148 }
149
150 # cleanpamd <pamd file>
151 #
152 # Cleans a pam.d file from modules that might not be present on the system
153 # where it's going to be installed
154 cleanpamd() {
155 while [[ -n $1 ]]; do
156 if ! has_version sys-libs/pam; then
157 sed -i -e '/pam_shells\|pam_console/s:^:#:' ${D}/etc/pam.d/$1
158 fi
159
160 shift
161 done
162 }

  ViewVC Help
Powered by ViewVC 1.1.20