2 * Copyright (c) 2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * AuthorizationPlugin.h
21 * AuthorizationPlugin -- APIs for implementing authorization plugins.
24 #if !defined(__AuthorizationPlugin__)
25 #define __AuthorizationPlugin__ 1
27 #include <Security/Authorization.h>
29 #if defined(__cplusplus)
35 @header AuthorizationPlugin
36 Version 0.3 05/09/2001
44 @typedef AuthorizationValue
47 typedef struct AuthorizationValue
53 typedef struct AuthorizationValueVector
56 AuthorizationValue
*values
;
57 } AuthorizationValueVector
;
59 typedef UInt32 AuthorizationContextFlags
;
62 /* If set, it will be possible to obtain the value of this attribute usingAuthorizationCopyInfo(). */
63 kAuthorizationContextFlagExtractable
= (1 << 0),
65 /* If set, this value will not be remembered in a "credential". @@@ Do we need this? */
66 kAuthorizationContextFlagVolatile
= (1 << 1)
71 @typedef AuthorizationMechanismId
74 typedef const AuthorizationString AuthorizationMechanismId
;
77 @typedef AuthorizationPluginRef
78 An instance of a plugin (even though there will probably only be one).
80 typedef void *AuthorizationPluginRef
;
83 @typedef AuthorizationMechanismRef
84 An instance of a mechanism in a plugin.
86 typedef void *AuthorizationMechanismRef
;
89 @typedef AuthorizationEngineRef
90 The engines handle for an instance of a mechanism in a plugin (corresponds to a particular AuthorizationMechanismRef).
92 typedef struct __OpaqueAuthorizationEngine
*AuthorizationEngineRef
;
96 @typedef AuthorizationSessionId
97 A unique value for an AuthorizationSession being evaluated, provided by the authorization engine.
98 A session is represented by a top level call to an Authorization API.
99 @@@ Should this be changed to tie a session to the lifetime of an AuthorizationRef? -- Michael
101 typedef void *AuthorizationSessionId
;
104 @typedef AuthorizationResult
105 Possible values that SetResult may use.
107 @param kAuthorizationResultAllow the operation succeeded and should be allowed as far as this mechanism is concerned.
108 @param kAuthorizationResultDeny the operation succeeded and should be denied as far as this mechanism is concerned.
109 @param kAuthorizationResultUndefined the operation failed for some reason and should not be retried for this session.
110 @param kAuthorizationResultUserCanceled the user has requested that the evaluation be terminated.
112 typedef UInt32 AuthorizationResult
;
115 kAuthorizationResultAllow
,
116 kAuthorizationResultDeny
,
117 kAuthorizationResultUndefined
,
118 kAuthorizationResultUserCanceled
,
122 kAuthorizationPluginInterfaceVersion
= 0,
126 kAuthorizationCallbacksVersion
= 0,
130 /* Callback API of the AuthorizationEngine. */
131 typedef struct AuthorizationCallbacks
{
132 /* Will be set to kAuthorizationCallbacksVersion. */
137 /* Set a result after a call to AuthorizationSessionInvoke. */
138 OSStatus (*SetResult
)(AuthorizationEngineRef inEngine
, AuthorizationResult inResult
);
140 /* Request authorization engine to interrupt all mechamisms invoked after this mechamism has called SessionSetResult and then call AuthorizationSessionInvoke again. */
141 OSStatus (*RequestInterrupt
)(AuthorizationEngineRef inEngine
);
143 OSStatus (*DidDeactivate
)(AuthorizationEngineRef inEngine
);
146 /* Getters and setters */
147 OSStatus (*GetContextValue
)(AuthorizationEngineRef inEngine
,
148 AuthorizationString inKey
,
149 AuthorizationContextFlags
*outContextFlags
,
150 const AuthorizationValue
**outValue
);
152 OSStatus (*SetContextValue
)(AuthorizationEngineRef inEngine
,
153 AuthorizationString inKey
,
154 AuthorizationContextFlags inContextFlags
,
155 const AuthorizationValue
*inValue
);
157 OSStatus (*GetHintValue
)(AuthorizationEngineRef inEngine
,
158 AuthorizationString inKey
,
159 const AuthorizationValue
**outValue
);
161 OSStatus (*SetHintValue
)(AuthorizationEngineRef inEngine
,
162 AuthorizationString inKey
,
163 const AuthorizationValue
*inValue
);
165 OSStatus (*GetArguments
)(AuthorizationEngineRef inEngine
,
166 const AuthorizationValueVector
**outArguments
);
168 OSStatus (*GetSessionId
)(AuthorizationEngineRef inEngine
,
169 AuthorizationSessionId
*outSessionId
);
172 } AuthorizationCallbacks
;
175 /* Functions that must be implemented by each plugin. */
177 typedef struct AuthorizationPluginInterface
179 /* Must be set to kAuthorizationPluginInterfaceVersion. */
182 /* 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. */
183 OSStatus (*PluginDestroy
)(AuthorizationPluginRef inPlugin
);
185 /* The plugin should create an AuthorizationMechanismRef and remeber inEngine, mechanismId and callbacks for future reference. It is guaranteed that MechanismDestroy will be called on the returned AuthorizationMechanismRef sometime after this function. */
186 OSStatus (*MechanismCreate
)(AuthorizationPluginRef inPlugin
,
187 AuthorizationEngineRef inEngine
,
188 AuthorizationMechanismId mechanismId
,
189 AuthorizationMechanismRef
*outMechanism
);
191 /* Invoke (or evaluate) an instance of a mechanism (created with MechanismCreate). It should call SetResult during or after returning from this function. */
192 OSStatus (*MechanismInvoke
)(AuthorizationMechanismRef inMechanism
);
194 /* Plugin should respond with a SessionDidDeactivate asap. */
195 OSStatus (*MechanismDeactivate
)(AuthorizationMechanismRef inMechanism
);
197 OSStatus (*MechanismDestroy
)(AuthorizationMechanismRef inMechanism
);
199 } AuthorizationPluginInterface
;
202 /* @function AuthorizationPluginCreate
204 Initialize a plugin after it gets loaded. This is the main entry point to a plugin. This function will only be called once and after all Mechanism instances have been destroyed outPluginInterface->PluginDestroy will be called.
206 @param callbacks (input) A pointer to an AuthorizationCallbacks which contains the callbacks implemented by the AuthorizationEngine.
207 @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.
208 @param outPluginInterface (output) On successful completion should contain a pointer to a AuthorizationPluginInterface that will stay valid until outPluginInterface->PluginDestroy is called. */
209 OSStatus
AuthorizationPluginCreate(const AuthorizationCallbacks
*callbacks
,
210 AuthorizationPluginRef
*outPlugin
,
211 const AuthorizationPluginInterface
**outPluginInterface
);
213 #if defined(__cplusplus)
217 #endif /* ! __AuthorizationPlugin__ */