From a702940e7f28eeef5ab820ac903db48df11ce987 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 4 Feb 2007 16:22:09 +0000 Subject: [PATCH] minor cleanups it netlink handling code: * fix warning message * don't warn if netlink messages from other processes have been received * don't access ucreds before checking cmsg validity git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1382 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/netlink.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/avahi-core/netlink.c b/avahi-core/netlink.c index 7411c90..5050801 100644 --- a/avahi-core/netlink.c +++ b/avahi-core/netlink.c @@ -59,7 +59,7 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { iov.iov_base = nl->buffer; iov.iov_len = nl->buffer_length; - smsg.msg_name = (void*) NULL; + smsg.msg_name = NULL; smsg.msg_namelen = 0; smsg.msg_iov = &iov; smsg.msg_iovlen = 1; @@ -76,17 +76,16 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { } cmsg = CMSG_FIRSTHDR(&smsg); - cred = (struct ucred *) CMSG_DATA (cmsg); - if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) { - avahi_log_error("No sender credentials received, ignoring data."); + if (!cmsg || cmsg->cmsg_type != SCM_CREDENTIALS) { + avahi_log_warn("No sender credentials received, ignoring data."); return -1; } - if (cred->uid != 0) { - avahi_log_warn("Netlink message received from cred->uid != 0 (%d)", cred->uid); + cred = (struct ucred*) CMSG_DATA(cmsg); + + if (cred->uid != 0) return -1; - } p = (struct nlmsghdr *) nl->buffer; @@ -139,7 +138,7 @@ AvahiNetlink *avahi_netlink_new(const AvahiPoll *poll_api, uint32_t groups, void } if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) { - avahi_log_error(__FILE__": bind(): %s", strerror(errno)); + avahi_log_error(__FILE__": SO_PASSCRED: %s", strerror(errno)); goto fail; } -- 2.39.5