diff options
| author | Ashish Sharma <ashishsharma@google.com> | 2011-08-03 00:31:19 -0700 |
|---|---|---|
| committer | JP Abgrall <jpa@google.com> | 2011-08-10 12:25:11 -0700 |
| commit | fa2f985b295fbf98eb45a9b5eb100f946055c5b4 (patch) | |
| tree | cdbc4b98662f38fb2ab993ed7d9222790d412c45 | |
| parent | 86993946391ba6603974b61f35fbaf4463893f00 (diff) | |
| download | core-fa2f985b295fbf98eb45a9b5eb100f946055c5b4.tar.gz core-fa2f985b295fbf98eb45a9b5eb100f946055c5b4.tar.bz2 core-fa2f985b295fbf98eb45a9b5eb100f946055c5b4.zip | |
libcutils: qtaguid: support socket untagging, return errors.
- Enable and rename qtaguid_tagSocket()
- Add qtaguid_untagSocket()
- Return kernel errors to caller
Change-Id: I8e33c8832b7f6b24ed9081f36ce1ea9ae6b099c0
Signed-off-by: Ashish Sharma <ashishsharma@google.com>
| -rw-r--r-- | include/cutils/qtaguid.h | 7 | ||||
| -rw-r--r-- | libcutils/qtaguid.c | 49 |
2 files changed, 42 insertions, 14 deletions
diff --git a/include/cutils/qtaguid.h b/include/cutils/qtaguid.h index 8aa34ea35..e6d61e639 100644 --- a/include/cutils/qtaguid.h +++ b/include/cutils/qtaguid.h @@ -28,7 +28,12 @@ extern "C" { /* * Set tags (and owning UIDs) for network sockets. */ -extern int set_qtaguid(int sockfd, int tag, uid_t uid); +extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid); + +/* + * Untag a network socket before closing. +*/ +extern int qtaguid_untagSocket(int sockfd); #ifdef __cplusplus } diff --git a/libcutils/qtaguid.c b/libcutils/qtaguid.c index 517e78422..218a21f13 100644 --- a/libcutils/qtaguid.c +++ b/libcutils/qtaguid.c @@ -19,26 +19,49 @@ #include <cutils/qtaguid.h> #include <cutils/log.h> +#include <errno.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> -extern int set_qtaguid(int sockfd, int tag, uid_t uid) { +extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid) { char lineBuf[128]; - int fd, cnt = 0; + int fd, cnt = 0, res = 0; uint64_t kTag = (uint64_t)tag << 32; snprintf(lineBuf, sizeof(lineBuf), "t %d %llu %d", sockfd, kTag, uid); - LOGV("Tagging Socket with command %s\n", lineBuf); - /* TODO: Enable after the kernel module is fixed. - fd = open("/proc/net/xt_qtaguid/ctrl", O_WRONLY); - if (fd < 0) { - return -1; - } - - cnt = write(fd, lineBuf, strlen(lineBuf)); - close(fd); - */ - return (cnt>0?0:-1); + LOGI("Tagging socket %d with tag %llx(%d) for uid %d", sockfd, kTag, tag, uid); + fd = open("/proc/net/xt_qtaguid/ctrl", O_WRONLY); + if (fd < 0) { + return -errno; + } + + cnt = write(fd, lineBuf, strlen(lineBuf)); + if (cnt < 0) { + res = -errno; + } + + close(fd); + return res; +} + +extern int qtaguid_untagSocket(int sockfd) { + char lineBuf[128]; + int fd, cnt = 0, res = 0; + snprintf(lineBuf, sizeof(lineBuf), "u %d", sockfd); + + LOGI("Untagging socket %d", sockfd); + fd = open("/proc/net/xt_qtaguid/ctrl", O_WRONLY); + if (fd < 0) { + return -errno; + } + + cnt = write(fd, lineBuf, strlen(lineBuf)); + if (cnt < 0) { + res = -errno; + } + + close(fd); + return res; } |
