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

Diff of /eclass/user.eclass

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

Revision 1.4 Revision 1.5
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.4 2011/10/31 17:39:52 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.5 2011/11/03 00:24:19 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)
28# @FUNCTION: egetent 28# @FUNCTION: egetent
29# @USAGE: <database> <key> 29# @USAGE: <database> <key>
30# @DESCRIPTION: 30# @DESCRIPTION:
31# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5), 31# 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(). 32# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
33#
34# Supported databases: group passwd
33egetent() { 35egetent() {
36 local db=$1 key=$2
37
38 [[ $# -ge 3 ]] && die "usage: egetent <database> <key>"
39
40 case ${db} in
41 passwd|group) ;;
42 *) die "sorry, database '${db}' not yet supported; file a bug" ;;
43 esac
44
34 case ${CHOST} in 45 case ${CHOST} in
35 *-darwin[678]) 46 *-darwin[678])
36 case "$2" in 47 case ${key} in
37 *[!0-9]*) # Non numeric 48 *[!0-9]*) # Non numeric
38 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2\$/) {print \$0;exit;} }" 49 nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
39 ;; 50 ;;
40 *) # Numeric 51 *) # Numeric
41 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 52 nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
42 ;; 53 ;;
43 esac 54 esac
44 ;; 55 ;;
45 *-darwin*) 56 *-darwin*)
46 local mytype=$1 57 local mykey
47 [[ "passwd" == $mytype ]] && mytype="Users"
48 [[ "group" == $mytype ]] && mytype="Groups"
49 case "$2" in 58 case ${db} in
59 passwd) db="Users" mykey="UniqueID" ;;
60 group) db="Groups" mykey="PrimaryGroupID" ;;
61 esac
62
63 case ${key} in
50 *[!0-9]*) # Non numeric 64 *[!0-9]*) # Non numeric
51 dscl . -read /$mytype/$2 2>/dev/null |grep RecordName 65 dscl . -read /${db}/${key} 2>/dev/null |grep RecordName
52 ;; 66 ;;
53 *) # Numeric 67 *) # Numeric
54 local mykey="UniqueID"
55 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID"
56 dscl . -search /$mytype $mykey $2 2>/dev/null 68 dscl . -search /${db} ${mykey} ${key} 2>/dev/null
57 ;; 69 ;;
58 esac 70 esac
59 ;; 71 ;;
60 *-freebsd*|*-dragonfly*) 72 *-freebsd*|*-dragonfly*)
61 local opts action="user" 73 case ${db} in
62 [[ $1 == "passwd" ]] || action="group" 74 passwd) db="user" ;;
75 *) ;;
76 esac
63 77
64 # lookup by uid/gid 78 # lookup by uid/gid
79 local opts
65 if [[ $2 == [[:digit:]]* ]] ; then 80 if [[ ${key} == [[:digit:]]* ]] ; then
66 [[ ${action} == "user" ]] && opts="-u" || opts="-g" 81 [[ ${action} == "user" ]] && opts="-u" || opts="-g"
67 fi 82 fi
68 83
69 pw show ${action} ${opts} "$2" -q 84 pw show ${action} ${opts} "${key}" -q
70 ;; 85 ;;
71 *-netbsd*|*-openbsd*) 86 *-netbsd*|*-openbsd*)
72 grep "$2:\*:" /etc/$1 87 grep "${key}:\*:" /etc/${db}
73 ;; 88 ;;
74 *) 89 *)
75 # ignore output if nscd doesn't exist, or we're not running as root 90 # ignore output if nscd doesn't exist, or we're not running as root
76 nscd -i "$1" 2>/dev/null 91 nscd -i "${db}" 2>/dev/null
77 getent "$1" "$2" 92 getent "${db}" "${key}"
78 ;; 93 ;;
79 esac 94 esac
80} 95}
81 96
82# @FUNCTION: enewuser 97# @FUNCTION: enewuser

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.20