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