From a30be3872fa13d3043bd6ae2caef229cdb54d97b Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Mon, 4 May 2020 23:16:19 +0200 Subject: [PATCH] Extract is_user() and is_group() functions --- CHANGELOG.md | 3 ++- shellpki | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0067443..49fe5c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Rename internal function usage() to show_usage() * More readable variable names * verify_ca_password() looks for a previously set password and verifies it -* Extract function cert_end_date() +* Extract cert_end_date() function +* Extract is_user() and is_group() functions ### Deprecated diff --git a/shellpki b/shellpki index 9afddf1..3b84973 100755 --- a/shellpki +++ b/shellpki @@ -612,6 +612,13 @@ check() { done } +is_user() { + getent passwd "${1}" >/dev/null +} +is_group() { + getent group "${1}" >/dev/null +} + main() { # default config # TODO : override with /etc/default/shellpki @@ -657,7 +664,7 @@ main() { OPENSSL_BIN=$(command -v openssl) SUFFIX=$(/bin/date +"%s") - if ! getent passwd "${PKI_USER}" >/dev/null ! getent group "${PKI_USER}" >/dev/null; then + if ! is_user "${PKI_USER}" || ! is_group "${PKI_USER}"; then error "You must create ${PKI_USER} user and group !" fi