Example #1
0
std::string SourceRootInfo::path() const {
  if (sandboxOn() || !m_path.empty()) {
    return std::string(m_path.data(), m_path.size());
  } else {
    return RuntimeOption::SourceRoot;
  }
}
SourceRootInfo::SourceRootInfo(const char *host)
    : m_sandboxCond(RuntimeOption::SandboxMode ? SandboxOn : SandboxOff) {
  s_path.destroy();
  s_phproot.destroy();
  if (!sandboxOn()) return;
  Variant matches;
  Variant r = preg_match(String(RuntimeOption::SandboxPattern.c_str(),
                                RuntimeOption::SandboxPattern.size(),
                                AttachLiteral), host, matches);
  if (!r.same(1)) {
    m_sandboxCond = SandboxOff;
    return;
  }
  if (RuntimeOption::SandboxFromCommonRoot) {
    String sandboxName = matches.rvalAt(1).toString();
    createFromCommonRoot(sandboxName);
  } else {
    Array pair = StringUtil::Explode(matches.rvalAt(1), "-", 2);
    m_user = pair.rvalAt(0).toString();
    bool defaultSb = pair.size() == 1;
    if (defaultSb) {
      m_sandbox = "default";
    } else {
      m_sandbox = pair.rvalAt(1).toString();
    }

    createFromUserConfig();
  }
  *s_path.getCheck() = m_path.c_str();
}
string SourceRootInfo::path() const {
  if (sandboxOn()) {
    // Should return RuntimeOption::SourceRoot if m_data is empty?
    return string(m_path.data(), m_path.size());
  } else {
    return RuntimeOption::SourceRoot;
  }
}
Example #4
0
SourceRootInfo::SourceRootInfo(const std::string &user,
                               const std::string &sandbox)
    : m_sandboxCond(RuntimeOption::SandboxMode ? SandboxOn : SandboxOff) {
  if (!sandboxOn()) return;
  m_user = user;
  m_sandbox = sandbox;
  createFromUserConfig();
}
SourceRootInfo::SourceRootInfo(const std::string &user,
                               const std::string &sandbox)
    : m_sandboxCond(RuntimeOption::SandboxMode ? SandboxOn : SandboxOff) {
  s_path.destroy();
  s_phproot.destroy();
  if (!sandboxOn()) return;
  m_user = user;
  m_sandbox = sandbox;
  createFromUserConfig();
  *s_path.getCheck() = m_path.c_str();
}
void SourceRootInfo::setServerVariables(Variant &server) const {
  if (!sandboxOn()) return;
  for (map<string, string>::const_iterator it =
         RuntimeOption::SandboxServerVariables.begin();
       it != RuntimeOption::SandboxServerVariables.end(); ++it) {
    server.set(String(it->first),
               String(parseSandboxServerVariable(it->second)));
  }

  if (!m_serverVars.empty()) {
    server += m_serverVars;
  }
}
void SourceRootInfo::setServerVariables(Variant &server) const {
  if (!sandboxOn()) return;
  for (map<string, string>::const_iterator it =
         RuntimeOption::SandboxServerVariables.begin();
       it != RuntimeOption::SandboxServerVariables.end(); ++it) {
    server.set(String(it->first),
               String(parseSandboxServerVariable(it->second)));
  }

  if (!m_serverVars.empty()) {
    cellAddEq(*server.asCell(), make_tv<KindOfArray>(m_serverVars.get()));
  }
}
Example #8
0
Array SourceRootInfo::setServerVariables(Array server) const {
  if (!sandboxOn()) return std::move(server);
  for (auto it = RuntimeOption::SandboxServerVariables.begin();
       it != RuntimeOption::SandboxServerVariables.end();
       ++it) {
    server.set(String(it->first),
               String(parseSandboxServerVariable(it->second)));
  }

  if (!m_serverVars.empty()) {
    server += m_serverVars;
  }

  return std::move(server);
}
Example #9
0
SourceRootInfo::SourceRootInfo(Transport* transport)
    : m_sandboxCond(RuntimeOption::SandboxMode ? SandboxCondition::On :
                                                 SandboxCondition::Off) {
  s_path.destroy();
  s_phproot.destroy();

  auto documentRoot = transport->getDocumentRoot();
  if (!documentRoot.empty()) {
    m_user = s___builtin;
    m_sandbox = s_default;
    // The transport take precedence over the config file
    m_path = documentRoot;
    *s_path.getCheck() = documentRoot;
    return;
  }

  if (!sandboxOn()) return;
  auto host = transport->getHeader("Host");
  Variant matches;
  Variant r = preg_match(String(RuntimeOption::SandboxPattern.c_str(),
                                RuntimeOption::SandboxPattern.size(),
                                CopyString), host, &matches);
  if (!same(r, 1)) {
    m_sandboxCond = SandboxCondition::Off;
    return;
  }
  if (RuntimeOption::SandboxFromCommonRoot) {
    auto sandboxName = tvCastToString(matches.toArray().rvalAt(1).tv());
    createFromCommonRoot(sandboxName);
  } else {
    Array pair = StringUtil::Explode(
      tvCastToString(matches.toArray().rvalAt(1).tv()),
      "-", 2
    ).toArray();
    m_user = tvCastToString(pair.rvalAt(0).tv());
    bool defaultSb = pair.size() == 1;
    if (defaultSb) {
      m_sandbox = s_default;
    } else {
      m_sandbox = tvCastToString(pair.rvalAt(1).tv());
    }

    createFromUserConfig();
  }
  *s_path.getCheck() = m_path.c_str();
}
Example #10
0
Array SourceRootInfo::setServerVariables(Array server) const {
  if (!sandboxOn()) return server;
  for (auto it = RuntimeOption::SandboxServerVariables.begin();
       it != RuntimeOption::SandboxServerVariables.end();
       ++it) {
    server.set(String(it->first),
               String(parseSandboxServerVariable(it->second)));
  }

  {
    SuppressHackArrCompatNotices suppress;
    if (!m_serverVars.empty()) {
      server += m_serverVars;
    }
  }

  return server;
}
Example #11
0
void SourceRootInfo::setServerVariables(Variant &server) const {
  if (!sandboxOn()) return;
  for (map<string, string>::const_iterator it =
         RuntimeOption::SandboxServerVariables.begin();
       it != RuntimeOption::SandboxServerVariables.end(); ++it) {
    server.set(String(it->first),
               String(parseSandboxServerVariable(it->second)));
  }

  if (!m_serverVars.empty()) {
    server += m_serverVars;
  }

  Eval::DSandboxInfo sandbox;
  sandbox.m_user = m_user.data();
  sandbox.m_name = m_sandbox.data();
  sandbox.m_path = m_path.data();
  server.set("HPHP_SANDBOX_ID", sandbox.id()); // EvalDebugger needs this
  Eval::Debugger::RegisterSandbox(sandbox);
}
Example #12
0
SourceRootInfo::~SourceRootInfo() {
  if (sandboxOn()) {
    Logger::ClearThreadLog();
    HttpRequestHandler::GetAccessLog().clearThreadLog();
  }
}