I am developing an OS X Firemonkey application that should run "openvpn", but OpenVPN requires administrator privileges to create the tunnel interface.
I am trying to convert the first sample from this blog post to Delphi:
http://www.michaelvobrien.com/blog/2009/07/authorizationexecutewithprivileges-a-simple-example/
An attempt to run this code sometimes leads to an authorization prompt, as expected, but pressing the OK button will completely freeze the debugger, and the entire system should be turned off. It works better without a debugger, but sometimes it will depend ... I caught the return code before it worked a couple of times, and that was errAuthorizationToolExecuteFailure
I'm not very good at how OSX does something, is there a better way? Apple does not recommend using AuthorizationExecuteWithPrivilegesfor this. I do not know any other way to start openvpn with the necessary permissions.
uses
Macapi.CoreFoundation, Macapi.Foundation, Macapi.Security;
const
kAuthorizationEmptyEnvironment = nil;
procedure TForm1.Button1Click(Sender: TObject);
var
AuthRef: AuthorizationRef;
Status: OSStatus;
begin
Status := AuthorizationCreate(nil,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,@AuthRef);
Status := AuthorizationExecuteWithPrivileges(AuthRef,'/sbin/dmesg',0,'',nil)
end;
source
share