Ignore:
Timestamp:
10/12/07 21:53:46 (13 years ago)
Author:
rchin
Message:

Leopard compatibility changes:

  • Removed some icon caching code that was causing crashes (not sure we really needed those optimizations anyway -- doesn't appear to affect performance)
  • Added code to automatically try to add certificate to keychain, for new code signing behavior (replaces previous procmod nonesense).
  • Note that the enclosed public certificate is mine, and so it will need to be signed by me. In the case that someone else wants to distribute this binary, please replace Certficiate.cer with your own public certificate, and then make sure o code sign the binary after it is built.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm

    r231 r342  
    2727#import "FSAApp.h"
    2828#import "FSAnywhere.h"
    29 #import <DSCL/PathManager.h>
    3029#import <CoreFoundation/CoreFoundation.h>
    3130#import <ApplicationServices/ApplicationServices.h>
     
    4544    { 5, @"F-Script Anywhere must be installed in a Cocoa application running as the current user.\n\nYou may be attempting to install in a setuid application, which is not supported" },
    4645    { 11, @"F-Script Anywhere cannot be installed in itself.\n\nIf you wish to install F-Script Anywhere in itself, make a copy of the F-Script Anywhere application and install one copy into the other" },
    47     { smUnExBusErr, @"a bus error occurred.\n\nTry switching to the application first then using F-Script AnywhereÕs dock menu to install" },
     46    { smUnExBusErr, @"a bus error occurred.\n\nTry switching to the application first then using F-Script Anywhere's dock menu to install" },
    4847    { fnfErr, @"F-Script Anywhere was unable to locate its component to install in the application.  Please try reinstalling F-Script Anywhere" },
    4948    { cfragDupRegistrationErr, @"another running copy of F-Script Anywhere is already installed in the application"},
     
    222221}
    223222
    224 -(tDirStatus)authorizeAndAddToProcMod:(NSString *)username
    225 {
    226     OSStatus myStatus;
    227    
    228     if(![self createAuthorization])
    229         return eDSAuthFailed;
    230    
    231     NSString *myToolPath = [[NSBundle mainBundle] pathForResource:@"AddToProcMod" ofType:@""];
    232     char *myArguments[] = { (char *)[username UTF8String], NULL };
    233     FILE *myCommunicationsPipe = NULL;
    234     char myReadBuffer[128];
    235     myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String],
    236                                                   myFlags, myArguments,
    237                                                   &myCommunicationsPipe);
    238    
    239     int didRead = 0;
    240     int lastRead;
    241     while((lastRead = read(fileno(myCommunicationsPipe), myReadBuffer, sizeof(myReadBuffer) - didRead - 1)) && (lastRead > 0))
    242         didRead += lastRead;
    243    
    244     myReadBuffer[didRead - 1] = 0;
    245    
    246     return (tDirStatus)strtol(myReadBuffer, NULL, 10);
    247 }
    248 
    249223- (void)finishLaunching
    250224{
    251225    mach_port_t     taskOfOurProcess = mach_task_self();
    252226    mach_port_t     machPortForProcess;
    253    
    254     if(task_for_pid(taskOfOurProcess, 1, &machPortForProcess) != KERN_SUCCESS){ // launchd should always be pid 1
    255         if(![[NSUserDefaults standardUserDefaults] objectForKey:@"doPathCheck"])
    256             [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"doPathCheck"];
    257        
    258         if([[NSUserDefaults standardUserDefaults] boolForKey:@"doPathCheck"]){
    259 top:
    260             PathManager *pm = [[PathManager alloc] initWithLocalNode];
    261             [pm backupStack];
    262             @try {
    263                 [pm cd:@"/Groups/procmod"];
    264             } @catch ( NSException *exception ) {
    265                 goto next;  // this means we must be on ppc 10.4 or less.
    266             }
    267             CFDictionaryRef sessionInfoDict = CGSessionCopyCurrentDictionary();
    268             if(sessionInfoDict){
    269                 CFStringRef shortUserName = (CFStringRef)CFDictionaryGetValue(sessionInfoDict, kCGSessionUserNameKey);
    270                 if(![[[pm lastObject] readArray:@"GroupMembership"] containsObject:(NSString *)shortUserName]){
    271                     switch([[NSAlert alertWithMessageText:[NSString stringWithFormat:@"User %@ not in the procmod group", shortUserName]
    272                                             defaultButton:@"Add me"
    273                                           alternateButton:@"Disable checking"
    274                                               otherButton:@"Ignore message"
    275                                 informativeTextWithFormat:@"F-Script Anywhere requires that you add yourself to the procmod "
    276                         "group in order for it to function properly. If you like, F-Script Anywhere can automatically add you "
    277                         "to the procmod group."] runModal]){
    278                         case NSAlertDefaultReturn:
    279                         {
    280                             tDirStatus status = [self authorizeAndAddToProcMod:(NSString *)shortUserName];
    281                             if(status != eDSNoErr){
    282                                 [[NSAlert alertWithMessageText:@"Error adding to procmod group"
    283                                                  defaultButton:nil
    284                                                alternateButton:nil
    285                                                    otherButton:nil
    286                                      informativeTextWithFormat:@"There was an error (%@) adding you to the procmod group. ", [[NSClassFromString(@"DSoStatus") sharedInstance] stringForStatus:status]] runModal];
    287                             } else {
    288                                 [[NSAlert alertWithMessageText:@"Adding user procmod group succeeded"
    289                                                  defaultButton:nil
    290                                                alternateButton:nil
    291                                                    otherButton:nil
    292                                      informativeTextWithFormat:@"You may have to wait a few minutes until the system updates its caches (or alternatively, reboot your machine) before things will work properly."] runModal];
    293                             }
    294                         }
    295                             [pm restoreStack];
    296                             [pm release];
    297                             goto top;
    298                         case NSAlertAlternateReturn:
    299                             [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"doPathCheck"];
    300                             break;
    301                         default:
    302                             break;
    303                     }           
    304                 }
    305             }
    306             [pm restoreStack];
    307             [pm release];
    308         }
     227    /* under new rules for task_for_pid, only processes with proper permissions can call task_for_pid successfullly */
     228    int ourPid = [[NSProcessInfo processInfo] processIdentifier];
     229    NSLog(@"our pid %d", ourPid);
     230    if(task_for_pid(taskOfOurProcess, ourPid, &machPortForProcess) == KERN_SUCCESS){ // launchd should always be pid 1
     231        mach_port_deallocate(taskOfOurProcess, machPortForProcess);
    309232    } else {
    310         mach_port_deallocate(taskOfOurProcess, machPortForProcess);
    311     }
    312 next:
     233        int result = NSRunInformationalAlertPanel(
     234                                                  NSLocalizedString(@"Certificate not trusted", "Framework not found alert title"),
     235                                                  NSLocalizedString(@"Due to new security features in Leopard, F-Script Anywhere requires you to to trust the signature on the current application. "
     236                                                                    "You have several options:\n"
     237                                                                    "1. You can add the signing certificate automatically to your keychain, in which case you should click \"OK\" in the next dialog box to add the certificate to your keychain, and then \"Always Trust.\"\n"
     238                                                                    "2. You can quit F-Script Anywhere, create a signing authority on your local machine, trust it, and then sign the application binary yourself.\n"
     239                                                                    @"Note that if you add the certificate properly and you still get an F-Script Anywhere error when injecting, you may need to restart your computer to clear the proper keychain caches.", @"no certificate warning message"),
     240                                                  NSLocalizedString(@"Add certificate", "'add certificate button title"),
     241                                                  NSLocalizedString(@"Quit", "Quit button title"),
     242                                                  NULL);
     243        switch (result) {
     244            case NSAlertDefaultReturn:
     245                NSString *certPath = [[NSBundle mainBundle] pathForResource:@"Certificate" ofType:@"cer"];
     246                [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:certPath]];
     247                break;
     248            case NSAlertAlternateReturn:
     249                [self terminate: self];
     250                break;
     251            default:
     252                break;
     253        }       
     254    }
    313255    patchController = new FSAPatchController(self);
    314256    patchController->AddPatch((CFStringRef)PatchBundleIdentifier, CFSTR("Contents/Resources/"),
Note: See TracChangeset for help on using the changeset viewer.