Update of /cvsroot/radmind/radmind-assistant/rsm
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv24489
Added Files:
AMAuthorization.h AMAuthorization.m
Log Message:
New Obj-C class wrapping Authorization API.
--- NEW FILE: AMAuthorization.m ---
//
// AMAuthorization.m
// rsm
//
// Created by Andrew Mortensen on 6/23/08.
// Copyright 2008 University of Michigan, The. All rights reserved.
//
#import "AMAuthorization.h"
@implementation AMAuthorization
+ ( AMAuthorization * )authorizationWithName: ( NSString * )name
{
return( [ AMAuthorization authorizationWithName: name preAuthorize: NO
allowInteraction: NO extendRights: NO ] );
}
+ ( AMAuthorization * )authorizationWithName: ( NSString * )name
preAuthorize: ( BOOL )preAuthorize
allowInteraction: ( BOOL )allowInteraction
extendRights: ( BOOL )extendRights
{
AMAuthorization *auth;
auth = [[[ AMAuthorization alloc ] init ] autorelease ];
return( [ auth initWithName: name preAuthorize: preAuthorize
allowInteraction: allowInteraction extendRights: extendRights ]);
}
- ( AMAuthorization * )initWithName: ( NSString * )name
{
return( [ self initWithName: name preAuthorize: NO
allowInteraction: NO extendRights: NO ] );
}
- ( AMAuthorization * )initWithName: ( NSString * )name
preAuthorize: ( BOOL )preAuthorize
allowInteraction: ( BOOL )allowInteraction
extendRights: ( BOOL )extendRights
{
OSStatus status;
memset( &_amAuthItem_, 0, sizeof( AuthorizationItem ));
_amAuthItem_.name = [ name UTF8String ];
_amAuthRights_.count = 1;
_amAuthRights_.items = &_amAuthItem_;
_amAuthFlags_ |= kAuthorizationFlagDefaults;
if ( preAuthorize ) {
_amAuthFlags_ |= kAuthorizationFlagPreAuthorize;
}
if ( allowInteraction ) {
_amAuthFlags_ |= kAuthorizationFlagInteractionAllowed;
}
if ( extendRights ) {
_amAuthFlags_ |= kAuthorizationFlagExtendRights;
}
_amAuthRef_ = NULL;
status = AuthorizationCreate( NULL, kAuthorizationEmptyEnvironment,
kAuthorizationFlagDefaults, &_amAuthRef_ );
if ( status != errAuthorizationSuccess ) {
return( nil );
}
status = AuthorizationCopyRights( _amAuthRef_, &_amAuthRights_,
kAuthorizationEmptyEnvironment,
_amAuthFlags_, NULL );
if ( status != errAuthorizationSuccess ) {
AuthorizationFree( _amAuthRef_, kAuthorizationFlagDefaults );
return( nil );
}
return( self );
}
/* advanced interface */
- ( AMAuthorization * )initWithAuthorizationItem: ( AuthorizationItem )item
authorizationFlags: ( AuthorizationFlags )flags
{
return( nil );
}
- ( BOOL )externalForm: ( AuthorizationExternalForm * )externalForm
{
if ( AuthorizationMakeExternalForm( _amAuthRef_,
externalForm ) != errAuthorizationSuccess ) {
return( NO );
}
return( YES );
}
- ( void )dealloc
{
if ( _amAuthRef_ != NULL ) {
AuthorizationFree( _amAuthRef_, kAuthorizationFlagDefaults );
}
[ super dealloc ];
}
@end
--- NEW FILE: AMAuthorization.h ---
//
// AMAuthorization.h
// rsm
//
// Created by Andrew Mortensen on 6/23/08.
// Copyright 2008 University of Michigan, The. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <Security/Authorization.h>
@interface AMAuthorization : NSObject
{
@private
AuthorizationItem _amAuthItem_;
AuthorizationRef _amAuthRef_;
AuthorizationRights _amAuthRights_;
AuthorizationFlags _amAuthFlags_;
}
+ ( AMAuthorization * )authorizationWithName: ( NSString * )name;
+ ( AMAuthorization * )authorizationWithName: ( NSString * )name
preAuthorize: ( BOOL )preAuthorize
allowInteraction: ( BOOL )allowInteraction
extendRights: ( BOOL )extendRights;
- ( AMAuthorization * )initWithName: ( NSString * )name;
- ( AMAuthorization * )initWithName: ( NSString * )name
preAuthorize: ( BOOL )preAuthorize
allowInteraction: ( BOOL )allowInteraction
extendRights: ( BOOL )extendRights;
/* advanced interface */
- ( AMAuthorization * )initWithAuthorizationItem: ( AuthorizationItem )item
authorizationFlags: ( AuthorizationFlags )flags;
- ( BOOL )externalForm: ( AuthorizationExternalForm * )externalForm;
@end
|