Kaynağa Gözat

kamctl: CMDHASH to specify password hashing command

- like md5sum, sha256sum
Daniel-Constantin Mierla 6 ay önce
ebeveyn
işleme
d901d4eab2
2 değiştirilmiş dosya ile 18 ekleme ve 12 silme
  1. 15 10
      utils/kamctl/kamctl.base
  2. 3 2
      utils/kamctl/kamctlrc

+ 15 - 10
utils/kamctl/kamctl.base

@@ -62,14 +62,19 @@ if [ -z "$GDB" ] ; then
 		GDB="$TOOLPATH"
 		GDB="$TOOLPATH"
 	fi
 	fi
 fi
 fi
-if [ -z "$MD5" ]; then
-	locate_tool md5sum md5
-	if [ -z "$TOOLPATH" ] ; then
-		# now error, but we can look for alternative names if it is the case
-		echo "error: 'md5sum' or 'md5' tool not found: set MD5 variable to correct tool path"
-		exit
+if [ -z "$CMDHASH" ]; then
+	if [ -z "$MD5" ]; then
+		locate_tool md5sum md5
+		if [ -z "$TOOLPATH" ] ; then
+			# now error, but we can look for alternative names if it is the case
+			echo "error: 'md5sum' or 'md5' tool not found: set CMDHASH variable to correct tool path"
+			exit
+		fi
+		CMDHASH="$TOOLPATH"
+	else
+		# handle old variable setting md5 tool
+		CMDHASH="$MD5"
 	fi
 	fi
-	MD5="$TOOLPATH"
 fi
 fi
 if [ -z "$LAST_LINE" ] ; then
 if [ -z "$LAST_LINE" ] ; then
 	locate_tool tail
 	locate_tool tail
@@ -777,7 +782,7 @@ filter_json()
 # output: HA1
 # output: HA1
 _gen_ha1()
 _gen_ha1()
 {
 {
-	HA1=`echo -n "$1:$2:$3" | $MD5 | $AWK '{ print $1 }'`
+	HA1=`echo -n "$1:$2:$3" | $CMDHASH | $AWK '{ print $1 }'`
 	if [ $? -ne 0 ] ; then
 	if [ $? -ne 0 ] ; then
 		echo "HA1 calculation failed"
 		echo "HA1 calculation failed"
 		exit 1
 		exit 1
@@ -788,7 +793,7 @@ _gen_ha1()
 # output: HA1B
 # output: HA1B
 _gen_ha1b()
 _gen_ha1b()
 {
 {
-	HA1B=`echo -n "$1@$2:$2:$3" | $MD5 | $AWK '{ print $1 }'`
+	HA1B=`echo -n "$1@$2:$2:$3" | $CMDHASH | $AWK '{ print $1 }'`
 	if [ $? -ne 0 ] ; then
 	if [ $? -ne 0 ] ; then
 		echo "HA1B calculation failed"
 		echo "HA1B calculation failed"
 		exit 1
 		exit 1
@@ -800,7 +805,7 @@ _gen_ha1b()
 _gen_phplib_id()
 _gen_phplib_id()
 {
 {
 	NOW=`date`;
 	NOW=`date`;
-	PHPLIB_ID=`echo -n "$1$2:$3:$NOW" | $MD5 | $AWK '{ print $1 }'`
+	PHPLIB_ID=`echo -n "$1$2:$3:$NOW" | $CMDHASH | $AWK '{ print $1 }'`
 }
 }
 
 
 # params: user, password
 # params: user, password

+ 3 - 2
utils/kamctl/kamctlrc

@@ -79,8 +79,9 @@
 # DEFAULT_Q="1.0"
 # DEFAULT_Q="1.0"
 
 
 
 
-## Program to calculate a message-digest fingerprint
-# MD5="md5sum"
+## Program to calculate the MD5/SHA256 message-digest fingerprint
+# - md5sum, sha256sum
+# CMDHASH="md5sum"
 
 
 ## awk tool
 ## awk tool
 # AWK="awk"
 # AWK="awk"