Changeset 229 for trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm
- Timestamp:
- 05/19/06 08:12:38 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm
r222 r229 27 27 #import "FSAApp.h" 28 28 #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> 29 34 30 35 NSString * const PatchBundleIdentifier = @"net.sabi.FScriptAnywhere"; … … 130 135 } 131 136 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 132 183 - (void)finishLaunching 133 184 { 185 #ifdef __i386__ 186 if(![[NSUserDefaults standardUserDefaults] objectForKey:@"doPathCheck"]) 187 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"doPathCheck"]; 188 189 if([[NSUserDefaults standardUserDefaults] boolForKey:@"doPathCheck"]){ 190 top: 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 134 231 patchController = new FSAPatchController(self); 135 232 patchController->AddPatch((CFStringRef)PatchBundleIdentifier, CFSTR("Contents/Resources/"),
Note:
See TracChangeset
for help on using the changeset viewer.