Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: content/common/sandbox_mac_diraccess_unittest.mm

Issue 1213113006: Revert of Refactor OS X sandbox processing and audit sandbox files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/sandbox_mac_compiler_unittest.mm ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #include <dirent.h> 6 #include <dirent.h>
7 7
8 extern "C" { 8 extern "C" {
9 #include <sandbox.h> 9 #include <sandbox.h>
10 } 10 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 EXPECT_TRUE(CheckSandbox(sandbox_dir.value())); 177 EXPECT_TRUE(CheckSandbox(sandbox_dir.value()));
178 } 178 }
179 } 179 }
180 180
181 MULTIPROCESS_TEST_MAIN(mac_sandbox_path_access) { 181 MULTIPROCESS_TEST_MAIN(mac_sandbox_path_access) {
182 char *sandbox_allowed_dir = getenv(kSandboxAccessPathKey); 182 char *sandbox_allowed_dir = getenv(kSandboxAccessPathKey);
183 if (!sandbox_allowed_dir) 183 if (!sandbox_allowed_dir)
184 return -1; 184 return -1;
185 185
186 std::string final_allowed_dir; 186 // Build up a sandbox profile that only allows access to a single directory.
187 EXPECT_TRUE( 187 NSString *sandbox_profile =
188 Sandbox::QuoteStringForRegex(sandbox_allowed_dir, &final_allowed_dir)); 188 @"(version 1)" \
189 "(deny default)" \
190 "(allow signal (target self))" \
191 "(allow sysctl-read)" \
192 ";ENABLE_DIRECTORY_ACCESS";
189 193
190 // Build up a sandbox profile that only allows access to a single directory. 194 std::string allowed_dir(sandbox_allowed_dir);
191 std::string sandbox_profile = 195 Sandbox::SandboxVariableSubstitions substitutions;
192 "(version 1)" 196 NSString* allow_dir_sandbox_code =
193 "(define perm_dir (param \"PERMITTED_DIR\"))" 197 Sandbox::BuildAllowDirectoryAccessSandboxString(
194 "(deny default)" 198 base::FilePath(sandbox_allowed_dir),
195 "(allow signal (target self))" 199 &substitutions);
196 "(allow sysctl-read)" 200 sandbox_profile = [sandbox_profile
197 "(if (string? perm_dir)" 201 stringByReplacingOccurrencesOfString:@";ENABLE_DIRECTORY_ACCESS"
198 " (begin" 202 withString:allow_dir_sandbox_code];
199 " (allow file-read-metadata )"
200 " (allow file-read* file-write* (regex (string-append #\"\" "
201 "perm_dir)))))";
202 203
203 // Setup the parameters to pass to the sandbox. 204 std::string final_sandbox_profile_str;
204 SandboxCompiler compiler(sandbox_profile); 205 if (!Sandbox::PostProcessSandboxProfile(sandbox_profile,
205 CHECK(compiler.InsertStringParam("PERMITTED_DIR", final_allowed_dir)); 206 [NSArray array],
206 207 substitutions,
207 // Enable Sandbox. 208 &final_sandbox_profile_str)) {
208 std::string error_str; 209 LOG(ERROR) << "Call to PostProcessSandboxProfile() failed";
209 if (!compiler.CompileAndApplyProfile(&error_str)) {
210 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_str;
211 return -1; 210 return -1;
212 } 211 }
213 212
213 // Enable Sandbox.
214 char* error_buff = NULL;
215 int error = sandbox_init(final_sandbox_profile_str.c_str(), 0, &error_buff);
216 if (error == -1) {
217 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff;
218 return -1;
219 }
220 sandbox_free_error(error_buff);
221
214 // Test Sandbox. 222 // Test Sandbox.
215 223
216 // We should be able to list the contents of the sandboxed directory. 224 // We should be able to list the contents of the sandboxed directory.
217 DIR *file_list = NULL; 225 DIR *file_list = NULL;
218 file_list = opendir(sandbox_allowed_dir); 226 file_list = opendir(sandbox_allowed_dir);
219 if (!file_list) { 227 if (!file_list) {
220 PLOG(ERROR) << "Sandbox overly restrictive: call to opendir(" 228 PLOG(ERROR) << "Sandbox overly restrictive: call to opendir("
221 << sandbox_allowed_dir 229 << sandbox_allowed_dir
222 << ") failed"; 230 << ") failed";
223 return -1; 231 return -1;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 PLOG(ERROR) << "Sandbox breach: was able to write (" 300 PLOG(ERROR) << "Sandbox breach: was able to write ("
293 << denied_file2.value() 301 << denied_file2.value()
294 << ")"; 302 << ")";
295 return -1; 303 return -1;
296 } 304 }
297 305
298 return 0; 306 return 0;
299 } 307 }
300 308
301 } // namespace content 309 } // namespace content
OLDNEW
« no previous file with comments | « content/common/sandbox_mac_compiler_unittest.mm ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698