• 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
[Q] copy operation and authorization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Q] copy operation and authorization


  • Subject: [Q] copy operation and authorization
  • From: JongAm Park <email@hidden>
  • Date: Thu, 12 Nov 2009 09:44:23 -0800

Hello,

I'm trying to copy a file from a desktop to a /Library/Application Supports/../Plugins directory.
Because the directory requires to obtain system administrator's privilege I should be authorized.


so, I wrote codes like this.

- (void)awakeFromNib
{
   [self authorize];
}

- (void) applicationWillTerminate:(NSNotification *)aNotification
{
OSStatus myStatus;
NSLog( @"applicationWillTerminate");
myStatus = AuthorizationFree( mAuthorizationRef, kAuthorizationFlagDestroyRights );
}


-(IBAction)copyWithNSFileManager:(id)sender
{
NSString *PlugInPath = [NSString stringWithString:@"/Library/Application Support/Final Cut Pro System Support/Plugins/test3.valm"];
NSString *sourceFile = [NSString stringWithFormat:@"%@/Desktop/test3.valm", NSHomeDirectory()];
BOOL isSuccessful;
isSuccessful = [[NSFileManager defaultManager] copyPath:sourceFile toPath:PlugInPath handler:nil];
}


-(IBAction)copyWithNSWorkspace:(id)sender
{
NSString *PluginPath = [NSString stringWithString:@"/Library/Application Support/Final Cut Pro System Support/Plugins"];
NSString *sourceDirectory = [NSString stringWithFormat:@"%@/Desktop", NSHomeDirectory()];
NSArray *files = [NSArray arrayWithObject:@"test3.valm"];
NSInteger tag;
BOOL isSuccessful = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceCopyOperation
source:sourceDirectory
destination:PluginPath
files:files
tag:&tag];
NSLog(@"isSuccessful = %@", isSuccessful? @"YES":@"NO" );
}


- (void)authorize
{ OSStatus myStatus;
myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &mAuthorizationRef);
AuthorizationItem myItems[1];
myItems[0].name = "com.greenleaf.FileCopyTest.myRight1";
myItems[0].valueLength = 0;
myItems[0].value = NULL;
myItems[0].flags = 0;
AuthorizationRights myRights;
myRights.count = sizeof( myItems ) / sizeof( myItems[0] );
myRights.items = myItems;
AuthorizationFlags myFlags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
myStatus = AuthorizationCopyRights(mAuthorizationRef, &myRights, kAuthorizationEmptyEnvironment, myFlags, NULL);
if( myStatus == errAuthorizationSuccess )
{
NSLog(@"Successful in authorizing.. " );
}
}


Although it returns "errAuthorizationSuccess" in "authorize" method, when a file is to be copied, it returns "fail" state and the file is not copied.
Can anyone help me to figure out why?


Should I use AuthorizationExecuteWithPrivileges() and invoke an external command like "cp"?
I think it should be possible to copy files with proper privilege with Cocoa calls.


Thank you.
JongAm Pawrk
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: [Q] copy operation and authorization
      • From: Kyle Sluder <email@hidden>
    • Re: [Q] copy operation and authorization
      • From: Sherm Pendley <email@hidden>
    • Re: [Q] copy operation and authorization
      • From: Nick Zitzmann <email@hidden>
    • Re: [Q] copy operation and authorization
      • From: Volker in Lists <email@hidden>
  • Prev by Date: How do I get Lucida Grande italic into my application?
  • Next by Date: Re: Weird problem with Core Text
  • Previous by thread: Re: How do I get Lucida Grande italic into my application?
  • Next by thread: Re: [Q] copy operation and authorization
  • Index(es):
    • Date
    • Thread