chiark / gitweb /
socket: add option for SO_PASSCRED
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 29 Nov 2011 21:15:41 +0000 (22:15 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 30 Nov 2011 08:52:34 +0000 (09:52 +0100)
Add an option to enable SO_PASSCRED for unix sockets.

src/dbus-socket.c
src/load-fragment-gperf.gperf.m4
src/socket.c
src/socket.h

index 2a1a17d..37ab7eb 100644 (file)
@@ -51,6 +51,7 @@
         "  <property name=\"FreeBind\" type=\"b\" access=\"read\"/>\n"  \
         "  <property name=\"Transparent\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"Broadcast\" type=\"b\" access=\"read\"/>\n" \
+        "  <property name=\"PassCred\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"Mark\" type=\"i\" access=\"read\"/>\n"      \
         "  <property name=\"MaxConnections\" type=\"u\" access=\"read\"/>\n" \
         "  <property name=\"NAccepted\" type=\"u\" access=\"read\"/>\n" \
@@ -113,6 +114,7 @@ DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMes
                 { "org.freedesktop.systemd1.Socket", "FreeBind",       bus_property_append_bool,         "b", &u->socket.free_bind       },
                 { "org.freedesktop.systemd1.Socket", "Transparent",    bus_property_append_bool,         "b", &u->socket.transparent     },
                 { "org.freedesktop.systemd1.Socket", "Broadcast",      bus_property_append_bool,         "b", &u->socket.broadcast       },
+                { "org.freedesktop.systemd1.Socket", "PassCred",       bus_property_append_bool,         "b", &u->socket.pass_cred       },
                 { "org.freedesktop.systemd1.Socket", "Mark",           bus_property_append_int,          "i", &u->socket.mark            },
                 { "org.freedesktop.systemd1.Socket", "MaxConnections", bus_property_append_unsigned,     "u", &u->socket.max_connections },
                 { "org.freedesktop.systemd1.Socket", "NConnections",   bus_property_append_unsigned,     "u", &u->socket.n_connections   },
index 41797d2..84ae28c 100644 (file)
@@ -177,6 +177,7 @@ Socket.PipeSize,                 config_parse_size,                  0,
 Socket.FreeBind,                 config_parse_bool,                  0,                             offsetof(Socket, free_bind)
 Socket.Transparent,              config_parse_bool,                  0,                             offsetof(Socket, transparent)
 Socket.Broadcast,                config_parse_bool,                  0,                             offsetof(Socket, broadcast)
+Socket.PassCred,                 config_parse_bool,                  0,                             offsetof(Socket, pass_cred)
 Socket.TCPCongestion,            config_parse_string,                0,                             offsetof(Socket, tcp_congestion)
 Socket.MessageQueueMaxMessages,  config_parse_long,                  0,                             offsetof(Socket, mq_maxmsg)
 Socket.MessageQueueMessageSize,  config_parse_long,                  0,                             offsetof(Socket, mq_msgsize)
index 7ddf326..0864cce 100644 (file)
@@ -406,6 +406,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 "%sFreeBind: %s\n"
                 "%sTransparent: %s\n"
                 "%sBroadcast: %s\n"
+                "%sPassCred: %s\n"
                 "%sTCPCongestion: %s\n",
                 prefix, socket_state_to_string(s->state),
                 prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
@@ -416,6 +417,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 prefix, yes_no(s->free_bind),
                 prefix, yes_no(s->transparent),
                 prefix, yes_no(s->broadcast),
+                prefix, yes_no(s->pass_cred),
                 prefix, strna(s->tcp_congestion));
 
         if (s->control_pid > 0)
@@ -657,6 +659,12 @@ static void socket_apply_socket_options(Socket *s, int fd) {
                         log_warning("SO_BROADCAST failed: %m");
         }
 
+        if (s->pass_cred) {
+                int one = 1;
+                if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0)
+                        log_warning("SO_PASSCRED failed: %m");
+        }
+
         if (s->priority >= 0)
                 if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &s->priority, sizeof(s->priority)) < 0)
                         log_warning("SO_PRIORITY failed: %m");
index fd13ac4..fbd29da 100644 (file)
@@ -118,6 +118,7 @@ struct Socket {
         bool free_bind;
         bool transparent;
         bool broadcast;
+        bool pass_cred;
         int priority;
         int mark;
         size_t receive_buffer;