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

Diff of /eclass/user.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.2
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.1 2011/10/27 07:16:08 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.2 2011/10/27 07:26:55 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)
10# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD) 10# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD)
11# @BLURB: user management in ebuilds 11# @BLURB: user management in ebuilds
12# @DESCRIPTION: 12# @DESCRIPTION:
13# The user eclass contains a suite of functions that allow ebuilds 13# The user eclass contains a suite of functions that allow ebuilds
14# to quickly make sure users in the installed system are sane. 14# to quickly make sure users in the installed system are sane.
15
16# @FUNCTION: _assert_pkg_ebuild_phase
17# @INTERNAL
18# @USAGE: <calling func name>
19_assert_pkg_ebuild_phase() {
20 case ${EBUILD_PHASE} in
21 unpack|prepare|configure|compile|test|install)
22 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 die "Bad package! $1 is only for use in pkg_* functions!"
25 esac
26}
15 27
16# @FUNCTION: egetent 28# @FUNCTION: egetent
17# @USAGE: <database> <key> 29# @USAGE: <database> <key>
18# @DESCRIPTION: 30# @DESCRIPTION:
19# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5), 31# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5),
73# a user to the system. The only required parameter is the username. 85# a user to the system. The only required parameter is the username.
74# Default uid is (pass -1 for this) next available, default shell is 86# Default uid is (pass -1 for this) next available, default shell is
75# /bin/false, default homedir is /dev/null, there are no default groups, 87# /bin/false, default homedir is /dev/null, there are no default groups,
76# and default params sets the comment as 'added by portage for ${PN}'. 88# and default params sets the comment as 'added by portage for ${PN}'.
77enewuser() { 89enewuser() {
78 case ${EBUILD_PHASE} in 90 _assert_pkg_ebuild_phase enewuser
79 unpack|compile|test|install)
80 eerror "'enewuser()' called from '${EBUILD_PHASE}()' which is not a pkg_* function."
81 eerror "Package fails at QA and at life. Please file a bug."
82 die "Bad package! enewuser is only for use in pkg_* functions!"
83 esac
84 91
85 # get the username 92 # get the username
86 local euser=$1; shift 93 local euser=$1; shift
87 if [[ -z ${euser} ]] ; then 94 if [[ -z ${euser} ]] ; then
88 eerror "No username specified !" 95 eerror "No username specified !"
280# This function does not require you to understand how to properly add a 287# This function does not require you to understand how to properly add a
281# group to the system. Just give it a group name to add and enewgroup will 288# group to the system. Just give it a group name to add and enewgroup will
282# do the rest. You may specify the gid for the group or allow the group to 289# do the rest. You may specify the gid for the group or allow the group to
283# allocate the next available one. 290# allocate the next available one.
284enewgroup() { 291enewgroup() {
285 case ${EBUILD_PHASE} in 292 _assert_pkg_ebuild_phase enewgroup
286 unpack|compile|test|install)
287 eerror "'enewgroup()' called from '${EBUILD_PHASE}()' which is not a pkg_* function."
288 eerror "Package fails at QA and at life. Please file a bug."
289 die "Bad package! enewgroup is only for use in pkg_* functions!"
290 esac
291 293
292 # get the group 294 # get the group
293 local egroup="$1"; shift 295 local egroup="$1"; shift
294 if [ -z "${egroup}" ] 296 if [ -z "${egroup}" ]
295 then 297 then
391# it's a wrap around egetent as the position of the home directory in the line 393# it's a wrap around egetent as the position of the home directory in the line
392# varies depending on the os used. 394# varies depending on the os used.
393# 395#
394# To use that, inherit eutils, not portability! 396# To use that, inherit eutils, not portability!
395egethome() { 397egethome() {
396 ent=$(egetent passwd $1) 398 local pos
397 399
398 case ${CHOST} in 400 case ${CHOST} in
399 *-darwin*|*-freebsd*|*-dragonfly*) 401 *-darwin*|*-freebsd*|*-dragonfly*)
400 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir 402 pos=9
401 echo ${ent} | cut -d: -f9
402 ;; 403 ;;
403 *) 404 *) # Linux, NetBSD, OpenBSD, etc...
404 # Linux, NetBSD and OpenBSD use position 6 instead 405 pos=6
405 echo ${ent} | cut -d: -f6
406 ;; 406 ;;
407 esac 407 esac
408
409 egetent passwd $1 | cut -d: -f${pos}
408} 410}
409 411
410# Gets the shell for the specified user 412# Gets the shell for the specified user
411# it's a wrap around egetent as the position of the home directory in the line 413# it's a wrap around egetent as the position of the home directory in the line
412# varies depending on the os used. 414# varies depending on the os used.
413# 415#
414# To use that, inherit eutils, not portability! 416# To use that, inherit eutils, not portability!
415egetshell() { 417egetshell() {
416 ent=$(egetent passwd "$1") 418 local pos
417 419
418 case ${CHOST} in 420 case ${CHOST} in
419 *-darwin*|*-freebsd*|*-dragonfly*) 421 *-darwin*|*-freebsd*|*-dragonfly*)
420 # Darwin, OSX, FreeBSD and DragonFly use position 9 to store homedir 422 pos=10
421 echo ${ent} | cut -d: -f10
422 ;; 423 ;;
423 *) 424 *) # Linux, NetBSD, OpenBSD, etc...
424 # Linux, NetBSD and OpenBSD use position 6 instead 425 pos=7
425 echo ${ent} cut -d: -f7
426 ;; 426 ;;
427 esac 427 esac
428
429 egetent passwd "$1" | cut -d: -f${pos}
428} 430}
429 431
430# Returns true if specified user has a shell that precludes logins 432# Returns true if specified user has a shell that precludes logins
431# on whichever operating system. 433# on whichever operating system.
432is-login-disabled() { 434is-login-disabled() {
435
433 shell=$(egetshell "$1") 436 case $(egetshell "$1") in
434
435 case ${shell} in
436 /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin) 437 /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin)
437 return 0 ;; 438 return 0 ;;
438 *) 439 *)
439 return 1 ;; 440 return 1 ;;
440 esac 441 esac

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.20