Ticket #29228: patch-src-darwintrace1.0.in.diff
File patch-src-darwintrace1.0.in.diff, 9.4 KB (added by gauravb7090@…, 11 years ago) |
---|
-
access.c
41 41 #include <sys/syscall.h> 42 42 #include <unistd.h> 43 43 44 int access(const char *path, int amode) {44 int _dt_access(const char *path, int amode) { 45 45 #define access(x, y) syscall(SYS_access, (x), (y)) 46 46 __darwintrace_setup(); 47 47 … … 59 59 return result; 60 60 #undef access 61 61 } 62 DARWINTRACE_INTERPOSE(_dt_access,access); -
close.c
50 50 * need to. This possibility is the \c __darwintrace_close_sock variable, which 51 51 * will be set to the FD to be closed when closing should be allowed. 52 52 */ 53 int close(int fd) {53 int _dt_close(int fd) { 54 54 #define close(x) syscall(SYS_close, (x)) 55 55 __darwintrace_setup(); 56 56 … … 66 66 return close(fd); 67 67 #undef close 68 68 } 69 DARWINTRACE_INTERPOSE(_dt_close,close); -
darwintrace.c
77 77 return result; 78 78 } 79 79 #endif 80 DARWINTRACE_INTERPOSE(strlcpy,strlcpy); 80 81 81 82 #include "../pextlib1.0/strlcat.c" 82 83 … … 158 159 return (pthread_t) pthread_getspecific(tid_key); 159 160 } 160 161 162 161 163 /** 162 164 * Convenience setter function for the thread-local darwintrace socket 163 165 */ -
darwintrace.h
44 44 #include <stdio.h> 45 45 46 46 /** 47 * DARWINTRACE_INTERPOSE: provides a way to override standard library functions with your own implementations 48 */ 49 #ifndef DARWINTRACE_INTERPOSE 50 #define DARWINTRACE_INTERPOSE(_replacement,_replacee) \ 51 __attribute__((used)) static struct { \ 52 const void* replacement; \ 53 const void* replacee; \ 54 } _interpose_##_replacee \ 55 __attribute__ ((section ("__DATA,__interpose"))) = { \ 56 (const void*)(unsigned long)&_replacement, \ 57 (const void*)(unsigned long)&_replacee \ 58 } 59 #endif 60 61 /** 47 62 * DARWINTRACE_DEBUG: verbose output of operations to debug darwintrace 48 63 */ 49 64 #ifndef DARWINTRACE_DEBUG -
dup2.c
48 48 * attempts to overwrite it using \c dup(2). Shells tend to do that a lot when 49 49 * FDs are numbered in ascending order. 50 50 */ 51 int dup2(int filedes, int filedes2) {51 int _dt_dup2(int filedes, int filedes2) { 52 52 #define dup2(x, y) syscall(SYS_dup2, (x), (y)) 53 53 __darwintrace_setup(); 54 54 … … 75 75 return dup2(filedes, filedes2); 76 76 #undef dup2 77 77 } 78 DARWINTRACE_INTERPOSE(_dt_dup2,dup2); -
mkdir.c
53 53 * the sandbox. Will silently do nothing and return success for directories 54 54 * outside the sandbox that already exist. 55 55 */ 56 int mkdir(const char *path, mode_t mode) {56 int _dt_mkdir(const char *path, mode_t mode) { 57 57 #define mkdir(x,y) syscall(SYS_mkdir, (x), (y)) 58 58 #define lstat(x,y) syscall(LSTATSYSNUM, (x), (y)) 59 59 __darwintrace_setup(); … … 78 78 #undef lstat 79 79 #undef mkdir 80 80 } 81 DARWINTRACE_INTERPOSE(_dt_mkdir,mkdir); -
open.c
48 48 * Indicates the file does not exist on sandbox violation, or permission denied 49 49 * when attempting to create a file, i.e., when \c O_CREAT is set. 50 50 */ 51 int open(const char *path, int flags, ...) {51 int _dt_open(const char *path, int flags, ...) { 52 52 #define open(x,y,z) syscall(SYS_open, (x), (y), (z)) 53 53 __darwintrace_setup(); 54 54 int result = 0; … … 70 70 return result; 71 71 #undef open 72 72 } 73 DARWINTRACE_INTERPOSE(_dt_open,open); -
proc.c
254 254 * exist, if it's outside the sandbox. Also checks for potential interpreters 255 255 * using \c check_interpreter. 256 256 */ 257 int execve(const char *path, char *const argv[], char *const envp[]) {257 int _dt_execve(const char *path, char *const argv[], char *const envp[]) { 258 258 #define execve(x,y,z) syscall(SYS_execve, (x), (y), (z)) 259 259 __darwintrace_setup(); 260 260 … … 288 288 return result; 289 289 #undef execve 290 290 } 291 DARWINTRACE_INTERPOSE(_dt_execve,execve); 291 292 292 293 #if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN) 293 294 // Let's save some typing work... … … 303 304 * exist, if it's outside the sandbox. Also checks for potential interpreters 304 305 * using \c check_interpreter. 305 306 */ 306 int posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions,307 int _dt_posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions, 307 308 const posix_spawnattr_t *restrict attrp, char *const argv[restrict], char *const envp[restrict]) { 308 309 __darwintrace_setup(); 309 310 … … 355 356 return result; 356 357 } 357 358 #endif 359 DARWINTRACE_INTERPOSE(_dt_posix_spawn,posix_spawn); -
readlink.c
46 46 * Deny \c readlink(2) if the file is not within the sandbox bounds. 47 47 */ 48 48 #ifdef READLINK_IS_NOT_P1003_1A 49 int readlink(const char *path, char *buf, int bufsiz) {49 int _dt_readlink(const char *path, char *buf, int bufsiz) { 50 50 #else 51 ssize_t readlink(const char *path, char *buf, size_t bufsiz) {51 ssize_t _dt_readlink(const char *path, char *buf, size_t bufsiz) { 52 52 #endif 53 53 #define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z)) 54 54 __darwintrace_setup(); … … 69 69 return result; 70 70 #undef readlink 71 71 } 72 DARWINTRACE_INTERPOSE(_dt_readlink,readlink); -
rename.c
46 46 * Wrapper around \c rename(2) to prevent moving a file outside, or out of the 47 47 * sandbox. 48 48 */ 49 int rename(const char *from, const char *to) {49 int _dt_rename(const char *from, const char *to) { 50 50 #define rename(x,y) syscall(SYS_rename, (x), (y)) 51 51 __darwintrace_setup(); 52 52 … … 67 67 return result; 68 68 #undef rename 69 69 } 70 DARWINTRACE_INTERPOSE(_dt_rename,rename); -
rmdir.c
46 46 * Wrapper around \c rmdir(2) to deny deleting directories outside of the 47 47 * sandbox. 48 48 */ 49 int rmdir(const char *path) {49 int _dt_rmdir(const char *path) { 50 50 #define rmdir(x) syscall(SYS_rmdir, (x)) 51 51 __darwintrace_setup(); 52 52 … … 64 64 return result; 65 65 #undef rmdir 66 66 } 67 DARWINTRACE_INTERPOSE(_dt_rmdir,rmdir); -
stat.c
47 47 * Wrapper around \c stat(2) to hide information about files outside the 48 48 * sandbox. 49 49 */ 50 int stat(const char *path, void *sb) {50 int _dt_stat(const char *path, void *sb) { 51 51 #define stat(path, sb) syscall(SYS_stat, path, sb) 52 52 __darwintrace_setup(); 53 53 … … 66 66 #undef stat 67 67 } 68 68 69 int stat(const char *path, void *sb); 70 DARWINTRACE_INTERPOSE(_dt_stat,stat); 71 69 72 // Don't provide stat64 on systems that have no stat64 syscall 70 73 #ifdef SYS_stat64 71 int stat64(const char *path, void *sb) {74 int _dt_stat64(const char *path, void *sb) { 72 75 #define stat64(path, sb) syscall(SYS_stat64, path, sb) 73 76 __darwintrace_setup(); 74 77 … … 87 90 #undef stat64 88 91 } 89 92 90 int stat$INODE64(const char *path, void *sb) { 91 return stat64(path, sb); 92 } 93 int stat64(const char *path, void *sb); 94 DARWINTRACE_INTERPOSE(_dt_stat64,stat64); 95 96 97 int stat$INODE64(const char *path, void *sb); 98 99 DARWINTRACE_INTERPOSE(_dt_stat64,stat$INODE64); 100 93 101 #endif /* defined(SYS_stat64) */ 94 102 95 int lstat(const char *path, void *sb) { 103 104 int _dt_lstat(const char *path, void *sb) { 96 105 #define lstat(path, sb) syscall(SYS_lstat, path, sb) 97 106 __darwintrace_setup(); 98 107 … … 112 121 #undef lstat 113 122 } 114 123 124 int lstat(const char *path, void *sb); 125 DARWINTRACE_INTERPOSE(_dt_lstat,lstat); 126 115 127 // Don't provide lstat64 on systems that have no lstat64 syscall 116 128 #ifdef SYS_lstat64 117 int lstat64(const char *path, void *sb) {129 int _dt_lstat64(const char *path, void *sb) { 118 130 #define lstat64(path, sb) syscall(SYS_lstat64, path, sb) 119 131 __darwintrace_setup(); 120 132 … … 134 146 #undef lstat64 135 147 } 136 148 137 int lstat$INODE64(const char *path, void *sb) { 138 return lstat64(path, sb); 139 } 149 int lstat64(const char *path, void *sb); 150 DARWINTRACE_INTERPOSE(_dt_lstat64,lstat64); 151 152 int lstat$INODE64(const char *path, void *sb); 153 154 DARWINTRACE_INTERPOSE(_dt_lstat64,lstat$INODE64); 155 140 156 #endif /* defined(SYS_lstat64) */ 157 -
unlink.c
46 46 * Wrapper around \c unlink(2) that will deny attempts to delete files outside 47 47 * of the sandbox and simulate non-existence of the file instead. 48 48 */ 49 int unlink(const char *path) {49 int _dt_unlink(const char *path) { 50 50 #define unlink(x) syscall(SYS_unlink, (x)) 51 51 __darwintrace_setup(); 52 52 … … 64 64 return result; 65 65 #undef unlink 66 66 } 67 DARWINTRACE_INTERPOSE(_dt_unlink,unlink);