blob: 517e78422f6ee0112c3595199d77216e674646a0 [file] [log] [blame]
Ashish Sharma8626cce2011-07-07 18:16:01 -07001/* libcutils/qtaguid.c
2**
3** Copyright 2011, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "qtaguid"
19
20#include <cutils/qtaguid.h>
21#include <cutils/log.h>
22#include <fcntl.h>
23#include <stdio.h>
24#include <string.h>
25#include <unistd.h>
26
27extern int set_qtaguid(int sockfd, int tag, uid_t uid) {
28 char lineBuf[128];
29 int fd, cnt = 0;
30 uint64_t kTag = (uint64_t)tag << 32;
31 snprintf(lineBuf, sizeof(lineBuf), "t %d %llu %d", sockfd, kTag, uid);
32
33 LOGV("Tagging Socket with command %s\n", lineBuf);
34 /* TODO: Enable after the kernel module is fixed.
35 fd = open("/proc/net/xt_qtaguid/ctrl", O_WRONLY);
36 if (fd < 0) {
37 return -1;
38 }
39
40 cnt = write(fd, lineBuf, strlen(lineBuf));
41 close(fd);
42 */
43 return (cnt>0?0:-1);
44}