sandbox_compiler.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sandbox/mac/sandbox_compiler.h"
  5. #include <map>
  6. #include <string>
  7. #include <vector>
  8. #include "sandbox/mac/seatbelt.h"
  9. namespace sandbox {
  10. SandboxCompiler::SandboxCompiler(const std::string& profile_str)
  11. : params_map_(), profile_str_(profile_str) {}
  12. SandboxCompiler::~SandboxCompiler() {}
  13. bool SandboxCompiler::InsertBooleanParam(const std::string& key, bool value) {
  14. return params_map_.insert(std::make_pair(key, value ? "TRUE" : "FALSE"))
  15. .second;
  16. }
  17. bool SandboxCompiler::InsertStringParam(const std::string& key,
  18. const std::string& value) {
  19. return params_map_.insert(std::make_pair(key, value)).second;
  20. }
  21. bool SandboxCompiler::CompileAndApplyProfile(std::string* error) {
  22. char* error_internal = nullptr;
  23. std::vector<const char*> params;
  24. for (const auto& kv : params_map_) {
  25. params.push_back(kv.first.c_str());
  26. params.push_back(kv.second.c_str());
  27. }
  28. // The parameters array must be null terminated.
  29. params.push_back(static_cast<const char*>(0));
  30. if (sandbox::Seatbelt::InitWithParams(profile_str_.c_str(), 0, params.data(),
  31. &error_internal)) {
  32. error->assign(error_internal);
  33. sandbox::Seatbelt::FreeError(error_internal);
  34. return false;
  35. }
  36. return true;
  37. }
  38. } // namespace sandbox