瀏覽代碼

fix user/host validation

tags/v1.4.28^0
Jonathan Cobb 3 年之前
父節點
當前提交
dd67eb3293
共有 1 個文件被更改,包括 9 次插入6 次删除
  1. +9
    -6
      bin/bubble_common

+ 9
- 6
bin/bubble_common 查看文件

@@ -33,18 +33,21 @@ function handle_help_request() {
}

# Validate that argument is "hostname" or "user@hostname"
# Validate that user (if present) is valid username and hostname is valid hostname
# Validate that user (if present) is valid username and hostname not invalid
# Does not perform a full RFC-compliant check, just some basics
function validate_user_at_host() {
HOST="${1}"
if [[ -z "$(echo "${HOST}" | grep '@')" ]] ; then
if [[ $(echo "${HOST}" | awk -F '@' '{print $2}' | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST} ]] ; then
if [[ $(echo "${HOST}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST} ]] ; then
die "Invalid host: ${HOST}"
elif [[ $(echo "${HOST}" | awk -F '@' '{print $1}' | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST} ]] ; then
die "Invalid user: ${HOST}"
fi
else
if [[ $(echo "${HOST}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST} ]] ; then
die "Invalid host: ${HOST}"
USER_PART="$(echo "${HOST}" | awk -F '@' '{print $1}')"
HOST_PART="$(echo "${HOST}" | awk -F '@' '{print $2}')"
if [[ $(echo "${USER_PART}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#USER_PART} ]] ; then
die "Invalid user: ${USER_PART}"
elif [[ $(echo "${HOST_PART}" | tr -cd '[:alnum:].-' | wc -c) -ne ${#HOST_PART} ]] ; then
die "Invalid host: ${HOST_PART}"
fi
fi
}


Loading…
取消
儲存