mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH v2 1/2] openssh/rc-once: deduplicate some data
@ 2020-08-08  8:34 Uwe Kleine-König
  2020-08-08  8:34 ` [ptxdist] [PATCH v2 2/2] openssh/rc-once: use fixed string grep to match filename Uwe Kleine-König
  2020-08-17  6:18 ` [ptxdist] [APPLIED] openssh/rc-once: deduplicate some data Michael Olbrich
  0 siblings, 2 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2020-08-08  8:34 UTC (permalink / raw)
  To: ptxdist

The create_keys() function passed the key type three times. Now it's
only passed once.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 projectroot/etc/rc.once.d/openssh | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
index 4a3c594cc3ae..bfec7064181a 100644
--- a/projectroot/etc/rc.once.d/openssh
+++ b/projectroot/etc/rc.once.d/openssh
@@ -18,32 +18,29 @@ host_keys_required() {
 }
 
 create_key() {
-	msg="$1"
+	keytype="$1"
+	prettykeytype="$(echo $_type | tr a-z A-Z)"
 	shift
 	hostkeys="$1"
 	shift
-	file="$1"
-	shift
+
+	file="/etc/ssh/ssh_host_${keytype}_key"
 
 	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
-		echo "$msg; this may take some time ..."
+		echo "Create $prettykeytype key; this may take some time ..."
 		rm -f $file &&
-		ssh-keygen -q -f "$file" -N '' "$@" || return
-		echo "$msg; done."
+		ssh-keygen -q -f "$file" -N '' -t "$keytype" "$@" || return
+		echo "Created $prettykeytype key."
 	fi
 }
 
 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] 4+ messages in thread

* [ptxdist] [PATCH v2 2/2] openssh/rc-once: use fixed string grep to match filename
  2020-08-08  8:34 [ptxdist] [PATCH v2 1/2] openssh/rc-once: deduplicate some data Uwe Kleine-König
@ 2020-08-08  8:34 ` Uwe Kleine-König
  2020-08-17  6:18   ` [ptxdist] [APPLIED] " Michael Olbrich
  2020-08-17  6:18 ` [ptxdist] [APPLIED] openssh/rc-once: deduplicate some data Michael Olbrich
  1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2020-08-08  8:34 UTC (permalink / raw)
  To: ptxdist

This is a (very) minor optimisation. There is no semantical change as
the fixed list of possible filenames doesn't contain anything that has a
different meaning when interpreted as a regex, still I consider it
better style to interpret the filename as a fixed string to match.

Both busybox and the "big" grep support -F unconditionally so there is
no problem in using -F.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 projectroot/etc/rc.once.d/openssh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
index bfec7064181a..66cfa06df12a 100644
--- a/projectroot/etc/rc.once.d/openssh
+++ b/projectroot/etc/rc.once.d/openssh
@@ -26,7 +26,7 @@ create_key() {
 
 	file="/etc/ssh/ssh_host_${keytype}_key"
 
-	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
+	if echo "$hostkeys" | grep -x -F "$file" >/dev/null; then
 		echo "Create $prettykeytype key; this may take some time ..."
 		rm -f $file &&
 		ssh-keygen -q -f "$file" -N '' -t "$keytype" "$@" || return
-- 
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] 4+ messages in thread

* Re: [ptxdist] [APPLIED] openssh/rc-once: deduplicate some data
  2020-08-08  8:34 [ptxdist] [PATCH v2 1/2] openssh/rc-once: deduplicate some data Uwe Kleine-König
  2020-08-08  8:34 ` [ptxdist] [PATCH v2 2/2] openssh/rc-once: use fixed string grep to match filename Uwe Kleine-König
@ 2020-08-17  6:18 ` Michael Olbrich
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Olbrich @ 2020-08-17  6:18 UTC (permalink / raw)
  To: ptxdist; +Cc: u.kleine-koenig

Thanks, applied as 0a4f1ee4ed231a4e95dad545ba52ed2679e122ec.

Michael

[sent from post-receive hook]

On Mon, 17 Aug 2020 08:18:25 +0200, Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> The create_keys() function passed the key type three times. Now it's
> only passed once.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Message-Id: <20200808083456.26483-1-u.kleine-koenig@pengutronix.de>
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
> index 4a3c594cc3ae..bfec7064181a 100644
> --- a/projectroot/etc/rc.once.d/openssh
> +++ b/projectroot/etc/rc.once.d/openssh
> @@ -18,32 +18,29 @@ host_keys_required() {
>  }
>  
>  create_key() {
> -	msg="$1"
> +	keytype="$1"
> +	prettykeytype="$(echo $_type | tr a-z A-Z)"
>  	shift
>  	hostkeys="$1"
>  	shift
> -	file="$1"
> -	shift
> +
> +	file="/etc/ssh/ssh_host_${keytype}_key"
>  
>  	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
> -		echo "$msg; this may take some time ..."
> +		echo "Create $prettykeytype key; this may take some time ..."
>  		rm -f $file &&
> -		ssh-keygen -q -f "$file" -N '' "$@" || return
> -		echo "$msg; done."
> +		ssh-keygen -q -f "$file" -N '' -t "$keytype" "$@" || return
> +		echo "Created $prettykeytype key."
>  	fi
>  }
>  
>  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

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

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

* Re: [ptxdist] [APPLIED] openssh/rc-once: use fixed string grep to match filename
  2020-08-08  8:34 ` [ptxdist] [PATCH v2 2/2] openssh/rc-once: use fixed string grep to match filename Uwe Kleine-König
@ 2020-08-17  6:18   ` Michael Olbrich
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Olbrich @ 2020-08-17  6:18 UTC (permalink / raw)
  To: ptxdist; +Cc: u.kleine-koenig

Thanks, applied as 99931412f758783a6d27bd8df3119bb3ce1e0aa6.

Michael

[sent from post-receive hook]

On Mon, 17 Aug 2020 08:18:25 +0200, Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> This is a (very) minor optimisation. There is no semantical change as
> the fixed list of possible filenames doesn't contain anything that has a
> different meaning when interpreted as a regex, still I consider it
> better style to interpret the filename as a fixed string to match.
> 
> Both busybox and the "big" grep support -F unconditionally so there is
> no problem in using -F.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Message-Id: <20200808083456.26483-2-u.kleine-koenig@pengutronix.de>
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
> index bfec7064181a..66cfa06df12a 100644
> --- a/projectroot/etc/rc.once.d/openssh
> +++ b/projectroot/etc/rc.once.d/openssh
> @@ -26,7 +26,7 @@ create_key() {
>  
>  	file="/etc/ssh/ssh_host_${keytype}_key"
>  
> -	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
> +	if echo "$hostkeys" | grep -x -F "$file" >/dev/null; then
>  		echo "Create $prettykeytype key; this may take some time ..."
>  		rm -f $file &&
>  		ssh-keygen -q -f "$file" -N '' -t "$keytype" "$@" || return

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

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

end of thread, other threads:[~2020-08-17  6:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-08  8:34 [ptxdist] [PATCH v2 1/2] openssh/rc-once: deduplicate some data Uwe Kleine-König
2020-08-08  8:34 ` [ptxdist] [PATCH v2 2/2] openssh/rc-once: use fixed string grep to match filename Uwe Kleine-König
2020-08-17  6:18   ` [ptxdist] [APPLIED] " Michael Olbrich
2020-08-17  6:18 ` [ptxdist] [APPLIED] openssh/rc-once: deduplicate some data Michael Olbrich

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