[v2] sshd-regen-keys: do not enable ssh server if previously disabled

Message ID 20210224134145.31094-1-Quirin.Gylstorff@siemens.com
State Superseded, archived
Headers show
Series [v2] sshd-regen-keys: do not enable ssh server if previously disabled | expand

Commit Message

Quirin Gylstorff Feb. 24, 2021, 3:41 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

The code 'test -n $SSHD_ENABLED' always returns "0" and enables ssh
even if deactivated previously.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
Changes V2:
add missing space
 meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Henning Schild Feb. 24, 2021, 10:26 a.m. UTC | #1
Am Wed, 24 Feb 2021 14:41:45 +0100
schrieb "[ext] Q. Gylstorff" <Quirin.Gylstorff@siemens.com>:

> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> The code 'test -n $SSHD_ENABLED' always returns "0" and enables ssh
> even if deactivated previously.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
> Changes V2:
> add missing space
>  meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
> b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh index
> 910d879..50f45eb 100644 ---
> a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh +++
> b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh @@
> -12,7 +12,7 @@ rm -v /etc/ssh/ssh_host_*_key* echo "Regenerating keys
> ..." dpkg-reconfigure openssh-server 
> -if test -n $SSHD_ENABLED; then
> +if [ -n "$SSHD_ENABLED" ]; then

Not sure i understand that. But i guess 'test -n "$SSHD_ENABLED"' would
also work, so we are looking at a quoting problem and the whole [] is
just syntactic sugar.

Sugar i would approve, just asking.

Henning

>      echo "Reenabling ssh server ..."
>      systemctl enable --no-reload ssh
>  fi
Henning Schild Feb. 24, 2021, 10:32 a.m. UTC | #2
Am Wed, 24 Feb 2021 21:26:12 +0100
schrieb "[ext] Henning Schild" <henning.schild@siemens.com>:

> Am Wed, 24 Feb 2021 14:41:45 +0100
> schrieb "[ext] Q. Gylstorff" <Quirin.Gylstorff@siemens.com>:
> 
> > From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> > 
> > The code 'test -n $SSHD_ENABLED' always returns "0" and enables ssh
> > even if deactivated previously.
> > 
> > Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> > ---
> > Changes V2:
> > add missing space
> >  meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh | 2
> > +- 1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git
> > a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
> > b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
> > index 910d879..50f45eb 100644 ---
> > a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh +++
> > b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh @@
> > -12,7 +12,7 @@ rm -v /etc/ssh/ssh_host_*_key* echo "Regenerating
> > keys ..." dpkg-reconfigure openssh-server 
> > -if test -n $SSHD_ENABLED; then
> > +if [ -n "$SSHD_ENABLED" ]; then  
> 
> Not sure i understand that. But i guess 'test -n "$SSHD_ENABLED"'
> would also work, so we are looking at a quoting problem and the whole
> [] is just syntactic sugar.
> 
> Sugar i would approve, just asking.

If it is all about quoting, maybe the commit message can be improved to
reflect that.

Henning

> Henning
> 
> >      echo "Reenabling ssh server ..."
> >      systemctl enable --no-reload ssh
> >  fi  
>
Quirin Gylstorff Feb. 24, 2021, 9:36 p.m. UTC | #3
On 2/24/21 9:32 PM, Henning Schild wrote:
> Am Wed, 24 Feb 2021 21:26:12 +0100
> schrieb "[ext] Henning Schild" <henning.schild@siemens.com>:
> 
>> Am Wed, 24 Feb 2021 14:41:45 +0100
>> schrieb "[ext] Q. Gylstorff" <Quirin.Gylstorff@siemens.com>:
>>
>>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>
>>> The code 'test -n $SSHD_ENABLED' always returns "0" and enables ssh
>>> even if deactivated previously.
>>>
>>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>> ---
>>> Changes V2:
>>> add missing space
>>>   meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh | 2
>>> +- 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git
>>> a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
>>> b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
>>> index 910d879..50f45eb 100644 ---
>>> a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh +++
>>> b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh @@
>>> -12,7 +12,7 @@ rm -v /etc/ssh/ssh_host_*_key* echo "Regenerating
>>> keys ..." dpkg-reconfigure openssh-server
>>> -if test -n $SSHD_ENABLED; then
>>> +if [ -n "$SSHD_ENABLED" ]; then
>>
>> Not sure i understand that. But i guess 'test -n "$SSHD_ENABLED"'
>> would also work, so we are looking at a quoting problem and the whole
>> [] is just syntactic sugar.
>>
>> Sugar i would approve, just asking.
> 
> If it is all about quoting, maybe the commit message can be improved to
> reflect that.
> 
> Henning

It is a quoting problem.  I will add some text to the commit message and 
send a v3.

Quirin

> 
>> Henning
>>
>>>       echo "Reenabling ssh server ..."
>>>       systemctl enable --no-reload ssh
>>>   fi
>>
>

Patch

diff --git a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
index 910d879..50f45eb 100644
--- a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
+++ b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
@@ -12,7 +12,7 @@  rm -v /etc/ssh/ssh_host_*_key*
 echo "Regenerating keys ..."
 dpkg-reconfigure openssh-server
 
-if test -n $SSHD_ENABLED; then
+if [ -n "$SSHD_ENABLED" ]; then
     echo "Reenabling ssh server ..."
     systemctl enable --no-reload ssh
 fi