| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // Some portions Copyright (c) 2009 The Chromium Authors. | 4 // Some portions Copyright (c) 2009 The Chromium Authors. |
| 5 // | 5 // |
| 6 // Driver program for applying a minijail from the commandline to | 6 // Driver program for applying a minijail from the commandline to |
| 7 // a process and its children (depending on the feature). | 7 // a process and its children (depending on the feature). |
| 8 | 8 |
| 9 #include "minijail/minijail.h" | 9 #include "minijail/minijail.h" |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 PLOG_IF(WARNING, errno) << "failed to parse gid"; | 109 PLOG_IF(WARNING, errno) << "failed to parse gid"; |
| 110 jail_opts->set_gid(gid); | 110 jail_opts->set_gid(gid); |
| 111 } | 111 } |
| 112 | 112 |
| 113 if (!jail_opts->FixUpDependencies()) { | 113 if (!jail_opts->FixUpDependencies()) { |
| 114 LOG(FATAL) << "Irreconcilable jail options given. Aborting."; | 114 LOG(FATAL) << "Irreconcilable jail options given. Aborting."; |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Grab the loose args to use as the command line. | 117 // Grab the loose args to use as the command line. |
| 118 // We have to wstring->argv[][] manually. Ugh. | 118 // We have to wstring->argv[][] manually. Ugh. |
| 119 std::vector<std::wstring> loose_wide_args = cl->GetLooseValues(); | 119 std::vector<std::string> loose_args = cl->args(); |
| 120 std::vector<std::string> loose_args(loose_wide_args.size()); | 120 char const* *jailed_argv = new char const*[loose_args.size() + 1]; |
| 121 char const* *jailed_argv = new char const*[loose_wide_args.size() + 1]; | 121 std::vector<std::string>::const_iterator arg_it = loose_args.begin(); |
| 122 std::vector<std::wstring>::const_iterator arg_it = loose_wide_args.begin(); | |
| 123 char const* *ja = jailed_argv; | 122 char const* *ja = jailed_argv; |
| 124 for (; arg_it != loose_wide_args.end(); ++arg_it) { | 123 for (; arg_it != loose_args.end(); ++arg_it) { |
| 125 std::string arg = WideToASCII(*arg_it); | |
| 126 loose_args.push_back(arg); | |
| 127 // XXX: clean up this leak even though it doesn't matter. | 124 // XXX: clean up this leak even though it doesn't matter. |
| 128 *ja++ = strdup(arg.c_str()); | 125 *ja++ = strdup(arg_it->c_str()); |
| 129 } | 126 } |
| 130 *ja = 0; | 127 *ja = 0; |
| 131 | 128 |
| 132 jail_opts->set_executable_path(jailed_argv[0]); | 129 jail_opts->set_executable_path(jailed_argv[0]); |
| 133 jail_opts->set_arguments(const_cast<char * const*>(jailed_argv), | 130 jail_opts->set_arguments(const_cast<char * const*>(jailed_argv), |
| 134 loose_args.size()); | 131 loose_args.size()); |
| 135 // XXX We just leak this since we're going to exec anyhow. | 132 // XXX We just leak this since we're going to exec anyhow. |
| 136 // delete jailed_argv; | 133 // delete jailed_argv; |
| 137 } | 134 } |
| 138 | 135 |
| 139 int main(int argc, char *argv[], char **envp) { | 136 int main(int argc, char *argv[], char **envp) { |
| 140 CommandLine::Init(argc, argv); | 137 CommandLine::Init(argc, argv); |
| 141 logging::InitLogging(NULL, | 138 logging::InitLogging(NULL, |
| 142 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 139 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
| 143 logging::DONT_LOCK_LOG_FILE, | 140 logging::DONT_LOCK_LOG_FILE, |
| 144 logging::APPEND_TO_OLD_LOG_FILE); | 141 logging::APPEND_TO_OLD_LOG_FILE); |
| 145 | 142 |
| 146 chromeos::MiniJailOptions jail_opts; | 143 chromeos::MiniJailOptions jail_opts; |
| 147 CommandLine *cl = CommandLine::ForCurrentProcess(); | 144 CommandLine *cl = CommandLine::ForCurrentProcess(); |
| 148 ProcessSwitches(cl, &jail_opts); | 145 ProcessSwitches(cl, &jail_opts); |
| 149 jail_opts.set_environment(envp); | 146 jail_opts.set_environment(envp); |
| 150 | 147 |
| 151 LOG_IF(FATAL, !jail_opts.executable_path()) << "No executable given"; | 148 LOG_IF(FATAL, !jail_opts.executable_path()) << "No executable given"; |
| 152 | 149 |
| 153 chromeos::MiniJail jail; | 150 chromeos::MiniJail jail; |
| 154 jail.Initialize(&jail_opts); | 151 jail.Initialize(&jail_opts); |
| 155 bool ok = jail.Jail() && jail.Run(); | 152 bool ok = jail.Jail() && jail.Run(); |
| 156 return !ok; | 153 return !ok; |
| 157 } | 154 } |
| 158 | |
| OLD | NEW |