mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] openssh: improve rc.once script to support locations other than /etc/ssh
@ 2013-12-18 15:13 Uwe Kleine-König
  2014-01-06 11:07 ` Michael Olbrich
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2013-12-18 15:13 UTC (permalink / raw)
  To: ptxdist

This is done by parsing the sshd_config using awk for the location of
the key files being used.

Note that the dependency on awk is a weak one because if awk isn't
available the script simply falls back to the default location.

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

diff --git a/generic/etc/rc.once.d/openssh b/generic/etc/rc.once.d/openssh
index 83e6e37..fea8472 100644
--- a/generic/etc/rc.once.d/openssh
+++ b/generic/etc/rc.once.d/openssh
@@ -2,13 +2,15 @@
 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
-OPENSSH_RSAKEY_DEFAULT="/etc/ssh/ssh_host_rsa_key"
-OPENSSH_DSAKEY_DEFAULT="/etc/ssh/ssh_host_dsa_key"
+get_default_key() {
+	key_type=$1
+	sshd_config="/etc/ssh/sshd_config"
+
+	awk -v type="$key_type" '/^HostKey/ && match($2, "/ssh_host_" type "_key$") { print $2; found=1 } END { exit !found }' "$sshd_config" || echo "/etc/ssh/ssh_host_${key_type}_key"
+}
 
-test -n "$OPENSSH_RSAKEY" || \
-	OPENSSH_RSAKEY=$OPENSSH_RSAKEY_DEFAULT
-test -n "$OPENSSH_DSAKEY" || \
-	OPENSSH_DSAKEY=$OPENSSH_DSAKEY_DEFAULT
+OPENSSH_RSAKEY="$(get_default_key rsa)"
+OPENSSH_DSAKEY="$(get_default_key dsa)"
 
 gen_key() {
 
-- 
1.8.4.4


-- 
ptxdist mailing list
ptxdist@pengutronix.de

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

end of thread, other threads:[~2014-01-06 11:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-18 15:13 [ptxdist] [PATCH] openssh: improve rc.once script to support locations other than /etc/ssh Uwe Kleine-König
2014-01-06 11:07 ` Michael Olbrich

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