/* Trap attempts to rename files/directories outside the sandbox. */ int rename(const char* from, const char* to) { #define __rename(x,y) syscall(SYS_rename, (x), (y)) int result = 0; int isInSandbox = __darwintrace_is_in_sandbox(from, 0); if (isInSandbox == 1) { debug_printf("darwintrace: rename was allowed at %s\n", from); } else if (isInSandbox == 0) { /* outside sandbox, but sandbox is defined: forbid */ debug_printf("darwintrace: renaming from %s was forbidden\n", from); errno = EACCES; result = -1; } if (result == 0) { isInSandbox = __darwintrace_is_in_sandbox(to, 0); if (isInSandbox == 1) { debug_printf("darwintrace: rename was allowed at %s\n", to); } else if (isInSandbox == 0) { /* outside sandbox, but sandbox is defined: forbid */ debug_printf("darwintrace: renaming to %s was forbidden\n", to); errno = EACCES; result = -1; } } if (result == 0) { result = __rename(from, to); } return result; }
int rename(const char *oldpath, const char *newpath) { _gfs_hook_debug_v(fputs("Hooking rename\n", stderr)); return (__rename(oldpath, newpath)); }