Platforms to show: All Mac Windows Linux Cross-Platform

Back to AuthorizationMBS class.

AuthorizationMBS.Authorize(rights as AuthorizationItemSetMBS, flags as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Short for Authorize without the resulting rights set.
Example
dim a as AuthorizationMBS
dim s as AuthorizationItemSetMBS
dim i as AuthorizationItemMBS
dim Flags as Integer

// check whether use is admin

a=new AuthorizationMBS

s=new AuthorizationItemSetMBS
i=new AuthorizationItemMBS
i.Name="com.mycompany.myapplication.command1"
s.Append i

if a.NewAuthorization(nil,a.kAuthorizationFlagDefaults) then // create
Flags=BitwiseOr(a.kAuthorizationFlagExtendRights,a.kAuthorizationFlagInteractionAllowed)

a.Authorize(s,flags)
MsgBox str(a.LastError)
// -60006 for cancel = no admin
// 0 on success
end if

See also:

AuthorizationMBS.Authorize(rights as AuthorizationItemSetMBS, flags as Integer, byref outrights as AuthorizationItemSetMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Tries to extend authorization to have root rights.

The Authorizated property is set if this function was successfull.
Lasterror is set.
outrights is on return a list of the rights which are authorized.

Extends the rights of the class.

When the kAuthorizationFlagInteractionAllowed flag is set, user interaction will happen when required. Failing to set this flag will result in this call failing with a errAuthorizationInteractionNotAllowed status when interaction is required.

Setting the kAuthorizationFlagExtendRights flag will extend the currently available rights.

Setting the kAuthorizationFlagPartialRights flag will cause this call to succeed if only some of the requested rights are being granted by the system. Unless this flag is set this API will fail if not all the requested rights could be obtained.

Setting the kAuthorizationFlagDestroyRights flag will prevent any additional rights obtained during this call from being preserved after returning from this API.

Setting the kAuthorizationFlagPreAuthorize flag will pre authorize the requested rights so that at a later time -- by calling GetExternalForm() follow by NewAuthorizationFromExternalForm() -- the obtained rights can be used in a different process. Rights that can't be preauthorized will be treated as if they were authorized for the sake of returning an error (in other words if all rights are either authorized or could not be preauthorized this call will still succeed).

The rights which could not be preauthorized are not currently authorized and may fail to authorize when a later call to Authorize() is made, unless the kAuthorizationFlagExtendRights and kAuthorizationFlagInteractionAllowed flags are set. Even then they might still fail if the user does not supply the correct credentials.

The reason for passing in this flag is to provide correct audit trail information and to avoid unnecessary user interaction.

Error codes:
errAuthorizationSuccess0No error.
errAuthorizationInvalidRef-60002The authorization parameter is invalid.
errAuthorizationInvalidSet-60001The rights parameter is invalid.
errAuthorizationInvalidPointer-60004The authorizedRights parameter is invalid.

See also:

AuthorizationMBS.Available as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 2.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns true if the Authorization Framework was loaded correctly.

Returns false on any error.

AuthorizationMBS.close

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 2.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
The destructor.

Strings made with the ExternalForm function will become invalid!

There is no need to call this method except you want to free all resources used by this object now without waiting for Xojo to do it for you.

AuthorizationMBS.closeStream

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Closes the stream.

AuthorizationMBS.EOFStream as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns true if the Stream is at the end.

AuthorizationMBS.Execute(toolpath as string, parameters() as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 2.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Executes a command line application in the background.

You may make some small shell script which you launch in background. This script can change some other utility to run as root (Setuid), so you can do admin stuff using the normal shell class.
Lasterror is set.
Currently this function is not available to RB versions before 3.5.
Note that the parameters parameter is an array of strings and not just one.
toolpath should use an absolute path in unix style.

Lasterror is set to -1 if the path is empty or you are not using Mac OS X.

See also:

AuthorizationMBS.Execute(toolpath as string, parameters() as string, openstream as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Same as Execute, but you can specify if the stream to the command line application should be opened.

Currently this function is not available to RB versions before 3.5.
Note that the parameters parameter is an array of strings and not just one.
toolpath should use an absolute path in unix style.

Lasterror is set to -1 if the path is empty or you are not using Mac OS X.

See also:

AuthorizationMBS.ExternalForm as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 2.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns a string with binary data about this Authorization object.

This external representation depends on your process. You can't save it to disk or keep it longer than the Authorization object exists.
If the Authorization object is destroyed, your application quits or the authorization times out, this external form becomes invalid.

AuthorizationMBS.FlushStream

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Flushs the stream to the background application.

AuthorizationMBS.Info as AuthorizationItemSetMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Returns the list of currently authorized rights.

Returns nil on any error.

AuthorizationMBS.MakeStreamAsyncron

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 6.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Modifies the Stream created in the Execute method to run non blocking.

Some examples using this method:

AuthorizationMBS.NewAuthorization(rights as AuthorizationItemSetMBS, flags as Integer) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 2.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Creates a new Authorization object.

Lasterror is set. Returns true if successfull.

Create a new autorization object which can be used in other authorization calls.

When the kAuthorizationFlagInteractionAllowed flag is set, user interaction will happen when required. Failing to set this flag will result in this call failing with a errAuthorizationInteractionNotAllowed status in the lasterror property when interaction is required.

Setting the kAuthorizationFlagExtendRights flag will extend the currently available rights. If this flag is set the class will grant all the rights requested when errAuthorizationSuccess is returned in the lasterror property. If this flag is not set the operation will almost certainly succeed, but no attempt will be made to make the requested rights availible.

Call the Info function to figure out which of the requested rights are granted by the system.

Setting the kAuthorizationFlagPartialRights flag will cause this call to succeed if only some of the requested rights are being granted by the system. Unless this flag is set this API will fail if not all the requested rights could be obtained.

Setting the kAuthorizationFlagPreAuthorize flag will pre authorize the requested rights so that at a later time -- by calling GetExternalForm() follow by NewAuthorizationFromExternalForm() in a different object -- the obtained rights can be used in a different process. Rights that can't be preauthorized will be treated as if they were authorized for the sake of returning an error (in other words if all rights are either authorized or could not be preauthorized this call will still succeed).

The rights which could not be preauthorized are not currently authorized and may fail to authorize when a later call to Authorize() is made, unless the kAuthorizationFlagExtendRights and kAuthorizationFlagInteractionAllowed flags are set. Even then they might still fail if the user does not supply the correct credentials.

The reason for passing in this flag is to provide correct audit trail information and to avoid unnecessary user interaction.

rights (input/optional):
An AuthorizationItemSet containing rights for which authorization is being requested. If nil are specified the class will authorize nothing at all.

flags (input) options specified using the different constants from this class.

Error codes:
errAuthorizationSuccess0Authorization or all requested rights succeeded.
errAuthorizationDenied-60005The authorization for one or more of the requested rights was denied.
errAuthorizationCanceled-60006The authorization was cancled by the user.
errAuthorizationInteractionNotAllowed-60007The authorization was denied since no interaction with the user was allowed.

AuthorizationMBS.NewAuthorizationFromExternalForm(s as string) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 2.8 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Creates a new Authorization object from data inside a string.

You can store an authorization in a string for use in a subprocess. For example your application can ask the user for Root rights and you pass this string to a launched terminal application which will use it without having it's own interface.
Lasterror is set. Returns true if successfull.

AuthorizationMBS.ReadStream(count as Integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Reads bytes from the output stream of the executing app.
Example
dim s(0) as String
dim a as AuthorizationMBS
dim e as Integer

s(0)="-show"

a=new AuthorizationMBS

if a.SimpleNewAuthorization then // create

a.Execute("/usr/sbin/dsconfigad",s,true) // and run it

if a.LastError<>0 then
MsgBox "Lasterror on Execute: "+str(a.LastError)
else
e=a.Wait // wait for process to terminate. Returns PID
if a.LastError<>0 then
MsgBox "Lasterror on Wait: "+str(a.LastError)
end if
end if
msgbox a.ReadStream(1024)
end if

Tries to read count bytes.

Lasterror is set.
The returned string will be as long as the number of strings read.

Lasterror is set to -1 by the plugin if the stream is not open, or you are not using Mac OS X or the memory allocation failed.

Some examples using this method:

AuthorizationMBS.SimpleAuthorize

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Just asks for the Authorization.

This is the function from MBS Plugin 3.0.

AuthorizationMBS.SimpleNewAuthorization as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Creates a new authorization handle.
Example
// uses chmod on test.pdf on the desktop to make
// it read-, write- and executeable by everyone.

dim s(1) as String
dim a as AuthorizationMBS

a=new AuthorizationMBS

if a.SimpleNewAuthorization then
s(0)="777"
s(1)=SpecialFolder.Desktop.Child("test.pdf").NativePath

MsgBox s(1)
a.execute("/bin/chmod",s)
msgbox "Executed:"+str(a.lasterror)
end if

This is the function from MBS Plugin 3.0.

Some examples using this method:

AuthorizationMBS.Wait as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Waits till the background application is done.

Returns the Process ID or -1 on an error.
Lasterror is set.

AuthorizationMBS.WriteStream(s as string) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Authorization MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Writes the given bytes in the string to the stream.

The items on this page are in the following plugins: MBS MacCF Plugin.


The biggest plugin in space...