X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fnetlink.c;h=4ded5ec7de371f34c642fc8af8f00febf9c4c1c7;hb=e11fda547143d8b1e931d77f1661668d41473c73;hp=7411c9050683328cf65add50c6f3ed43b1cc46b7;hpb=37b2be93e63ceff95698f24cd91cb11774eb621c;p=catta diff --git a/avahi-core/netlink.c b/avahi-core/netlink.c index 7411c90..4ded5ec 100644 --- a/avahi-core/netlink.c +++ b/avahi-core/netlink.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -53,13 +51,13 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { struct iovec iov; struct nlmsghdr *p; char cred_msg[CMSG_SPACE(sizeof(struct ucred))]; - + assert(nl); 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; @@ -70,37 +68,36 @@ int avahi_netlink_work(AvahiNetlink *nl, int block) { if ((bytes = recvmsg(nl->fd, &smsg, 0)) < 0) { if (errno == EAGAIN || errno == EINTR) return 0; - + avahi_log_error(__FILE__": recvmsg() failed: %s", strerror(errno)); return -1; } 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; - + assert(nl->callback); - + for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) { if (!NLMSG_OK(p, (size_t) bytes)) { avahi_log_warn(__FILE__": packet truncated"); return -1; } - + nl->callback(nl, p, nl->userdata); } - + return 0; } @@ -127,7 +124,7 @@ AvahiNetlink *avahi_netlink_new(const AvahiPoll *poll_api, uint32_t groups, void avahi_log_error(__FILE__": socket(PF_NETLINK): %s", strerror(errno)); return NULL; } - + memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; addr.nl_groups = groups; @@ -139,7 +136,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; } @@ -163,7 +160,7 @@ AvahiNetlink *avahi_netlink_new(const AvahiPoll *poll_api, uint32_t groups, void avahi_log_error(__FILE__": Failed to create watch."); goto fail; } - + return nl; fail: @@ -187,7 +184,7 @@ void avahi_netlink_free(AvahiNetlink *nl) { if (nl->fd >= 0) close(nl->fd); - + avahi_free(nl->buffer); avahi_free(nl); } @@ -195,7 +192,7 @@ void avahi_netlink_free(AvahiNetlink *nl) { int avahi_netlink_send(AvahiNetlink *nl, struct nlmsghdr *m, unsigned *ret_seq) { assert(nl); assert(m); - + m->nlmsg_seq = nl->seq++; m->nlmsg_flags |= NLM_F_ACK;