Skip to contentSkip to conversation

package/dropbear: Fix symlink only if pointing to the right directory

PATCH New Paul Cercueil 3 participants 3 messages Jul 28, 2015 – Jul 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 package/dropbear: Fix symlink only if pointing to the right directory

This commit ensures that the /etc/dropbear symlink won't be removed if it points elsewhere than /var/run/dropbear.

---

v2: Use "readlink -f", as the symbolic link might be pointing to a relative path and not an absolute path.

 package/dropbear/S50dropbear      | 6 ++++--
 package/dropbear/dropbear.service | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
package/dropbear/S50dropbear +4 -2
index af50ccf..f551677 100644
@@ -12,12 +12,14 @@ start() {
 	echo -n "Starting dropbear sshd: "
 	umask 077
 
-	# If /etc/dropbear is not a directory, and
+	# If /etc/dropbear is a symlink to /var/run/dropbear, and
 	#   - the filesystem is RO (i.e. we can not rm the symlink),
 	#     create the directory pointed to by the symlink.
 	#   - the filesystem is RW (i.e. we can rm the symlink),
 	#     replace the symlink with an actual directory
-	if ! [ -d /etc/dropbear ]; then
+	if [ -L /etc/dropbear \
+		-a "$(readlink -f /etc/dropbear)" = "/var/run/dropbear" ]
+	then
 		if rm -f /etc/dropbear; then
 			mkdir -p /etc/dropbear
 		else
package/dropbear/dropbear.service +2 -2
index 0e2cf54..f1d4d5d 100644
@@ -3,13 +3,13 @@ Description=Dropbear SSH daemon
 After=syslog.target network.target auditd.service
 
 [Service]
-# If /etc/dropbear is not a directory, and
+# If /etc/dropbear is a symlink to /var/run/dropbear, and
 #   - the filesystem is RO (i.e. we can not rm the symlink),
 #     create the directory pointed to by the symlink.
 #   - the filesystem is RW (i.e. we can rm the symlink),
 #     replace the symlink with an actual directory
 ExecStartPre=/bin/sh -c '\
-if ! [ -d /etc/dropbear ]; then \
+if [ -L /etc/dropbear -a "$(readlink -f /etc/dropbear)" = "/var/run/dropbear" ]; then \
     if rm -f /etc/dropbear; then \
         mkdir -p /etc/dropbear; \
     else \
Signature · 1 line
2.4.6
#1 lore raw

PATCH v2 1/1 package/dropbear: Fix symlink only if pointing to the right directory

Paul, All,

On 2015-07-28 10:21 +0200, Paul Cercueil spake thusly:

Quoted 20 lines

This commit ensures that the /etc/dropbear symlink won't be removed if it points elsewhere than /var/run/dropbear.

---

v2: Use "readlink -f", as the symbolic link might be pointing to a relative path and not an absolute path.

 package/dropbear/S50dropbear      | 6 ++++--
 package/dropbear/dropbear.service | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
package/dropbear/S50dropbear +0 -0
index af50ccf..f551677 100644
@@ -12,12 +12,14 @@ start() {
 	echo -n "Starting dropbear sshd: "
 	umask 077

package/dropbear/S50dropbear start() { · line 21

Quoted 10 lines
package/dropbear/S50dropbear +3 -2
 
-	# If /etc/dropbear is not a directory, and
+	# If /etc/dropbear is a symlink to /var/run/dropbear, and
 	#   - the filesystem is RO (i.e. we can not rm the symlink),
 	#     create the directory pointed to by the symlink.
 	#   - the filesystem is RW (i.e. we can rm the symlink),
 	#     replace the symlink with an actual directory
-	if ! [ -d /etc/dropbear ]; then
+	if [ -L /etc/dropbear \
+		-a "$(readlink -f /etc/dropbear)" = "/var/run/dropbear" ]

Indentation here is a bit too much, I'd line up the '-a' below the '-L'.

Quoted 11 lines
package/dropbear/S50dropbear +1 -0
+	then
 		if rm -f /etc/dropbear; then
 			mkdir -p /etc/dropbear
 		else
package/dropbear/dropbear.service +0 -0
index 0e2cf54..f1d4d5d 100644
@@ -3,13 +3,13 @@ Description=Dropbear SSH daemon
 After=syslog.target network.target auditd.service
 

package/dropbear/dropbear.service Description=Dropbear SSH daemon · line 12

Quoted 10 lines
package/dropbear/dropbear.service +2 -2
 [Service]
-# If /etc/dropbear is not a directory, and
+# If /etc/dropbear is a symlink to /var/run/dropbear, and
 #   - the filesystem is RO (i.e. we can not rm the symlink),
 #     create the directory pointed to by the symlink.
 #   - the filesystem is RW (i.e. we can rm the symlink),
 #     replace the symlink with an actual directory
 ExecStartPre=/bin/sh -c '\
-if ! [ -d /etc/dropbear ]; then \
+if [ -L /etc/dropbear -a "$(readlink -f /etc/dropbear)" = "/var/run/dropbear" ]; then \

It would be good here to keep the lines short, too.

Otherwise, I'm OK; once you fix this (or the maintainer applies this, you can add my:

Regards,
Yann E. MORIN.

Quoted 10 lines
package/dropbear/dropbear.service +0 -0
     if rm -f /etc/dropbear; then \
         mkdir -p /etc/dropbear; \
     else \
Signature · 6 lines
2.4.6

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH v2 1/1 package/dropbear: Fix symlink only if pointing to the right directory

In reply to Paul Cercueil

Dear Paul Cercueil,

Quoted 5 lines · Paul Cercueil

This commit ensures that the /etc/dropbear symlink won't be removed if it points elsewhere than /var/run/dropbear.

---

Applied after fixing the issues pointed by Yann.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com