X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsocket-util.c;h=3a00fcf43f1289c728d5566ecedaf16dcdbcf95e;hb=ee5762e3780c048b230e8c1e7659e40fc1f443bf;hp=442abfe1affb2bd8615f1739913fbacc64190f98;hpb=b15bdda87046f5e46080fd84fda878cba2da0fc8;p=elogind.git diff --git a/src/socket-util.c b/src/socket-util.c index 442abfe1a..3a00fcf43 100644 --- a/src/socket-util.c +++ b/src/socket-util.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "macro.h" #include "util.h" @@ -305,7 +306,7 @@ int socket_address_listen( bool free_bind, mode_t directory_mode, mode_t socket_mode, - /* FIXME SELINUX: pass SELinux context object here */ + security_context_t scon, int *ret) { int r, fd, one; @@ -315,11 +316,19 @@ int socket_address_listen( if ((r = socket_address_verify(a)) < 0) return r; - /* FIXME SELINUX: The socket() here should be done with the - * right SELinux context set */ + if (setsockcreatecon(scon) < 0) { + log_error("Failed to set SELinux context (%s) on socket: %m", scon); + if (security_getenforce() == 1) + return -errno; + } + + fd = socket(socket_address_family(a), a->type | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); + r = fd < 0 ? -errno : 0; + + setsockcreatecon(NULL); - if ((fd = socket(socket_address_family(a), a->type | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)) < 0) - return -errno; + if (r < 0) + return r; if (socket_address_family(a) == AF_INET6 && only != SOCKET_ADDRESS_DEFAULT) { int flag = only == SOCKET_ADDRESS_IPV6_ONLY;