| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.2 2011/10/27 07:26:55 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.12 2011/11/26 06:45:38 vapier Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: user.eclass |
5 | # @ECLASS: user.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org (Linux) |
7 | # base-system@gentoo.org (Linux) |
| 8 | # Joe Jezak <josejx@gmail.com> (OS X) |
8 | # Joe Jezak <josejx@gmail.com> (OS X) |
| … | |
… | |
| 16 | # @FUNCTION: _assert_pkg_ebuild_phase |
16 | # @FUNCTION: _assert_pkg_ebuild_phase |
| 17 | # @INTERNAL |
17 | # @INTERNAL |
| 18 | # @USAGE: <calling func name> |
18 | # @USAGE: <calling func name> |
| 19 | _assert_pkg_ebuild_phase() { |
19 | _assert_pkg_ebuild_phase() { |
| 20 | case ${EBUILD_PHASE} in |
20 | case ${EBUILD_PHASE} in |
| 21 | unpack|prepare|configure|compile|test|install) |
21 | setup|preinst|postinst) ;; |
|
|
22 | *) |
| 22 | eerror "'$1()' called from '${EBUILD_PHASE}()' which is not a pkg_* function." |
23 | eerror "'$1()' called from '${EBUILD_PHASE}()' which is not a pkg_* function." |
| 23 | eerror "Package fails at QA and at life. Please file a bug." |
24 | eerror "Package fails at QA and at life. Please file a bug." |
| 24 | die "Bad package! $1 is only for use in pkg_* functions!" |
25 | die "Bad package! $1 is only for use in pkg_* functions!" |
| 25 | esac |
26 | esac |
| 26 | } |
27 | } |
| … | |
… | |
| 28 | # @FUNCTION: egetent |
29 | # @FUNCTION: egetent |
| 29 | # @USAGE: <database> <key> |
30 | # @USAGE: <database> <key> |
| 30 | # @DESCRIPTION: |
31 | # @DESCRIPTION: |
| 31 | # Small wrapper for getent (Linux), nidump (< Mac OS X 10.5), |
32 | # Small wrapper for getent (Linux), nidump (< Mac OS X 10.5), |
| 32 | # dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup(). |
33 | # dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup(). |
|
|
34 | # |
|
|
35 | # Supported databases: group passwd |
| 33 | egetent() { |
36 | egetent() { |
|
|
37 | local db=$1 key=$2 |
|
|
38 | |
|
|
39 | [[ $# -ge 3 ]] && die "usage: egetent <database> <key>" |
|
|
40 | |
|
|
41 | case ${db} in |
|
|
42 | passwd|group) ;; |
|
|
43 | *) die "sorry, database '${db}' not yet supported; file a bug" ;; |
|
|
44 | esac |
|
|
45 | |
| 34 | case ${CHOST} in |
46 | case ${CHOST} in |
| 35 | *-darwin[678]) |
47 | *-darwin[678]) |
| 36 | case "$2" in |
48 | case ${key} in |
| 37 | *[!0-9]*) # Non numeric |
49 | *[!0-9]*) # Non numeric |
| 38 | nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2\$/) {print \$0;exit;} }" |
50 | nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}" |
| 39 | ;; |
51 | ;; |
| 40 | *) # Numeric |
52 | *) # Numeric |
| 41 | nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" |
53 | nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}" |
| 42 | ;; |
54 | ;; |
| 43 | esac |
55 | esac |
| 44 | ;; |
56 | ;; |
| 45 | *-darwin*) |
57 | *-darwin*) |
| 46 | local mytype=$1 |
58 | local mykey |
| 47 | [[ "passwd" == $mytype ]] && mytype="Users" |
|
|
| 48 | [[ "group" == $mytype ]] && mytype="Groups" |
|
|
| 49 | case "$2" in |
59 | case ${db} in |
|
|
60 | passwd) db="Users" mykey="UniqueID" ;; |
|
|
61 | group) db="Groups" mykey="PrimaryGroupID" ;; |
|
|
62 | esac |
|
|
63 | |
|
|
64 | case ${key} in |
| 50 | *[!0-9]*) # Non numeric |
65 | *[!0-9]*) # Non numeric |
| 51 | dscl . -read /$mytype/$2 2>/dev/null |grep RecordName |
66 | dscl . -read /${db}/${key} 2>/dev/null |grep RecordName |
| 52 | ;; |
67 | ;; |
| 53 | *) # Numeric |
68 | *) # Numeric |
| 54 | local mykey="UniqueID" |
|
|
| 55 | [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID" |
|
|
| 56 | dscl . -search /$mytype $mykey $2 2>/dev/null |
69 | dscl . -search /${db} ${mykey} ${key} 2>/dev/null |
| 57 | ;; |
70 | ;; |
| 58 | esac |
71 | esac |
| 59 | ;; |
72 | ;; |
| 60 | *-freebsd*|*-dragonfly*) |
73 | *-freebsd*|*-dragonfly*) |
| 61 | local opts action="user" |
74 | case ${db} in |
| 62 | [[ $1 == "passwd" ]] || action="group" |
75 | passwd) db="user" ;; |
|
|
76 | *) ;; |
|
|
77 | esac |
| 63 | |
78 | |
| 64 | # lookup by uid/gid |
79 | # lookup by uid/gid |
|
|
80 | local opts |
| 65 | if [[ $2 == [[:digit:]]* ]] ; then |
81 | if [[ ${key} == [[:digit:]]* ]] ; then |
| 66 | [[ ${action} == "user" ]] && opts="-u" || opts="-g" |
82 | [[ ${db} == "user" ]] && opts="-u" || opts="-g" |
| 67 | fi |
83 | fi |
| 68 | |
84 | |
| 69 | pw show ${action} ${opts} "$2" -q |
85 | pw show ${db} ${opts} "${key}" -q |
| 70 | ;; |
86 | ;; |
| 71 | *-netbsd*|*-openbsd*) |
87 | *-netbsd*|*-openbsd*) |
| 72 | grep "$2:\*:" /etc/$1 |
88 | grep "${key}:\*:" /etc/${db} |
| 73 | ;; |
89 | ;; |
| 74 | *) |
90 | *) |
| 75 | type -p nscd >& /dev/null && nscd -i "$1" |
91 | # ignore output if nscd doesn't exist, or we're not running as root |
| 76 | getent "$1" "$2" |
92 | nscd -i "${db}" 2>/dev/null |
|
|
93 | getent "${db}" "${key}" |
| 77 | ;; |
94 | ;; |
| 78 | esac |
95 | esac |
| 79 | } |
96 | } |
| 80 | |
97 | |
| 81 | # @FUNCTION: enewuser |
98 | # @FUNCTION: enewuser |
| 82 | # @USAGE: <user> [uid] [shell] [homedir] [groups] [params] |
99 | # @USAGE: <user> [uid] [shell] [homedir] [groups] |
| 83 | # @DESCRIPTION: |
100 | # @DESCRIPTION: |
| 84 | # Same as enewgroup, you are not required to understand how to properly add |
101 | # Same as enewgroup, you are not required to understand how to properly add |
| 85 | # a user to the system. The only required parameter is the username. |
102 | # a user to the system. The only required parameter is the username. |
| 86 | # Default uid is (pass -1 for this) next available, default shell is |
103 | # Default uid is (pass -1 for this) next available, default shell is |
| 87 | # /bin/false, default homedir is /dev/null, there are no default groups, |
104 | # /bin/false, default homedir is /dev/null, and there are no default groups. |
| 88 | # and default params sets the comment as 'added by portage for ${PN}'. |
|
|
| 89 | enewuser() { |
105 | enewuser() { |
| 90 | _assert_pkg_ebuild_phase enewuser |
106 | _assert_pkg_ebuild_phase enewuser |
| 91 | |
107 | |
| 92 | # get the username |
108 | # get the username |
| 93 | local euser=$1; shift |
109 | local euser=$1; shift |
| … | |
… | |
| 122 | if [[ ${euid} == "next" ]] ; then |
138 | if [[ ${euid} == "next" ]] ; then |
| 123 | for ((euid = 101; euid <= 999; euid++)); do |
139 | for ((euid = 101; euid <= 999; euid++)); do |
| 124 | [[ -z $(egetent passwd ${euid}) ]] && break |
140 | [[ -z $(egetent passwd ${euid}) ]] && break |
| 125 | done |
141 | done |
| 126 | fi |
142 | fi |
| 127 | opts="${opts} -u ${euid}" |
143 | opts+=" -u ${euid}" |
| 128 | einfo " - Userid: ${euid}" |
144 | einfo " - Userid: ${euid}" |
| 129 | |
145 | |
| 130 | # handle shell |
146 | # handle shell |
| 131 | local eshell=$1; shift |
147 | local eshell=$1; shift |
| 132 | if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then |
148 | if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then |
| … | |
… | |
| 154 | fi |
170 | fi |
| 155 | |
171 | |
| 156 | eshell=${shell} |
172 | eshell=${shell} |
| 157 | fi |
173 | fi |
| 158 | einfo " - Shell: ${eshell}" |
174 | einfo " - Shell: ${eshell}" |
| 159 | opts="${opts} -s ${eshell}" |
175 | opts+=" -s ${eshell}" |
| 160 | |
176 | |
| 161 | # handle homedir |
177 | # handle homedir |
| 162 | local ehome=$1; shift |
178 | local ehome=$1; shift |
| 163 | if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then |
179 | if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then |
| 164 | ehome="/dev/null" |
180 | ehome="/dev/null" |
| 165 | fi |
181 | fi |
| 166 | einfo " - Home: ${ehome}" |
182 | einfo " - Home: ${ehome}" |
| 167 | opts="${opts} -d ${ehome}" |
183 | opts+=" -d ${ehome}" |
| 168 | |
184 | |
| 169 | # handle groups |
185 | # handle groups |
| 170 | local egroups=$1; shift |
186 | local egroups=$1; shift |
| 171 | if [[ ! -z ${egroups} ]] ; then |
187 | if [[ ! -z ${egroups} ]] ; then |
| 172 | local oldifs=${IFS} |
188 | local oldifs=${IFS} |
| … | |
… | |
| 186 | fi |
202 | fi |
| 187 | export IFS="," |
203 | export IFS="," |
| 188 | done |
204 | done |
| 189 | export IFS=${oldifs} |
205 | export IFS=${oldifs} |
| 190 | |
206 | |
| 191 | opts="${opts} -g ${defgroup}" |
207 | opts+=" -g ${defgroup}" |
| 192 | if [[ ! -z ${exgroups} ]] ; then |
208 | if [[ ! -z ${exgroups} ]] ; then |
| 193 | opts="${opts} -G ${exgroups:1}" |
209 | opts+=" -G ${exgroups:1}" |
| 194 | fi |
210 | fi |
| 195 | else |
211 | else |
| 196 | egroups="(none)" |
212 | egroups="(none)" |
| 197 | fi |
213 | fi |
| 198 | einfo " - Groups: ${egroups}" |
214 | einfo " - Groups: ${egroups}" |
| 199 | |
215 | |
| 200 | # handle extra and add the user |
216 | # handle extra args |
| 201 | local oldsandbox=${SANDBOX_ON} |
217 | if [[ $# -gt 0 ]] ; then |
| 202 | export SANDBOX_ON="0" |
218 | die "extra arguments no longer supported; please file a bug" |
|
|
219 | else |
|
|
220 | set -- -c "added by portage for ${PN}" |
|
|
221 | einfo " - Extra: $@" |
|
|
222 | fi |
|
|
223 | |
|
|
224 | # add the user |
| 203 | case ${CHOST} in |
225 | case ${CHOST} in |
| 204 | *-darwin*) |
226 | *-darwin*) |
| 205 | ### Make the user |
227 | ### Make the user |
| 206 | if [[ -z $@ ]] ; then |
|
|
| 207 | dscl . create /users/${euser} uid ${euid} |
228 | dscl . create /users/${euser} uid ${euid} |
| 208 | dscl . create /users/${euser} shell ${eshell} |
229 | dscl . create /users/${euser} shell ${eshell} |
| 209 | dscl . create /users/${euser} home ${ehome} |
230 | dscl . create /users/${euser} home ${ehome} |
| 210 | dscl . create /users/${euser} realname "added by portage for ${PN}" |
231 | dscl . create /users/${euser} realname "added by portage for ${PN}" |
| 211 | ### Add the user to the groups specified |
232 | ### Add the user to the groups specified |
| 212 | local oldifs=${IFS} |
233 | local oldifs=${IFS} |
| 213 | export IFS="," |
234 | export IFS="," |
| 214 | for g in ${egroups} ; do |
235 | for g in ${egroups} ; do |
| 215 | dscl . merge /groups/${g} users ${euser} |
236 | dscl . merge /groups/${g} users ${euser} |
| 216 | done |
237 | done |
| 217 | export IFS=${oldifs} |
238 | export IFS=${oldifs} |
| 218 | else |
|
|
| 219 | einfo "Extra options are not supported on Darwin yet" |
|
|
| 220 | einfo "Please report the ebuild along with the info below" |
|
|
| 221 | einfo "eextra: $@" |
|
|
| 222 | die "Required function missing" |
|
|
| 223 | fi |
|
|
| 224 | ;; |
239 | ;; |
|
|
240 | |
| 225 | *-freebsd*|*-dragonfly*) |
241 | *-freebsd*|*-dragonfly*) |
| 226 | if [[ -z $@ ]] ; then |
|
|
| 227 | pw useradd ${euser} ${opts} \ |
242 | pw useradd ${euser} ${opts} "$@" || die |
| 228 | -c "added by portage for ${PN}" \ |
|
|
| 229 | die "enewuser failed" |
|
|
| 230 | else |
|
|
| 231 | einfo " - Extra: $@" |
|
|
| 232 | pw useradd ${euser} ${opts} \ |
|
|
| 233 | "$@" || die "enewuser failed" |
|
|
| 234 | fi |
|
|
| 235 | ;; |
243 | ;; |
| 236 | |
244 | |
| 237 | *-netbsd*) |
245 | *-netbsd*) |
| 238 | if [[ -z $@ ]] ; then |
|
|
| 239 | useradd ${opts} ${euser} || die "enewuser failed" |
|
|
| 240 | else |
|
|
| 241 | einfo " - Extra: $@" |
|
|
| 242 | useradd ${opts} ${euser} "$@" || die "enewuser failed" |
246 | useradd ${opts} ${euser} "$@" || die |
| 243 | fi |
|
|
| 244 | ;; |
247 | ;; |
| 245 | |
248 | |
| 246 | *-openbsd*) |
249 | *-openbsd*) |
| 247 | if [[ -z $@ ]] ; then |
250 | # all ops the same, except the -g vs -g/-G ... |
| 248 | useradd -u ${euid} -s ${eshell} \ |
251 | useradd -u ${euid} -s ${eshell} \ |
| 249 | -d ${ehome} -c "Added by portage for ${PN}" \ |
252 | -d ${ehome} -g ${egroups} "$@" ${euser} || die |
| 250 | -g ${egroups} ${euser} || die "enewuser failed" |
|
|
| 251 | else |
|
|
| 252 | einfo " - Extra: $@" |
|
|
| 253 | useradd -u ${euid} -s ${eshell} \ |
|
|
| 254 | -d ${ehome} -c "Added by portage for ${PN}" \ |
|
|
| 255 | -g ${egroups} ${euser} "$@" || die "enewuser failed" |
|
|
| 256 | fi |
|
|
| 257 | ;; |
253 | ;; |
| 258 | |
254 | |
| 259 | *) |
255 | *) |
| 260 | if [[ -z $@ ]] ; then |
|
|
| 261 | useradd -r ${opts} \ |
|
|
| 262 | -c "added by portage for ${PN}" \ |
|
|
| 263 | ${euser} \ |
|
|
| 264 | || die "enewuser failed" |
|
|
| 265 | else |
|
|
| 266 | einfo " - Extra: $@" |
|
|
| 267 | useradd -r ${opts} "$@" \ |
256 | useradd -r ${opts} "$@" ${euser} || die |
| 268 | ${euser} \ |
|
|
| 269 | || die "enewuser failed" |
|
|
| 270 | fi |
|
|
| 271 | ;; |
257 | ;; |
| 272 | esac |
258 | esac |
| 273 | |
259 | |
| 274 | if [[ ! -e ${ROOT}/${ehome} ]] ; then |
260 | if [[ ! -e ${ROOT}/${ehome} ]] ; then |
| 275 | einfo " - Creating ${ehome} in ${ROOT}" |
261 | einfo " - Creating ${ehome} in ${ROOT}" |
| 276 | mkdir -p "${ROOT}/${ehome}" |
262 | mkdir -p "${ROOT}/${ehome}" |
| 277 | chown ${euser} "${ROOT}/${ehome}" |
263 | chown ${euser} "${ROOT}/${ehome}" |
| 278 | chmod 755 "${ROOT}/${ehome}" |
264 | chmod 755 "${ROOT}/${ehome}" |
| 279 | fi |
265 | fi |
| 280 | |
|
|
| 281 | export SANDBOX_ON=${oldsandbox} |
|
|
| 282 | } |
266 | } |
| 283 | |
267 | |
| 284 | # @FUNCTION: enewgroup |
268 | # @FUNCTION: enewgroup |
| 285 | # @USAGE: <group> [gid] |
269 | # @USAGE: <group> [gid] |
| 286 | # @DESCRIPTION: |
270 | # @DESCRIPTION: |
| … | |
… | |
| 315 | if [ "${egid}" -gt 0 ] |
299 | if [ "${egid}" -gt 0 ] |
| 316 | then |
300 | then |
| 317 | if [ -z "`egetent group ${egid}`" ] |
301 | if [ -z "`egetent group ${egid}`" ] |
| 318 | then |
302 | then |
| 319 | if [[ "${CHOST}" == *-darwin* ]]; then |
303 | if [[ "${CHOST}" == *-darwin* ]]; then |
| 320 | opts="${opts} ${egid}" |
304 | opts+=" ${egid}" |
| 321 | else |
305 | else |
| 322 | opts="${opts} -g ${egid}" |
306 | opts+=" -g ${egid}" |
| 323 | fi |
307 | fi |
| 324 | else |
308 | else |
| 325 | egid="next available; requested gid taken" |
309 | egid="next available; requested gid taken" |
| 326 | fi |
310 | fi |
| 327 | else |
311 | else |
| … | |
… | |
| 332 | egid="next available" |
316 | egid="next available" |
| 333 | fi |
317 | fi |
| 334 | einfo " - Groupid: ${egid}" |
318 | einfo " - Groupid: ${egid}" |
| 335 | |
319 | |
| 336 | # handle extra |
320 | # handle extra |
| 337 | local eextra="$@" |
321 | if [ $# -gt 0 ] ; then |
| 338 | opts="${opts} ${eextra}" |
322 | die "extra arguments no longer supported; please file a bug" |
|
|
323 | fi |
| 339 | |
324 | |
| 340 | # add the group |
325 | # add the group |
| 341 | local oldsandbox="${SANDBOX_ON}" |
|
|
| 342 | export SANDBOX_ON="0" |
|
|
| 343 | case ${CHOST} in |
326 | case ${CHOST} in |
| 344 | *-darwin*) |
327 | *-darwin*) |
| 345 | if [ ! -z "${eextra}" ]; |
|
|
| 346 | then |
|
|
| 347 | einfo "Extra options are not supported on Darwin/OS X yet" |
|
|
| 348 | einfo "Please report the ebuild along with the info below" |
|
|
| 349 | einfo "eextra: ${eextra}" |
|
|
| 350 | die "Required function missing" |
|
|
| 351 | fi |
|
|
| 352 | |
|
|
| 353 | # If we need the next available |
328 | # If we need the next available |
| 354 | case ${egid} in |
329 | case ${egid} in |
| 355 | *[!0-9]*) # Non numeric |
330 | *[!0-9]*) # Non numeric |
| 356 | for ((egid = 101; egid <= 999; egid++)); do |
331 | for ((egid = 101; egid <= 999; egid++)); do |
| 357 | [[ -z $(egetent group ${egid}) ]] && break |
332 | [[ -z $(egetent group ${egid}) ]] && break |
| … | |
… | |
| 366 | *[!0-9]*) # Non numeric |
341 | *[!0-9]*) # Non numeric |
| 367 | for ((egid = 101; egid <= 999; egid++)); do |
342 | for ((egid = 101; egid <= 999; egid++)); do |
| 368 | [[ -z $(egetent group ${egid}) ]] && break |
343 | [[ -z $(egetent group ${egid}) ]] && break |
| 369 | done |
344 | done |
| 370 | esac |
345 | esac |
| 371 | pw groupadd ${egroup} -g ${egid} || die "enewgroup failed" |
346 | pw groupadd ${egroup} -g ${egid} || die |
| 372 | ;; |
347 | ;; |
| 373 | |
348 | |
| 374 | *-netbsd*) |
349 | *-netbsd*) |
| 375 | case ${egid} in |
350 | case ${egid} in |
| 376 | *[!0-9]*) # Non numeric |
351 | *[!0-9]*) # Non numeric |
| 377 | for ((egid = 101; egid <= 999; egid++)); do |
352 | for ((egid = 101; egid <= 999; egid++)); do |
| 378 | [[ -z $(egetent group ${egid}) ]] && break |
353 | [[ -z $(egetent group ${egid}) ]] && break |
| 379 | done |
354 | done |
| 380 | esac |
355 | esac |
| 381 | groupadd -g ${egid} ${egroup} || die "enewgroup failed" |
356 | groupadd -g ${egid} ${egroup} || die |
| 382 | ;; |
357 | ;; |
| 383 | |
358 | |
| 384 | *) |
359 | *) |
| 385 | # We specify -r so that we get a GID in the system range from login.defs |
360 | # We specify -r so that we get a GID in the system range from login.defs |
| 386 | groupadd -r ${opts} ${egroup} || die "enewgroup failed" |
361 | groupadd -r ${opts} ${egroup} || die |
| 387 | ;; |
362 | ;; |
| 388 | esac |
363 | esac |
| 389 | export SANDBOX_ON="${oldsandbox}" |
|
|
| 390 | } |
364 | } |
| 391 | |
365 | |
|
|
366 | # @FUNCTION: egethome |
|
|
367 | # @USAGE: <user> |
|
|
368 | # @DESCRIPTION: |
| 392 | # Gets the home directory for the specified user |
369 | # Gets the home directory for the specified user. |
| 393 | # it's a wrap around egetent as the position of the home directory in the line |
|
|
| 394 | # varies depending on the os used. |
|
|
| 395 | # |
|
|
| 396 | # To use that, inherit eutils, not portability! |
|
|
| 397 | egethome() { |
370 | egethome() { |
| 398 | local pos |
371 | local pos |
|
|
372 | |
|
|
373 | [[ $# -eq 1 ]] || die "usage: egethome <user>" |
| 399 | |
374 | |
| 400 | case ${CHOST} in |
375 | case ${CHOST} in |
| 401 | *-darwin*|*-freebsd*|*-dragonfly*) |
376 | *-darwin*|*-freebsd*|*-dragonfly*) |
| 402 | pos=9 |
377 | pos=9 |
| 403 | ;; |
378 | ;; |
| … | |
… | |
| 407 | esac |
382 | esac |
| 408 | |
383 | |
| 409 | egetent passwd $1 | cut -d: -f${pos} |
384 | egetent passwd $1 | cut -d: -f${pos} |
| 410 | } |
385 | } |
| 411 | |
386 | |
|
|
387 | # @FUNCTION: egetshell |
|
|
388 | # @USAGE: <user> |
|
|
389 | # @DESCRIPTION: |
| 412 | # Gets the shell for the specified user |
390 | # Gets the shell for the specified user. |
| 413 | # it's a wrap around egetent as the position of the home directory in the line |
|
|
| 414 | # varies depending on the os used. |
|
|
| 415 | # |
|
|
| 416 | # To use that, inherit eutils, not portability! |
|
|
| 417 | egetshell() { |
391 | egetshell() { |
| 418 | local pos |
392 | local pos |
|
|
393 | |
|
|
394 | [[ $# -eq 1 ]] || die "usage: egetshell <user>" |
| 419 | |
395 | |
| 420 | case ${CHOST} in |
396 | case ${CHOST} in |
| 421 | *-darwin*|*-freebsd*|*-dragonfly*) |
397 | *-darwin*|*-freebsd*|*-dragonfly*) |
| 422 | pos=10 |
398 | pos=10 |
| 423 | ;; |
399 | ;; |
| … | |
… | |
| 426 | ;; |
402 | ;; |
| 427 | esac |
403 | esac |
| 428 | |
404 | |
| 429 | egetent passwd "$1" | cut -d: -f${pos} |
405 | egetent passwd "$1" | cut -d: -f${pos} |
| 430 | } |
406 | } |
| 431 | |
|
|
| 432 | # Returns true if specified user has a shell that precludes logins |
|
|
| 433 | # on whichever operating system. |
|
|
| 434 | is-login-disabled() { |
|
|
| 435 | |
|
|
| 436 | case $(egetshell "$1") in |
|
|
| 437 | /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin) |
|
|
| 438 | return 0 ;; |
|
|
| 439 | *) |
|
|
| 440 | return 1 ;; |
|
|
| 441 | esac |
|
|
| 442 | } |
|
|