Not enough privileges to copy a VST bundle in the VST folder


#1

Hi everyone!

I am trying to make my own VST plug-in Installer app. I have found a lot of little obstacles in CoreFoundation because I do not master OSX world (I am a Win32 guy). As a result, every line I have coded costed me hours or days.

Well, I am almost finishing this installer, but I have found a trouble that I really do not know ho to solve. The issue is the following:

The app installer is a bundle and inside this bundle there is a VST payload as a resource, this is, the VST plugin (that, in fact, is another bundle as you know). Well the purpose of the showed excerpt code is to handle the resource (the VST folder/bundle) and try to copy it to the Library/Audio/Plug-Ins/VST destination. All the references are tested and they worked. The problem is that the VST bundle is not copied because apparently there is not enough privileges to do such operation.
The osstatus output code is: [color=#FF0000]“afpAccessDenied” “Insufficient access privileges for operation” code -5000[/color]

[code] CFBundleRef mainBundle;

// Get the main bundle for the app
mainBundle = CFBundleGetMainBundle();
CFURLRef cfURLref;
cfURLref = CFBundleCopyResourceURL (mainBundle,
                                    CFSTR("OnTime.vst"),
                                    NULL,
                                    NULL);
FSRef source, destDir;
CFURLGetFSRef(cfURLref, &source);

OSStatus osstatus;    
Boolean isDirectory;
UInt8 pathIn[] = "/Library/Audio/Plug-Ins/VST";
FSPathMakeRef (
                        pathIn,
                        &destDir,
                        &isDirectory
                        );

osstatus = FSCopyObjectSync(&source, &destDir, NULL, NULL, kFSFileOperationOverwrite);

[/code]

Please, does anybody know how to solve this problem. For instance, how can I get the modal dialogue to allow a user to grant permission by inputting the password, or how can I circumvent this privileges or how can I say to the system that I have enough privileges to copy such bundle?

Any solution is good for me as far as I can get rid of this… nightmare!

Thank you colleagues!

Gabriel


#2

Do you have to install it into the root library directory? If you put it in the user’s library folder that should work e.g. “~/Library/Audio/Plug-Ins/VST”.

Of course this is more of a work around than a solution.


#3

Aha! Dave!

Let me try it!


#4

Not sure if this will help…

Make a script to do the copying and run it with elevated privileges

{
		NSString *sourcePath=[[NSBundle mainBundle]resourcePath];
		
		AuthorizationRef myAuthorizationRef;
		OSStatus myStatus;
		myStatus = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &myAuthorizationRef);	
		if (myStatus ==noErr)
		{
			AuthorizationItem myItems[1];
			
			myItems[0].name = "com.jaydee.install";
			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;
			myFlags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
			{
				NSString *installToolPath=[[NSBundle mainBundle]pathForResource:@"plugininst" ofType:@""];
				if (installToolPath)
				{
					FILE *myCommunicationsPipe = NULL;
					char *myArguments[] ={(char*)[sourcePath UTF8String],NULL} ;
					const char *myPath=[installToolPath UTF8String];
					
					myStatus = AuthorizationExecuteWithPrivileges (myAuthorizationRef, myPath, kAuthorizationFlagDefaults, myArguments, &myCommunicationsPipe);
				}
			}
			AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDestroyRights);
			if (myStatus==noErr)
				AlertWindow::showMessageBox(AlertWindow::NoIcon,TRANS("Installed"),TRANS("Successfully updated/installed.\r"));
			
		}	
		else
			{
jassertfalse;
}

	}

The script then could just be

#!/bin/sh


###
# Install
# call: installfile( src, dest )
###

srcdir="$1"
vstDir="/Library/Audio/Plug-Ins/VST"
#installdir()
{
#  I should create the path
  if [ ! -d "${vstDir}" ]; then
    # if directory already exists leave it untouched
   echo "Creating Directory"
	 mkdir -p "${vstDir}"
  fi
}
if [ -e "${vstDir}/PlugIn.bundle" ]; then
rm -R "${vstDir}/PlugIn.bundle"
fi
cp -R -v "${srcdir}/PlugIn.bundle" "${vstDir}"

if [ -e "${vstDir}/PlugIn.bundle" ]; then
rm -R "${vstDir}/PlugIn.bundle"
fi
#cp -R "${srcdir}/PlugIn.bundle" "${vstDir}"
if [ ! -e "${vstDir}/PlugIn.bundle" ]; then
echo "Installing PlugIn Bundle"
cp -R "${srcdir}/PlugIn.bundle" "${vstDir}"
fi

#5

No luck!

osstatus yields: -36 “ioErr” “I/O error(bummers)”

Any another idea, (please :wink:


#6

Oh, the header for the Authorization API is in

#include <Security/Authorization.h>

https://developer.apple.com/library/mac/#documentation/Security/Reference/authorization_ref/Reference/reference.html

This might disturb you though…

But AFAIK, there’s no other way to get stuff into the /Library folder(so its available to all users) without running escalated privileges


#7

If you just want to copy to ~/Library, you might want to just use some Cocoa calls (make your source file a .mm file so you can mix in some C++ if you want)

You can get the path to your plugin(in your resources folder)
NSString *installPlugIn=[[NSBundle mainBundle]pathForResource:@“OnTime” ofType:@“vst”];

Then use the NSFileManager to do the copying, something like

NSFileManager* fm = [NSFileManager defaultManager];
[fm copyPath:installPlugIn toPath:@"~/Library/Audio/etc" handler:nil];


#8

[quote]If you just want to copy to ~/Library, you might want to just use some Cocoa calls (make your source file a .mm file so you can mix in some C++ if you want)

You can get the path to your plugin(in your resources folder)
NSString *installPlugIn=[[NSBundle mainBundle]pathForResource:@“OnTime” ofType:@“vst”];

Then use the NSFileManager to do the copying, something like

NSFileManager* fm = [NSFileManager defaultManager];
[fm copyPath:installPlugIn toPath:@"~/Library/Audio/etc" handler:nil];[/quote]

Thank you justin.

I am not good at Objective-C (at all!) but I’ll start to work on it. The Script shell solution encapsulated in code is another less smart solution but if there is no other option…

Nevertheless, I would like to make a last call for a native C++ CoreFoundation solution, anybody else, pleeeeeease?


#9

[quote=“dave96”]Do you have to install it into the root library directory? If you put it in the user’s library folder that should work e.g. “~/Library/Audio/Plug-Ins/VST”.

Of course this is more of a work around than a solution.[/quote]

Dave you were absolutely and definitely right. This was the problem (and the solution!)

Thank you! Case closed.

Gabriel


#10

I’m glad that’s a viable workaround.

Out of interest do you need an application based installer package? Usually this is only needed if you have to copy custom resources or make file associations etc. I’ve always used a custom dmg installer as described here and dynamically loaded resources from the binary at run time. Its a nice, tidy and portable way to package an app.

I’m sure doing this and providing the root VST folder as the destination would show the Finder’s permission window.


#11

Dave,

I positively believe that. Nevertheless, I have not checked it.

Yes! because half of the Software License Management code is there. The other half is in the plug-in.

Gabriel :smiley: