Skip to content

Commit 3900e5f

Browse files
committed
socket: add SocketUser= and SocketGroup= for chown()ing sockets in the file system
This is relatively complex, as we cannot invoke NSS from PID 1, and thus need to fork a helper process temporarily.
1 parent a8330cd commit 3900e5f

File tree

7 files changed

+248
-90
lines changed

7 files changed

+248
-90
lines changed

man/systemd.socket.xml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,21 @@
372372
</varlistentry>
373373

374374
<varlistentry>
375-
<term><varname>DirectoryMode=</varname></term>
376-
<listitem><para>If listening on a file
377-
system socket or FIFO, the parent
378-
directories are automatically created
379-
if needed. This option specifies the
380-
file system access mode used when
381-
creating these directories. Takes an
382-
access mode in octal
383-
notation. Defaults to
384-
0755.</para></listitem>
375+
<term><varname>SocketUser=</varname></term>
376+
<term><varname>SocketGroup=</varname></term>
377+
378+
<listitem><para>Takes a UNIX
379+
user/group name. When specified
380+
all AF_UNIX sockets and FIFO nodes in
381+
the file system are owned by the
382+
specified user and group. If unset
383+
(the default), the nodes are owned by
384+
the root user/group (if run in system
385+
context) or the invoking user/group
386+
(if run in user context). If only a
387+
user is specified but no group, then
388+
the group is derived from the user's
389+
default group.</para></listitem>
385390
</varlistentry>
386391

387392
<varlistentry>
@@ -395,6 +400,19 @@
395400
0666.</para></listitem>
396401
</varlistentry>
397402

403+
<varlistentry>
404+
<term><varname>DirectoryMode=</varname></term>
405+
<listitem><para>If listening on a file
406+
system socket or FIFO, the parent
407+
directories are automatically created
408+
if needed. This option specifies the
409+
file system access mode used when
410+
creating these directories. Takes an
411+
access mode in octal
412+
notation. Defaults to
413+
0755.</para></listitem>
414+
</varlistentry>
415+
398416
<varlistentry>
399417
<term><varname>Accept=</varname></term>
400418
<listitem><para>Takes a boolean

src/core/dbus-socket.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ const sd_bus_vtable bus_socket_vtable[] = {
9191
SD_BUS_PROPERTY("Backlog", "u", bus_property_get_unsigned, offsetof(Socket, backlog), SD_BUS_VTABLE_PROPERTY_CONST),
9292
SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Socket, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
9393
SD_BUS_PROPERTY("BindToDevice", "s", NULL, offsetof(Socket, bind_to_device), SD_BUS_VTABLE_PROPERTY_CONST),
94-
SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Socket, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
94+
SD_BUS_PROPERTY("SocketUser", "s", NULL, offsetof(Socket, user), SD_BUS_VTABLE_PROPERTY_CONST),
95+
SD_BUS_PROPERTY("SocketGroup", "s", NULL, offsetof(Socket, group), SD_BUS_VTABLE_PROPERTY_CONST),
9596
SD_BUS_PROPERTY("SocketMode", "u", bus_property_get_mode, offsetof(Socket, socket_mode), SD_BUS_VTABLE_PROPERTY_CONST),
97+
SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Socket, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
9698
SD_BUS_PROPERTY("Accept", "b", bus_property_get_bool, offsetof(Socket, accept), SD_BUS_VTABLE_PROPERTY_CONST),
9799
SD_BUS_PROPERTY("KeepAlive", "b", bus_property_get_bool, offsetof(Socket, keep_alive), SD_BUS_VTABLE_PROPERTY_CONST),
98100
SD_BUS_PROPERTY("Priority", "i", bus_property_get_int, offsetof(Socket, priority), SD_BUS_VTABLE_PROPERTY_CONST),

src/core/load-fragment-gperf.gperf.m4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ Socket.ExecStartPost, config_parse_exec, SOCKET_EXEC
221221
Socket.ExecStopPre, config_parse_exec, SOCKET_EXEC_STOP_PRE, offsetof(Socket, exec_command)
222222
Socket.ExecStopPost, config_parse_exec, SOCKET_EXEC_STOP_POST, offsetof(Socket, exec_command)
223223
Socket.TimeoutSec, config_parse_sec, 0, offsetof(Socket, timeout_usec)
224-
Socket.DirectoryMode, config_parse_mode, 0, offsetof(Socket, directory_mode)
224+
Socket.SocketUser, config_parse_unit_string_printf, 0, offsetof(Socket, user)
225+
Socket.SocketGroup, config_parse_unit_string_printf, 0, offsetof(Socket, group)
225226
Socket.SocketMode, config_parse_mode, 0, offsetof(Socket, socket_mode)
227+
Socket.DirectoryMode, config_parse_mode, 0, offsetof(Socket, directory_mode)
226228
Socket.Accept, config_parse_bool, 0, offsetof(Socket, accept)
227229
Socket.MaxConnections, config_parse_unsigned, 0, offsetof(Socket, max_connections)
228230
Socket.KeepAlive, config_parse_bool, 0, offsetof(Socket, keep_alive)

0 commit comments

Comments
 (0)