From bad3a4a4cb69acc9278eedbade1323cbb7ef6cc2 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 1 Oct 2019 10:04:57 +0200 Subject: [PATCH] [__group] Fall back to /etc files if getent(1) is not available Some (embedded) systems (and Mac OS X) don't provide getent(1). The workaround parses /etc/group under the assumption that the system only uses local users and groups. --- cdist/conf/type/__group/explorer/group | 19 +++++++++++++-- cdist/conf/type/__group/explorer/gshadow | 30 ++++++++++++++++++------ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cdist/conf/type/__group/explorer/group b/cdist/conf/type/__group/explorer/group index 07f73a91..dc673f61 100755 --- a/cdist/conf/type/__group/explorer/group +++ b/cdist/conf/type/__group/explorer/group @@ -1,6 +1,7 @@ #!/bin/sh # # 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) # # This file is part of cdist. # @@ -21,7 +22,21 @@ # Get an existing groups group entry. # +not_supported() { + echo "Your operating system ($("$__explorer/os")) is currently not supported." >&2 + echo "Cannot extract group information." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 +} + name=$__object_id -getent group "$name" || true - +if command -v getent >/dev/null +then + getent group "$name" || true +elif [ -f /etc/group ] +then + grep "^${name}:" /etc/group || true +else + not_supported +fi diff --git a/cdist/conf/type/__group/explorer/gshadow b/cdist/conf/type/__group/explorer/gshadow index ef40b7bc..05841d69 100755 --- a/cdist/conf/type/__group/explorer/gshadow +++ b/cdist/conf/type/__group/explorer/gshadow @@ -1,6 +1,7 @@ #!/bin/sh # # 2011-2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) # # This file is part of cdist. # @@ -22,13 +23,28 @@ # name=$__object_id -os="$("$__explorer/os")" +os=$("$__explorer/os") -case "$os" in - "freebsd"|"netbsd") - echo "$os does not have getent gshadow" - exit 0 - ;; +not_supported() { + echo "Your operating system ($os) is currently not supported." >&2 + echo "Cannot extract group information." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 +} + +case $os in + "freebsd"|"netbsd") + echo "$os does not have getent gshadow" >&2 + exit 0 + ;; esac -getent gshadow "$name" || true +if command -v getent >/dev/null +then + getent gshadow "$name" || true +elif [ -f /etc/gshadow ] +then + grep "^${name}:" /etc/gshadow || true +else + not_supported +fi