#import "CheatServer.h"
-
@class AboutBoxController;
@class HelpController;
@class PreferenceController;
- (IBAction)checkForUpdate:(id)sender;
+// Privilage elevation stuff
+AuthorizationRef _authRef;
+AuthorizationItem _authItem;
+AuthorizationRights _authRights;
+- (int) preAuthorize;
+- (int) launchAuthPrgm;
+
// Server Stuff
- (CheatServer *)cheatServer;
- (BOOL)startCheatServer;
#import "HelpController.h"
#import "PreferenceController.h"
+// Privilage elevation libs
+#include <security/authorization.h>
+#include <security/authorizationdb.h>
+#include <security/authorizationtags.h>
+#include <sys/types.h>
+#include <unistd.h>
@implementation AppController
- (id)init
{
- if ( self = [super init] ) {
- [self setDelegate:self];
+ if ( self = [super init] )
+ {
+ if( geteuid() != 0 )
+ {
+ [self launchAuthPrgm];
+ [self setDelegate:self];
+ }
}
+ if( geteuid() != 0 )
+ {
+ NSRunAlertPanel(@"The Cheat must be run as root,",
+ @"Due to a limitation of Leopard, the application needs elevated privileges to run.",
+ @"Exit", nil, nil );
+ [self terminate: 0];
+ }
+
return self;
}
+- (int) preAuthorize
+{
+ int err;
+ AuthorizationFlags authFlags;
+
+
+ NSLog (@"MyWindowController: preAuthorize");
+
+ if (_authRef)
+ return errAuthorizationSuccess;
+
+ NSLog (@"MyWindowController: preAuthorize: ** calling AuthorizationCreate...**\n");
+
+ authFlags = kAuthorizationFlagDefaults;
+ err = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment, authFlags, &_authRef);
+ if (err != errAuthorizationSuccess)
+ return err;
+
+ NSLog (@"MyWindowController: preAuthorize: ** calling AuthorizationCopyRights...**\n");
+
+ _authItem.name = kAuthorizationRightExecute;
+ _authItem.valueLength = 0;
+ _authItem.value = NULL;
+ _authItem.flags = 0;
+ _authRights.count = 1;
+ _authRights.items = (AuthorizationItem*) malloc (sizeof (_authItem));
+ memcpy (&_authRights.items[0], &_authItem, sizeof (_authItem));
+ authFlags = kAuthorizationFlagDefaults
+ | kAuthorizationFlagExtendRights
+ | kAuthorizationFlagInteractionAllowed
+ | kAuthorizationFlagPreAuthorize;
+ err = AuthorizationCopyRights (_authRef, &_authRights, kAuthorizationEmptyEnvironment, authFlags, NULL);
+
+ return err;
+}
+
+- (int) launchAuthPrgm
+{
+ AuthorizationFlags authFlags;
+ int err;
+
+ // path
+ NSString * path = [[NSBundle mainBundle] executablePath];
+ if (![[NSFileManager defaultManager] isExecutableFileAtPath: path])
+ return -1;
+
+ // auth
+
+ if (!_authRef)
+ {
+ err = [self preAuthorize];
+ if (err != errAuthorizationSuccess)
+ return err;
+ }
+
+ // launch
+
+ NSLog (@"MyWindowController: launchWithPath: ** calling AuthorizationExecuteWithPrivileges...**\n");
+ authFlags = kAuthorizationFlagDefaults;
+ err = AuthorizationExecuteWithPrivileges (_authRef, [path cString], authFlags, NULL, NULL);
+ if(err==0) [NSApp terminate:self];
+
+ return err;
+}
- (void)dealloc
{
-{
- IBClasses = (
- {
- ACTIONS = {ibEmailButton = id; ibWebsiteButton = id; };
- CLASS = AboutBoxController;
- LANGUAGE = ObjC;
- OUTLETS = {
- ibDateText = NSTextField;
- ibEmailButton = NSButton;
- ibNameVersionText = NSTextField;
- ibWebsiteButton = NSButton;
- };
- SUPERCLASS = NSWindowController;
- },
- {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
- );
- IBVersion = 1;
-}
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IBClasses</key>
+ <array>
+ <dict>
+ <key>ACTIONS</key>
+ <dict>
+ <key>ibEmailButton</key>
+ <string>id</string>
+ <key>ibWebsiteButton</key>
+ <string>id</string>
+ </dict>
+ <key>CLASS</key>
+ <string>AboutBoxController</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>OUTLETS</key>
+ <dict>
+ <key>ibDateText</key>
+ <string>NSTextField</string>
+ <key>ibEmailButton</key>
+ <string>NSButton</string>
+ <key>ibNameVersionText</key>
+ <string>NSTextField</string>
+ <key>ibWebsiteButton</key>
+ <string>NSButton</string>
+ </dict>
+ <key>SUPERCLASS</key>
+ <string>NSWindowController</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSMenu</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSObject</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>FirstResponder</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSObject</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSObject</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ </dict>
+ </array>
+ <key>IBVersion</key>
+ <string>1</string>
+</dict>
+</plist>
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>IBDocumentLocation</key>
- <string>124 93 356 241 0 0 1280 938 </string>
<key>IBFramework Version</key>
- <string>364.0</string>
- <key>IBGroupedObjects</key>
- <dict>
- <key>3</key>
- <array>
- <string>93</string>
- <string>91</string>
- </array>
- <key>7</key>
- <array>
- <string>77</string>
- <string>80</string>
- <string>87</string>
- </array>
- <key>8</key>
- <array>
- <string>89</string>
- <string>81</string>
- </array>
- </dict>
- <key>IBLastGroupID</key>
- <string>9</string>
+ <string>677</string>
+ <key>IBLastKnownRelativeProjectPath</key>
+ <string>../The Cheat.xcodeproj</string>
+ <key>IBOldestOS</key>
+ <integer>5</integer>
<key>IBOpenObjects</key>
<array>
- <integer>85</integer>
+ <integer>78</integer>
</array>
<key>IBSystem Version</key>
- <string>7U16</string>
+ <string>9C7010</string>
+ <key>targetFramework</key>
+ <string>IBCocoaFramework</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<key>CFBundleExecutable</key>
<string>The Cheat</string>
<key>CFBundleGetInfoString</key>
- <string>The Cheat 1.2.1</string>
+ <string>The Cheat 1.2.2</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>1.2.1</string>
+ <string>1.2.2</string>
<key>CFBundleSignature</key>
<string>chœt</string>
<key>CFBundleURLTypes</key>
</dict>
</array>
<key>CFBundleVersion</key>
- <string>1.2.1</string>
+ <string>1.2.2</string>
<key>NSAppleScriptEnabled</key>
<string>YES</string>
<key>NSMainNibFile</key>
#import <Cocoa/Cocoa.h>
#include "ChazLog.h"
-
int main( int argc, const char *argv[] )
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];