summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-08-10 12:22:44 -0700
committerTom Cherry <tomcherry@google.com>2017-08-11 15:01:15 -0700
commite662a69bfa28e3fd41c228c36a01f075fa22e242 (patch)
tree9e9de4883bf303fc678385e60f27d37125bde926 /init/builtins.cpp
parenta1bfc2f7ce2072b15d0b9d3385c000ac6b3bda8f (diff)
init: split security functions out of init.cpp
This change splits out the selinux initialization and supporting functionality into selinux.cpp and splits the security related initialization of the rng, etc to security.cpp. It also provides additional documentation for SEPolicy loading as this has been requested by some teams. It additionally cleans up sehandle and sehandle_prop. The former is static within selinux.cpp and new wrapper functions are created around selabel_lookup*() to better serve the users. The latter is moved to property_service.cpp as it is isolated to that file for its usage. Test: boot bullhead Merged-In: Idc95d493cebc681fbe686b5160502f36af149f60 Change-Id: Idc95d493cebc681fbe686b5160502f36af149f60 (cherry picked from commit 9afb86b25d8675927cb37c86119a7ecf19f74819)
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r--init/builtins.cpp37
1 files changed, 12 insertions, 25 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 5335608bcc..fa93dfd34a 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -224,23 +224,22 @@ static int do_insmod(const std::vector<std::string>& args) {
return insmod(filename.c_str(), options.c_str(), flags);
}
+// mkdir <path> [mode] [owner] [group]
static int do_mkdir(const std::vector<std::string>& args) {
mode_t mode = 0755;
- int ret;
-
- /* mkdir <path> [mode] [owner] [group] */
-
if (args.size() >= 3) {
mode = std::strtoul(args[2].c_str(), 0, 8);
}
- ret = make_dir(args[1].c_str(), mode, sehandle);
- /* chmod in case the directory already exists */
- if (ret == -1 && errno == EEXIST) {
- ret = fchmodat(AT_FDCWD, args[1].c_str(), mode, AT_SYMLINK_NOFOLLOW);
- }
- if (ret == -1) {
- return -errno;
+ if (!make_dir(args[1], mode)) {
+ /* chmod in case the directory already exists */
+ if (errno == EEXIST) {
+ if (fchmodat(AT_FDCWD, args[1].c_str(), mode, AT_SYMLINK_NOFOLLOW) == -1) {
+ return -errno;
+ }
+ } else {
+ return -errno;
+ }
}
if (args.size() >= 4) {
@@ -265,8 +264,7 @@ static int do_mkdir(const std::vector<std::string>& args) {
/* chown may have cleared S_ISUID and S_ISGID, chmod again */
if (mode & (S_ISUID | S_ISGID)) {
- ret = fchmodat(AT_FDCWD, args[1].c_str(), mode, AT_SYMLINK_NOFOLLOW);
- if (ret == -1) {
+ if (fchmodat(AT_FDCWD, args[1].c_str(), mode, AT_SYMLINK_NOFOLLOW) == -1) {
return -errno;
}
}
@@ -834,17 +832,6 @@ static int do_wait_for_prop(const std::vector<std::string>& args) {
return 0;
}
-/*
- * Callback to make a directory from the ext4 code
- */
-static int do_installkeys_ensure_dir_exists(const char* dir) {
- if (make_dir(dir, 0700, sehandle) && errno != EEXIST) {
- return -1;
- }
-
- return 0;
-}
-
static bool is_file_crypto() {
return android::base::GetProperty("ro.crypto.type", "") == "file";
}
@@ -854,7 +841,7 @@ static int do_installkey(const std::vector<std::string>& args) {
return 0;
}
auto unencrypted_dir = args[1] + e4crypt_unencrypted_folder;
- if (do_installkeys_ensure_dir_exists(unencrypted_dir.c_str())) {
+ if (!make_dir(unencrypted_dir, 0700) && errno != EEXIST) {
PLOG(ERROR) << "Failed to create " << unencrypted_dir;
return -1;
}