X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fthecheat;a=blobdiff_plain;f=main.m;h=444451b79e3400b9a69613a58a81e74759122ff5;hp=7075d5dff800dfcd9b569558a32c3f2185b07d99;hb=179538478d0db2e5f8f2b50ccb3ff889b474aa01;hpb=ad02580588e2ca41f15ba8f9bd084561d8d485c2 diff --git a/main.m b/main.m index 7075d5d..444451b 100644 --- a/main.m +++ b/main.m @@ -23,6 +23,9 @@ #import #import #include "ChazLog.h" +#include +#include +#include void authMe(char * FullPathToMe) { @@ -74,13 +77,21 @@ void authMe(char * FullPathToMe) } } +bool checkExecutablePermissions(void) +{ + NSDictionary *applicationAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:[[NSBundle mainBundle] executablePath] traverseLink: YES]; + + // We expect 2755 as octal (1517 as decimal, -rwxr-sr-x as extended notation) + return ([applicationAttributes filePosixPermissions] == 1517 && [[applicationAttributes fileGroupOwnerAccountName] isEqualToString: @"procmod"]); +} + bool amIWorthy(void) { // running as root? AuthorizationRef myAuthRef; OSStatus stat = AuthorizationCopyPrivilegedReference(&myAuthRef,kAuthorizationFlagDefaults); - return stat == errAuthorizationSuccess; + return stat == errAuthorizationSuccess || checkExecutablePermissions(); } int main( int argc, char *argv[] ) @@ -92,18 +103,31 @@ int main( int argc, char *argv[] ) ChazDebugSetup(); ChazMapLogToDebug(); - [pool release]; +#ifdef __ppc__ + // PPC machines whose operating system is below leopard do not need authorization + SInt32 osxMajorVersion; + Gestalt(gestaltSystemVersionMinor, &osxMajorVersion); + if (osxMajorVersion < 5) + { + [pool release]; + return NSApplicationMain(argc, (const char **) argv); + } +#endif if (amIWorthy()) { - printf("Don't forget to flush! ;-) "); // signal back to close caller +#ifndef _DEBUG + printf("Don't forget to flush! ;-) "); // signal back to close caller +#endif fflush(stdout); + [pool release]; return NSApplicationMain(argc, (const char **) argv); } else { authMe(argv[0]); + [pool release]; return 0; }