mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] openssh/rc-once: deduplicate some function parameters
@ 2020-08-07  9:16 Uwe Kleine-König
  2020-08-07 12:41 ` Michael Olbrich
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2020-08-07  9:16 UTC (permalink / raw)
  To: ptxdist

The create_keys() function passed the key type three times. Now it's
only passed once. While at it also use the shell builtin case instead of
echo | grep to find the needed keys.

The only visible change is that the end message message changes from

	Creating RSA key; done.

to

	Created RSA key.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

I noticed this "triplication" while updating a BSP and merging in some
BSP specific features. I guess it is subjective if you consider this an
improvement, so judge freely if you want it in ptxdist or not.

Best regards
Uwe

 projectroot/etc/rc.once.d/openssh | 35 +++++++++++++++++--------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
index 4a3c594cc3ae..813e7c620e49 100644
--- a/projectroot/etc/rc.once.d/openssh
+++ b/projectroot/etc/rc.once.d/openssh
@@ -18,32 +18,35 @@ host_keys_required() {
 }
 
 create_key() {
-	msg="$1"
+	_type="$1"
+	prettytype="$(echo $_type | tr a-z A-Z)"
 	shift
 	hostkeys="$1"
 	shift
-	file="$1"
-	shift
 
-	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
-		echo "$msg; this may take some time ..."
+	file="/etc/ssh/ssh_host_${_type}_key"
+
+	case "
+$hostkeys
+" in
+	*"
+$file
+"*)
+		echo "Create $prettytype key; this may take some time ..."
 		rm -f $file &&
-		ssh-keygen -q -f "$file" -N '' "$@" || return
-		echo "$msg; done."
-	fi
+		ssh-keygen -q -f "$file" -N '' -t "$_type" "$@" || return
+		echo "Created $prettytype key."
+		;;
+	esac
 }
 
 create_keys() {
 	hostkeys="$(host_keys_required)"
 
-	create_key "Creating DSA key" \
-		"$hostkeys" /etc/ssh/ssh_host_dsa_key -t dsa &&
-	create_key "Creating ECDSA key" \
-		"$hostkeys" /etc/ssh/ssh_host_ecdsa_key -t ecdsa &&
-	create_key "Creating ED25519 key" \
-		"$hostkeys" /etc/ssh/ssh_host_ed25519_key -t ed25519 &&
-	create_key "Creating RSA key" \
-		"$hostkeys" /etc/ssh/ssh_host_rsa_key -t rsa -b 4096
+	create_key "dsa" "$hostkeys" &&
+	create_key "ecdsa" "$hostkeys" &&
+	create_key "ed25519" "$hostkeys" &&
+	create_key "rsa" "$hostkeys" -b 4096
 }
 
 if ! create_keys; then
-- 
2.28.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de
To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ptxdist] [PATCH] openssh/rc-once: deduplicate some function parameters
  2020-08-07  9:16 [ptxdist] [PATCH] openssh/rc-once: deduplicate some function parameters Uwe Kleine-König
@ 2020-08-07 12:41 ` Michael Olbrich
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Olbrich @ 2020-08-07 12:41 UTC (permalink / raw)
  To: ptxdist

On Fri, Aug 07, 2020 at 11:16:04AM +0200, Uwe Kleine-König wrote:
> The create_keys() function passed the key type three times. Now it's
> only passed once. While at it also use the shell builtin case instead of
> echo | grep to find the needed keys.
> 
> The only visible change is that the end message message changes from
> 
> 	Creating RSA key; done.
> 
> to
> 
> 	Created RSA key.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> I noticed this "triplication" while updating a BSP and merging in some
> BSP specific features. I guess it is subjective if you consider this an
> improvement, so judge freely if you want it in ptxdist or not.
> 
> Best regards
> Uwe
> 
>  projectroot/etc/rc.once.d/openssh | 35 +++++++++++++++++--------------
>  1 file changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
> index 4a3c594cc3ae..813e7c620e49 100644
> --- a/projectroot/etc/rc.once.d/openssh
> +++ b/projectroot/etc/rc.once.d/openssh
> @@ -18,32 +18,35 @@ host_keys_required() {
>  }
>  
>  create_key() {
> -	msg="$1"
> +	_type="$1"
> +	prettytype="$(echo $_type | tr a-z A-Z)"
>  	shift
>  	hostkeys="$1"
>  	shift
> -	file="$1"
> -	shift
>  
> -	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
> -		echo "$msg; this may take some time ..."
> +	file="/etc/ssh/ssh_host_${_type}_key"
> +
> +	case "
> +$hostkeys
> +" in
> +	*"
> +$file
> +"*)

This looks quite strange. Maybe:

	case " $(echo $hostkeys) " in
	*" $file "*)

Michael

> +		echo "Create $prettytype key; this may take some time ..."
>  		rm -f $file &&
> -		ssh-keygen -q -f "$file" -N '' "$@" || return
> -		echo "$msg; done."
> -	fi
> +		ssh-keygen -q -f "$file" -N '' -t "$_type" "$@" || return
> +		echo "Created $prettytype key."
> +		;;
> +	esac
>  }
>  
>  create_keys() {
>  	hostkeys="$(host_keys_required)"
>  
> -	create_key "Creating DSA key" \
> -		"$hostkeys" /etc/ssh/ssh_host_dsa_key -t dsa &&
> -	create_key "Creating ECDSA key" \
> -		"$hostkeys" /etc/ssh/ssh_host_ecdsa_key -t ecdsa &&
> -	create_key "Creating ED25519 key" \
> -		"$hostkeys" /etc/ssh/ssh_host_ed25519_key -t ed25519 &&
> -	create_key "Creating RSA key" \
> -		"$hostkeys" /etc/ssh/ssh_host_rsa_key -t rsa -b 4096
> +	create_key "dsa" "$hostkeys" &&
> +	create_key "ecdsa" "$hostkeys" &&
> +	create_key "ed25519" "$hostkeys" &&
> +	create_key "rsa" "$hostkeys" -b 4096
>  }
>  
>  if ! create_keys; then
> -- 
> 2.28.0
> 
> 
> _______________________________________________
> ptxdist mailing list
> ptxdist@pengutronix.de
> To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de
To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-07 12:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07  9:16 [ptxdist] [PATCH] openssh/rc-once: deduplicate some function parameters Uwe Kleine-König
2020-08-07 12:41 ` Michael Olbrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox