• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Still can't get auth to work correctly.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Still can't get auth to work correctly.


  • Subject: Still can't get auth to work correctly.
  • From: Mark Williams <email@hidden>
  • Date: Thu, 29 Sep 2005 22:35:15 -0700

Okay. Below is the code I am trying to use but it does not work. I am trying to just use ditto to do the copy since it will preserve the resource fork.
This code does not work and I do not have the knowledge to figure out why.
When I run it nothing is copied, ditto never appears to launch, as I watch it from the activity monitor. And I get an OSStatus return from the run authorized command of -600031
I'm cannot remember how to read a pipe between ditto and the authexecute command so that I can get an idea of might might be happening but anyway, with any luck, some one here can help with figure out the problem. Sorry about the messy code. Part of this is just C&P from cageFighter something that the writer of it suggested I look at for some guidance. The authorization seems to work but again I don't know enough about it to even make that determination.



-(void)systemBackup { NSAutoreleasePool * thePool = [[NSAutoreleasePool alloc]init];

NSMutableArray * baseSystem = [[NSMutableArray alloc]initWithArray:
[NSArray arrayWithObjects:@".hidden",@".vol",@".VolumeIcon.icns",@"automount",@"b in",@"cores",@"Desktop DB",
@"Desktop DF",@"etc",@"Library",@"mach",@"mach.sym",@"mach_kernel",@"private",@"sb in",@"System",
@"tmp",@"usr",@"var",nil]];
NSEnumerator * iter = [baseSystem objectEnumerator];
NSString * file;
while(file = [iter nextObject]){
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.00001]];
NSString * path= [NSString stringWithFormat:@"%@/% @",folderOnePath,file];
if(![[NSFileManager defaultManager] fileExistsAtPath:path]){
[notSystem makeKeyAndOrderFront:self];
return;
}
}//end while
[sysWarning makeKeyAndOrderFront:self];
int agreed = [NSApp runModalForWindow:sysWarning];
[sysWarning orderOut:self];
if(!agreed) return;


        if([appFolderCopy state]){
            [baseSystem addObject:@"Applications"];
            }
        if([userFolderCopy state]){
            [baseSystem addObject:@"Users"];
            }

    // get user authentication
    AuthorizationRights rights;
    AuthorizationFlags flags;
    AuthorizationRef auth = NULL;
    OSStatus err = 0;

    // initialize authorizationref
    rights.count = 0;
    rights.items = NULL;
    flags = kAuthorizationFlagDefaults;
    err = AuthorizationCreate( &rights, kAuthorizationEmptyEnvironment,
                               flags, &auth );

// build the rights
//NSBundle *mainBundle = [NSBundle mainBundle];
NSString *consoleFile = @"/usr/bin/ditto"; //[NSString stringWithFormat:@"%@/asdAuth",[mainBundle resourcePath]];
char *systemCopier = ( char * ) [consoleFile cString];
BOOL authorized = NO;
AuthorizationItem items[ 1 ];


    // cagefighter command
    items[ 0 ].name = kAuthorizationRightExecute;
    items[ 0 ].value = systemCopier;
    items[ 0 ].valueLength = strlen( systemCopier );
    items[ 0 ].flags = 0;

    rights.count = 1;
    rights.items = items;
    flags = kAuthorizationFlagInteractionAllowed |
        kAuthorizationFlagExtendRights;

    // prompt for password
    err = AuthorizationCopyRights( auth, &rights,
                                   kAuthorizationEmptyEnvironment,
                                   flags, NULL );

    authorized = ( errAuthorizationSuccess == err );

    // execute cagefighter console app with privledges
    if ( authorized ) {
        // set prefs
        // copy the files over

        //here we will call the app and copy the files.
        NSEnumerator * iter = [baseSystem objectEnumerator];
        NSString * file;
        //Okay in the working app we'll
        [sysProgressWindow makeKeyAndOrderFront:self];
        [sysProgress setIndeterminate:YES];
        [sysProgress startAnimation:self];
        int basecount =0;
        [itemProgress setIndeterminate:YES];
        [itemProgress startAnimation:self];


iter = [baseSystem objectEnumerator]; [sysProgress setIndeterminate:NO]; [sysProgress setDoubleValue:0.0]; [sysProgress setMinValue:0.0]; [sysProgress setMaxValue:[baseSystem count]]; [sysProgress startAnimation:self]; [itemProgress setIndeterminate:YES]; [itemProgress startAnimation:self];

while(file = [iter nextObject]){
NSFileManager * fileManager = [NSFileManager defaultManager];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
BOOL isDir =NO;
[fileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/%@",folderOnePath,file] isDirectory:&isDir];
if(!isDir){//make sure it's not a directory;
[systemText performSelectorOnMainThread:@selector (setStringValue:)
withObject:[NSString stringWithFormat:@"Copying %@",[file lastPathComponent]] waitUntilDone:YES];


char *args[ 3 ];
args[0] = "-rsrc";
args[1] = (char*)[[NSString stringWithFormat:@"% @/%@",folderOnePath,file]cString];
args[2] = (char*)[[NSString stringWithFormat:@"% @/%@",folderTwoPath,file]cString];


OSStatus result = AuthorizationExecuteWithPrivileges( auth, systemCopier, 0, args, NULL );

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
NSLog(@"Result %i",result);
[sysProgress incrementBy:1.0];
}//end of not dir
if(isDir){
NSLog([NSString stringWithFormat:@"%@/% @",folderOnePath,file]);
[systemText setStringValue:[NSString stringWithFormat:@"Copying %@",[file lastPathComponent]]];
[sysProgress incrementBy:1.0];//First we will count the directory
NSDirectoryEnumerator * dirIter = [[NSFileManager defaultManager]enumeratorAtPath:[NSString stringWithFormat:@"%@/%@",folderOnePath,file]];
NSString * subItem;
isDir = NO;
int itemCount = [[dirIter allObjects]count];
[itemProgress setDoubleValue:0.0];
[itemProgress setIndeterminate:NO];
[itemProgress setMinValue:0.0];
[itemProgress setMaxValue:itemCount];


while(subItem = [dirIter nextObject]){
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
[[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/% @",folderOnePath,file] isDirectory:&isDir];
if(isDir) [itemProgress incrementBy: 1.0];//Just inc the counter we won't cp a folder.
else{
NSLog([NSString stringWithFormat:@"%@/%@",folderOnePath,subItem]);
[subText performSelectorOnMainThread:@selector(setStringValue:)
withObject:[NSString stringWithFormat:@"Copying: %@",[subItem lastPathComponent]] waitUntilDone:YES];
char *args[ 3 ];
args[0] = "-rsrc";
args[1] = (char*)[[NSString stringWithFormat:@"%@/%@",folderOnePath,subItem]cString];
args[2] = (char*)[[NSString stringWithFormat:@"%@/%@",folderTwoPath,subItem]cString];


OSStatus result = AuthorizationExecuteWithPrivileges( auth, systemCopier, 0, args, NULL );

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
NSLog(@"Result %i",result);
[itemProgress incrementBy:1.0];
}//end of copy the file
}//end inner while loop
[itemProgress setIndeterminate:YES];
[itemProgress startAnimation:self];
}
}//end of while loop
}


    // destroy auth rights
    AuthorizationFree( auth, kAuthorizationFlagDestroyRights );

    [thePool release];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Turning NSMenuItem into separator
  • Next by Date: Re: Turning NSMenuItem into separator
  • Previous by thread: Re: customizing a drive (or partition) icon
  • Next by thread: NSPersistentDocument Tutorial - Crash
  • Index(es):
    • Date
    • Thread