]> git.meshlink.io Git - catta/commitdiff
minor cleanups it netlink handling code:
authorLennart Poettering <lennart@poettering.net>
Sun, 4 Feb 2007 16:22:09 +0000 (16:22 +0000)
committerLennart Poettering <lennart@poettering.net>
Sun, 4 Feb 2007 16:22:09 +0000 (16:22 +0000)
* 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

index 7411c9050683328cf65add50c6f3ed43b1cc46b7..5050801de831eebe5f9457723bfbd4e1fa690848 100644 (file)
@@ -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;
     }