Skip to contentSkip to conversation

busybox: add support for command openvt/passwd/pidof/ping/ps/pwd

PATCH Superseded Wang Mingyu 2 participants 2 messages Jul 30, 2018 – Aug 1, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 busybox: add support for command openvt/passwd/pidof/ping/ps/pwd

---
 .../Functional.busybox/tests/busybox_openvt.sh     | 25 ++++++++++++++++
 .../Functional.busybox/tests/busybox_passwd.sh     | 34 ++++++++++++++++++++++
 .../Functional.busybox/tests/busybox_pidof.sh      | 15 ++++++++++
 .../tests/Functional.busybox/tests/busybox_ping.sh | 22 ++++++++++++++
 .../tests/Functional.busybox/tests/busybox_ps.sh   | 13 +++++++++
 .../tests/Functional.busybox/tests/busybox_pwd.sh  | 13 +++++++++
 6 files changed, 122 insertions(+)
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_openvt.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_passwd.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_pidof.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ping.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ps.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_pwd.sh
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +25 -0
new file mode 100644
index 0000000..c596569
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command openvt
+#  1) Option none
+
+test="openvt"
+
+killall sleep
+busybox openvt -f -c 2 sleep 15000
+if ps aux | grep sleep | grep -v grep | grep ".*sleep 15000"
+then
+    echo " -> $test: ps aux | grep sleep | grep -v grep executed."
+else
+    echo " -> $test: ps aux | grep sleep | grep -v grep failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi;
+
+killall sleep
+if ps aux | grep sleep | grep -v grep | grep ".*sleep.*"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +34 -0
new file mode 100644
index 0000000..e383f56
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command passwd
+#  1) Option none
+
+test="passwd"
+
+if [ -e /etc/shadow ]
+then
+    cp /etc/shadow /etc/shadow.backup
+fi
+
+userdel -r test_busybox_passwd
+ls /
+useradd test_busybox_passwd
+
+expect <<-EOF
+spawn busybox.suid passwd test_busybox_passwd
+expect "New password:"
+send_user " -> $test: busybox.suid passwd test_busybox_passwd executed.\n"
+send "test123\r"
+expect "Retype password:"
+send_user " -> $test: retype passwd executed.\n"
+send "test123\r"
+expect "Password for test_busybox_passwd changed by root"
+send_user " -> $test: TEST-PASS\n"
+expect eof
+EOF
+
+userdel -r test_busybox_passwd
+if [ -e /etc/shadow.backup ]
+then
+    mv -f /etc/shadow.backup /etc/shadow
+fi
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +15 -0
new file mode 100644
index 0000000..838864c
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pidof
+#  1) Option none
+
+test="pidof"
+
+busybox pidof `ps -e | awk '{if($1 == 1) print $4}'`
+
+if busybox pidof xyz || echo fail
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +22 -0
new file mode 100644
index 0000000..289f265
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ping
+#  1) Option none
+
+test="ping"
+
+busybox.suid ping -c 2 $IPADDR > log
+log1=$(head -n 1 log)
+log2=$(head -n 2 log | head -n 1)
+log3=$(tail -n 1 log)
+pair1="PING"
+pair2="seq=0."
+pair3="seq=0."
+
+if [[ $log1 = *$pari1* ]] && [[ $log2 = *$pari2* ]] && [[ $log3 = *$pari3* ]]
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log;
engine/tests/Functional.busybox/tests/busybox_ps.sh new file +13 -0
new file mode 100644
index 0000000..1dfe4e4
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ps
+#  1) Option none
+
+test="ps"
+
+if busybox ps | grep -v grep | grep "busybox ps"
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_pwd.sh new file +13 -0
new file mode 100644
index 0000000..a0034df
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pwd
+#  1) Option none
+
+test="pwd"
+
+if busybox pwd
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 33 lines

-----Original Message-----
From: Wang Mingyu

---
 .../Functional.busybox/tests/busybox_openvt.sh     | 25
++++++++++++++++
 .../Functional.busybox/tests/busybox_passwd.sh     | 34
++++++++++++++++++++++
 .../Functional.busybox/tests/busybox_pidof.sh      | 15 ++++++++++
 .../tests/Functional.busybox/tests/busybox_ping.sh | 22 ++++++++++++++
 .../tests/Functional.busybox/tests/busybox_ps.sh   | 13 +++++++++
 .../tests/Functional.busybox/tests/busybox_pwd.sh  | 13 +++++++++
 6 files changed, 122 insertions(+)
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_openvt.sh
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_passwd.sh
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_pidof.sh
 create mode 100644
engine/tests/Functional.busybox/tests/busybox_ping.sh
 create mode 100644 engine/tests/Functional.busybox/tests/busybox_ps.sh
 create mode 100644

engine/tests/Functional.busybox/tests/busybox_pwd.sh

engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +0 -0
new file mode 100644
index 0000000..c596569

engine/tests/Functional.busybox/tests/busybox_openvt.sh line 10

Quoted 10 lines
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +10 -0
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command openvt
+#  1) Option none
+
+test="openvt"
+
+killall sleep
+busybox openvt -f -c 2 sleep 15000
+if ps aux | grep sleep | grep -v grep | grep ".*sleep 15000"

This will work as is, but can be optimized.

There's a trick you can use to avoid seeing the 'grep' line when grepping 'ps' output. The trick is to use regular expression syntax that doesn't match itself. The following is simpler and faster than what you have above.

if ps aux | grep "[s]leep 15000"

engine/tests/Functional.busybox/tests/busybox_openvt.sh line 12

Quoted 2 lines
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +2 -0
+then
+    echo " -> $test: ps aux | grep sleep | grep -v grep executed."

If you remove the grep -v, then this line should change.

engine/tests/Functional.busybox/tests/busybox_openvt.sh line 14

Quoted 2 lines
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +2 -0
+else
+    echo " -> $test: ps aux | grep sleep | grep -v grep failed."

if you remove the grep -v, then this line should change.

engine/tests/Functional.busybox/tests/busybox_openvt.sh line 19

Quoted 5 lines
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +5 -0
+    echo " -> $test: TEST-FAIL"
+    exit
+fi;
+
+killall sleep

Whoah! This is dangerous. there might be something else using sleep on the system, if the system is in a production configuration, or there are other tests, monitors, tracers, or load-generators running. It would be better to parse the process id for the sleep that is going for 15000 seconds (and maybe use a weird value for seconds, so it's unique in the system - like say, 15753 seconds), and only kill that id.

Quoted 20 lines
engine/tests/Functional.busybox/tests/busybox_openvt.sh new file +6 -0
+if ps aux | grep sleep | grep -v grep | grep ".*sleep.*"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi;
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +7 -0
new file mode 100644
index 0000000..e383f56
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command passwd
+#  1) Option none
+
+test="passwd"
+

engine/tests/Functional.busybox/tests/busybox_passwd.sh line 17

Quoted 10 lines
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +10 -0
+if [ -e /etc/shadow ]
+then
+    cp /etc/shadow /etc/shadow.backup
+fi
+
+userdel -r test_busybox_passwd
+ls /
+useradd test_busybox_passwd
+
+expect <<-EOF

This test should be added to the list for "skip_if_comamnd_unavailable expect ..." in fuego_test.sh

Quoted 7 lines
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +3 -0
+spawn busybox.suid passwd test_busybox_passwd
+expect "New password:"
+send_user " -> $test: busybox.suid passwd test_busybox_passwd

executed.\n"

engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +3 -0
+send "test123\r"
+expect "Retype password:"
+send_user " -> $test: retype passwd executed.\n"

engine/tests/Functional.busybox/tests/busybox_passwd.sh line 33

Quoted 10 lines
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +10 -0
+send "test123\r"
+expect "Password for test_busybox_passwd changed by root"
+send_user " -> $test: TEST-PASS\n"
+expect eof
+EOF
+
+userdel -r test_busybox_passwd
+if [ -e /etc/shadow.backup ]
+then
+    mv -f /etc/shadow.backup /etc/shadow

This requires root privileges. This test should be added to the list for "skip_if_not_root" in fuego_test.sh

Quoted 8 lines
engine/tests/Functional.busybox/tests/busybox_passwd.sh new file +1 -0
+fi
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +0 -0
new file mode 100644
index 0000000..838864c

engine/tests/Functional.busybox/tests/busybox_pidof.sh line 8

Quoted 8 lines
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +8 -0
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pidof
+#  1) Option none
+
+test="pidof"
+
+busybox pidof `ps -e | awk '{if($1 == 1) print $4}'`

Can we use something besides awk here to parse the command name for process 1. Maybe cut -b?
In my experience, awk is often missing from embedded projects.

engine/tests/Functional.busybox/tests/busybox_pidof.sh line 10

Quoted 2 lines
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +2 -0
+
+if busybox pidof xyz || echo fail

I don't see how this can ever fail.
The if will use the exit code of the last command executed, which in this case is "echo", which pretty much always succeeds (returns 0).

This needs to be restructured.

Quoted 18 lines
engine/tests/Functional.busybox/tests/busybox_pidof.sh new file +5 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +6 -0
new file mode 100644
index 0000000..289f265
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ping
+#  1) Option none
+
+test="ping"

engine/tests/Functional.busybox/tests/busybox_ping.sh line 16

Quoted 10 lines
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +10 -0
+
+busybox.suid ping -c 2 $IPADDR > log
+log1=$(head -n 1 log)
+log2=$(head -n 2 log | head -n 1)
+log3=$(tail -n 1 log)
+pair1="PING"
+pair2="seq=0."
+pair3="seq=0."
+
+if [[ $log1 = *$pari1* ]] && [[ $log2 = *$pari2* ]] && [[ $log3 = *$pari3* ]]

"pair" is misspelled here.

Using [[ and wildcard matching is a bash-ism that should be removed. Please replace this with 'grep' or some other mechanism.

Quoted 13 lines
engine/tests/Functional.busybox/tests/busybox_ping.sh new file +6 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
+rm log;
engine/tests/Functional.busybox/tests/busybox_ps.sh new file +0 -0
new file mode 100644
index 0000000..1dfe4e4

engine/tests/Functional.busybox/tests/busybox_ps.sh line 8

Quoted 8 lines
engine/tests/Functional.busybox/tests/busybox_ps.sh new file +8 -0
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command ps
+#  1) Option none
+
+test="ps"
+
+if busybox ps | grep -v grep | grep "busybox ps"

This can be simplified to:
if busybox ps | grep "[b]usybox ps"

Quoted 26 lines
engine/tests/Functional.busybox/tests/busybox_ps.sh new file +5 -0
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
engine/tests/Functional.busybox/tests/busybox_pwd.sh new file +13 -1
new file mode 100644
index 0000000..a0034df
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  The testscript checks the following options of the command pwd
+#  1) Option none
+
+test="pwd"
+
+if busybox pwd
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi;
--
Quoted 1 line

1.8.3.1

Thanks for the submission!

Please fix the issues listed above and resubmit.
-- Tim