From 092dd19611eaa40a23d0ec1c5cd9bf770579f082 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 1 Oct 2019 08:11:41 +0200 Subject: [PATCH] [__ssh_dot_ssh] Fall back to /etc files if getent(1) is not available Some (embedded) systems don't provide getent(1). The workaround parses /etc/passwd and /etc/group under the assumption that these sysems only use local users and groups. --- cdist/conf/type/__ssh_dot_ssh/explorer/group | 11 +++++++++-- cdist/conf/type/__ssh_dot_ssh/explorer/passwd | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__ssh_dot_ssh/explorer/group b/cdist/conf/type/__ssh_dot_ssh/explorer/group index cdea6fe7..faf44cb8 100755 --- a/cdist/conf/type/__ssh_dot_ssh/explorer/group +++ b/cdist/conf/type/__ssh_dot_ssh/explorer/group @@ -1,6 +1,7 @@ #!/bin/sh # # 2014 Steven Armstrong (steven-cdist at armstrong.cc) +# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) # # This file is part of cdist. # @@ -18,5 +19,11 @@ # along with cdist. If not, see . # -gid="$("$__type_explorer/passwd" | cut -d':' -f 4)" -getent group "$gid" || true +gid=$("$__type_explorer/passwd" | cut -d':' -f4) + +if command -v getent >/dev/null +then + getent group "$gid" || true +else + awk -F: "\$3 == \"$gid\" { print }" /etc/group +fi diff --git a/cdist/conf/type/__ssh_dot_ssh/explorer/passwd b/cdist/conf/type/__ssh_dot_ssh/explorer/passwd index 3fbad06f..42686b20 100755 --- a/cdist/conf/type/__ssh_dot_ssh/explorer/passwd +++ b/cdist/conf/type/__ssh_dot_ssh/explorer/passwd @@ -2,6 +2,7 @@ # # 2012 Steven Armstrong (steven-cdist at armstrong.cc) # 2014 Nico Schottelius (nico-cdist at schottelius.org) +# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) # # This file is part of cdist. # @@ -21,4 +22,16 @@ owner="$__object_id" -getent passwd "$owner" || true +if command -v getent >/dev/null +then + getent passwd "$owner" || true +else + case $owner in + [0-9][0-9]*) + awk -F: "\$3 == \"$owner\" { print }" /etc/passwd + ;; + *) + grep "^$owner:" /etc/passwd || true + ;; + esac +fi