Loading init/builtins.cpp +55 −17 Original line number Original line Diff line number Diff line Loading @@ -150,7 +150,12 @@ static int do_class_restart(const std::vector<std::string>& args) { } } static int do_domainname(const std::vector<std::string>& args) { static int do_domainname(const std::vector<std::string>& args) { return write_file("/proc/sys/kernel/domainname", args[1]) ? 0 : 1; std::string err; if (!WriteFile("/proc/sys/kernel/domainname", args[1], &err)) { LOG(ERROR) << err; return -1; } return 0; } } static int do_enable(const std::vector<std::string>& args) { static int do_enable(const std::vector<std::string>& args) { Loading @@ -174,7 +179,12 @@ static int do_export(const std::vector<std::string>& args) { } } static int do_hostname(const std::vector<std::string>& args) { static int do_hostname(const std::vector<std::string>& args) { return write_file("/proc/sys/kernel/hostname", args[1]) ? 0 : 1; std::string err; if (!WriteFile("/proc/sys/kernel/hostname", args[1], &err)) { LOG(ERROR) << err; return -1; } return 0; } } static int do_ifup(const std::vector<std::string>& args) { static int do_ifup(const std::vector<std::string>& args) { Loading Loading @@ -215,11 +225,19 @@ static int do_mkdir(const std::vector<std::string>& args) { } } if (args.size() >= 4) { if (args.size() >= 4) { uid_t uid = decode_uid(args[3].c_str()); uid_t uid; std::string decode_uid_err; if (!DecodeUid(args[3], &uid, &decode_uid_err)) { LOG(ERROR) << "Unable to find UID for '" << args[3] << "': " << decode_uid_err; return -1; } gid_t gid = -1; gid_t gid = -1; if (args.size() == 5) { if (args.size() == 5) { gid = decode_uid(args[4].c_str()); if (!DecodeUid(args[4], &gid, &decode_uid_err)) { LOG(ERROR) << "Unable to find GID for '" << args[3] << "': " << decode_uid_err; return -1; } } } if (lchown(args[1].c_str(), uid, gid) == -1) { if (lchown(args[1].c_str(), uid, gid) == -1) { Loading Loading @@ -643,29 +661,49 @@ static int do_verity_update_state(const std::vector<std::string>& args) { } } static int do_write(const std::vector<std::string>& args) { static int do_write(const std::vector<std::string>& args) { return write_file(args[1], args[2]) ? 0 : 1; std::string err; if (!WriteFile(args[1], args[2], &err)) { LOG(ERROR) << err; return -1; } return 0; } } static int do_copy(const std::vector<std::string>& args) { static int do_copy(const std::vector<std::string>& args) { std::string data; std::string data; if (read_file(args[1], &data)) { std::string err; return write_file(args[2], data) ? 0 : 1; if (!ReadFile(args[1], &data, &err)) { LOG(ERROR) << err; return -1; } if (!WriteFile(args[2], data, &err)) { LOG(ERROR) << err; return -1; } } return 1; return 0; } } static int do_chown(const std::vector<std::string>& args) { static int do_chown(const std::vector<std::string>& args) { /* GID is optional. */ uid_t uid; if (args.size() == 3) { std::string decode_uid_err; if (lchown(args[2].c_str(), decode_uid(args[1].c_str()), -1) == -1) if (!DecodeUid(args[1], &uid, &decode_uid_err)) { return -errno; LOG(ERROR) << "Unable to find UID for '" << args[1] << "': " << decode_uid_err; } else if (args.size() == 4) { if (lchown(args[3].c_str(), decode_uid(args[1].c_str()), decode_uid(args[2].c_str())) == -1) return -errno; } else { return -1; return -1; } } // GID is optional and pushes the index of path out by one if specified. const std::string& path = (args.size() == 4) ? args[3] : args[2]; gid_t gid = -1; if (args.size() == 4) { if (!DecodeUid(args[2], &gid, &decode_uid_err)) { LOG(ERROR) << "Unable to find GID for '" << args[2] << "': " << decode_uid_err; return -1; } } if (lchown(path.c_str(), uid, gid) == -1) return -errno; return 0; return 0; } } Loading init/init.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -871,7 +871,9 @@ static void selinux_initialize(bool in_kernel_domain) { } } } } if (!write_file("/sys/fs/selinux/checkreqprot", "0")) { std::string err; if (!WriteFile("/sys/fs/selinux/checkreqprot", "0", &err)) { LOG(ERROR) << err; security_failure(); security_failure(); } } Loading init/init_parser.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -110,7 +110,9 @@ bool Parser::ParseConfigFile(const std::string& path) { LOG(INFO) << "Parsing file " << path << "..."; LOG(INFO) << "Parsing file " << path << "..."; Timer t; Timer t; std::string data; std::string data; if (!read_file(path, &data)) { std::string err; if (!ReadFile(path, &data, &err)) { LOG(ERROR) << err; return false; return false; } } Loading init/init_parser_test.cpp +14 −4 Original line number Original line Diff line number Diff line Loading @@ -86,19 +86,29 @@ static void Test_make_exec_oneshot_service(bool dash_dash, bool seclabel, bool u ASSERT_EQ("", svc->seclabel()); ASSERT_EQ("", svc->seclabel()); } } if (uid) { if (uid) { ASSERT_EQ(decode_uid("log"), svc->uid()); uid_t decoded_uid; std::string err; ASSERT_TRUE(DecodeUid("log", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->uid()); } else { } else { ASSERT_EQ(0U, svc->uid()); ASSERT_EQ(0U, svc->uid()); } } if (gid) { if (gid) { ASSERT_EQ(decode_uid("shell"), svc->gid()); uid_t decoded_uid; std::string err; ASSERT_TRUE(DecodeUid("shell", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->gid()); } else { } else { ASSERT_EQ(0U, svc->gid()); ASSERT_EQ(0U, svc->gid()); } } if (supplementary_gids) { if (supplementary_gids) { ASSERT_EQ(2U, svc->supp_gids().size()); ASSERT_EQ(2U, svc->supp_gids().size()); ASSERT_EQ(decode_uid("system"), svc->supp_gids()[0]); uid_t decoded_uid; ASSERT_EQ(decode_uid("adb"), svc->supp_gids()[1]); std::string err; ASSERT_TRUE(DecodeUid("system", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->supp_gids()[0]); ASSERT_TRUE(DecodeUid("adb", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->supp_gids()[1]); } else { } else { ASSERT_EQ(0U, svc->supp_gids().size()); ASSERT_EQ(0U, svc->supp_gids().size()); } } Loading init/init_test.cpp +4 −3 Original line number Original line Diff line number Diff line Loading @@ -152,10 +152,11 @@ TEST(init, EventTriggerOrderMultipleFiles) { "on boot\n" "on boot\n" "execute 3"; "execute 3"; // clang-format on // clang-format on // write_file() ensures the right mode is set // WriteFile() ensures the right mode is set ASSERT_TRUE(write_file(std::string(dir.path) + "/a.rc", dir_a_script)); std::string err; ASSERT_TRUE(WriteFile(std::string(dir.path) + "/a.rc", dir_a_script, &err)); ASSERT_TRUE(write_file(std::string(dir.path) + "/b.rc", "on boot\nexecute 5")); ASSERT_TRUE(WriteFile(std::string(dir.path) + "/b.rc", "on boot\nexecute 5", &err)); // clang-format off // clang-format off std::string start_script = "import " + std::string(first_import.path) + "\n" std::string start_script = "import " + std::string(first_import.path) + "\n" Loading Loading
init/builtins.cpp +55 −17 Original line number Original line Diff line number Diff line Loading @@ -150,7 +150,12 @@ static int do_class_restart(const std::vector<std::string>& args) { } } static int do_domainname(const std::vector<std::string>& args) { static int do_domainname(const std::vector<std::string>& args) { return write_file("/proc/sys/kernel/domainname", args[1]) ? 0 : 1; std::string err; if (!WriteFile("/proc/sys/kernel/domainname", args[1], &err)) { LOG(ERROR) << err; return -1; } return 0; } } static int do_enable(const std::vector<std::string>& args) { static int do_enable(const std::vector<std::string>& args) { Loading @@ -174,7 +179,12 @@ static int do_export(const std::vector<std::string>& args) { } } static int do_hostname(const std::vector<std::string>& args) { static int do_hostname(const std::vector<std::string>& args) { return write_file("/proc/sys/kernel/hostname", args[1]) ? 0 : 1; std::string err; if (!WriteFile("/proc/sys/kernel/hostname", args[1], &err)) { LOG(ERROR) << err; return -1; } return 0; } } static int do_ifup(const std::vector<std::string>& args) { static int do_ifup(const std::vector<std::string>& args) { Loading Loading @@ -215,11 +225,19 @@ static int do_mkdir(const std::vector<std::string>& args) { } } if (args.size() >= 4) { if (args.size() >= 4) { uid_t uid = decode_uid(args[3].c_str()); uid_t uid; std::string decode_uid_err; if (!DecodeUid(args[3], &uid, &decode_uid_err)) { LOG(ERROR) << "Unable to find UID for '" << args[3] << "': " << decode_uid_err; return -1; } gid_t gid = -1; gid_t gid = -1; if (args.size() == 5) { if (args.size() == 5) { gid = decode_uid(args[4].c_str()); if (!DecodeUid(args[4], &gid, &decode_uid_err)) { LOG(ERROR) << "Unable to find GID for '" << args[3] << "': " << decode_uid_err; return -1; } } } if (lchown(args[1].c_str(), uid, gid) == -1) { if (lchown(args[1].c_str(), uid, gid) == -1) { Loading Loading @@ -643,29 +661,49 @@ static int do_verity_update_state(const std::vector<std::string>& args) { } } static int do_write(const std::vector<std::string>& args) { static int do_write(const std::vector<std::string>& args) { return write_file(args[1], args[2]) ? 0 : 1; std::string err; if (!WriteFile(args[1], args[2], &err)) { LOG(ERROR) << err; return -1; } return 0; } } static int do_copy(const std::vector<std::string>& args) { static int do_copy(const std::vector<std::string>& args) { std::string data; std::string data; if (read_file(args[1], &data)) { std::string err; return write_file(args[2], data) ? 0 : 1; if (!ReadFile(args[1], &data, &err)) { LOG(ERROR) << err; return -1; } if (!WriteFile(args[2], data, &err)) { LOG(ERROR) << err; return -1; } } return 1; return 0; } } static int do_chown(const std::vector<std::string>& args) { static int do_chown(const std::vector<std::string>& args) { /* GID is optional. */ uid_t uid; if (args.size() == 3) { std::string decode_uid_err; if (lchown(args[2].c_str(), decode_uid(args[1].c_str()), -1) == -1) if (!DecodeUid(args[1], &uid, &decode_uid_err)) { return -errno; LOG(ERROR) << "Unable to find UID for '" << args[1] << "': " << decode_uid_err; } else if (args.size() == 4) { if (lchown(args[3].c_str(), decode_uid(args[1].c_str()), decode_uid(args[2].c_str())) == -1) return -errno; } else { return -1; return -1; } } // GID is optional and pushes the index of path out by one if specified. const std::string& path = (args.size() == 4) ? args[3] : args[2]; gid_t gid = -1; if (args.size() == 4) { if (!DecodeUid(args[2], &gid, &decode_uid_err)) { LOG(ERROR) << "Unable to find GID for '" << args[2] << "': " << decode_uid_err; return -1; } } if (lchown(path.c_str(), uid, gid) == -1) return -errno; return 0; return 0; } } Loading
init/init.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -871,7 +871,9 @@ static void selinux_initialize(bool in_kernel_domain) { } } } } if (!write_file("/sys/fs/selinux/checkreqprot", "0")) { std::string err; if (!WriteFile("/sys/fs/selinux/checkreqprot", "0", &err)) { LOG(ERROR) << err; security_failure(); security_failure(); } } Loading
init/init_parser.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -110,7 +110,9 @@ bool Parser::ParseConfigFile(const std::string& path) { LOG(INFO) << "Parsing file " << path << "..."; LOG(INFO) << "Parsing file " << path << "..."; Timer t; Timer t; std::string data; std::string data; if (!read_file(path, &data)) { std::string err; if (!ReadFile(path, &data, &err)) { LOG(ERROR) << err; return false; return false; } } Loading
init/init_parser_test.cpp +14 −4 Original line number Original line Diff line number Diff line Loading @@ -86,19 +86,29 @@ static void Test_make_exec_oneshot_service(bool dash_dash, bool seclabel, bool u ASSERT_EQ("", svc->seclabel()); ASSERT_EQ("", svc->seclabel()); } } if (uid) { if (uid) { ASSERT_EQ(decode_uid("log"), svc->uid()); uid_t decoded_uid; std::string err; ASSERT_TRUE(DecodeUid("log", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->uid()); } else { } else { ASSERT_EQ(0U, svc->uid()); ASSERT_EQ(0U, svc->uid()); } } if (gid) { if (gid) { ASSERT_EQ(decode_uid("shell"), svc->gid()); uid_t decoded_uid; std::string err; ASSERT_TRUE(DecodeUid("shell", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->gid()); } else { } else { ASSERT_EQ(0U, svc->gid()); ASSERT_EQ(0U, svc->gid()); } } if (supplementary_gids) { if (supplementary_gids) { ASSERT_EQ(2U, svc->supp_gids().size()); ASSERT_EQ(2U, svc->supp_gids().size()); ASSERT_EQ(decode_uid("system"), svc->supp_gids()[0]); uid_t decoded_uid; ASSERT_EQ(decode_uid("adb"), svc->supp_gids()[1]); std::string err; ASSERT_TRUE(DecodeUid("system", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->supp_gids()[0]); ASSERT_TRUE(DecodeUid("adb", &decoded_uid, &err)); ASSERT_EQ(decoded_uid, svc->supp_gids()[1]); } else { } else { ASSERT_EQ(0U, svc->supp_gids().size()); ASSERT_EQ(0U, svc->supp_gids().size()); } } Loading
init/init_test.cpp +4 −3 Original line number Original line Diff line number Diff line Loading @@ -152,10 +152,11 @@ TEST(init, EventTriggerOrderMultipleFiles) { "on boot\n" "on boot\n" "execute 3"; "execute 3"; // clang-format on // clang-format on // write_file() ensures the right mode is set // WriteFile() ensures the right mode is set ASSERT_TRUE(write_file(std::string(dir.path) + "/a.rc", dir_a_script)); std::string err; ASSERT_TRUE(WriteFile(std::string(dir.path) + "/a.rc", dir_a_script, &err)); ASSERT_TRUE(write_file(std::string(dir.path) + "/b.rc", "on boot\nexecute 5")); ASSERT_TRUE(WriteFile(std::string(dir.path) + "/b.rc", "on boot\nexecute 5", &err)); // clang-format off // clang-format off std::string start_script = "import " + std::string(first_import.path) + "\n" std::string start_script = "import " + std::string(first_import.path) + "\n" Loading