From 1c8da044469acabcfc479ba3276954da53210830 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 18 Feb 2015 19:20:47 +0100 Subject: shared: introduce cmsg_close_all() call The call iterates through cmsg list and closes all fds passed via SCM_RIGHTS. This patch also ensures the call is used wherever appropriate, where we might get spurious fds sent and we should better close them, then leave them lying around. --- src/import/importd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/import') diff --git a/src/import/importd.c b/src/import/importd.c index 2eef476015..eaf04e6a2b 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -518,12 +518,10 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void return -errno; } + cmsg_close_all(&msghdr); + for (cmsg = CMSG_FIRSTHDR(&msghdr); cmsg; cmsg = CMSG_NXTHDR(&msghdr, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { - close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int)); - log_warning("Somebody sent us unexpected fds, ignoring."); - return 0; - } else if (cmsg->cmsg_level == SOL_SOCKET && + if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS && cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) { -- cgit v1.2.3-54-g00ecf