AuthorizationDB.pas 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. {
  2. * Copyright (c) 2003 Apple Computer, Inc. All Rights Reserved.
  3. *
  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
  8. * using this file.
  9. *
  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.
  16. }
  17. { Pascal Translation: Peter N Lewis, <[email protected]>, 2004 }
  18. {
  19. * AuthorizationDB.h -- APIs for managing the authorization policy database
  20. * and daemons.
  21. }
  22. {
  23. Modified for use with Free Pascal
  24. Version 200
  25. Please report any bugs to <[email protected]>
  26. }
  27. {$mode macpas}
  28. {$packenum 1}
  29. {$macro on}
  30. {$inline on}
  31. {$CALLING MWPASCAL}
  32. unit AuthorizationDB;
  33. interface
  34. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  35. {$setc GAP_INTERFACES_VERSION := $0200}
  36. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  37. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  38. {$endc}
  39. {$ifc defined CPUPOWERPC and defined CPUI386}
  40. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  41. {$endc}
  42. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  43. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  44. {$endc}
  45. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  46. {$setc __ppc__ := 1}
  47. {$elsec}
  48. {$setc __ppc__ := 0}
  49. {$endc}
  50. {$ifc not defined __i386__ and defined CPUI386}
  51. {$setc __i386__ := 1}
  52. {$elsec}
  53. {$setc __i386__ := 0}
  54. {$endc}
  55. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  56. {$error Conflicting definitions for __ppc__ and __i386__}
  57. {$endc}
  58. {$ifc defined __ppc__ and __ppc__}
  59. {$setc TARGET_CPU_PPC := TRUE}
  60. {$setc TARGET_CPU_X86 := FALSE}
  61. {$elifc defined __i386__ and __i386__}
  62. {$setc TARGET_CPU_PPC := FALSE}
  63. {$setc TARGET_CPU_X86 := TRUE}
  64. {$elsec}
  65. {$error Neither __ppc__ nor __i386__ is defined.}
  66. {$endc}
  67. {$setc TARGET_CPU_PPC_64 := FALSE}
  68. {$ifc defined FPC_BIG_ENDIAN}
  69. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  70. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  71. {$elifc defined FPC_LITTLE_ENDIAN}
  72. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  73. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  74. {$elsec}
  75. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  76. {$endc}
  77. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  78. {$setc CALL_NOT_IN_CARBON := FALSE}
  79. {$setc OLDROUTINENAMES := FALSE}
  80. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  81. {$setc OPAQUE_UPP_TYPES := TRUE}
  82. {$setc OTCARBONAPPLICATION := TRUE}
  83. {$setc OTKERNEL := FALSE}
  84. {$setc PM_USE_SESSION_APIS := TRUE}
  85. {$setc TARGET_API_MAC_CARBON := TRUE}
  86. {$setc TARGET_API_MAC_OS8 := FALSE}
  87. {$setc TARGET_API_MAC_OSX := TRUE}
  88. {$setc TARGET_CARBON := TRUE}
  89. {$setc TARGET_CPU_68K := FALSE}
  90. {$setc TARGET_CPU_MIPS := FALSE}
  91. {$setc TARGET_CPU_SPARC := FALSE}
  92. {$setc TARGET_OS_MAC := TRUE}
  93. {$setc TARGET_OS_UNIX := FALSE}
  94. {$setc TARGET_OS_WIN32 := FALSE}
  95. {$setc TARGET_RT_MAC_68881 := FALSE}
  96. {$setc TARGET_RT_MAC_CFM := FALSE}
  97. {$setc TARGET_RT_MAC_MACHO := TRUE}
  98. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  99. {$setc TYPE_BOOL := FALSE}
  100. {$setc TYPE_EXTENDED := FALSE}
  101. {$setc TYPE_LONGLONG := TRUE}
  102. uses MacTypes,Authorization,CFBase,CFDictionary,CFString,CFBundle;
  103. {$ALIGN MAC68K}
  104. {!
  105. @header AuthorizationDB
  106. Version 1.0
  107. 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.
  108. AuthorizationRightSet(NULL, "com.ifoo.ifax.send", CFSTR(kRuleIsAdmin), CFSTR("You must authenticate to send a fax."), NULL, NULL)
  109. 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.
  110. AuthorizationRightSet(NULL, "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)
  111. add identical rule, but specify additional attributes this time.
  112. 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.
  113. }
  114. {! @define kRightRule
  115. rule delegation key. Instead of specifying exact behavior some canned rules
  116. are shipped that may be switched by configurable security.
  117. }
  118. const kAuthorizationRightRule = 'rule';
  119. {! @defined kRuleIsAdmin
  120. canned rule values for use with rule delegation definitions: require user to be an admin.
  121. }
  122. const kAuthorizationRuleIsAdmin = 'is-admin';
  123. {! @defined kRuleAuthenticateAsSessionUser
  124. canned rule value for use with rule delegation definitions: require user to authenticate as the session owner (logged-in user).
  125. }
  126. const kAuthorizationRuleAuthenticateAsSessionUser= 'authenticate-session-user';
  127. {! @defined kRuleAuthenticateAsAdmin
  128. Canned rule value for use with rule delegation definitions: require user to authenticate as admin.
  129. }
  130. const kAuthorizationRuleAuthenticateAsAdmin = 'authenticate-admin';
  131. {! @defined kAuthorizationRuleClassAllow
  132. Class that allows anything.
  133. }
  134. const kAuthorizationRuleClassAllow = 'allow';
  135. {! @defined kAuthorizationRuleClassDeny
  136. Class that denies anything.
  137. }
  138. const kAuthorizationRuleClassDeny = 'deny';
  139. {! @defined kAuthorizationComment
  140. comments for the administrator on what is being customized here;
  141. as opposed to (localized) descriptions presented to the user.
  142. }
  143. const kAuthorizationComment = 'comment';
  144. {!
  145. @function AuthorizationRightGet
  146. Retrieves a right definition as a dictionary. There are no restrictions to keep anyone from retrieving these definitions.
  147. @param rightName (input) the rightname (ASCII). Wildcard rightname definitions are okay.
  148. @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.
  149. @result errAuthorizationSuccess 0 No error.
  150. errAuthorizationDenied -60005 No definition found.
  151. }
  152. function AuthorizationRightGet( rightName: ConstCStringPtr; rightDefinition: CFDictionaryRefPtr ): OSStatus; external name '_AuthorizationRightGet';
  153. // attribute(weak_import);
  154. {!
  155. @function AuthorizationRightSet
  156. 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.
  157. @param authRef (input) authRef to authorize modifications.
  158. @param rightName (input) the rightname (ASCII). Wildcard rightnames are not okay.
  159. @param rightDefinition (input) a CFString of the name of a rule to use (delegate) or CFDictionary containing keys defining one.
  160. @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.
  161. @param bundle (input/optional) a bundle to get localizations from if not the main bundle.
  162. @param localeTableName (input/optional) stringtable name to get localizations from.
  163. @result errAuthorizationSuccess 0 added right definition successfully.
  164. errAuthorizationDenied -60005 Unable to create or update right definition.
  165. errAuthorizationCanceled -60006 Authorization was canceled by user.
  166. errAuthorizationInteractionNotAllowed -60007 Interaction was required but not possible.
  167. }
  168. function AuthorizationRightSet(authRef: AuthorizationRef; rightName: ConstCStringPtr; rightDefinition: CFTypeRef; descriptionKey: CFStringRef; bundle: CFBundleRef; localeTableName: CFStringRef): OSStatus; external name '_AuthorizationRightSet';
  169. // attribute(weak_import);
  170. {!
  171. @function AuthorizationRightRemove
  172. Request to remove a right from the policy database.
  173. @param authRef (input) authRef, to be used to authorize this action.
  174. @param rightName (input) the rightname (ASCII). Wildcard rightnames are not okay.
  175. }
  176. function AuthorizationRightRemove(authRef: AuthorizationRef; rightName: ConstCStringPtr): OSStatus; external name '_AuthorizationRightRemove';
  177. end.