From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2C7C1138334 for ; Tue, 11 Jun 2019 16:27:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 86A51E095F; Tue, 11 Jun 2019 16:24:04 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id EA8B9E095C for ; Tue, 11 Jun 2019 16:24:03 +0000 (UTC) Received: from localhost.localdomain (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 4F49D345E94; Tue, 11 Jun 2019 16:24:02 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH v4 08/19] user.eclass: Factor out finding nologin into separate function Date: Tue, 11 Jun 2019 18:23:36 +0200 Message-Id: <20190611162347.2989-9-mgorny@gentoo.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190611162347.2989-1-mgorny@gentoo.org> References: <20190611162347.2989-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 489eddc5-aa49-4499-a0cf-80176b6f17e4 X-Archives-Hash: 81737c193d1196ba71a4ba623372ebc7 Signed-off-by: Michał Górny --- eclass/user.eclass | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/eclass/user.eclass b/eclass/user.eclass index 8afbc101fac3..54d7a3fdbe28 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -70,6 +70,31 @@ egetent() { esac } +# @FUNCTION: user_get_nologin +# @INTERNAL +# @DESCRIPTION: +# Find an appropriate 'nologin' shell for the platform, and output +# its path. +user_get_nologin() { + local eshell + + for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do + [[ -x ${ROOT}${eshell} ]] && break + done + + if [[ ${eshell} == "/dev/null" ]] ; then + ewarn "Unable to identify the shell to use, proceeding with userland default." + case ${USERLAND} in + GNU) eshell="/bin/false" ;; + BSD) eshell="/sbin/nologin" ;; + Darwin) eshell="/usr/sbin/nologin" ;; + *) die "Unable to identify the default shell for userland ${USERLAND}" + esac + fi + + echo "${eshell}" +} + # @FUNCTION: enewuser # @USAGE: [-F] [-M] [uid] [shell] [homedir] [groups] # @DESCRIPTION: @@ -152,19 +177,7 @@ enewuser() { die "Pass '-1' as the shell parameter" fi else - for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do - [[ -x ${ROOT}${eshell} ]] && break - done - - if [[ ${eshell} == "/dev/null" ]] ; then - eerror "Unable to identify the shell to use, proceeding with userland default." - case ${USERLAND} in - GNU) eshell="/bin/false" ;; - BSD) eshell="/sbin/nologin" ;; - Darwin) eshell="/usr/sbin/nologin" ;; - *) die "Unable to identify the default shell for userland ${USERLAND}" - esac - fi + eshell=$(user_get_nologin) fi einfo " - Shell: ${eshell}" opts+=( -s "${eshell}" ) -- 2.22.0