summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2015-01-16 06:07:29 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-01-16 06:07:29 +0000
commit7c42c7f84f2ff9997a5990986e6f450d7e07496a (patch)
tree0ea61cc33c5f15be34a82503b692b95d98ee135b /libcutils
parentf5a6c6bbb5e83824161356106876baeb80d8a986 (diff)
parent9f72ef8944a93bd333c6c7f87c7f7d79207ae663 (diff)
downloadsystem_core-7c42c7f84f2ff9997a5990986e6f450d7e07496a.zip
system_core-7c42c7f84f2ff9997a5990986e6f450d7e07496a.tar.gz
system_core-7c42c7f84f2ff9997a5990986e6f450d7e07496a.tar.bz2
am 9f72ef89: Merge "Extend to receive NFLOG packets."
* commit '9f72ef8944a93bd333c6c7f87c7f7d79207ae663': Extend to receive NFLOG packets.
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/uevent.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/libcutils/uevent.c b/libcutils/uevent.c
index 97a81e3..827170a 100644
--- a/libcutils/uevent.c
+++ b/libcutils/uevent.c
@@ -31,12 +31,12 @@
*/
ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length)
{
- uid_t user = -1;
- return uevent_kernel_multicast_uid_recv(socket, buffer, length, &user);
+ uid_t uid = -1;
+ return uevent_kernel_multicast_uid_recv(socket, buffer, length, &uid);
}
/**
- * Like the above, but passes a uid_t in by reference. In the event that this
+ * Like the above, but passes a uid_t in by pointer. In the event that this
* fails due to a bad uid check, the uid_t will be set to the uid of the
* socket's peer.
*
@@ -44,8 +44,12 @@ ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length)
* returns -1, sets errno to EIO, and sets "user" to the UID associated with the
* message. If the peer UID cannot be determined, "user" is set to -1."
*/
-ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer,
- size_t length, uid_t *user)
+ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid)
+{
+ return uevent_kernel_recv(socket, buffer, length, true, uid);
+}
+
+ssize_t uevent_kernel_recv(int socket, void *buffer, size_t length, bool require_group, uid_t *uid)
{
struct iovec iov = { buffer, length };
struct sockaddr_nl addr;
@@ -60,7 +64,7 @@ ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer,
0,
};
- *user = -1;
+ *uid = -1;
ssize_t n = recvmsg(socket, &hdr, 0);
if (n <= 0) {
return n;
@@ -73,14 +77,18 @@ ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer,
}
struct ucred *cred = (struct ucred *)CMSG_DATA(cmsg);
- *user = cred->uid;
+ *uid = cred->uid;
if (cred->uid != 0) {
/* ignoring netlink message from non-root user */
goto out;
}
- if (addr.nl_groups == 0 || addr.nl_pid != 0) {
- /* ignoring non-kernel or unicast netlink message */
+ if (addr.nl_pid != 0) {
+ /* ignore non-kernel */
+ goto out;
+ }
+ if (require_group && addr.nl_groups == 0) {
+ /* ignore unicast messages when requested */
goto out;
}