Authorization.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. {
  2. * Copyright (c) 2000-2004,2007 Apple Inc. All Rights Reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  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
  11. * file.
  12. *
  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.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. }
  23. { Pascal Translation: Peter N Lewis, <[email protected]>, 2004 }
  24. { Pascal Translation Update: Gorazd Krosl <[email protected]>, October 2009 }
  25. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2009 }
  26. {
  27. Modified for use with Free Pascal
  28. Version 308
  29. Please report any bugs to <[email protected]>
  30. }
  31. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  32. {$mode macpas}
  33. {$packenum 1}
  34. {$macro on}
  35. {$inline on}
  36. {$calling mwpascal}
  37. unit Authorization;
  38. interface
  39. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  40. {$setc GAP_INTERFACES_VERSION := $0308}
  41. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  42. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  43. {$endc}
  44. {$ifc defined CPUPOWERPC and defined CPUI386}
  45. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  46. {$endc}
  47. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  48. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  49. {$endc}
  50. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  51. {$setc __ppc__ := 1}
  52. {$elsec}
  53. {$setc __ppc__ := 0}
  54. {$endc}
  55. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  56. {$setc __ppc64__ := 1}
  57. {$elsec}
  58. {$setc __ppc64__ := 0}
  59. {$endc}
  60. {$ifc not defined __i386__ and defined CPUI386}
  61. {$setc __i386__ := 1}
  62. {$elsec}
  63. {$setc __i386__ := 0}
  64. {$endc}
  65. {$ifc not defined __x86_64__ and defined CPUX86_64}
  66. {$setc __x86_64__ := 1}
  67. {$elsec}
  68. {$setc __x86_64__ := 0}
  69. {$endc}
  70. {$ifc not defined __arm__ and defined CPUARM}
  71. {$setc __arm__ := 1}
  72. {$elsec}
  73. {$setc __arm__ := 0}
  74. {$endc}
  75. {$ifc defined cpu64}
  76. {$setc __LP64__ := 1}
  77. {$elsec}
  78. {$setc __LP64__ := 0}
  79. {$endc}
  80. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  81. {$error Conflicting definitions for __ppc__ and __i386__}
  82. {$endc}
  83. {$ifc defined __ppc__ and __ppc__}
  84. {$setc TARGET_CPU_PPC := TRUE}
  85. {$setc TARGET_CPU_PPC64 := FALSE}
  86. {$setc TARGET_CPU_X86 := FALSE}
  87. {$setc TARGET_CPU_X86_64 := FALSE}
  88. {$setc TARGET_CPU_ARM := FALSE}
  89. {$setc TARGET_OS_MAC := TRUE}
  90. {$setc TARGET_OS_IPHONE := FALSE}
  91. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  92. {$elifc defined __ppc64__ and __ppc64__}
  93. {$setc TARGET_CPU_PPC := TFALSE}
  94. {$setc TARGET_CPU_PPC64 := TRUE}
  95. {$setc TARGET_CPU_X86 := FALSE}
  96. {$setc TARGET_CPU_X86_64 := FALSE}
  97. {$setc TARGET_CPU_ARM := FALSE}
  98. {$setc TARGET_OS_MAC := TRUE}
  99. {$setc TARGET_OS_IPHONE := FALSE}
  100. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  101. {$elifc defined __i386__ and __i386__}
  102. {$setc TARGET_CPU_PPC := FALSE}
  103. {$setc TARGET_CPU_PPC64 := FALSE}
  104. {$setc TARGET_CPU_X86 := TRUE}
  105. {$setc TARGET_CPU_X86_64 := FALSE}
  106. {$setc TARGET_CPU_ARM := FALSE}
  107. {$ifc defined(iphonesim)}
  108. {$setc TARGET_OS_MAC := FALSE}
  109. {$setc TARGET_OS_IPHONE := TRUE}
  110. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  111. {$elsec}
  112. {$setc TARGET_OS_MAC := TRUE}
  113. {$setc TARGET_OS_IPHONE := FALSE}
  114. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  115. {$endc}
  116. {$elifc defined __x86_64__ and __x86_64__}
  117. {$setc TARGET_CPU_PPC := FALSE}
  118. {$setc TARGET_CPU_PPC64 := FALSE}
  119. {$setc TARGET_CPU_X86 := FALSE}
  120. {$setc TARGET_CPU_X86_64 := TRUE}
  121. {$setc TARGET_CPU_ARM := FALSE}
  122. {$setc TARGET_OS_MAC := TRUE}
  123. {$setc TARGET_OS_IPHONE := FALSE}
  124. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  125. {$elifc defined __arm__ and __arm__}
  126. {$setc TARGET_CPU_PPC := FALSE}
  127. {$setc TARGET_CPU_PPC64 := FALSE}
  128. {$setc TARGET_CPU_X86 := FALSE}
  129. {$setc TARGET_CPU_X86_64 := FALSE}
  130. {$setc TARGET_CPU_ARM := TRUE}
  131. { will require compiler define when/if other Apple devices with ARM cpus ship }
  132. {$setc TARGET_OS_MAC := FALSE}
  133. {$setc TARGET_OS_IPHONE := TRUE}
  134. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  135. {$elsec}
  136. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  137. {$endc}
  138. {$ifc defined __LP64__ and __LP64__ }
  139. {$setc TARGET_CPU_64 := TRUE}
  140. {$elsec}
  141. {$setc TARGET_CPU_64 := FALSE}
  142. {$endc}
  143. {$ifc defined FPC_BIG_ENDIAN}
  144. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  145. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  146. {$elifc defined FPC_LITTLE_ENDIAN}
  147. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  148. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  149. {$elsec}
  150. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  151. {$endc}
  152. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  153. {$setc CALL_NOT_IN_CARBON := FALSE}
  154. {$setc OLDROUTINENAMES := FALSE}
  155. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  156. {$setc OPAQUE_UPP_TYPES := TRUE}
  157. {$setc OTCARBONAPPLICATION := TRUE}
  158. {$setc OTKERNEL := FALSE}
  159. {$setc PM_USE_SESSION_APIS := TRUE}
  160. {$setc TARGET_API_MAC_CARBON := TRUE}
  161. {$setc TARGET_API_MAC_OS8 := FALSE}
  162. {$setc TARGET_API_MAC_OSX := TRUE}
  163. {$setc TARGET_CARBON := TRUE}
  164. {$setc TARGET_CPU_68K := FALSE}
  165. {$setc TARGET_CPU_MIPS := FALSE}
  166. {$setc TARGET_CPU_SPARC := FALSE}
  167. {$setc TARGET_OS_UNIX := FALSE}
  168. {$setc TARGET_OS_WIN32 := FALSE}
  169. {$setc TARGET_RT_MAC_68881 := FALSE}
  170. {$setc TARGET_RT_MAC_CFM := FALSE}
  171. {$setc TARGET_RT_MAC_MACHO := TRUE}
  172. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  173. {$setc TYPE_BOOL := FALSE}
  174. {$setc TYPE_EXTENDED := FALSE}
  175. {$setc TYPE_LONGLONG := TRUE}
  176. uses MacTypes;
  177. {$endc} {not MACOSALLINCLUDE}
  178. {$ifc TARGET_OS_MAC}
  179. {$ALIGN POWER}
  180. {
  181. * Authorization.h -- APIs for implementing access control in applications
  182. * and daemons.
  183. }
  184. {!
  185. @header Authorization
  186. Version 1.0 10/16/2000
  187. The Authorization API contains all the APIs that a application or tool that need pre-authorization or need an authorization desision made.
  188. A typical use cases are a preference panel that would start off calling AuthorizationCreate() (without UI) to get an authorization object. Then call AuthorizationCopyRights() to figure out what is currently allowed.
  189. If any of the operations that the preference panel wishes to perform are currently not allowed the lock icon in the window would show up in the locked state. Otherwise it would show up unlocked.
  190. When the user locks the lock AuthorizationFree() is called with the kAuthorizationFlagDestroyRights to destroy any authorization rights that have been aquired.
  191. When the user unlocks the lock AuthorizationCreate() is called with the kAuthorizationFlagInteractionAllowed and kAuthorizationFlagExtendRights flags to obtain all required rights. The old authorization object can be freed by calling AuthorizationFree() with no flags.
  192. }
  193. {!
  194. @defined kAuthorizationEmptyEnvironment
  195. Parameter to specify to AuthorizationCreate when no environment is being provided.
  196. }
  197. const kAuthorizationEmptyEnvironment = nil;
  198. {!
  199. @enum AuthorizationStatus
  200. Error codes returned by Authorization API.
  201. }
  202. {
  203. Note: the comments that appear after these errors are used to create SecErrorMessages.strings.
  204. The comments must not be multi-line, and should be in a form meaningful to an end user. If
  205. a different or additional comment is needed, it can be put in the header doc format, or on a
  206. line that does not start with errZZZ.
  207. errAuthorizationSuccess can't include a string as it's also errSecSuccess in libsecurity_keychain/lib/SecBase.h
  208. }
  209. const
  210. errAuthorizationSuccess = 0;
  211. errAuthorizationInvalidSet = -60001; { The authorization rights are invalid. }
  212. errAuthorizationInvalidRef = -60002; { The authorization reference is invalid. }
  213. errAuthorizationInvalidTag = -60003; { The authorization tag is invalid. }
  214. errAuthorizationInvalidPointer = -60004; { The returned authorization is invalid. }
  215. errAuthorizationDenied = -60005; { The authorization was denied. }
  216. errAuthorizationCanceled = -60006; { The authorization was cancelled by the user. }
  217. errAuthorizationInteractionNotAllowed = -60007; { The authorization was denied since no user interaction was possible. }
  218. errAuthorizationInternal = -60008; { Unable to obtain authorization for this operation. }
  219. errAuthorizationExternalizeNotAllowed = -60009; { The authorization is not allowed to be converted to an external format. }
  220. errAuthorizationInternalizeNotAllowed = -60010; { The authorization is not allowed to be created from an external format. }
  221. errAuthorizationInvalidFlags = -60011; { The provided option flag(s) are invalid for this authorization operation. }
  222. errAuthorizationToolExecuteFailure = -60031; { The specified program could not be executed. }
  223. errAuthorizationToolEnvironmentError = -60032; { An invalid status was returned during execution of a privileged tool. }
  224. errAuthorizationBadAddress = -60033; { The requested socket address is invalid (must be 0-1023 inclusive). }
  225. {!
  226. @enum AuthorizationFlags
  227. Optional flags passed in to serveral Authorization APIs. See the description of AuthorizationCreate, AuthorizationCopyRights and AuthorizationFree for a description of how they affect those calls.
  228. }
  229. const
  230. kAuthorizationFlagDefaults = 0;
  231. kAuthorizationFlagInteractionAllowed = 1 shl 0;
  232. kAuthorizationFlagExtendRights = 1 shl 1;
  233. kAuthorizationFlagPartialRights = 1 shl 2;
  234. kAuthorizationFlagDestroyRights = 1 shl 3;
  235. kAuthorizationFlagPreAuthorize = 1 shl 4;
  236. // private bits (do not use)
  237. kAuthorizationFlagNoData = 1 shl 20;
  238. {!
  239. @typedef AuthorizationFlags
  240. Optional flags passed in to AuthorizationCreate.
  241. }
  242. type
  243. AuthorizationFlags = UInt32;
  244. {!
  245. @enum AuthorizationRightFlags
  246. Flags returned in the flags field of ItemSet Items when calling AuthorizationCopyRights().
  247. }
  248. const
  249. kAuthorizationFlagCanNotPreAuthorize = 1 shl 0;
  250. {!
  251. @typedef AuthorizationRef
  252. Opaque reference to an authorization object.
  253. }
  254. type
  255. AuthorizationRef = ^SInt32;
  256. {!
  257. @typedef AuthorizationString
  258. A zero terminated string in UTF-8 encoding.
  259. }
  260. type AuthorizationString = CStringPtr;
  261. ConstAuthorizationString = ConstCStringPtr; { will need later in AuthorizationPlugin }
  262. {!
  263. @struct AuthorizationItem
  264. Each AuthorizationItem describes a single string-named item with optional
  265. parameter value. The value must be contiguous memory of valueLength bytes;
  266. internal structure is defined separately for each name.
  267. @field name name of the item, as an AuthorizationString. Mandatory.
  268. @field valueLength Number of bytes in parameter value. Must be 0 if no parameter value.
  269. @field value Pointer to the optional parameter value associated with name.
  270. Must be NULL if no parameter value.
  271. @field flags Reserved field. Must be set to 0 on creation. Do not modify after that.
  272. }
  273. type
  274. AuthorizationItem = record
  275. name: AuthorizationString;
  276. valueLength: size_t;
  277. value: UnivPtr;
  278. flags: UInt32;
  279. end;
  280. AuthorizationItemPtr = ^AuthorizationItem;
  281. {!
  282. @struct AuthorizationItemSet
  283. An AuthorizationItemSet structure represents a set of zero or more AuthorizationItems. Since it is a set it should not contain any identical AuthorizationItems.
  284. @field count Number of items identified by items.
  285. @field items Pointer to an array of items.
  286. }
  287. type
  288. AuthorizationItemSet = record
  289. count: UInt32;
  290. items: AuthorizationItemPtr;
  291. end;
  292. AuthorizationItemSetPtr = ^AuthorizationItemSet;
  293. {!
  294. @struct AuthorizationExternalForm
  295. An AuthorizationExternalForm structure can hold the externalized form of
  296. an AuthorizationRef. As such, it can be transmitted across IPC channels
  297. to other processes, which can re-internalize it to recover a valid AuthorizationRef
  298. handle.
  299. The data contained in an AuthorizationExternalForm should be considered opaque.
  300. SECURITY NOTE: Applications should take care to not disclose the AuthorizationExternalForm to
  301. potential attackers since it would authorize rights to them.
  302. }
  303. const
  304. kAuthorizationExternalFormLength = 32;
  305. type
  306. AuthorizationExternalForm = record
  307. bytes: packed array[0..(kAuthorizationExternalFormLength)-1] of char;
  308. end;
  309. {!
  310. @typedef AuthorizationRights
  311. An AuthorizationItemSet representing a set of rights each with an associated argument (value).
  312. Each argument value is as defined for the specific right they belong to. Argument values may not contain pointers as the should be copyable to different address spaces.
  313. }
  314. type AuthorizationRights = AuthorizationItemSet;
  315. type AuthorizationRightsPtr = ^AuthorizationRights;
  316. type AuthorizationRightsPtrPtr = ^AuthorizationRightsPtr;
  317. {!
  318. @typedef AuthorizationEnvironment
  319. An AuthorizationItemSet representing environmental information of potential use
  320. to authorization decisions.
  321. }
  322. type AuthorizationEnvironment = AuthorizationItemSet;
  323. type AuthorizationEnvironmentPtr = ^AuthorizationEnvironment;
  324. {!
  325. @function AuthorizationCreate
  326. Create a new autorization object which can be used in other authorization calls. When the authorization is no longer needed AuthorizationFree should be called.
  327. 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.
  328. Setting the kAuthorizationFlagExtendRights flag will extend the currently available rights. If this flag is set the returned AuthorizationRef will grant all the rights requested when errAuthorizationSuccess is returned. If this flag is not set the operation will almost certainly succeed, but no attempt will be made to make the requested rights availible.
  329. Call AuthorizationCopyRights to figure out which of the requested rights are granted by the returned AuthorizationRef.
  330. Setting the kAuthorizationFlagPartialRights flag will cause this call to succeed if only some of the requested rights are being granted by the returned AuthorizationRef. Unless this flag is set this API will fail if not all the requested rights could be obtained.
  331. Setting the kAuthorizationFlagDestroyRights flag will prevent any rights obtained during this call from being preserved after returning from this API (This is most useful when the authorization parameter is NULL and the caller doesn't want to affect the session state in any way).
  332. Setting the kAuthorizationFlagPreAuthorize flag will pre authorize the requested rights so that at a later time -- by calling AuthorizationMakeExternalForm() follow by AuthorizationCreateFromExternalForm() -- 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).
  333. The rights which could not be preauthorized are not currently authorized and may fail to authorize when a later call to AuthorizationCopyRights() 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.
  334. The reason for passing in this flag is to provide correct audit trail information and to avoid unnecessary user interaction.
  335. @param rights (input/optional) An AuthorizationItemSet containing rights for which authorization is being requested. If none are specified the resulting AuthorizationRef will authorize nothing at all.
  336. @param environment (input/optional) An AuthorizationItemSet containing enviroment state used when making the autorization decision. See the AuthorizationEnvironment type for details.
  337. @param flags (input) options specified by the AuthorizationFlags enum. set all unused bits to zero to allow for future expansion.
  338. @param authorization (output optional) A pointer to an AuthorizationRef to be returned. When the returned AuthorizationRef is no longer needed AuthorizationFree should be called to prevent anyone from using the aquired rights. If NULL is specified no new rights are returned, but the system will attempt to authorize all the requested rights and return the appropriate status.
  339. @result errAuthorizationSuccess 0 authorization or all requested rights succeeded.
  340. errAuthorizationDenied -60005 The authorization for one or more of the requested rights was denied.
  341. errAuthorizationCanceled -60006 The authorization was cancelled by the user.
  342. errAuthorizationInteractionNotAllowed -60007 The authorization was denied since no interaction with the user was allowed.
  343. }
  344. function AuthorizationCreate( rights: AuthorizationRightsPtr; environment: AuthorizationEnvironmentPtr; flags: AuthorizationFlags; var authorization: AuthorizationRef ): OSStatus; external name '_AuthorizationCreate';
  345. {!
  346. @function AuthorizationFree
  347. Destroy an AutorizationRef object. If the kAuthorizationFlagDestroyRights flag is passed,
  348. any rights associated with the authorization are lost. Otherwise, only local resources
  349. are released, and the rights may still be available to other clients.
  350. Setting the kAuthorizationFlagDestroyRights flag will prevent any rights that were obtained by the specified authorization object to be preserved after returning from this API. This effectivaly locks down all potentially shared authorizations.
  351. @param authorization (input) The authorization object on which this operation is performed.
  352. @param flags (input) Bit mask of option flags to this call.
  353. @result errAuthorizationSuccess 0 No error.
  354. errAuthorizationInvalidRef -60002 The authorization parameter is invalid.
  355. }
  356. function AuthorizationFree( authorization: AuthorizationRef; flags: AuthorizationFlags ): OSStatus; external name '_AuthorizationFree';
  357. {!
  358. @function AuthorizationCopyRights
  359. Given a set of rights, return the subset that is currently authorized
  360. by the AuthorizationRef given.
  361. 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.
  362. Setting the kAuthorizationFlagExtendRights flag will extend the currently available rights.
  363. Setting the kAuthorizationFlagPartialRights flag will cause this call to succeed if only some of the requested rights are being granted by the returned AuthorizationRef. Unless this flag is set this API will fail if not all the requested rights could be obtained.
  364. Setting the kAuthorizationFlagDestroyRights flag will prevent any additional rights obtained during this call from being preserved after returning from this API.
  365. Setting the kAuthorizationFlagPreAuthorize flag will pre authorize the requested rights so that at a later time -- by calling AuthorizationMakeExternalForm() follow by AuthorizationCreateFromExternalForm() -- 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), and they will be returned in authorizedRights with their kAuthorizationFlagCanNotPreAuthorize bit in the flags field set to 1.
  366. The rights which could not be preauthorized are not currently authorized and may fail to authorize when a later call to AuthorizationCopyRights() 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.
  367. The reason for passing in this flag is to provide correct audit trail information and to avoid unnecessary user interaction.
  368. Setting the kAuthorizationFlagPreAuthorize flag will pre authorize the requested rights so that at a later time -- by calling AuthorizationMakeExternalForm() follow by AuthorizationCreateFromExternalForm() -- the obtained rights can be used in a different process. When this flags is specified rights that can't be preauthorized will be returned as if they were authorized with their kAuthorizationFlagCanNotPreAuthorize bit in the flags field set to 1. These rights are not currently authorized and may fail to authorize later unless kAuthorizationFlagExtendRights and kAuthorizationFlagInteractionAllowed flags are set when the actual authorization is done. And even then they might still fail if the user does not supply the correct credentials.
  369. @param authorization (input) The authorization object on which this operation is performed.
  370. @param rights (input) A rights set (see AuthorizationCreate).
  371. @param environment (input/optional) An AuthorizationItemSet containing enviroment state used when making the autorization decision. See the AuthorizationEnvironment type for details.
  372. @param flags (input) options specified by the AuthorizationFlags enum. set all unused bits to zero to allow for future expansion.
  373. @param authorizedRights (output/optional) A pointer to a newly allocated AuthorizationInfoSet in which the authorized subset of rights are returned (authorizedRights should be deallocated by calling AuthorizationFreeItemSet() when it is no longer needed). If NULL the only information returned is the status. Note that if the kAuthorizationFlagPreAuthorize flag was specified rights that could not be preauthorized are returned in authorizedRights, but their flags contains the kAuthorizationFlagCanNotPreAuthorize bit.
  374. @result errAuthorizationSuccess 0 No error.
  375. errAuthorizationInvalidRef -60002 The authorization parameter is invalid.
  376. errAuthorizationInvalidSet -60001 The rights parameter is invalid.
  377. errAuthorizationInvalidPointer -60004 The authorizedRights parameter is invalid.
  378. }
  379. function AuthorizationCopyRights( authorization: AuthorizationRef; const (*var*) rights: AuthorizationRights; environment: AuthorizationEnvironmentPtr; flags: AuthorizationFlags; authorizedRights: AuthorizationRightsPtrPtr ): OSStatus; external name '_AuthorizationCopyRights';
  380. {!
  381. @function AuthorizationCopyInfo
  382. Returns sideband information (e.g. access credentials) obtained from a call to AuthorizationCreate. The format of this data depends of the tag specified.
  383. @param authorization (input) The authorization object on which this operation is performed.
  384. @param tag (input/optional) An optional string tag specifing which sideband information should be returned. When NULL is specified all available information is returned.
  385. @param flags (input) options specified by the AuthorizationFlags enum. set all unused bits to zero to allow for future expansion.
  386. @param info (output) A pointer to a newly allocated AuthorizationInfoSet in which the requested sideband infomation is returned (info should be deallocated by calling AuthorizationFreeItemSet() when it is no longer needed).
  387. @result errAuthorizationSuccess 0 No error.
  388. errAuthorizationInvalidRef -60002 The authorization parameter is invalid.
  389. errAuthorizationInvalidTag -60003 The tag parameter is invalid.
  390. errAuthorizationInvalidPointer -60004 The info parameter is invalid.
  391. }
  392. function AuthorizationCopyInfo( authorization: AuthorizationRef; tag: AuthorizationString; var info: AuthorizationItemSetPtr ): OSStatus; external name '_AuthorizationCopyInfo';
  393. {!
  394. @function AuthorizationMakeExternalForm
  395. Turn an Authorization into an external "byte blob" form so it can be
  396. transmitted to another process.
  397. Note that *storing* the external form somewhere will probably not do what
  398. you want, since authorizations are bounded by sessions, processes, and possibly
  399. time limits. This is for online transmission of authorizations.
  400. @param authorization The (valid) authorization reference to externalize
  401. @param extForm Pointer to an AuthorizationExternalForm variable to fill.
  402. @result errAuthorizationSuccess 0 No error.
  403. errAuthorizationExternalizeNotAllowed -60009 Externalizing this authorization is not allowed.
  404. errAuthorizationInvalidRef -60002 The authorization parameter is invalid.
  405. }
  406. function AuthorizationMakeExternalForm( authorization: AuthorizationRef; var extForm: AuthorizationExternalForm ): OSStatus; external name '_AuthorizationMakeExternalForm';
  407. {!
  408. @function AuthorizationCreateFromExternalForm
  409. Turn an Authorization into an external "byte blob" form so it can be
  410. transmitted to another process.
  411. Note that *storing* the external form somewhere will probably not do what
  412. you want, since authorizations are bounded by sessions, processes, and possibly
  413. time limits. This is for online transmission of authorizations.
  414. @param extForm Pointer to an AuthorizationExternalForm value.
  415. @param authorization Will be filled with a valid AuthorizationRef on success.
  416. @result errAuthorizationInternalizeNotAllowed -60010 Internalizing this authorization is not allowed.
  417. }
  418. function AuthorizationCreateFromExternalForm( const (*var*) extForm: AuthorizationExternalForm; var authorization: AuthorizationRef ): OSStatus; external name '_AuthorizationCreateFromExternalForm';
  419. {!
  420. @function AuthorizationFreeItemSet
  421. Release the memory allocated for an AuthorizationItemSet that was allocated
  422. by an API call.
  423. @param set The AuthorizationItemSet to deallocate.
  424. @result errAuthorizationSuccess 0 No error.
  425. errAuthorizationInvalidSet -60001 The set parameter is invalid.
  426. }
  427. function AuthorizationFreeItemSet( var setx: AuthorizationItemSet ): OSStatus; external name '_AuthorizationFreeItemSet';
  428. {!
  429. @function AuthorizationExecuteWithPrivileges
  430. Run an executable tool with enhanced privileges after passing
  431. suitable authorization procedures.
  432. @param authorization An authorization reference that is used to authorize
  433. access to the enhanced privileges. It is also passed to the tool for
  434. further access control.
  435. @param pathToTool Full pathname to the tool that should be executed
  436. with enhanced privileges.
  437. @param options Option bits (reserved). Must be zero.
  438. @param arguments An argv-style vector of strings to be passed to the tool.
  439. @param communicationsPipe Assigned a UNIX stdio FILE pointer for
  440. a bidirectional pipe to communicate with the tool. The tool will have
  441. this pipe as its standard I/O channels (stdin/stdout). If NULL, do not
  442. establish a communications pipe.
  443. }
  444. type
  445. Arg10000Type = array[0..10000] of CStringPtr;
  446. Arg10000TypePtr = ^Arg10000Type;
  447. function AuthorizationExecuteWithPrivileges( authorization: AuthorizationRef; pathToTool: CStringPtr; options: AuthorizationFlags; arguments: Arg10000TypePtr; communicationsPipe: UnivPtr ): OSStatus; external name '_AuthorizationExecuteWithPrivileges';
  448. // communicationsPipe not yet supported
  449. {!
  450. @function AuthorizationCopyPrivilegedReference
  451. From within a tool launched via the AuthorizationExecuteWithPrivileges function
  452. ONLY, retrieve the AuthorizationRef originally passed to that function.
  453. While AuthorizationExecuteWithPrivileges already verified the authorization to
  454. launch your tool, the tool may want to avail itself of any additional pre-authorizations
  455. the caller may have obtained through that reference.
  456. }
  457. function AuthorizationCopyPrivilegedReference( var authorization: AuthorizationRef; flags: AuthorizationFlags ): OSStatus; external name '_AuthorizationCopyPrivilegedReference';
  458. {$endc} {TARGET_OS_MAC}
  459. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  460. end.
  461. {$endc} {not MACOSALLINCLUDE}