| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
set -u |
| 5 |
|
| 6 |
exec 2>&1 |
| 7 |
set -x |
| 8 |
|
| 9 |
failed= |
| 10 |
# An ordinary, unprivileged user |
| 11 |
user="${AUTOPKGTEST_NORMAL_USER:-nobody}" |
| 12 |
|
| 13 |
as_normal_user () { |
| 14 |
runuser -u "$user" -- "$@" |
| 15 |
} |
| 16 |
|
| 17 |
test -S /var/run/dbus/system_bus_socket || failed=1 |
| 18 |
test /run/dbus/system_bus_socket -ef /var/run/dbus/system_bus_socket || failed=1 |
| 19 |
getent passwd messagebus || failed=1 |
| 20 |
getent group messagebus || failed=1 |
| 21 |
|
| 22 |
if [ -d /run/systemd/system ]; then |
| 23 |
journalctl -f & |
| 24 |
journalctl_pid="$!" |
| 25 |
fi |
| 26 |
|
| 27 |
as_normal_user dbus-send --system --dest="org.freedesktop.DBus" \ |
| 28 |
--type=method_call --print-reply \ |
| 29 |
/org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect \ |
| 30 |
|| failed=1 |
| 31 |
|
| 32 |
as_normal_user dbus-send --system --dest="org.freedesktop.DBus" \ |
| 33 |
--type=method_call --print-reply \ |
| 34 |
/org/freedesktop/DBus org.freedesktop.DBus.ListNames \ |
| 35 |
|| failed=1 |
| 36 |
|
| 37 |
as_normal_user dbus-send --system --dest="org.freedesktop.DBus" \ |
| 38 |
--type=method_call --print-reply \ |
| 39 |
/org/freedesktop/DBus org.freedesktop.DBus.ListActivatableNames \ |
| 40 |
|| failed=1 |
| 41 |
|
| 42 |
if as_normal_user dbus-send --system --dest="org.freedesktop.DBus" \ |
| 43 |
--type=method_call --print-reply \ |
| 44 |
/org/freedesktop/DBus org.freedesktop.DBus.RequestName \ |
| 45 |
string:com.example.Nope uint32:0 \ |
| 46 |
; then |
| 47 |
set +x |
| 48 |
echo "Owning name com.example.Nope should not have been allowed" |
| 49 |
set -x |
| 50 |
failed=1 |
| 51 |
fi |
| 52 |
|
| 53 |
if dbus-send --system --dest="org.freedesktop.DBus" \ |
| 54 |
--type=method_call --print-reply \ |
| 55 |
/org/freedesktop/DBus org.freedesktop.DBus.RequestName \ |
| 56 |
string:com.example.Nope uint32:0 \ |
| 57 |
; then |
| 58 |
set +x |
| 59 |
echo "Owning name com.example.Nope should not have been allowed for root" |
| 60 |
set -x |
| 61 |
failed=1 |
| 62 |
fi |
| 63 |
|
| 64 |
dbus-send --system --dest="org.freedesktop.DBus" \ |
| 65 |
--type=method_call --print-reply \ |
| 66 |
/org/freedesktop/DBus org.freedesktop.DBus.Debug.Stats.GetStats \ |
| 67 |
|| failed=1 |
| 68 |
|
| 69 |
if as_normal_user dbus-send --system --dest="org.freedesktop.DBus" \ |
| 70 |
--type=method_call --print-reply \ |
| 71 |
/org/freedesktop/DBus org.freedesktop.DBus.Debug.Stats.GetStats \ |
| 72 |
; then |
| 73 |
set +x |
| 74 |
echo "Unprivileged user should not have been able to get stats" |
| 75 |
set -x |
| 76 |
failed=1 |
| 77 |
fi |
| 78 |
|
| 79 |
install -d /usr/local/share/dbus-1/system-services |
| 80 |
cat > /usr/local/share/dbus-1/system-services/org.debian.packages.dbus.TradActivation.service <<EOF |
| 81 |
[D-BUS Service] |
| 82 |
Name=org.debian.packages.dbus.TradActivation |
| 83 |
Exec=/usr/bin/dbus-test-tool echo --system --name=org.debian.packages.dbus.TradActivation |
| 84 |
User=daemon |
| 85 |
EOF |
| 86 |
cat > /usr/local/share/dbus-1/system-services/org.debian.packages.dbus.SystemdActivation.service <<EOF |
| 87 |
[D-BUS Service] |
| 88 |
Name=org.debian.packages.dbus.SystemdActivation |
| 89 |
Exec=/bin/false |
| 90 |
User=daemon |
| 91 |
SystemdService=dbus-org.debian.packages.dbus.SystemdActivation.service |
| 92 |
EOF |
| 93 |
install -d /etc/systemd/system |
| 94 |
cat > /etc/systemd/system/dbus-org.debian.packages.dbus.SystemdActivation.service <<EOF |
| 95 |
[Unit] |
| 96 |
Description=systemd-activatable D-Bus service |
| 97 |
[Service] |
| 98 |
Type=dbus |
| 99 |
BusName=org.debian.packages.dbus.SystemdActivation |
| 100 |
User=daemon |
| 101 |
ExecStart=/usr/bin/dbus-test-tool echo --system --name=org.debian.packages.dbus.SystemdActivation |
| 102 |
EOF |
| 103 |
|
| 104 |
install -d /etc/dbus-1/system.d |
| 105 |
cat > /etc/dbus-1/system.d/org.debian.packages.dbus.Test.conf <<EOF |
| 106 |
<busconfig> |
| 107 |
<policy user="daemon"> |
| 108 |
<allow own="org.debian.packages.dbus.TradActivation"/> |
| 109 |
<allow own="org.debian.packages.dbus.SystemdActivation"/> |
| 110 |
</policy> |
| 111 |
<policy context="default"> |
| 112 |
<allow send_destination="org.debian.packages.dbus.TradActivation"/> |
| 113 |
<allow send_destination="org.debian.packages.dbus.SystemdActivation"/> |
| 114 |
</policy> |
| 115 |
</busconfig> |
| 116 |
EOF |
| 117 |
|
| 118 |
dbus-send --system --dest=org.freedesktop.DBus --type=method_call \ |
| 119 |
--print-reply /org/freedesktop/DBus org.freedesktop.DBus.ReloadConfig \ |
| 120 |
|| failed=1 |
| 121 |
dbus-send --system --dest="org.debian.packages.dbus.TradActivation" \ |
| 122 |
--type=method_call --print-reply \ |
| 123 |
/ org.freedesktop.DBus.Peer.Ping \ |
| 124 |
|| failed=1 |
| 125 |
|
| 126 |
if [ -d /run/systemd/system ]; then |
| 127 |
systemctl daemon-reload |
| 128 |
|
| 129 |
dbus-send --system --dest="org.debian.packages.dbus.SystemdActivation" \ |
| 130 |
--type=method_call --print-reply \ |
| 131 |
/ org.freedesktop.DBus.Peer.Ping \ |
| 132 |
|| failed=1 |
| 133 |
|
| 134 |
for api in hostname1 locale1 login1 systemd1 timedate1; do |
| 135 |
dbus-send --system --dest="org.freedesktop.$api" \ |
| 136 |
--type=method_call --print-reply \ |
| 137 |
/ org.freedesktop.DBus.Peer.Ping \ |
| 138 |
|| failed=1 |
| 139 |
done |
| 140 |
|
| 141 |
kill -INT "$journalctl_pid" |
| 142 |
fi |
| 143 |
|
| 144 |
if [ -n "$failed" ]; then |
| 145 |
exit 1 |
| 146 |
fi |
| 147 |
|
| 148 |
set +x |
| 149 |
|
| 150 |
case "${AUTOPKGTEST_REBOOT_MARK-}" in |
| 151 |
("") |
| 152 |
if [ -x /tmp/autopkgtest-reboot ]; then |
| 153 |
/tmp/autopkgtest-reboot rebooted |
| 154 |
fi |
| 155 |
;; |
| 156 |
|
| 157 |
(rebooted) |
| 158 |
;; |
| 159 |
|
| 160 |
(*) |
| 161 |
echo "internal error" >&2 |
| 162 |
exit 2 |
| 163 |
;; |
| 164 |
esac |
| 165 |
|
| 166 |
if [ -n "$failed" ]; then |
| 167 |
exit 1 |
| 168 |
fi |
| 169 |
|
| 170 |
exit 0 |