AuthorizationDB.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. {
  2. * Copyright (c) 2003 Apple Computer, 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: Gorazd Krosl <[email protected]>, October 2009 }
  24. { Pascal Translation Update: Jonas Maebe <[email protected]>, October 2012 }
  25. {
  26. Modified for use with Free Pascal
  27. Version 308
  28. Please report any bugs to <[email protected]>
  29. }
  30. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  31. {$mode macpas}
  32. {$packenum 1}
  33. {$macro on}
  34. {$inline on}
  35. {$calling mwpascal}
  36. unit AuthorizationDB;
  37. interface
  38. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  39. {$setc GAP_INTERFACES_VERSION := $0308}
  40. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  41. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  42. {$endc}
  43. {$ifc defined CPUPOWERPC and defined CPUI386}
  44. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  45. {$endc}
  46. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  47. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  48. {$endc}
  49. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  50. {$setc __ppc__ := 1}
  51. {$elsec}
  52. {$setc __ppc__ := 0}
  53. {$endc}
  54. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  55. {$setc __ppc64__ := 1}
  56. {$elsec}
  57. {$setc __ppc64__ := 0}
  58. {$endc}
  59. {$ifc not defined __i386__ and defined CPUI386}
  60. {$setc __i386__ := 1}
  61. {$elsec}
  62. {$setc __i386__ := 0}
  63. {$endc}
  64. {$ifc not defined __x86_64__ and defined CPUX86_64}
  65. {$setc __x86_64__ := 1}
  66. {$elsec}
  67. {$setc __x86_64__ := 0}
  68. {$endc}
  69. {$ifc not defined __arm__ and defined CPUARM}
  70. {$setc __arm__ := 1}
  71. {$elsec}
  72. {$setc __arm__ := 0}
  73. {$endc}
  74. {$ifc defined cpu64}
  75. {$setc __LP64__ := 1}
  76. {$elsec}
  77. {$setc __LP64__ := 0}
  78. {$endc}
  79. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  80. {$error Conflicting definitions for __ppc__ and __i386__}
  81. {$endc}
  82. {$ifc defined __ppc__ and __ppc__}
  83. {$setc TARGET_CPU_PPC := TRUE}
  84. {$setc TARGET_CPU_PPC64 := FALSE}
  85. {$setc TARGET_CPU_X86 := FALSE}
  86. {$setc TARGET_CPU_X86_64 := FALSE}
  87. {$setc TARGET_CPU_ARM := FALSE}
  88. {$setc TARGET_OS_MAC := TRUE}
  89. {$setc TARGET_OS_IPHONE := FALSE}
  90. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  91. {$setc TARGET_OS_EMBEDDED := FALSE}
  92. {$elifc defined __ppc64__ and __ppc64__}
  93. {$setc TARGET_CPU_PPC := FALSE}
  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. {$setc TARGET_OS_EMBEDDED := FALSE}
  102. {$elifc defined __i386__ and __i386__}
  103. {$setc TARGET_CPU_PPC := FALSE}
  104. {$setc TARGET_CPU_PPC64 := FALSE}
  105. {$setc TARGET_CPU_X86 := TRUE}
  106. {$setc TARGET_CPU_X86_64 := FALSE}
  107. {$setc TARGET_CPU_ARM := FALSE}
  108. {$ifc defined(iphonesim)}
  109. {$setc TARGET_OS_MAC := FALSE}
  110. {$setc TARGET_OS_IPHONE := TRUE}
  111. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  112. {$elsec}
  113. {$setc TARGET_OS_MAC := TRUE}
  114. {$setc TARGET_OS_IPHONE := FALSE}
  115. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  116. {$endc}
  117. {$setc TARGET_OS_EMBEDDED := FALSE}
  118. {$elifc defined __x86_64__ and __x86_64__}
  119. {$setc TARGET_CPU_PPC := FALSE}
  120. {$setc TARGET_CPU_PPC64 := FALSE}
  121. {$setc TARGET_CPU_X86 := FALSE}
  122. {$setc TARGET_CPU_X86_64 := TRUE}
  123. {$setc TARGET_CPU_ARM := FALSE}
  124. {$setc TARGET_OS_MAC := TRUE}
  125. {$setc TARGET_OS_IPHONE := FALSE}
  126. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  127. {$setc TARGET_OS_EMBEDDED := FALSE}
  128. {$elifc defined __arm__ and __arm__}
  129. {$setc TARGET_CPU_PPC := FALSE}
  130. {$setc TARGET_CPU_PPC64 := FALSE}
  131. {$setc TARGET_CPU_X86 := FALSE}
  132. {$setc TARGET_CPU_X86_64 := FALSE}
  133. {$setc TARGET_CPU_ARM := TRUE}
  134. { will require compiler define when/if other Apple devices with ARM cpus ship }
  135. {$setc TARGET_OS_MAC := FALSE}
  136. {$setc TARGET_OS_IPHONE := TRUE}
  137. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  138. {$setc TARGET_OS_EMBEDDED := TRUE}
  139. {$elsec}
  140. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  141. {$endc}
  142. {$ifc defined __LP64__ and __LP64__ }
  143. {$setc TARGET_CPU_64 := TRUE}
  144. {$elsec}
  145. {$setc TARGET_CPU_64 := FALSE}
  146. {$endc}
  147. {$ifc defined FPC_BIG_ENDIAN}
  148. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  149. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  150. {$elifc defined FPC_LITTLE_ENDIAN}
  151. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  152. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  153. {$elsec}
  154. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  155. {$endc}
  156. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  157. {$setc CALL_NOT_IN_CARBON := FALSE}
  158. {$setc OLDROUTINENAMES := FALSE}
  159. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  160. {$setc OPAQUE_UPP_TYPES := TRUE}
  161. {$setc OTCARBONAPPLICATION := TRUE}
  162. {$setc OTKERNEL := FALSE}
  163. {$setc PM_USE_SESSION_APIS := TRUE}
  164. {$setc TARGET_API_MAC_CARBON := TRUE}
  165. {$setc TARGET_API_MAC_OS8 := FALSE}
  166. {$setc TARGET_API_MAC_OSX := TRUE}
  167. {$setc TARGET_CARBON := TRUE}
  168. {$setc TARGET_CPU_68K := FALSE}
  169. {$setc TARGET_CPU_MIPS := FALSE}
  170. {$setc TARGET_CPU_SPARC := FALSE}
  171. {$setc TARGET_OS_UNIX := FALSE}
  172. {$setc TARGET_OS_WIN32 := FALSE}
  173. {$setc TARGET_RT_MAC_68881 := FALSE}
  174. {$setc TARGET_RT_MAC_CFM := FALSE}
  175. {$setc TARGET_RT_MAC_MACHO := TRUE}
  176. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  177. {$setc TYPE_BOOL := FALSE}
  178. {$setc TYPE_EXTENDED := FALSE}
  179. {$setc TYPE_LONGLONG := TRUE}
  180. uses MacTypes,Authorization,CFBase,CFDictionary,CFString,CFBundle;
  181. {$endc} {not MACOSALLINCLUDE}
  182. {$ifc TARGET_OS_MAC}
  183. {$ALIGN POWER}
  184. {
  185. * AuthorizationDB.h -- APIs for managing the authorization policy database
  186. * and daemons.
  187. }
  188. {!
  189. @header AuthorizationDB
  190. Version 1.0
  191. This API allows for any programs to get, modify, delete and add new right definitions to the policy database. Meta-rights specify whether and what authorization is required to make these modifications.
  192. AuthorizationRightSet(authRef, "com.ifoo.ifax.send", CFSTR(kRuleIsAdmin), CFSTR("You must authenticate to send a fax."), NULL, NULL)
  193. add a rule for letting admins send faxes using a canned rule, delegating to a pre-specified rule that authorizes everyone who is an admin.
  194. AuthorizationRightSet(authRef, "com.ifoo.ifax.send", [[CFSTR(kRightRule), CFSTR(kRuleIsAdmin)], [CFSTR(kRightComment), CFSTR("authorizes sending of 1 fax message")]], CFSTR("Authorize sending of a fax"), NULL, NULL)
  195. add identical rule, but specify additional attributes this time.
  196. Keep in mind while specifying a comment to be specific about what you need to authorize for (1 fax), in terms of a general message for user. The means of proof required for kRuleIsAdmin (enter username/password for example) should not be included here, since it could be configured differently. Also note that the "authRef" variable used in each of the above examples must be a vaild AuthorizationRef obtained from AuthorizationCreate().
  197. }
  198. {! @define kRightRule
  199. rule delegation key. Instead of specifying exact behavior some canned rules
  200. are shipped that may be switched by configurable security.
  201. }
  202. const
  203. kAuthorizationRightRule = 'rule';
  204. {! @defined kRuleIsAdmin
  205. canned rule values for use with rule delegation definitions: require user to be an admin.
  206. }
  207. const
  208. kAuthorizationRuleIsAdmin = 'is-admin';
  209. {! @defined kRuleAuthenticateAsSessionUser
  210. canned rule value for use with rule delegation definitions: require user to authenticate as the session owner (logged-in user).
  211. }
  212. const
  213. kAuthorizationRuleAuthenticateAsSessionUser = 'authenticate-session-owner';
  214. {! @defined kRuleAuthenticateAsAdmin
  215. Canned rule value for use with rule delegation definitions: require user to authenticate as admin.
  216. }
  217. const
  218. kAuthorizationRuleAuthenticateAsAdmin = 'authenticate-admin';
  219. {! @defined kAuthorizationRuleClassAllow
  220. Class that allows anything.
  221. }
  222. const
  223. kAuthorizationRuleClassAllow = 'allow';
  224. {! @defined kAuthorizationRuleClassDeny
  225. Class that denies anything.
  226. }
  227. const
  228. kAuthorizationRuleClassDeny = 'deny';
  229. {! @defined kAuthorizationComment
  230. comments for the administrator on what is being customized here;
  231. as opposed to (localized) descriptions presented to the user.
  232. }
  233. const
  234. kAuthorizationComment = 'comment';
  235. {!
  236. @function AuthorizationRightGet
  237. Retrieves a right definition as a dictionary. There are no restrictions to keep anyone from retrieving these definitions.
  238. @param rightName (input) the rightname (ASCII). Wildcard rightname definitions are okay.
  239. @param rightDefinition (output/optional) the dictionary with all keys defining the right. See documented keys. Passing in NULL will just check if there is a definition. The caller is responsible for releasing the returned dictionary.
  240. @result errAuthorizationSuccess 0 No error.
  241. errAuthorizationDenied -60005 No definition found.
  242. }
  243. function AuthorizationRightGet( rightName: ConstCStringPtr; rightDefinition: CFDictionaryRefPtr ): OSStatus; external name '_AuthorizationRightGet';
  244. {!
  245. @function AuthorizationRightSet
  246. Create or update a right entry. Only normal rights can be registered (wildcard rights are denied); wildcard rights are considered to be put in by an administrator putting together a site configuration.
  247. @param authRef (input) authRef to authorize modifications.
  248. @param rightName (input) the rightname (ASCII). Wildcard rightnames are not okay.
  249. @param rightDefinition (input) a CFString of the name of a rule to use (delegate) or CFDictionary containing keys defining one.
  250. @param descriptionKey (input/optional) a CFString to use as a key for looking up localized descriptions. If no localization is found this will be the description itself.
  251. @param bundle (input/optional) a bundle to get localizations from if not the main bundle.
  252. @param localeTableName (input/optional) stringtable name to get localizations from.
  253. @result errAuthorizationSuccess 0 added right definition successfully.
  254. errAuthorizationDenied -60005 Unable to create or update right definition.
  255. errAuthorizationCanceled -60006 Authorization was canceled by user.
  256. errAuthorizationInteractionNotAllowed -60007 Interaction was required but not possible.
  257. }
  258. function AuthorizationRightSet( authRef: AuthorizationRef; rightName: ConstCStringPtr; rightDefinition: CFTypeRef; descriptionKey: CFStringRef; bundle: CFBundleRef; localeTableName: CFStringRef ): OSStatus; external name '_AuthorizationRightSet';
  259. {!
  260. @function AuthorizationRightRemove
  261. Request to remove a right from the policy database.
  262. @param authRef (input) authRef, to be used to authorize this action.
  263. @param rightName (input) the rightname (ASCII). Wildcard rightnames are not okay.
  264. }
  265. function AuthorizationRightRemove( authRef: AuthorizationRef; rightName: ConstCStringPtr ): OSStatus; external name '_AuthorizationRightRemove';
  266. {$endc} {TARGET_OS_MAC}
  267. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  268. end.
  269. {$endc} {not MACOSALLINCLUDE}