Changeset 3857

Show
Ignore:
Timestamp:
03/01/06 19:43:47 (3 years ago)
Author:
morris
Message:

Write extra flags to etc/wired.flags, and only touch etc/wired.startup for launch at boot

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredServer/trunk/PreferencePane/WPWired.m

    r3403 r3857  
    147147                        [NSArray arrayWithObjects: 
    148148                                WCExpandWiredPath(@"wiredctl"), 
     149                                @"/usr/bin/touch", 
    149150                                @"/bin/mv", 
    150151                                @"/bin/rm", 
  • WiredServer/trunk/WCAuthorization.h

    r3011 r3857  
    4444- (BOOL)launchTaskWithPath:(NSString *)path arguments:(NSArray *)arguments; 
    4545 
     46- (BOOL)createFileAtPath:(NSString *)path; 
    4647- (BOOL)movePath:(NSString *)fromPath toPath:(NSString *)toPath; 
    4748- (BOOL)removeFileAtPath:(NSString *)path; 
  • WiredServer/trunk/WCAuthorization.m

    r2975 r3857  
    206206#pragma mark - 
    207207 
     208- (BOOL)createFileAtPath:(NSString *)path { 
     209        return [self launchTaskWithPath:@"/usr/bin/touch" arguments:[NSArray arrayWithObject:path]]; 
     210} 
     211 
     212 
     213 
    208214- (BOOL)movePath:(NSString *)fromPath toPath:(NSString *)toPath { 
    209215        NSArray         *arguments; 
  • WiredServer/trunk/WCConfigController.m

    r3675 r3857  
    4747- (void)_readFromFile:(NSString *)path; 
    4848- (BOOL)_writeToFile:(NSString *)path; 
     49- (BOOL)_writeFlagsToFile:(NSString *)path; 
    4950 
    5051- (void)_setLaunchesAtBoot:(BOOL)value; 
     
    357358 
    358359 
     360- (BOOL)_writeFlagsToFile:(NSString *)path { 
     361        WCAuthorization         *authorization; 
     362        NSString                        *string, *owner, *temp; 
     363        BOOL                            status = YES; 
     364         
     365        string = [[_dashboardController launchArguments] componentsJoinedByString:@" "]; 
     366 
     367        owner = [[NSFileManager defaultManager] ownerAtPath:path]; 
     368         
     369        if(!owner) 
     370                owner = [[NSFileManager defaultManager] ownerAtPath:[path stringByDeletingLastPathComponent]]; 
     371 
     372        if([[[NSFileManager defaultManager] ownerAtPath:path] isEqualToString:NSUserName()]) { 
     373                status = [string writeToFile:path atomically:YES]; 
     374        } else { 
     375                authorization = [WCAuthorization authorization]; 
     376 
     377                if(status) { 
     378                        temp = [NSFileManager temporaryPathWithPrefix:@"wired" suffix:@"flags"]; 
     379                        status = [string writeToFile:temp atomically:YES]; 
     380                } 
     381                 
     382                if(status) 
     383                        status = [authorization movePath:temp toPath:path]; 
     384                 
     385                if(status) { 
     386                        status = [authorization changeOwnerOfPath:path 
     387                                                                                          toOwner:[_config stringForKey:@"user"] 
     388                                                                                                group:[_config stringForKey:@"group"]]; 
     389                } 
     390        } 
     391         
     392        return status; 
     393} 
     394 
     395 
     396 
    359397#pragma mark - 
    360398 
    361399- (void)_setLaunchesAtBoot:(BOOL)value { 
    362         NSFileManager           *fileManager; 
    363         NSString                        *path, *owner, *temp, *string; 
    364400        WCAuthorization         *authorization; 
    365         WCConfig                        *config; 
    366         BOOL                            status; 
    367          
    368         authorization = [WCAuthorization authorization]; 
    369         fileManager = [NSFileManager defaultManager]; 
     401        NSString                        *path, *owner; 
     402         
    370403        path = WCExpandWiredPath(@"etc/wired.startup"); 
    371          
    372         if(value) { 
    373                 string = [[_dashboardController launchArguments] componentsJoinedByString:@" "]; 
    374                 owner = [fileManager ownerAtPath:path]; 
    375                  
    376                 if(!owner) 
    377                         owner = [fileManager ownerAtPath:[path stringByDeletingLastPathComponent]]; 
    378                  
    379                 if([owner isEqualToString:NSUserName()]) { 
    380                         [string writeToFile:path atomically:YES]; 
     404        owner = [[NSFileManager defaultManager] ownerAtPath:path]; 
     405         
     406        if(!owner) 
     407                owner = [[NSFileManager defaultManager] ownerAtPath:[path stringByDeletingLastPathComponent]]; 
     408 
     409        if([[[NSFileManager defaultManager] ownerAtPath:path] isEqualToString:NSUserName()]) { 
     410                if(value) 
     411                        [[NSFileManager defaultManager] createFileAtPath:path]; 
     412                else 
     413                        [[NSFileManager defaultManager] removeFileAtPath:path]; 
     414        } else { 
     415                authorization = [WCAuthorization authorization]; 
     416 
     417                if(value) { 
     418                        if([authorization createFileAtPath:path]) { 
     419                                [authorization changeOwnerOfPath:path 
     420                                                                                 toOwner:[_config stringForKey:@"user"] 
     421                                                                                   group:[_config stringForKey:@"group"]]; 
     422                        } 
     423                } else { 
     424                        [authorization removeFileAtPath:path]; 
    381425                } 
    382                 else if([authorization isAuthorized]) { 
    383                         temp = [NSFileManager temporaryPathWithPrefix:@"wired" suffix:@"startup"]; 
    384                         status = [string writeToFile:temp atomically:YES]; 
    385                          
    386                         if(status) 
    387                                 status = [authorization movePath:temp toPath:path]; 
    388                          
    389                         if(status) { 
    390                                 config = [self config]; 
    391                                 status = [authorization changeOwnerOfPath:path 
    392                                                                                                   toOwner:[config stringForKey:@"user"] 
    393                                                                                                         group:[config stringForKey:@"group"]]; 
    394                         } 
    395                 } 
    396         } else { 
    397                 if([[fileManager ownerAtPath:path] isEqualToString:NSUserName()]) 
    398                         [fileManager removeFileAtPath:path]; 
    399                 else if([authorization isAuthorized]) 
    400                         [authorization removeFileAtPath:path]; 
    401426        } 
    402427} 
     
    524549                                _logTouched = YES; 
    525550                        } 
     551                         
     552                        [self _writeFlagsToFile:WCExpandWiredPath(@"etc/wired.flags")]; 
     553                        [self _setLaunchesAtBoot:[_launchAtBootButton state]]; 
    526554                } 
    527                  
    528                 [self _setLaunchesAtBoot:[_launchAtBootButton state]]; 
    529555        } 
    530556         
  • WiredServer/trunk/WCDashboardController.m

    r3675 r3857  
    192192        arguments = [NSMutableArray array]; 
    193193         
    194         if([_statusController isRunning]) { 
     194        if([_statusController isRunning]) 
    195195                [arguments addObject:@"stop"]; 
    196         } else { 
     196        else 
    197197                [arguments addObject:@"start"]; 
    198                 [arguments addObjectsFromArray:[self launchArguments]]; 
    199         } 
    200198         
    201199        [[WCAuthorization authorization] launchTaskWithPath:WCExpandWiredPath(@"wiredctl") 
     
    210208        arguments = [NSMutableArray array]; 
    211209        [arguments addObject:@"restart"]; 
    212         [arguments addObjectsFromArray:[self launchArguments]]; 
    213210         
    214211        [[WCAuthorization authorization] launchTaskWithPath:WCExpandWiredPath(@"wiredctl")