Changeset 3859

Show
Ignore:
Timestamp:
03/02/06 19:10:35 (3 years ago)
Author:
morris
Message:

Automatically create a wired.flags if it doesn't exist

Files:

Legend:

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

    r3729 r3859  
    260260 
    261261- (BOOL)_writeUsersToFile:(NSString *)path { 
    262         NSString                *temp; 
    263         WCAuthorization *authorization; 
    264         WCConfig                *config; 
    265         BOOL                    status = YES
     262        NSString                       *temp; 
     263        WCAuthorization        *authorization; 
     264        WCConfig                       *config; 
     265        BOOL                           status
    266266         
    267267        [self _unselectAccount:[self _selectedAccount]]; 
    268268         
    269         if([[[NSFileManager defaultManager] ownerAtPath:path] isEqualToString:NSUserName()]) { 
    270                 status = [_users writeToFile:path]; 
    271         } else { 
    272                 authorization = [WCAuthorization authorization]; 
    273                  
    274                 if(status) { 
    275                         temp = [NSFileManager temporaryPathWithPrefix:@"users" suffix:@"conf"]; 
    276                         status = [_users writeToFile:temp]; 
    277                 } 
    278                  
    279                 if(status) 
    280                         status = [authorization movePath:temp toPath:path]; 
    281                  
    282                 if(status) { 
    283                         config = [_configController config]; 
    284                         status = [authorization changeOwnerOfPath:path 
    285                                                                                           toOwner:[config stringForKey:@"user"] 
    286                                                                                                 group:[config stringForKey:@"group"]]; 
    287                 } 
     269        authorization   = [WCAuthorization authorization]; 
     270        temp                    = [NSFileManager temporaryPathWithPrefix:@"users" suffix:@"conf"]; 
     271        status                  = [_users writeToFile:temp]; 
     272         
     273        if(status) 
     274                status = [authorization movePath:temp toPath:path]; 
     275         
     276        if(status) { 
     277                config = [_configController config]; 
     278                status = [authorization changeOwnerOfPath:path 
     279                                                                                  toOwner:[config stringForKey:@"user"] 
     280                                                                                        group:[config stringForKey:@"group"]]; 
    288281        } 
    289282 
     
    297290 
    298291- (BOOL)_writeGroupsToFile:(NSString *)path { 
    299         NSString                *temp; 
    300         WCAuthorization *authorization; 
    301         WCConfig                *config; 
    302         BOOL                    status = YES
     292        NSString                       *temp; 
     293        WCAuthorization        *authorization; 
     294        WCConfig                       *config; 
     295        BOOL                           status
    303296         
    304297        [self _unselectAccount:[self _selectedAccount]]; 
    305298 
    306         if([[[NSFileManager defaultManager] ownerAtPath:path] isEqualToString:NSUserName()]) { 
    307                 status = [_groups writeToFile:path]; 
    308         } else { 
    309                 authorization = [WCAuthorization authorization]; 
    310  
    311                 if(status) { 
    312                         temp = [NSFileManager temporaryPathWithPrefix:@"groups" suffix:@"conf"]; 
    313                         status = [_groups writeToFile:temp]; 
    314                 } 
    315                  
    316                 if(status) 
    317                         status = [[WCAuthorization authorization] movePath:temp toPath:path]; 
    318                  
    319                 if(status) { 
    320                         config = [_configController config]; 
    321                         status = [authorization changeOwnerOfPath:path 
    322                                                                                           toOwner:[config stringForKey:@"user"] 
    323                                                                                                 group:[config stringForKey:@"group"]]; 
    324                 } 
     299        authorization   = [WCAuthorization authorization]; 
     300        temp                    = [NSFileManager temporaryPathWithPrefix:@"groups" suffix:@"conf"]; 
     301        status                  = [_groups writeToFile:temp]; 
     302         
     303        if(status) 
     304                status = [authorization movePath:temp toPath:path]; 
     305         
     306        if(status) { 
     307                config = [_configController config]; 
     308                status = [authorization changeOwnerOfPath:path 
     309                                                                                  toOwner:[config stringForKey:@"user"] 
     310                                                                                        group:[config stringForKey:@"group"]]; 
    325311        } 
    326312 
  • WiredServer/trunk/WCConfigController.m

    r3857 r3859  
    255255        NSString                *temp; 
    256256        WCAuthorization *authorization; 
    257         BOOL                    status = YES
     257        BOOL                    status
    258258 
    259259        // --- config 
     
    330330        [_config setString:[_groupPopUpButton titleOfSelectedItem] forKey:@"group"]; 
    331331         
    332         if([[[NSFileManager defaultManager] ownerAtPath:path] isEqualToString:NSUserName()]) { 
    333                 status = [_config writeToFile:path]; 
    334         } else { 
    335                 authorization = [WCAuthorization authorization]; 
    336  
    337                 if(status) { 
    338                         temp = [NSFileManager temporaryPathWithPrefix:@"config" suffix:@"conf"]; 
    339                         status = [_config writeToFile:temp]; 
    340                 } 
     332        authorization   = [WCAuthorization authorization]; 
     333        temp                    = [NSFileManager temporaryPathWithPrefix:@"config" suffix:@"conf"]; 
     334        status                  = [_config writeToFile:temp]; 
    341335                 
    342                 if(status) 
    343                         status = [authorization movePath:temp toPath:path]; 
    344                  
    345                 if(status) { 
    346                         status = [authorization changeOwnerOfPath:[WCSettings objectForKey:WCPrefixPath] 
    347                                                                                           toOwner:[_config stringForKey:@"user"] 
    348                                                                                                 group:[_config stringForKey:@"group"]]; 
    349                 } 
     336        if(status) 
     337                status = [authorization movePath:temp toPath:path]; 
     338         
     339        if(status) { 
     340                status = [authorization changeOwnerOfPath:[WCSettings objectForKey:WCPrefixPath] 
     341                                                                                  toOwner:[_config stringForKey:@"user"] 
     342                                                                                        group:[_config stringForKey:@"group"]]; 
    350343        } 
    351344         
     
    360353- (BOOL)_writeFlagsToFile:(NSString *)path { 
    361354        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                 } 
     355        NSString                        *string, *temp; 
     356        BOOL                            status; 
     357         
     358        authorization   = [WCAuthorization authorization]; 
     359        string                  = [[_dashboardController launchArguments] componentsJoinedByString:@" "]; 
     360        temp                    = [NSFileManager temporaryPathWithPrefix:@"wired" suffix:@"flags"]; 
     361        status                  = [string writeToFile:temp atomically:YES]; 
     362         
     363        if(status) 
     364                status = [authorization movePath:temp toPath:path]; 
     365         
     366        if(status) { 
     367                status = [authorization changeOwnerOfPath:path 
     368                                                                                  toOwner:[_config stringForKey:@"user"] 
     369                                                                                        group:[_config stringForKey:@"group"]]; 
    390370        } 
    391371         
     
    399379- (void)_setLaunchesAtBoot:(BOOL)value { 
    400380        WCAuthorization         *authorization; 
    401         NSString                        *path, *owner; 
    402          
    403         path = WCExpandWiredPath(@"etc/wired.startup"); 
    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]; 
     381        NSString                        *path; 
     382         
     383        path                    = WCExpandWiredPath(@"etc/wired.startup"); 
     384        authorization   = [WCAuthorization authorization]; 
     385 
     386        if(value) { 
     387                if([authorization createFileAtPath:path]) { 
     388                        [authorization changeOwnerOfPath:path 
     389                                                                         toOwner:[_config stringForKey:@"user"] 
     390                                                                           group:[_config stringForKey:@"group"]]; 
     391                } 
    414392        } 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]; 
    425                 } 
     393                [authorization removeFileAtPath:path]; 
    426394        } 
    427395} 
     
    575543- (void)authorizationStatusDidChange:(NSNotification *)notification { 
    576544        _authorized = [[notification object] boolValue]; 
     545         
     546        if(_authorized) { 
     547                if(![[NSFileManager defaultManager] fileExistsAtPath:WCExpandWiredPath(@"etc/wired.flags")]) 
     548                        [self _writeFlagsToFile:WCExpandWiredPath(@"etc/wired.flags")]; 
     549        } 
    577550 
    578551        [self _update]; 
     
    677650        NSBitmapImageRep        *imageRep; 
    678651        NSData                          *data; 
    679         NSString                        *path, *owner, *temp; 
     652        NSString                        *path, *temp; 
    680653        WCAuthorization         *authorization; 
    681654        NSSize                          size; 
    682         BOOL                            status = YES
     655        BOOL                            status
    683656         
    684657        image = [_bannerImageView image]; 
     
    709682    } 
    710683         
    711         imageRep = [NSBitmapImageRep imageRepWithData:[[_bannerImageView image] TIFFRepresentation]]; 
    712         data = [imageRep representationUsingType:NSPNGFileType properties:NULL]; 
    713          
    714         path = WCExpandWiredPath(@"banner.png"); 
    715         owner = [[NSFileManager defaultManager] ownerAtPath:path]; 
    716          
    717         if(!owner) 
    718                 owner = [[NSFileManager defaultManager] ownerAtPath:[path stringByDeletingLastPathComponent]]; 
    719          
    720         if([owner isEqualToString:NSUserName()]) { 
    721                 status = [data writeToFile:path atomically:YES]; 
    722         } else { 
    723                 authorization = [WCAuthorization authorization]; 
    724  
    725                 if(status) { 
    726                         temp = [NSFileManager temporaryPathWithPrefix:@"banner" suffix:@"png"]; 
    727                         status = [data writeToFile:temp atomically:YES]; 
    728                 } 
    729                  
    730                 if(status) 
    731                         status = [authorization movePath:temp toPath:path]; 
    732                  
    733                 if(status) { 
    734                         status = [authorization changeOwnerOfPath:path 
    735                                                                                           toOwner:[_config stringForKey:@"user"] 
    736                                                                                                 group:[_config stringForKey:@"group"]]; 
    737                 } 
     684        imageRep                = [NSBitmapImageRep imageRepWithData:[[_bannerImageView image] TIFFRepresentation]]; 
     685        data                    = [imageRep representationUsingType:NSPNGFileType properties:NULL]; 
     686        path                    = WCExpandWiredPath(@"banner.png"); 
     687        authorization   = [WCAuthorization authorization]; 
     688        temp                    = [NSFileManager temporaryPathWithPrefix:@"banner" suffix:@"png"]; 
     689        status                  = [data writeToFile:temp atomically:YES]; 
     690         
     691        if(status) 
     692                status = [authorization movePath:temp toPath:path]; 
     693         
     694        if(status) { 
     695                status = [authorization changeOwnerOfPath:path 
     696                                                                                  toOwner:[_config stringForKey:@"user"] 
     697                                                                                        group:[_config stringForKey:@"group"]]; 
    738698        } 
    739699         
     
    792752 
    793753- (IBAction)createCertificate:(id)sender { 
    794         NSMutableArray  *arguments; 
    795         NSTask                  *task; 
    796         NSString                *path, *owner, *temp; 
    797         WCAuthorization *authorization; 
    798         BOOL                    status = YES; 
     754        NSArray                         *arguments; 
     755        NSString                        *path, *temp; 
     756        WCAuthorization         *authorization; 
     757        BOOL                            status; 
    799758         
    800759        [_certificateProgressIndicator startAnimation:self]; 
     
    806765          contextInfo:NULL]; 
    807766         
    808         arguments = [NSMutableArray arrayWithObjects: 
     767        authorization   = [WCAuthorization authorization]; 
     768        path                    = WCExpandWiredPath(@"etc/certificate.pem"); 
     769        temp                    = [NSFileManager temporaryPathWithPrefix:@"certificate" suffix:@"pem"]; 
     770        arguments               = [NSArray arrayWithObjects: 
    809771                @"req", 
    810772                @"-x509", 
     
    816778                        @"3650", 
    817779                @"-nodes", 
     780                @"-keyout", 
     781                        temp, 
     782                @"-out", 
     783                        temp, 
    818784                NULL]; 
    819785         
    820         path = WCExpandWiredPath(@"etc/certificate.pem"); 
    821         owner = [[NSFileManager defaultManager] ownerAtPath:path]; 
    822          
    823         if(!owner) 
    824                 owner = [[NSFileManager defaultManager] ownerAtPath:[path stringByDeletingLastPathComponent]]; 
    825  
    826         if([owner isEqualToString:NSUserName()]) { 
    827                 [arguments addObjectsFromArray:[NSArray arrayWithObjects: 
    828                         @"-keyout", 
    829                                 path, 
    830                         @"-out", 
    831                                 path, 
    832                         NULL]]; 
    833                  
    834                 task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/openssl"  
    835                                                                                 arguments:arguments]; 
    836                 [task waitUntilExit]; 
    837                 status = ([task terminationStatus] == 0); 
    838         } else { 
    839                 authorization = [WCAuthorization authorization]; 
    840  
    841                 temp = [NSFileManager temporaryPathWithPrefix:@"certificate" suffix:@"pem"]; 
    842                 [arguments addObjectsFromArray:[NSArray arrayWithObjects: 
    843                         @"-keyout", 
    844                                 temp, 
    845                         @"-out", 
    846                                 temp, 
    847                         NULL]]; 
    848                 status = [authorization launchTaskWithPath:@"/usr/bin/openssl" arguments:arguments]; 
    849                  
    850                 if(status) 
    851                         status = [authorization movePath:temp toPath:path]; 
    852                  
    853                 if(status) { 
    854                         status = [authorization changeOwnerOfPath:path 
    855                                                                                           toOwner:[_config stringForKey:@"user"] 
    856                                                                                                 group:[_config stringForKey:@"group"]]; 
    857                 } 
     786        status = [authorization launchTaskWithPath:@"/usr/bin/openssl" arguments:arguments]; 
     787         
     788        if(status) 
     789                status = [authorization movePath:temp toPath:path]; 
     790         
     791        if(status) { 
     792                status = [authorization changeOwnerOfPath:path 
     793                                                                                  toOwner:[_config stringForKey:@"user"] 
     794                                                                                        group:[_config stringForKey:@"group"]]; 
    858795        } 
    859796