diff options
author | Tom Cherry <tomcherry@google.com> | 2017-08-14 16:50:01 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-08-14 16:50:01 +0000 |
commit | b6b9629f02175f6fe8b0a19645c21b117ffe673b (patch) | |
tree | 93942e14faa25c1747cf81776ddf4aa6ab4965dc /init/builtins.cpp | |
parent | a457c32fa9e48f4f07bf8c9ad668ebae65aca492 (diff) | |
parent | 08228116a88ecc3fccd2265054de5e2fc776b4d3 (diff) |
Merge "init: split security functions out of init.cpp" into oc-dev-plus-aosp
am: 08228116a8
Change-Id: I3fc6288cf03cd1e262852ceb3fc9dbcedb32c7c3
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index b24bb9559..a1eab06f1 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -225,23 +225,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) { @@ -266,8 +265,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; } } @@ -912,17 +910,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"; } @@ -932,7 +919,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; } |