chiark / gitweb /
Revert "Implement SocketUser= and SocketGroup= for [Socket]"
[elogind.git] / src / core / dbus-mount.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23
24 #include "dbus-unit.h"
25 #include "dbus-mount.h"
26 #include "dbus-kill.h"
27 #include "dbus-execute.h"
28 #include "dbus-common.h"
29 #include "selinux-access.h"
30
31 #define BUS_MOUNT_INTERFACE                                             \
32         " <interface name=\"org.freedesktop.systemd1.Mount\">\n"        \
33         "  <property name=\"Where\" type=\"s\" access=\"read\"/>\n"     \
34         "  <property name=\"What\" type=\"s\" access=\"read\"/>\n"      \
35         "  <property name=\"Options\" type=\"s\" access=\"read\"/>\n"   \
36         "  <property name=\"Type\" type=\"s\" access=\"read\"/>\n"      \
37         "  <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
38         BUS_EXEC_COMMAND_INTERFACE("ExecMount")                         \
39         BUS_EXEC_COMMAND_INTERFACE("ExecUnmount")                       \
40         BUS_EXEC_COMMAND_INTERFACE("ExecRemount")                       \
41         BUS_EXEC_CONTEXT_INTERFACE                                      \
42         BUS_KILL_CONTEXT_INTERFACE                                      \
43         "  <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
44         "  <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
45         "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
46         " </interface>\n"
47
48 #define INTROSPECTION                                                   \
49         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
50         "<node>\n"                                                      \
51         BUS_UNIT_INTERFACE                                              \
52         BUS_MOUNT_INTERFACE                                             \
53         BUS_PROPERTIES_INTERFACE                                        \
54         BUS_PEER_INTERFACE                                              \
55         BUS_INTROSPECTABLE_INTERFACE                                    \
56         "</node>\n"
57
58 #define INTERFACES_LIST                              \
59         BUS_UNIT_INTERFACES_LIST                     \
60         "org.freedesktop.systemd1.Mount\0"
61
62 const char bus_mount_interface[] _introspect_("Mount") = BUS_MOUNT_INTERFACE;
63
64 const char bus_mount_invalidating_properties[] =
65         "What\0"
66         "Options\0"
67         "Type\0"
68         "ExecMount\0"
69         "ExecUnmount\0"
70         "ExecRemount\0"
71         "ControlPID\0"
72         "Result\0";
73
74 static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
75         Mount *m = data;
76         const char *d;
77
78         assert(i);
79         assert(property);
80         assert(m);
81
82         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
83                 d = m->parameters_proc_self_mountinfo.what;
84         else if (m->from_fragment && m->parameters_fragment.what)
85                 d = m->parameters_fragment.what;
86         else
87                 d = "";
88
89         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
90                 return -ENOMEM;
91
92         return 0;
93 }
94
95 static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
96         Mount *m = data;
97         const char *d;
98
99         assert(i);
100         assert(property);
101         assert(m);
102
103         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
104                 d = m->parameters_proc_self_mountinfo.options;
105         else if (m->from_fragment && m->parameters_fragment.options)
106                 d = m->parameters_fragment.options;
107         else
108                 d = "";
109
110         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
111                 return -ENOMEM;
112
113         return 0;
114 }
115
116 static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
117         Mount *m = data;
118         const char *d;
119
120         assert(i);
121         assert(property);
122         assert(m);
123
124         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
125                 d = m->parameters_proc_self_mountinfo.fstype;
126         else if (m->from_fragment && m->parameters_fragment.fstype)
127                 d = m->parameters_fragment.fstype;
128         else
129                 d = "";
130
131         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
132                 return -ENOMEM;
133
134         return 0;
135 }
136
137 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_mount_append_mount_result, mount_result, MountResult);
138
139 static const BusProperty bus_mount_properties[] = {
140         { "Where",         bus_property_append_string, "s", offsetof(Mount, where),    true },
141         { "What",          bus_mount_append_what,      "s", 0 },
142         { "Options",       bus_mount_append_options,   "s", 0 },
143         { "Type",          bus_mount_append_type,      "s", 0 },
144         { "TimeoutUSec",   bus_property_append_usec,   "t", offsetof(Mount, timeout_usec)   },
145         BUS_EXEC_COMMAND_PROPERTY("ExecMount",   offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]),   false),
146         BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false),
147         BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false),
148         { "ControlPID",    bus_property_append_pid,    "u", offsetof(Mount, control_pid)    },
149         { "DirectoryMode", bus_property_append_mode,   "u", offsetof(Mount, directory_mode) },
150         { "Result",        bus_mount_append_mount_result, "s", offsetof(Mount, result)      },
151         { NULL, }
152 };
153
154 DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
155         Mount *m = MOUNT(u);
156
157         const BusBoundProperties bps[] = {
158                 { "org.freedesktop.systemd1.Unit",  bus_unit_properties,         u },
159                 { "org.freedesktop.systemd1.Mount", bus_mount_properties,        m },
160                 { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context },
161                 { "org.freedesktop.systemd1.Mount", bus_kill_context_properties, &m->kill_context },
162                 { NULL, }
163         };
164
165         SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
166
167         return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps );
168 }