From c3b066c14733fd62969abd7a36e3ac881ed71227 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 24 Oct 2019 19:44:51 +0200 Subject: [PATCH] [__hostname] Check hostname length if getconf(1) is available --- cdist/conf/type/__hostname/explorer/max_len | 10 ++++++++++ cdist/conf/type/__hostname/manifest | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 cdist/conf/type/__hostname/explorer/max_len diff --git a/cdist/conf/type/__hostname/explorer/max_len b/cdist/conf/type/__hostname/explorer/max_len new file mode 100644 index 00000000..97d8a142 --- /dev/null +++ b/cdist/conf/type/__hostname/explorer/max_len @@ -0,0 +1,10 @@ +#!/bin/sh -e + +command -v getconf >/dev/null || exit 0 + +val=$(getconf HOST_NAME_MAX 2>/dev/null) + +if test -n "${val}" -a "${val}" != 'undefined' +then + echo "${val}" +fi diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 58034a19..2c6057d6 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -20,6 +20,13 @@ # along with cdist. If not, see . # +not_supported() { + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 +} + + os=$(cat "$__global/explorer/os") if [ -f "$__object/parameter/name" ]; then name_should="$(cat "$__object/parameter/name")" @@ -38,12 +45,11 @@ else esac fi - -not_supported() { - echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 - echo "Please contribute an implementation for it if you can." >&2 - exit 1 -} +if test -n "${max_len}" -a "$(wc -c "${name_should}")" -gt "${max_len}"a +then + printf "Host name too long. Up to %u characters allowed.\n" "${max_len}" >&2 + exit 1 +fi case $os in