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

Contents of /eclass/pam.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Fri Sep 9 10:31:35 2005 UTC (8 years, 11 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 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.9 # $Header: /var/cvsroot/gentoo-x86/eclass/pam.eclass,v 1.8 2005/07/06 20:23:20 agriffis 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 flameeyes 1.3 INSDESTTREE=/etc/pam.d \
22 flameeyes 1.1 doins "$@" || die "failed to install $@"
23 flameeyes 1.9 cleanpamd "$@"
24 flameeyes 1.1 }
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 flameeyes 1.3 INSDESTTREE=/etc/pam.d \
37 flameeyes 1.1 newins "$1" "$2" || die "failed to install $1 as $2"
38 flameeyes 1.9 cleanpamd $2
39 flameeyes 1.1 }
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 flameeyes 1.3 INSDESTTREE=/etc/security/$1 \
52 flameeyes 1.5 doins "${@:2}" || die "failed to install ${@:2}"
53 flameeyes 1.1 }
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 flameeyes 1.3 INSDESTTREE=/etc/security/$1 \
66 flameeyes 1.1 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 flameeyes 1.4 if has_version sys-libs/pam || has_version sys-libs/openpam; then
74 flameeyes 1.1 PAM_MOD_DIR=/$(get_libdir)/security
75 flameeyes 1.4 elif use ppc-macos; then
76     # OSX looks there for pam modules
77     PAM_MOD_DIR=/usr/lib/pam
78 flameeyes 1.1 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 flameeyes 1.4
131 flameeyes 1.1 authlevels="auth account password session"
132    
133 flameeyes 1.6 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 flameeyes 1.1 shift
140    
141     while [[ -n $1 ]]; do
142     hasq $1 ${authlevels} || die "unknown level type"
143    
144 flameeyes 1.6 echo -e "$1${mimic}" >> ${pamdfile}
145 flameeyes 1.1
146     shift
147     done
148     }
149 flameeyes 1.9
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