adlin: able to tokenize every arguments

This commit is contained in:
nemunaire 2018-02-21 01:25:31 +01:00 committed by Pierre-Olivier Mercier
parent 800bc7a921
commit 19de9c271b

View File

@ -36,10 +36,15 @@ token_format() {
DATA="$DATA]" DATA="$DATA]"
} }
local challenge=
[ -z "${TID}" ] || {
challenge="
\"challenge\": ${TID},"
}
>&2 cat <<EOF >&2 cat <<EOF
{ {
"login": "${ULGN}", "login": "${ULGN}",${challenge}
"challenge": ${TID},
"token": "${TOKEN}"${DATA} "token": "${TOKEN}"${DATA}
} }
EOF EOF
@ -65,7 +70,8 @@ PKEY=$(cmdline adlin.key)
[ $# -lt 1 ] && { usage; exit 1; } [ $# -lt 1 ] && { usage; exit 1; }
case "$1" in TOKENID="$1"
case "${TOKENID}" in
token1|token2) token1|token2)
HDATA=42 HDATA=42
;; ;;
@ -73,7 +79,7 @@ case "$1" in
DATA=$(date +%s%N) DATA=$(date +%s%N)
;; ;;
token4) token4)
echo "$1 is not here! Perhaps it has been accidentally deleted?" >&2 echo "${TOKENID} is not here! Perhaps it has been accidentally deleted?" >&2
exit 2 exit 2
;; ;;
token5) token5)
@ -84,10 +90,9 @@ case "$1" in
echo $HDATA | grep "not here" 2> /dev/null && exit 3 echo $HDATA | grep "not here" 2> /dev/null && exit 3
;; ;;
*) *)
echo "Invalid argument: $1" >&2 DATA=$@
usage TOKENID=
exit 1
;; ;;
esac esac
token_format "${1#token}" "$(token_generator ${1#token} ${HDATA} ${DATA})" ${DATA} token_format "${TOKENID#token}" "$(token_generator ${TOKENID#token} ${HDATA} ${DATA})" ${DATA}