2009-03-04 04:32:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2010-04-14 04:35:09 +02:00
|
|
|
#include <time.h>
|
2013-07-12 00:38:26 +02:00
|
|
|
#include <ftw.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2012-01-13 14:48:47 +01:00
|
|
|
#include <selinux/label.h>
|
2014-01-28 16:34:09 +01:00
|
|
|
#include <selinux/android.h>
|
2012-01-13 14:48:47 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
|
|
|
/* for ANDROID_SOCKET_* */
|
|
|
|
#include <cutils/sockets.h>
|
|
|
|
|
2015-03-16 11:29:36 +01:00
|
|
|
#include <utils/file.h>
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <private/android_filesystem_config.h>
|
|
|
|
|
2012-01-13 14:48:47 +01:00
|
|
|
#include "init.h"
|
2010-04-20 02:05:34 +02:00
|
|
|
#include "log.h"
|
2010-04-21 21:04:20 +02:00
|
|
|
#include "util.h"
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* android_name_to_id - returns the integer uid/gid associated with the given
|
|
|
|
* name, or -1U on error.
|
|
|
|
*/
|
|
|
|
static unsigned int android_name_to_id(const char *name)
|
|
|
|
{
|
2012-07-26 20:09:13 +02:00
|
|
|
const struct android_id_info *info = android_ids;
|
2009-03-04 04:32:55 +01:00
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
for (n = 0; n < android_id_count; n++) {
|
|
|
|
if (!strcmp(info[n].name, name))
|
|
|
|
return info[n].aid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1U;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decode_uid - decodes and returns the given string, which can be either the
|
|
|
|
* numeric or name representation, into the integer uid or gid. Returns -1U on
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
unsigned int decode_uid(const char *s)
|
|
|
|
{
|
|
|
|
unsigned int v;
|
|
|
|
|
|
|
|
if (!s || *s == '\0')
|
|
|
|
return -1U;
|
|
|
|
if (isalpha(s[0]))
|
|
|
|
return android_name_to_id(s);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
v = (unsigned int) strtoul(s, 0, 0);
|
|
|
|
if (errno)
|
|
|
|
return -1U;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create_socket - creates a Unix domain socket in ANDROID_SOCKET_DIR
|
|
|
|
* ("/dev/socket") as dictated in init.rc. This socket is inherited by the
|
|
|
|
* daemon. We communicate the file descriptor's value via the environment
|
|
|
|
* variable ANDROID_SOCKET_ENV_PREFIX<name> ("ANDROID_SOCKET_foo").
|
|
|
|
*/
|
2013-05-13 18:37:04 +02:00
|
|
|
int create_socket(const char *name, int type, mode_t perm, uid_t uid,
|
|
|
|
gid_t gid, const char *socketcon)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
int fd, ret;
|
2013-05-13 18:37:04 +02:00
|
|
|
char *filecon;
|
|
|
|
|
|
|
|
if (socketcon)
|
|
|
|
setsockcreatecon(socketcon);
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
fd = socket(PF_UNIX, type, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
ERROR("Failed to open socket '%s': %s\n", name, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-13 18:37:04 +02:00
|
|
|
if (socketcon)
|
|
|
|
setsockcreatecon(NULL);
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
memset(&addr, 0 , sizeof(addr));
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
snprintf(addr.sun_path, sizeof(addr.sun_path), ANDROID_SOCKET_DIR"/%s",
|
|
|
|
name);
|
|
|
|
|
|
|
|
ret = unlink(addr.sun_path);
|
|
|
|
if (ret != 0 && errno != ENOENT) {
|
|
|
|
ERROR("Failed to unlink old socket '%s': %s\n", name, strerror(errno));
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
2013-05-13 18:37:04 +02:00
|
|
|
filecon = NULL;
|
2012-01-13 14:48:47 +01:00
|
|
|
if (sehandle) {
|
2013-05-13 18:37:04 +02:00
|
|
|
ret = selabel_lookup(sehandle, &filecon, addr.sun_path, S_IFSOCK);
|
2012-01-13 14:48:47 +01:00
|
|
|
if (ret == 0)
|
2013-05-13 18:37:04 +02:00
|
|
|
setfscreatecon(filecon);
|
2012-01-13 14:48:47 +01:00
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
|
|
|
|
if (ret) {
|
|
|
|
ERROR("Failed to bind socket '%s': %s\n", name, strerror(errno));
|
|
|
|
goto out_unlink;
|
|
|
|
}
|
|
|
|
|
2012-01-13 14:48:47 +01:00
|
|
|
setfscreatecon(NULL);
|
2013-05-13 18:37:04 +02:00
|
|
|
freecon(filecon);
|
2012-01-13 14:48:47 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
chown(addr.sun_path, uid, gid);
|
|
|
|
chmod(addr.sun_path, perm);
|
|
|
|
|
|
|
|
INFO("Created socket '%s' with mode '%o', user '%d', group '%d'\n",
|
|
|
|
addr.sun_path, perm, uid, gid);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
out_unlink:
|
|
|
|
unlink(addr.sun_path);
|
|
|
|
out_close:
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-06 21:19:48 +01:00
|
|
|
bool read_file(const char* path, std::string* content) {
|
|
|
|
content->clear();
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-02-06 21:19:48 +01:00
|
|
|
int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC));
|
|
|
|
if (fd == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-02-06 21:19:48 +01:00
|
|
|
// For security reasons, disallow world-writable
|
|
|
|
// or group-writable files.
|
|
|
|
struct stat sb;
|
|
|
|
if (fstat(fd, &sb) == -1) {
|
|
|
|
ERROR("fstat failed for '%s': %s\n", path, strerror(errno));
|
|
|
|
return false;
|
2012-01-18 19:39:01 +01:00
|
|
|
}
|
|
|
|
if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
|
2015-02-06 21:19:48 +01:00
|
|
|
ERROR("skipping insecure file '%s'\n", path);
|
|
|
|
return false;
|
2012-01-18 19:39:01 +01:00
|
|
|
}
|
|
|
|
|
2015-03-16 11:29:36 +01:00
|
|
|
bool okay = android::ReadFdToString(fd, content);
|
2015-02-06 21:19:48 +01:00
|
|
|
TEMP_FAILURE_RETRY(close(fd));
|
|
|
|
if (okay) {
|
|
|
|
content->append("\n", 1);
|
|
|
|
}
|
|
|
|
return okay;
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-02-06 21:19:48 +01:00
|
|
|
int write_file(const char* path, const char* content) {
|
|
|
|
int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0600));
|
|
|
|
if (fd == -1) {
|
|
|
|
return -errno;
|
|
|
|
}
|
2015-03-16 11:29:36 +01:00
|
|
|
int result = android::WriteStringToFd(content, fd) ? 0 : -errno;
|
2015-02-06 21:19:48 +01:00
|
|
|
TEMP_FAILURE_RETRY(close(fd));
|
|
|
|
return result;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2010-04-13 03:51:06 +02:00
|
|
|
#define MAX_MTD_PARTITIONS 16
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char name[16];
|
|
|
|
int number;
|
|
|
|
} mtd_part_map[MAX_MTD_PARTITIONS];
|
|
|
|
|
|
|
|
static int mtd_part_count = -1;
|
|
|
|
|
|
|
|
static void find_mtd_partitions(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char buf[1024];
|
|
|
|
char *pmtdbufp;
|
|
|
|
ssize_t pmtdsize;
|
|
|
|
int r;
|
|
|
|
|
2015-02-02 23:37:22 +01:00
|
|
|
fd = open("/proc/mtd", O_RDONLY|O_CLOEXEC);
|
2010-04-13 03:51:06 +02:00
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
pmtdsize = read(fd, buf, sizeof(buf) - 1);
|
|
|
|
pmtdbufp = buf;
|
|
|
|
while (pmtdsize > 0) {
|
|
|
|
int mtdnum, mtdsize, mtderasesize;
|
|
|
|
char mtdname[16];
|
|
|
|
mtdname[0] = '\0';
|
|
|
|
mtdnum = -1;
|
|
|
|
r = sscanf(pmtdbufp, "mtd%d: %x %x %15s",
|
|
|
|
&mtdnum, &mtdsize, &mtderasesize, mtdname);
|
|
|
|
if ((r == 4) && (mtdname[0] == '"')) {
|
|
|
|
char *x = strchr(mtdname + 1, '"');
|
|
|
|
if (x) {
|
|
|
|
*x = 0;
|
|
|
|
}
|
|
|
|
INFO("mtd partition %d, %s\n", mtdnum, mtdname + 1);
|
|
|
|
if (mtd_part_count < MAX_MTD_PARTITIONS) {
|
|
|
|
strcpy(mtd_part_map[mtd_part_count].name, mtdname + 1);
|
|
|
|
mtd_part_map[mtd_part_count].number = mtdnum;
|
|
|
|
mtd_part_count++;
|
|
|
|
} else {
|
|
|
|
ERROR("too many mtd partitions\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (pmtdsize > 0 && *pmtdbufp != '\n') {
|
|
|
|
pmtdbufp++;
|
|
|
|
pmtdsize--;
|
|
|
|
}
|
|
|
|
if (pmtdsize > 0) {
|
|
|
|
pmtdbufp++;
|
|
|
|
pmtdsize--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mtd_name_to_number(const char *name)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
if (mtd_part_count < 0) {
|
|
|
|
mtd_part_count = 0;
|
|
|
|
find_mtd_partitions();
|
|
|
|
}
|
|
|
|
for (n = 0; n < mtd_part_count; n++) {
|
|
|
|
if (!strcmp(name, mtd_part_map[n].name)) {
|
|
|
|
return mtd_part_map[n].number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-14 04:35:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* gettime() - returns the time in seconds of the system's monotonic clock or
|
|
|
|
* zero on error.
|
|
|
|
*/
|
|
|
|
time_t gettime(void)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("clock_gettime(CLOCK_MONOTONIC) failed: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ts.tv_sec;
|
|
|
|
}
|
2010-04-09 01:16:20 +02:00
|
|
|
|
|
|
|
int mkdir_recursive(const char *pathname, mode_t mode)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
const char *slash;
|
|
|
|
const char *p = pathname;
|
|
|
|
int width;
|
|
|
|
int ret;
|
|
|
|
struct stat info;
|
|
|
|
|
|
|
|
while ((slash = strchr(p, '/')) != NULL) {
|
|
|
|
width = slash - pathname;
|
|
|
|
p = slash + 1;
|
|
|
|
if (width < 0)
|
|
|
|
break;
|
|
|
|
if (width == 0)
|
|
|
|
continue;
|
|
|
|
if ((unsigned int)width > sizeof(buf) - 1) {
|
|
|
|
ERROR("path too long for mkdir_recursive\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(buf, pathname, width);
|
|
|
|
buf[width] = 0;
|
|
|
|
if (stat(buf, &info) != 0) {
|
2012-06-11 19:37:39 +02:00
|
|
|
ret = make_dir(buf, mode);
|
2010-04-09 01:16:20 +02:00
|
|
|
if (ret && errno != EEXIST)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-06-11 19:37:39 +02:00
|
|
|
ret = make_dir(pathname, mode);
|
2010-04-09 01:16:20 +02:00
|
|
|
if (ret && errno != EEXIST)
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-18 16:41:19 +02:00
|
|
|
/*
|
|
|
|
* replaces any unacceptable characters with '_', the
|
|
|
|
* length of the resulting string is equal to the input string
|
|
|
|
*/
|
2010-04-09 01:16:20 +02:00
|
|
|
void sanitize(char *s)
|
|
|
|
{
|
2012-04-18 16:41:19 +02:00
|
|
|
const char* accept =
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"0123456789"
|
|
|
|
"_-.";
|
|
|
|
|
2010-04-09 01:16:20 +02:00
|
|
|
if (!s)
|
|
|
|
return;
|
2012-04-18 16:41:19 +02:00
|
|
|
|
2014-09-22 20:35:54 +02:00
|
|
|
while (*s) {
|
2012-04-18 16:41:19 +02:00
|
|
|
s += strspn(s, accept);
|
2014-09-22 20:35:54 +02:00
|
|
|
if (*s) *s++ = '_';
|
2012-04-18 16:41:19 +02:00
|
|
|
}
|
2010-04-09 01:16:20 +02:00
|
|
|
}
|
2012-04-18 16:41:19 +02:00
|
|
|
|
2010-04-09 01:16:20 +02:00
|
|
|
void make_link(const char *oldpath, const char *newpath)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char buf[256];
|
|
|
|
char *slash;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
slash = strrchr(newpath, '/');
|
|
|
|
if (!slash)
|
|
|
|
return;
|
|
|
|
width = slash - newpath;
|
|
|
|
if (width <= 0 || width > (int)sizeof(buf) - 1)
|
|
|
|
return;
|
|
|
|
memcpy(buf, newpath, width);
|
|
|
|
buf[width] = 0;
|
|
|
|
ret = mkdir_recursive(buf, 0755);
|
|
|
|
if (ret)
|
|
|
|
ERROR("Failed to create directory %s: %s (%d)\n", buf, strerror(errno), errno);
|
|
|
|
|
|
|
|
ret = symlink(oldpath, newpath);
|
|
|
|
if (ret && errno != EEXIST)
|
|
|
|
ERROR("Failed to symlink %s to %s: %s (%d)\n", oldpath, newpath, strerror(errno), errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove_link(const char *oldpath, const char *newpath)
|
|
|
|
{
|
|
|
|
char path[256];
|
|
|
|
ssize_t ret;
|
|
|
|
ret = readlink(newpath, path, sizeof(path) - 1);
|
|
|
|
if (ret <= 0)
|
|
|
|
return;
|
|
|
|
path[ret] = 0;
|
|
|
|
if (!strcmp(path, oldpath))
|
|
|
|
unlink(newpath);
|
|
|
|
}
|
2010-04-20 02:10:24 +02:00
|
|
|
|
|
|
|
int wait_for_file(const char *filename, int timeout)
|
|
|
|
{
|
|
|
|
struct stat info;
|
|
|
|
time_t timeout_time = gettime() + timeout;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
while (gettime() < timeout_time && ((ret = stat(filename, &info)) < 0))
|
|
|
|
usleep(10000);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-21 21:04:20 +02:00
|
|
|
|
|
|
|
void open_devnull_stdio(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
static const char *name = "/dev/__null__";
|
|
|
|
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
|
|
|
|
fd = open(name, O_RDWR);
|
|
|
|
unlink(name);
|
|
|
|
if (fd >= 0) {
|
|
|
|
dup2(fd, 0);
|
|
|
|
dup2(fd, 1);
|
|
|
|
dup2(fd, 2);
|
|
|
|
if (fd > 2) {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-02-04 02:12:07 +01:00
|
|
|
void get_hardware_name(char *hardware, unsigned int *revision) {
|
|
|
|
// Hardware string was provided on kernel command line.
|
|
|
|
if (hardware[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* fp = fopen("/proc/cpuinfo", "re");
|
|
|
|
if (fp == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char buf[1024];
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
|
if (strncmp(buf, "Hardware", 8) == 0) {
|
|
|
|
const char* hw = strstr(buf, ": ");
|
|
|
|
if (hw) {
|
|
|
|
hw += 2;
|
|
|
|
size_t n = 0;
|
|
|
|
while (*hw) {
|
|
|
|
if (!isspace(*hw)) {
|
|
|
|
hardware[n++] = tolower(*hw);
|
|
|
|
}
|
|
|
|
hw++;
|
|
|
|
if (n == 31) break;
|
2010-04-21 21:04:20 +02:00
|
|
|
}
|
2015-02-04 02:12:07 +01:00
|
|
|
hardware[n] = 0;
|
|
|
|
}
|
|
|
|
} else if (strncmp(buf, "Revision", 8) == 0) {
|
2015-02-04 19:25:09 +01:00
|
|
|
sscanf(buf, "Revision : %ux", revision);
|
2010-04-21 21:04:20 +02:00
|
|
|
}
|
2015-02-04 02:12:07 +01:00
|
|
|
}
|
|
|
|
fclose(fp);
|
2010-04-21 21:04:20 +02:00
|
|
|
}
|
2011-09-28 18:55:31 +02:00
|
|
|
|
|
|
|
void import_kernel_cmdline(int in_qemu,
|
|
|
|
void (*import_kernel_nv)(char *name, int in_qemu))
|
|
|
|
{
|
2013-09-09 22:08:17 +02:00
|
|
|
char cmdline[2048];
|
2011-09-28 18:55:31 +02:00
|
|
|
char *ptr;
|
|
|
|
int fd;
|
|
|
|
|
2015-02-02 23:37:22 +01:00
|
|
|
fd = open("/proc/cmdline", O_RDONLY | O_CLOEXEC);
|
2011-09-28 18:55:31 +02:00
|
|
|
if (fd >= 0) {
|
2013-09-09 22:08:17 +02:00
|
|
|
int n = read(fd, cmdline, sizeof(cmdline) - 1);
|
2011-09-28 18:55:31 +02:00
|
|
|
if (n < 0) n = 0;
|
|
|
|
|
|
|
|
/* get rid of trailing newline, it happens */
|
|
|
|
if (n > 0 && cmdline[n-1] == '\n') n--;
|
|
|
|
|
|
|
|
cmdline[n] = 0;
|
|
|
|
close(fd);
|
|
|
|
} else {
|
|
|
|
cmdline[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = cmdline;
|
|
|
|
while (ptr && *ptr) {
|
|
|
|
char *x = strchr(ptr, ' ');
|
|
|
|
if (x != 0) *x++ = 0;
|
|
|
|
import_kernel_nv(ptr, in_qemu);
|
|
|
|
ptr = x;
|
|
|
|
}
|
|
|
|
}
|
2012-06-11 19:37:39 +02:00
|
|
|
|
|
|
|
int make_dir(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
char *secontext = NULL;
|
|
|
|
|
|
|
|
if (sehandle) {
|
|
|
|
selabel_lookup(sehandle, &secontext, path, mode);
|
|
|
|
setfscreatecon(secontext);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = mkdir(path, mode);
|
|
|
|
|
|
|
|
if (secontext) {
|
|
|
|
int save_errno = errno;
|
|
|
|
freecon(secontext);
|
|
|
|
setfscreatecon(NULL);
|
|
|
|
errno = save_errno;
|
|
|
|
}
|
2012-10-17 08:07:05 +02:00
|
|
|
|
2012-06-11 19:37:39 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:34:09 +01:00
|
|
|
int restorecon(const char* pathname)
|
2012-06-11 19:37:39 +02:00
|
|
|
{
|
2014-02-07 15:14:13 +01:00
|
|
|
return selinux_android_restorecon(pathname, 0);
|
2013-07-12 00:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int restorecon_recursive(const char* pathname)
|
|
|
|
{
|
2014-02-07 15:14:13 +01:00
|
|
|
return selinux_android_restorecon(pathname, SELINUX_ANDROID_RESTORECON_RECURSE);
|
2013-07-12 00:38:26 +02:00
|
|
|
}
|