Problems with authorization (error -60002, errAuthorizationInvalidRef)

  • Hi

    I am trying to get "system.privilege.admin" rights to run a script in my code. To get this authorization I am calling the method below. But I am getting the error -60002, errAuthorizationInvalidRef, why am I getting this. The same code works fine in other projects.

    -----------------------------------------------
    #include <Security/Security.h>

    @interface build : NSObject {
      AuthroizatonRef  authRef;
    }

    @implementation build {
    - (BOOL)getAuthorizationRef {

      AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
      AuthorizationRights myRights = {1, &myItems};
      AuthorizationFlags flags = kAuthorizationFlagDefaults |
            kAuthorizationFlagInteractionAllowed |
            kAuthorizationFlagPreAuthorize |
            kAuthorizationFlagExtendRights;

      OSStatus status = AuthorizationCopyRights(authRef_, &myRights,
                                      kAuthorizationEmptyEnvironment, flags, NULL);

      if (status != errAuthorizationSuccess) {
        return NO;
      }
      return YES;
    }

    Thank you
    DG

          Share files, take polls, and discuss your passions - all under one roof. Go to http://in.promos.yahoo.com/groups
  • On 02/10/2007, at 4:29 AM, deepak gopal wrote:

    > @interface build : NSObject {
    > AuthroizatonRef  authRef;
    > }
    >
    > @implementation build {
    > - (BOOL)getAuthorizationRef {

    typo?
  • Hello! I don't see the actual creation of security context with
    AuthorizationCreate function... so you should type something like

    AuthorizationItem item = {kAuthorizationRightExecute, 0, 0, 0};
    AuthorizationRights rights = {1, &item};
    AuthorizationRef auth;
    OSStatus status;

    status = AuthorizationCreate (&rights,
    kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults |
    kAuthorizationFlagExtendRights |
    kAuthorizationFlagInteractionAllowed, &auth);
    if (status == errAuthorizationSuccess)
    {

    }
    else
    {

    }
    The second thing having place in execution of some external programs
    with root privileges is that the external program you execute mustn't
    be a script it must be a binary file!

    On Oct 1, 2007, at 22:29 , deepak gopal wrote:

    > Hi
    >
    > I am trying to get "system.privilege.admin" rights to run a script
    > in my code. To get this authorization I am calling the method
    > below. But I am getting the error -60002,
    > errAuthorizationInvalidRef, why am I getting this. The same code
    > works fine in other projects.
    >
    > -----------------------------------------------
    > #include <Security/Security.h>
    >
    > @interface build : NSObject {
    > AuthroizatonRef  authRef;
    > }
    >
    > @implementation build {
    > - (BOOL)getAuthorizationRef {
    >
    > AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL,
    > 0};
    > AuthorizationRights myRights = {1, &myItems};
    > AuthorizationFlags flags = kAuthorizationFlagDefaults |
    > kAuthorizationFlagInteractionAllowed |
    > kAuthorizationFlagPreAuthorize |
    > kAuthorizationFlagExtendRights;
    >
    > OSStatus status = AuthorizationCopyRights(authRef_, &myRights,
    > kAuthorizationEmptyEnvironment,
    > flags, NULL);
    >
    > if (status != errAuthorizationSuccess) {
    > return NO;
    > }
    > return YES;
    > }
    >
    > Thank you
    > DG
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today