2  * Copyright (c) 2001-2002,2004,2011-2012,2014 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  26  *  AuthorizationPlugin.h 
  27  *  AuthorizationPlugin -- APIs for implementing authorization plugins. 
  30 #ifndef _SECURITY_AUTHORIZATIONPLUGIN_H_ 
  31 #define _SECURITY_AUTHORIZATIONPLUGIN_H_ 
  33 #include <Security/Authorization.h> 
  35 #if defined(__cplusplus) 
  39 CF_ASSUME_NONNULL_BEGIN
 
  42         @header AuthorizationPlugin 
  44         The AuthorizationPlugin API allows the creation of plugins that can participate 
  45         in authorization decisions.  Using the AuthorizationDB API the system can be configured 
  46         to use these plugins.  Plugins are loaded into a separate process, the pluginhost, to  
  47         isolate the process of authorization from the client.  There are two types of pluginhosts. 
  48         One runs as an anonymous user and can be used to communicate with the user, for example 
  49         to ask for a password.  Another one runs with root privileges to perform privileged 
  50         operations that may be required. 
  52     A typical use is to implement additional policies that cannot be expressed in the 
  53     authorization configuration. 
  55     Plugins implement a handshake function called AuthorizationPluginCreate with which 
  56     their interface (AuthorizationPluginInterface) and the engine's interface 
  57     (AuthorizationCallbacks) are exchanged.  Plugins are asked to create  
  58     Mechanisms, which are the basic element as authorizations are performed.   
  60     Mechanisms are invoked when it is time for them to make a decision.  A decision is  
  61     made by setting a single result (AuthorizationResult).  Mechanisms in the  
  62     authorization can communicate auxiliary information by setting and/or getting hints  
  63     and setting and/or getting context data.  Hints are advisory and don't need to be 
  64     looked at, nor are they preserved as part of the authorization result. Context data 
  65     becomes part of the result of the authorization. 
  67     Context data is tagged with a flag that describes whether the information is returned 
  68     to the authorization client upon request (AuthorizationCopyInfo() in Authorization.h) 
  69     or whether it's private to the mechanisms making a decision. 
  75         @typedef AuthorizationValue 
  76     Auxiliary data is passed between the engine and the mechanism as AuthorizationValues 
  78 typedef struct AuthorizationValue
 
  85     @typedef AuthorizationValueVector 
  86     A vector of AuthorizationValues.  Used to communicate arguments passed from the  
  87     configuration file <code>authorization(5)</code>. 
  89 typedef struct AuthorizationValueVector
 
  92         AuthorizationValue 
*values
; 
  93 } AuthorizationValueVector
; 
  97     Data produced as context during the authorization evaluation is tagged.   
  98     If data is set to be extractable (kAuthorizationContextFlagExtractable), it will be possible for the client of authorization to obtain the value of this attribute using AuthorizationCopyInfo(). 
  99     If data is marked as volatile (kAuthorizationContextFlagVolatile), this value will not be remembered in the AuthorizationRef. 
 100     Sticky data (kAuthorizationContextFlagSticky) persists through a failed or interrupted evaluation. It can be used to propagate an error condition from a downstream plugin to an upstream one. It is not remembered in the AuthorizationRef. 
 102 typedef CF_OPTIONS(UInt32
, AuthorizationContextFlags
) 
 104     kAuthorizationContextFlagExtractable 
= (1 << 0), 
 105     kAuthorizationContextFlagVolatile 
= (1 << 1), 
 106     kAuthorizationContextFlagSticky 
= (1 << 2) 
 111         @typedef AuthorizationMechanismId 
 112     The mechanism id specified in the configuration is passed to the plugin to create the appropriate mechanism. 
 114 typedef const AuthorizationString AuthorizationMechanismId
; 
 117     @typedef AuthorizationPluginId 
 118         Not used by plugin writers.  Loaded plugins are identified by their name. 
 120 typedef const AuthorizationString AuthorizationPluginId
; 
 123         @typedef AuthorizationPluginRef 
 124         Handle passed back by the plugin writer when creating a plugin.  Any pluginhost will only instantiate one instance.  The handle is used when creating mechanisms. 
 126 typedef void *AuthorizationPluginRef
; 
 129         @typedef AuthorizationMechanismRef 
 130         Handle passed back by the plugin writer when creating an an instance of a mechanism in a plugin.  One instance will be created for any authorization. 
 132 typedef void *AuthorizationMechanismRef
; 
 135         @typedef AuthorizationEngineRef 
 136         Handle passed from the engine to an instance of a mechanism in a plugin (corresponds to a particular AuthorizationMechanismRef). 
 138 typedef struct __OpaqueAuthorizationEngine 
*AuthorizationEngineRef
; 
 141         @typedef AuthorizationSessionId 
 142         A unique value for an AuthorizationSession being evaluated, provided by the authorization engine. 
 143     A session is represented by a top level call to an Authorization API. 
 145 typedef void *AuthorizationSessionId
; 
 148     @enum AuthorizationResult 
 149         Possible values for SetResult() in AuthorizationCallbacks. 
 151     @constant kAuthorizationResultAllow the operation succeeded and authorization should be granted as far as this mechanism is concerned. 
 152     @constant kAuthorizationResultDeny the operation succeeded but authorization should be denied as far as this mechanism is concerned. 
 153     @constant kAuthorizationResultUndefined the operation failed for some reason and should not be retried for this session. 
 154     @constant kAuthorizationResultUserCanceled the user has requested that the evaluation be terminated. 
 156 typedef CF_ENUM(UInt32
, AuthorizationResult
) { 
 157     kAuthorizationResultAllow
, 
 158     kAuthorizationResultDeny
, 
 159     kAuthorizationResultUndefined
, 
 160     kAuthorizationResultUserCanceled
, 
 165     Version of the interface (AuthorizationPluginInterface) implemented by the plugin. 
 166     The value is matched to the definition in this file. 
 169     kAuthorizationPluginInterfaceVersion 
= 0 
 174     Version of the callback structure (AuthorizationCallbacks) passed to the plugin. 
 175     The value is matched to the definition in this file.  The engine may provide a newer 
 179     kAuthorizationCallbacksVersion 
= 1 
 185     Callback API provided by the AuthorizationEngine.  
 187     @field version      Engine callback version. 
 188     @field SetResult    Set a result after a call to AuthorizationSessionInvoke. 
 189     @field RequestInterrupt Request authorization engine to interrupt all mechamisms invoked after this mechamism has called SessionSetResult and then call AuthorizationSessionInvoke again. 
 190     @field DidDeactivate    Respond to the Deactivate request. 
 191     @field GetContextValue  Read value from context.  AuthorizationValue does not own data. 
 192     @field SetContextValue  Write value to context.  AuthorizationValue and data are copied. 
 193     @field GetHintValue     Read value from hints. AuthorizationValue does not own data. 
 194     @field SetHintValue     Write value to hints.  AuthorizationValue and data are copied. 
 195     @field GetArguments     Read arguments passed.  AuthorizationValueVector does not own data. 
 196     @field GetSessionId     Read SessionId. 
 198 typedef struct AuthorizationCallbacks 
{ 
 200     /* Engine callback version. */ 
 203     /* Set a result after a call to AuthorizationSessionInvoke. */ 
 204     OSStatus (*SetResult
)(AuthorizationEngineRef inEngine
, AuthorizationResult inResult
); 
 206     /* Request authorization engine to interrupt all mechamisms invoked after  
 207         this mechamism has called SessionSetResult and then call  
 208         AuthorizationSessionInvoke again. */ 
 209     OSStatus (*RequestInterrupt
)(AuthorizationEngineRef inEngine
); 
 211     /* Respond to the Deactivate request. */ 
 212     OSStatus (*DidDeactivate
)(AuthorizationEngineRef inEngine
); 
 214     /* Read value from context.  AuthorizationValue does not own data. */ 
 215     OSStatus (*GetContextValue
)(AuthorizationEngineRef inEngine
, 
 216         AuthorizationString inKey
, 
 217         AuthorizationContextFlags 
* __nullable outContextFlags
, 
 218         const AuthorizationValue 
* __nullable 
* __nullable outValue
); 
 220     /* Write value to context.  AuthorizationValue and data are copied. */ 
 221     OSStatus (*SetContextValue
)(AuthorizationEngineRef inEngine
, 
 222         AuthorizationString inKey
, 
 223         AuthorizationContextFlags inContextFlags
, 
 224         const AuthorizationValue 
*inValue
); 
 226     /* Read value from hints. AuthorizationValue does not own data. */ 
 227     OSStatus (*GetHintValue
)(AuthorizationEngineRef inEngine
, 
 228         AuthorizationString inKey
, 
 229         const AuthorizationValue 
* __nullable 
* __nullable outValue
); 
 231     /* Write value to hints.  AuthorizationValue and data are copied. */ 
 232     OSStatus (*SetHintValue
)(AuthorizationEngineRef inEngine
, 
 233         AuthorizationString inKey
, 
 234         const AuthorizationValue 
*inValue
); 
 236     /* Read arguments passed.  AuthorizationValueVector does not own data. */ 
 237     OSStatus (*GetArguments
)(AuthorizationEngineRef inEngine
, 
 238         const AuthorizationValueVector 
* __nullable 
* __nonnull outArguments
); 
 240     /* Read SessionId. */ 
 241     OSStatus (*GetSessionId
)(AuthorizationEngineRef inEngine
, 
 242         AuthorizationSessionId __nullable 
* __nullable outSessionId
); 
 244     /* Read value from hints. AuthorizationValue does not own data. */ 
 245     OSStatus (*GetImmutableHintValue
)(AuthorizationEngineRef inEngine
, 
 246         AuthorizationString inKey
, 
 247         const AuthorizationValue 
* __nullable 
* __nullable outValue
); 
 249 } AuthorizationCallbacks
; 
 254     Interface that must be implemented by each plugin.  
 256     @field version  Must be set to kAuthorizationPluginInterfaceVersion 
 257     @field PluginDestroy    Plugin should clean up and release any resources it is holding. 
 258     @field MechanismCreate  The plugin should create a mechanism named mechanismId.  The mechanism needs to use the AuthorizationEngineRef for the callbacks and pass back a   AuthorizationMechanismRef for itself.  MechanismDestroy will be called when it is no longer needed. 
 259     @field MechanismInvoke  Invoke an instance of a mechanism.  It should call SetResult during or after returning from this function. 
 260     @field MechanismDeactivate  Mechanism should respond with a DidDeactivate as soon as possible 
 261     @field MechanismDestroy Mechanism should clean up and release any resources it is holding 
 263 typedef struct AuthorizationPluginInterface
 
 265     /* Must be set to kAuthorizationPluginInterfaceVersion. */ 
 268     /* Notify a plugin that it is about to be unloaded so it get a chance to clean up and release any resources it is holding.  */ 
 269     OSStatus (*PluginDestroy
)(AuthorizationPluginRef inPlugin
); 
 271     /* The plugin should create a mechanism named mechanismId.  The mechanism needs to use the 
 272         AuthorizationEngineRef for the callbacks and pass back an AuthorizationMechanismRef for 
 273         itself.  MechanismDestroy will be called when it is no longer needed. */ 
 274     OSStatus (*MechanismCreate
)(AuthorizationPluginRef inPlugin
, 
 275         AuthorizationEngineRef inEngine
, 
 276         AuthorizationMechanismId mechanismId
, 
 277         AuthorizationMechanismRef __nullable 
* __nonnull outMechanism
); 
 279     /* Invoke an instance of a mechanism.  It should call SetResult during or after returning from this function.  */ 
 280     OSStatus (*MechanismInvoke
)(AuthorizationMechanismRef inMechanism
); 
 282     /* Mechanism should respond with a DidDeactivate as soon as possible. */ 
 283     OSStatus (*MechanismDeactivate
)(AuthorizationMechanismRef inMechanism
); 
 285     /* Mechanism should clean up and release any resources it is holding. */ 
 286     OSStatus (*MechanismDestroy
)(AuthorizationMechanismRef inMechanism
); 
 288 } AuthorizationPluginInterface
; 
 292     @function AuthorizationPluginCreate 
 294     Initialize a plugin after it gets loaded.  This is the main entry point to a plugin.  This function will only be called once.   
 295     After all Mechanism instances have been destroyed outPluginInterface->PluginDestroy will be called. 
 297     @param callbacks (input) A pointer to an AuthorizationCallbacks which contains the callbacks implemented by the AuthorizationEngine. 
 298     @param outPlugin (output) On successful completion should contain a valid AuthorizationPluginRef.  This will be passed in to any subsequent calls the engine makes to  outPluginInterface->MechanismCreate and outPluginInterface->PluginDestroy. 
 299     @param outPluginInterface (output) On successful completion should contain a pointer to a AuthorizationPluginInterface that will stay valid until outPluginInterface->PluginDestroy is called. */ 
 300 OSStatus 
AuthorizationPluginCreate(const AuthorizationCallbacks 
*callbacks
, 
 301     AuthorizationPluginRef __nullable 
* __nonnull outPlugin
, 
 302     const AuthorizationPluginInterface 
* __nullable 
* __nonnull outPluginInterface
); 
 304 CF_ASSUME_NONNULL_END
 
 306 #if defined(__cplusplus) 
 310 #endif /* _SECURITY_AUTHORIZATIONPLUGIN_H_ */