1#include <stdio.h> 2#include <stdlib.h> 3#include <dlfcn.h> 4#include <unistd.h> 5#include <stdlib.h> 6#include <string.h> 7 8#include <mach/mach.h> 9#include <System/sys/codesign.h> 10 11#include "test.h" 12 13 14int main() 15{ 16#if ENFORCE 17 uint32_t flags = CS_ENFORCEMENT | CS_KILL; 18 if ( csops(0, CS_OPS_SET_STATUS, &flags, sizeof(flags)) != 0 ) { 19 FAIL("dlopen-codesign-dynamic: csops() failed"); 20 return EXIT_SUCCESS; 21 } 22 23 void* handle = dlopen("libfoo.dylib", RTLD_LAZY); 24 if ( handle != NULL ) { 25 FAIL("dlopen-codesign-dynamic: load of libfoo.dylib should have failed"); 26 return EXIT_SUCCESS; 27 } 28 const char* msg = dlerror(); 29 if ( strstr(msg, "signature") == NULL ) { 30 FAIL("dlopen-codesign-dynamic: load of libfoo.dylib failed, but message was wrong: %s", msg); 31 return EXIT_SUCCESS; 32 } 33 34#else 35 void* handle = dlopen("libfoo.dylib", RTLD_LAZY); 36 if ( handle == NULL ) { 37 FAIL("dlopen-codesign-dynamic: load of libfoo.dylib failed"); 38 return EXIT_SUCCESS; 39 } 40 41#endif 42 43 PASS("dlopen-codesign-dynamic"); 44 return EXIT_SUCCESS; 45} 46