[__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.
This commit is contained in:
Dennis Camera 2019-10-01 08:11:41 +02:00
parent 97bcfcc23c
commit 092dd19611
2 changed files with 23 additions and 3 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

@ -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