From 24d9a6dfc64fa430566abc1d98b5dc222697ddbd Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 7 Jul 2023 20:10:51 +0200 Subject: [PATCH] klinfix: add new commands password [generate | encrypt] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An excellent example of how to define commands with optional subcommands and optional parameters: password encrypt [type ] [salt STRING] [PASSWORD] The tricks here are two: 1. mode="switch" in the top-level password command 2. min="0" in the encrypt subcommands The first turns the COMMAND element into a SWITCH element (with command matching), and the second makes a COMMAND optional. If an optional command is input by the user, then the enclosed PARAM is mandatory. Please note, due to limitations in the mkpasswd¹ utility, spaces are not supported in PASSWORD, i.e., when read from CLI prompt. However, spaces are allowed when using the interactive prompt, i.e., when omitting the PASSWORD from the CLI prompt. ¹) mkpasswd does not look for any leading ' or " in the password arg. Signed-off-by: Joachim Wiberg --- src/klinfix/xml/infix.xml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/klinfix/xml/infix.xml b/src/klinfix/xml/infix.xml index 1e286b38..ee912fb3 100644 --- a/src/klinfix/xml/infix.xml +++ b/src/klinfix/xml/infix.xml @@ -124,6 +124,34 @@ + + + pwgen -c -n -B -C + + + + + + + + + + md5 + sha256 + sha512 + + + + + + + type=${KLISH_PARAM_pwhash:-md5} + salt=${KLISH_PARAM_pwsalt:+-S $KLISH_PARAM_pwsalt} + mkpasswd -m $type $salt $KLISH_PARAM_pwpass + + + +