diff options
author | Jeff Sharkey <jsharkey@android.com> | 2015-01-16 01:11:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-01-16 01:11:02 +0000 |
commit | 9f72ef8944a93bd333c6c7f87c7f7d79207ae663 (patch) | |
tree | dbf08a4059fbbf4d838802fbddba9b9ad242e80f /libcutils/uevent.c | |
parent | 17e2f436f0da70673498482921a642c8917677aa (diff) | |
parent | 9a20e67fa62c1e0e0080910deec4be82ebecc922 (diff) | |
download | system_core-9f72ef8944a93bd333c6c7f87c7f7d79207ae663.zip system_core-9f72ef8944a93bd333c6c7f87c7f7d79207ae663.tar.gz system_core-9f72ef8944a93bd333c6c7f87c7f7d79207ae663.tar.bz2 |
Merge "Extend to receive NFLOG packets."
Diffstat (limited to 'libcutils/uevent.c')
-rw-r--r-- | libcutils/uevent.c | 26 |
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; } |