diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-11-26 07:20:31 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-11-26 07:20:31 +0000 |
commit | 3d1f1546d8e5ee1c266b2e6584d8f4e1ac19697b (patch) | |
tree | 0a399b9f11499076e0a600441136988a39ae276b /eclass | |
parent | re-use "eshell" when searching for a shell to avoid missing "local shell" dec... (diff) | |
download | gentoo-2-3d1f1546d8e5ee1c266b2e6584d8f4e1ac19697b.tar.gz gentoo-2-3d1f1546d8e5ee1c266b2e6584d8f4e1ac19697b.tar.bz2 gentoo-2-3d1f1546d8e5ee1c266b2e6584d8f4e1ac19697b.zip |
rewrite a bit of code to quote all user/group/shell/home strings
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/user.eclass | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/eclass/user.eclass b/eclass/user.eclass index 07ebc90c8a2d..2b5be7956eab 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.13 2011/11/26 06:50:27 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.14 2011/11/26 07:20:31 vapier Exp $ # @ECLASS: user.eclass # @MAINTAINER: @@ -119,7 +119,7 @@ enewuser() { einfo "Adding user '${euser}' to your system ..." # options to pass to useradd - local opts= + local opts=() # handle uid local euid=$1; shift @@ -140,7 +140,7 @@ enewuser() { [[ -z $(egetent passwd ${euid}) ]] && break done fi - opts+=" -u ${euid}" + opts+=( -u ${euid} ) einfo " - Userid: ${euid}" # handle shell @@ -170,7 +170,7 @@ enewuser() { fi fi einfo " - Shell: ${eshell}" - opts+=" -s ${eshell}" + opts+=( -s "${eshell}" ) # handle homedir local ehome=$1; shift @@ -178,7 +178,7 @@ enewuser() { ehome="/dev/null" fi einfo " - Home: ${ehome}" - opts+=" -d ${ehome}" + opts+=( -d "${ehome}" ) # handle groups local egroups=$1; shift @@ -202,9 +202,9 @@ enewuser() { done export IFS=${oldifs} - opts+=" -g ${defgroup}" + opts+=( -g "${defgroup}" ) if [[ ! -z ${exgroups} ]] ; then - opts+=" -G ${exgroups:1}" + opts+=( -G "${exgroups:1}" ) fi else egroups="(none)" @@ -215,50 +215,51 @@ enewuser() { if [[ $# -gt 0 ]] ; then die "extra arguments no longer supported; please file a bug" else - set -- -c "added by portage for ${PN}" - einfo " - Extra: $@" + local comment="added by portage for ${PN}" + opts+=( -c "${comment}" ) + einfo " - GECOS: ${comment}" fi # add the user case ${CHOST} in *-darwin*) ### Make the user - dscl . create /users/${euser} uid ${euid} - dscl . create /users/${euser} shell ${eshell} - dscl . create /users/${euser} home ${ehome} - dscl . create /users/${euser} realname "added by portage for ${PN}" + dscl . create "/users/${euser}" uid ${euid} + dscl . create "/users/${euser}" shell "${eshell}" + dscl . create "/users/${euser}" home "${ehome}" + dscl . create "/users/${euser}" realname "added by portage for ${PN}" ### Add the user to the groups specified - local oldifs=${IFS} + local g oldifs=${IFS} export IFS="," for g in ${egroups} ; do - dscl . merge /groups/${g} users ${euser} + dscl . merge "/groups/${g}" users "${euser}" done export IFS=${oldifs} ;; *-freebsd*|*-dragonfly*) - pw useradd ${euser} ${opts} "$@" || die + pw useradd "${euser}" "${opts[@]}" || die ;; *-netbsd*) - useradd ${opts} ${euser} "$@" || die + useradd "${opts[@]}" "${euser}" || die ;; *-openbsd*) # all ops the same, except the -g vs -g/-G ... - useradd -u ${euid} -s ${eshell} \ - -d ${ehome} -g ${egroups} "$@" ${euser} || die + useradd -u ${euid} -s "${eshell}" \ + -d "${ehome}" -g "${egroups}" "${euser}" || die ;; *) - useradd -r ${opts} "$@" ${euser} || die + useradd -r "${opts[@]}" "${euser}" || die ;; esac if [[ ! -e ${ROOT}/${ehome} ]] ; then einfo " - Creating ${ehome} in ${ROOT}" mkdir -p "${ROOT}/${ehome}" - chown ${euser} "${ROOT}/${ehome}" + chown "${euser}" "${ROOT}/${ehome}" chmod 755 "${ROOT}/${ehome}" fi } @@ -274,36 +275,23 @@ enewgroup() { _assert_pkg_ebuild_phase enewgroup # get the group - local egroup="$1"; shift - if [ -z "${egroup}" ] - then + local egroup=$1; shift + if [[ -z ${egroup} ]] ; then eerror "No group specified !" die "Cannot call enewgroup without a group" fi # see if group already exists - if [[ -n $(egetent group "${egroup}") ]]; then + if [[ -n $(egetent group "${egroup}") ]] ; then return 0 fi einfo "Adding group '${egroup}' to your system ..." - # options to pass to useradd - local opts= - # handle gid - local egid="$1"; shift - if [ ! -z "${egid}" ] - then - if [ "${egid}" -gt 0 ] - then - if [ -z "`egetent group ${egid}`" ] - then - if [[ "${CHOST}" == *-darwin* ]]; then - opts+=" ${egid}" - else - opts+=" -g ${egid}" - fi - else + local egid=$1; shift + if [[ ! -z ${egid} ]] ; then + if [[ ${egid} -gt 0 ]] ; then + if [[ -n $(egetent group ${egid}) ]] ; then egid="next available; requested gid taken" fi else @@ -316,47 +304,48 @@ enewgroup() { einfo " - Groupid: ${egid}" # handle extra - if [ $# -gt 0 ] ; then + if [[ $# -gt 0 ]] ; then die "extra arguments no longer supported; please file a bug" fi + # Some targets need to find the next available GID manually + _enewgroup_next_gid() { + if [[ ${egid} == *[!0-9]* ]] ; then + # Non numeric + for ((egid = 101; egid <= 999; egid++)) ; do + [[ -z $(egetent group ${egid}) ]] && break + done + fi + } + # add the group case ${CHOST} in *-darwin*) - # If we need the next available - case ${egid} in - *[!0-9]*) # Non numeric - for ((egid = 101; egid <= 999; egid++)); do - [[ -z $(egetent group ${egid}) ]] && break - done - esac - dscl . create /groups/${egroup} gid ${egid} - dscl . create /groups/${egroup} passwd '*' + _enewgroup_next_gid + dscl . create "/groups/${egroup}" gid ${egid} + dscl . create "/groups/${egroup}" passwd '*' ;; *-freebsd*|*-dragonfly*) - case ${egid} in - *[!0-9]*) # Non numeric - for ((egid = 101; egid <= 999; egid++)); do - [[ -z $(egetent group ${egid}) ]] && break - done - esac - pw groupadd ${egroup} -g ${egid} || die + _enewgroup_next_gid + pw groupadd "${egroup}" -g ${egid} || die ;; *-netbsd*) - case ${egid} in - *[!0-9]*) # Non numeric - for ((egid = 101; egid <= 999; egid++)); do - [[ -z $(egetent group ${egid}) ]] && break - done - esac - groupadd -g ${egid} ${egroup} || die + _enewgroup_next_gid + groupadd -g ${egid} "${egroup}" || die ;; *) + local opts + if [[ ${egid} == *[!0-9]* ]] ; then + # Non numeric; let groupadd figure out a GID for us + opts="" + else + opts="-g ${egid}" + fi # We specify -r so that we get a GID in the system range from login.defs - groupadd -r ${opts} ${egroup} || die + groupadd -r ${opts} "${egroup}" || die ;; esac } @@ -379,7 +368,7 @@ egethome() { ;; esac - egetent passwd $1 | cut -d: -f${pos} + egetent passwd "$1" | cut -d: -f${pos} } # @FUNCTION: egetshell |