Changeset 18721 for trunk/base
- Timestamp:
- Jul 25, 2006, 4:01:34 AM (18 years ago)
- Location:
- trunk/base
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/base/src/darwintracelib1.0/darwintrace.c
r18709 r18721 4 4 * All rights reserved. 5 5 * 6 * $Id: darwintrace.c,v 1.1 5 2006/07/24 05:55:43 pguyot Exp $6 * $Id: darwintrace.c,v 1.16 2006/07/25 04:01:33 pguyot Exp $ 7 7 * 8 8 * @APPLE_BSD_LICENSE_HEADER_START@ … … 59 59 * DARWINTRACE_SHOW_PROCESS: show the process id of every access 60 60 * DARWINTRACE_LOG_CREATE: log creation of files as well. 61 * DARWINTRACE_SANDBOX: control creation and writing to files.61 * DARWINTRACE_SANDBOX: control creation, deletion and writing to files. 62 62 * DARWINTRACE_LOG_FULL_PATH: use F_GETPATH to log the full path. 63 63 * DARWINTRACE_DEBUG_OUTPUT: verbose output of stuff to debug darwintrace. … … 332 332 } 333 333 334 #if DARWINTRACE_SANDBOX 335 /* 336 * return 1 if path (once normalized) is in sandbox, 0 otherwise. 337 * return -1 if no sandbox is defined or if the path couldn't be normalized. 338 */ 339 inline int __darwintrace_is_in_sandbox(const char* path) { 340 int result = -1; /* no sandbox is defined */ 341 __darwintrace_setup(); 342 if (__darwintrace_sandbox_bounds != NULL) { 343 /* check the path */ 344 char** basePathsCrsr = __darwintrace_sandbox_bounds; 345 char* basepath = *basePathsCrsr++; 346 /* normalize the path */ 347 char createpath[MAXPATHLEN]; 348 if (realpath(path, createpath) != NULL) { 349 __darwintrace_cleanup_path(createpath); 350 /* say it's outside unless it's proved inside */ 351 result = 0; 352 while (basepath != NULL) { 353 if (__darwintrace_strbeginswith(createpath, basepath)) { 354 result = 1; 355 break; 356 } 357 basepath = *basePathsCrsr++;; 358 } 359 } /* otherwise, operation will fail anyway */ 360 } 361 return result; 362 } 363 #endif 364 334 365 /* Log calls to open(2) into the file specified by DARWINTRACE_LOG. 335 366 Only logs if the DARWINTRACE_LOG environment variable is set. … … 354 385 result = 0; 355 386 if (flags & (O_CREAT | O_APPEND | O_RDWR | O_WRONLY | O_TRUNC)) { 356 __darwintrace_setup(); 357 if (__darwintrace_sandbox_bounds != NULL) { 358 /* check the path */ 359 char** basePathsCrsr = __darwintrace_sandbox_bounds; 360 char* basepath = *basePathsCrsr++; 361 /* normalize the path */ 362 char createpath[MAXPATHLEN]; 363 if (realpath(path, createpath) != NULL) { 364 __darwintrace_cleanup_path(createpath); 365 /* forbid unless allowed */ 366 result = -1; 367 while (basepath != NULL) { 368 if (__darwintrace_strbeginswith(createpath, basepath)) { 369 result = 0; 370 break; 371 } 372 basepath = *basePathsCrsr++;; 373 } 374 } /* otherwise, open will fail anyway */ 375 } 376 if (result == 0) { 387 int isInSandbox = __darwintrace_is_in_sandbox(path); 388 if (isInSandbox == 1) { 377 389 dprintf("darwintrace: creation/writing was allowed at %s\n", path); 390 } else if (isInSandbox == 0) { 391 /* outside sandbox, but sandbox is defined: forbid */ 392 dprintf("darwintrace: creation/writing was forbidden at %s\n", path); 393 __darwintrace_log_op("sandbox_violation", NULL, path, 0); 394 errno = EACCES; 395 result = -1; 378 396 } 379 397 } 380 398 if (result == 0) { 381 399 result = open(path, flags, mode); 382 } else {383 dprintf("darwintrace: creation/writing was forbidden at %s\n", path);384 __darwintrace_log_op("sandbox_violation", NULL, path, result);385 errno = EACCES;386 400 } 387 401 #else … … 527 541 #undef close 528 542 } 543 544 #if DARWINTRACE_SANDBOX 545 /* Trap attempts to unlink a file outside the sandbox. 546 */ 547 int unlink(const char* path) { 548 #define __unlink(x) syscall(SYS_unlink, (x)) 549 int result = 0; 550 int isInSandbox = __darwintrace_is_in_sandbox(path); 551 if (isInSandbox == 1) { 552 dprintf("darwintrace: unlink was allowed at %s\n", path); 553 } else if (isInSandbox == 0) { 554 /* outside sandbox, but sandbox is defined: forbid */ 555 dprintf("darwintrace: unlink was forbidden at %s\n", path); 556 __darwintrace_log_op("sandbox_violation", NULL, path, 0); 557 errno = EACCES; 558 result = -1; 559 } 560 561 if (result == 0) { 562 result = __unlink(path); 563 } 564 565 return result; 566 } 567 #endif -
trunk/base/src/port1.0/porttrace.tcl
r18709 r18721 2 2 # porttrace.tcl 3 3 # 4 # $Id: porttrace.tcl,v 1.1 7 2006/07/24 05:55:44 pguyot Exp $4 # $Id: porttrace.tcl,v 1.18 2006/07/25 04:01:34 pguyot Exp $ 5 5 # 6 6 # Copyright (c) 2005-2006 Paul Guyot <pguyot@kallisys.net>, … … 118 118 119 119 foreach violation [lsort $violations] { 120 ui_warn "A file creation/ writingwas attempted outside sandbox: $violation"120 ui_warn "A file creation/deletion/modification was attempted outside sandbox: $violation" 121 121 } 122 122 } -
trunk/base/tests/Makefile
r18709 r18721 3 3 SUBDIR=checksums-1 envvariables site-tags trace xcodeversion 4 4 5 .PHONY: test 5 .PHONY: test clean 6 6 7 7 all: … … 23 23 @exit 1 24 24 25 test: /tmp/darwinports-tests/opt/local/etc/ports/sources.conf25 test: clean /tmp/darwinports-tests/opt/local/etc/ports/sources.conf 26 26 @for subdir in $(SUBDIR); do\ 27 27 echo ===\> test ${DIRPRFX}$$subdir; \ … … 39 39 exit 1; \ 40 40 else \ 41 rm -f difference ; \41 rm -f difference output.sed; \ 42 42 fi) \ 43 43 fi || exit 1; \ -
trunk/base/tests/trace/Makefile
r18709 r18721 9 9 test: 10 10 @PORTSRC=$(PORTSRC) $(bindir)/port clean > /dev/null 11 @touch delete-trace 11 12 @PORTSRC=$(PORTSRC) $(bindir)/port -t test > output 2>&1 || (cat output; exit 1) 13 @rm -f delete-trace 12 14 @sed -e "s|${PWD}|PWD|g" < output > output.sed 13 15 @diff output.sed master 2>&1 | tee difference … … 15 17 exit 1; \ 16 18 else \ 17 rm -f difference ; \19 rm -f difference output.sed; \ 18 20 fi -
trunk/base/tests/trace/Portfile
r18709 r18721 1 # $Id: Portfile,v 1. 2 2006/07/24 05:55:44 pguyot Exp $1 # $Id: Portfile,v 1.3 2006/07/25 04:01:34 pguyot Exp $ 2 2 3 3 PortSystem 1.0 … … 20 20 21 21 test { 22 catch {system "rm -f hello-trace && touch hello-trace && rm hello-trace"} 22 catch {system "rm -f create-trace && touch create-trace && rm create-trace"} 23 catch {system "rm delete-trace"} 23 24 catch {system "rm -f /tmp/hello-trace && /tmp/hello-trace && rm /tmp/hello-trace"} 24 25 } -
trunk/base/tests/trace/master
r18709 r18721 5 5 ---> Building trace with target all 6 6 ---> Testing trace 7 Warning: A file creation/writing was attempted outside sandbox: PWD/hello-trace 7 Warning: A file creation/deletion/modification was attempted outside sandbox: PWD/create-trace 8 Warning: A file creation/deletion/modification was attempted outside sandbox: PWD/delete-trace
Note: See TracChangeset
for help on using the changeset viewer.