Ignore:
Timestamp:
05/19/06 08:12:38 (18 years ago)
Author:
rchin
Message:

Created DSCL framework from DSCL open source code (distributed as a part of Darwin from Apple). This is for programmatically testing and adding entries to directory services, so that I can add the user to the procmod group. The modified DSCL code is in a zip file available for people to use (had to add some methods to provide better read functionality). Also has a binary that does the adding to procmod group with escalated privileges when the user authenticates via the authorization services security framework. Updated the readme to reflect this additional step for building.

File:
1 edited

Legend:

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

    r222 r229  
    2727#import "FSAApp.h"
    2828#import "FSAnywhere.h"
     29#import <DSCL/PathManager.h>
     30#import <CoreFoundation/CoreFoundation.h>
     31#import <ApplicationServices/ApplicationServices.h>
     32#import <Security/Authorization.h>
     33#import <Security/AuthorizationTags.h>
    2934
    3035NSString * const PatchBundleIdentifier = @"net.sabi.FScriptAnywhere";
     
    130135}
    131136
     137-(tDirStatus)authorizeAndAddToProcMod:(NSString *)username
     138{
     139    OSStatus myStatus;
     140    AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
     141    AuthorizationRef myAuthorizationRef;
     142   
     143    myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
     144                                   myFlags, &myAuthorizationRef);
     145    if(myStatus != errAuthorizationSuccess)
     146        return eDSAuthFailed;
     147   
     148    AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
     149    AuthorizationRights myRights = {1, &myItems};
     150   
     151    myFlags = kAuthorizationFlagDefaults
     152        | kAuthorizationFlagInteractionAllowed
     153        | kAuthorizationFlagPreAuthorize
     154        | kAuthorizationFlagExtendRights;
     155    myStatus = AuthorizationCopyRights(myAuthorizationRef, &myRights,
     156                                       NULL, myFlags, NULL);
     157   
     158    if(myStatus != errAuthorizationSuccess)
     159        return eDSAuthFailed;
     160   
     161    myFlags = kAuthorizationFlagDefaults;
     162   
     163    NSString *myToolPath = [[NSBundle mainBundle] pathForResource:@"AddToProcMod" ofType:@""];
     164    char *myArguments[] = { (char *)[username UTF8String], NULL };
     165    FILE *myCommunicationsPipe = NULL;
     166    char myReadBuffer[128];
     167    myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String],
     168                                                  myFlags, myArguments,
     169                                                  &myCommunicationsPipe);
     170   
     171    int didRead = 0;
     172    int lastRead;
     173    while((lastRead = read(fileno(myCommunicationsPipe), myReadBuffer, sizeof(myReadBuffer) - didRead - 1)) && (lastRead > 0))
     174        didRead += lastRead;
     175   
     176    myReadBuffer[didRead - 1] = 0;
     177   
     178    AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDefaults);
     179
     180    return (tDirStatus)strtol(myReadBuffer, NULL, 10);
     181}
     182
    132183- (void)finishLaunching
    133184{
     185#ifdef __i386__
     186    if(![[NSUserDefaults standardUserDefaults] objectForKey:@"doPathCheck"])
     187        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"doPathCheck"];
     188   
     189    if([[NSUserDefaults standardUserDefaults] boolForKey:@"doPathCheck"]){
     190top:
     191        PathManager *pm = [[PathManager alloc] initWithLocalNode];
     192        [pm backupStack];
     193        [pm cd:@"/Groups/procmod"];
     194        CFDictionaryRef sessionInfoDict = CGSessionCopyCurrentDictionary();
     195        if(sessionInfoDict){
     196            CFStringRef shortUserName = (CFStringRef)CFDictionaryGetValue(sessionInfoDict, kCGSessionUserNameKey);
     197            if(![[[pm lastObject] readArray:@"GroupMembership"] containsObject:(NSString *)shortUserName]){
     198                switch([[NSAlert alertWithMessageText:[NSString stringWithFormat:@"User %@ not in the procmod group", shortUserName]
     199                                        defaultButton:@"Add me"
     200                                      alternateButton:@"Disable checking"
     201                                          otherButton:@"Ignore message"
     202                            informativeTextWithFormat:@"F-Script Anywhere requires that you add yourself to the procmod "
     203                    "group in order for it to function properly. If you like, F-Script Anywhere can automatically add you "
     204                    "to the procmod group."] runModal]){
     205                    case NSAlertDefaultReturn:
     206                    {
     207                        tDirStatus status = [self authorizeAndAddToProcMod:(NSString *)shortUserName];
     208                        if(status != eDSNoErr){
     209                            [[NSAlert alertWithMessageText:@"Error adding to procmod group"
     210                                             defaultButton:nil
     211                                           alternateButton:nil
     212                                               otherButton:nil
     213                                 informativeTextWithFormat:@"There was an error (%@) adding you to the procmod group. ", [[NSClassFromString(@"DSoStatus") sharedInstance] stringForStatus:status]] runModal];
     214                        }
     215                    }
     216                        [pm restoreStack];
     217                        [pm release];
     218                        goto top;
     219                    case NSAlertAlternateReturn:
     220                        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"doPathCheck"];
     221                        break;
     222                    default:
     223                        break;
     224                }           
     225            }
     226        }
     227        [pm restoreStack];
     228        [pm release];
     229    }
     230#endif
    134231    patchController = new FSAPatchController(self);
    135232    patchController->AddPatch((CFStringRef)PatchBundleIdentifier, CFSTR("Contents/Resources/"),
Note: See TracChangeset for help on using the changeset viewer.