aboutsummaryrefslogtreecommitdiff
path: root/tests/dbus-vmstate-daemon.sh
blob: 474e250154854ee31139cb2870810a744a792b88 (plain)
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
#!/bin/sh

# dbus-daemon wrapper script for dbus-vmstate testing
#
# This script allows to tweak the dbus-daemon policy during the test
# to test different configurations.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2019 Red Hat, Inc.

write_config()
{
    CONF="$1"
    cat > "$CONF" <<EOF
<busconfig>
  <type>session</type>
  <listen>unix:tmpdir=$DBUS_VMSTATE_TEST_TMPDIR</listen>

  <policy context="default">
     <!-- Holes must be punched in service configuration files for
          name ownership and sending method calls -->
     <deny own="*"/>
     <deny send_type="method_call"/>

     <!-- Signals and reply messages (method returns, errors) are allowed
          by default -->
     <allow send_type="signal"/>
     <allow send_requested_reply="true" send_type="method_return"/>
     <allow send_requested_reply="true" send_type="error"/>

     <!-- All messages may be received by default -->
     <allow receive_type="method_call"/>
     <allow receive_type="method_return"/>
     <allow receive_type="error"/>
     <allow receive_type="signal"/>

     <!-- Allow anyone to talk to the message bus -->
     <allow send_destination="org.freedesktop.DBus"
            send_interface="org.freedesktop.DBus" />
     <allow send_destination="org.freedesktop.DBus"
            send_interface="org.freedesktop.DBus.Introspectable"/>
     <allow send_destination="org.freedesktop.DBus"
            send_interface="org.freedesktop.DBus.Properties"/>
     <!-- But disallow some specific bus services -->
     <deny send_destination="org.freedesktop.DBus"
           send_interface="org.freedesktop.DBus"
           send_member="UpdateActivationEnvironment"/>
     <deny send_destination="org.freedesktop.DBus"
           send_interface="org.freedesktop.DBus.Debug.Stats"/>
     <deny send_destination="org.freedesktop.DBus"
           send_interface="org.freedesktop.systemd1.Activator"/>

     <allow own="org.qemu.VMState1"/>
     <allow send_destination="org.qemu.VMState1"/>
     <allow receive_sender="org.qemu.VMState1"/>

  </policy>

  <include if_selinux_enabled="yes"
   selinux_root_relative="yes">contexts/dbus_contexts</include>

</busconfig>
EOF
}

ARGS=
for arg in "$@"
do
    case $arg in
        --config-file=*)
          CONF="${arg#*=}"
          write_config "$CONF"
          ARGS="$ARGS $1"
          shift
        ;;
        *)
          ARGS="$ARGS $1"
          shift
        ;;
    esac
done

exec dbus-daemon $ARGS