Loading include/cutils/qtaguid.h 0 → 100644 +36 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __CUTILS_QTAGUID_H #define __CUTILS_QTAGUID_H #include <stdint.h> #include <sys/types.h> #ifdef __cplusplus extern "C" { #endif /* * Set tags (and owning UIDs) for network sockets. */ extern int set_qtaguid(int sockfd, int tag, uid_t uid); #ifdef __cplusplus } #endif #endif /* __CUTILS_QTAG_UID_H */ libcutils/Android.mk +2 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,8 @@ commonSources := \ threads.c \ sched_policy.c \ iosched_policy.c \ str_parms.c str_parms.c \ qtaguid.c commonHostSources := \ ashmem-host.c Loading libcutils/qtaguid.c 0 → 100644 +44 −0 Original line number Diff line number Diff line /* libcutils/qtaguid.c ** ** Copyright 2011, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ #define LOG_TAG "qtaguid" #include <cutils/qtaguid.h> #include <cutils/log.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> extern int set_qtaguid(int sockfd, int tag, uid_t uid) { char lineBuf[128]; int fd, cnt = 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); } Loading
include/cutils/qtaguid.h 0 → 100644 +36 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __CUTILS_QTAGUID_H #define __CUTILS_QTAGUID_H #include <stdint.h> #include <sys/types.h> #ifdef __cplusplus extern "C" { #endif /* * Set tags (and owning UIDs) for network sockets. */ extern int set_qtaguid(int sockfd, int tag, uid_t uid); #ifdef __cplusplus } #endif #endif /* __CUTILS_QTAG_UID_H */
libcutils/Android.mk +2 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,8 @@ commonSources := \ threads.c \ sched_policy.c \ iosched_policy.c \ str_parms.c str_parms.c \ qtaguid.c commonHostSources := \ ashmem-host.c Loading
libcutils/qtaguid.c 0 → 100644 +44 −0 Original line number Diff line number Diff line /* libcutils/qtaguid.c ** ** Copyright 2011, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ #define LOG_TAG "qtaguid" #include <cutils/qtaguid.h> #include <cutils/log.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> extern int set_qtaguid(int sockfd, int tag, uid_t uid) { char lineBuf[128]; int fd, cnt = 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); }