AuthSession.pas 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. {
  2. * Copyright (c) 2000-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. * AuthSession.h
  20. * AuthSession - APIs for managing login, authorization, and security Sessions.
  21. }
  22. {
  23. Modified for use with Free Pascal
  24. Version 210
  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 AuthSession;
  33. interface
  34. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  35. {$setc GAP_INTERFACES_VERSION := $0210}
  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;
  103. {$ALIGN MAC68K}
  104. {!
  105. @header AuthSession
  106. The Session API provides specialized applications access to Session management and inquiry
  107. functions. This is a specialized API that should not be of interest to most people.
  108. The Security subsystem separates all processes into Security "sessions". Each process is in
  109. exactly one session, and session membership inherits across fork/exec. Sessions form boundaries
  110. for security-related state such as authorizations, keychain lock status, and the like.
  111. Typically, each successful login (whether graphical or through ssh & friends) creates
  112. a separate session. System daemons (started at system startup) belong to the "root session"
  113. which has no user nor graphics access.
  114. Sessions are identified with SecuritySessionIds. A session has a set of attributes
  115. that are set on creation and can be retrieved with SessionGetInfo().
  116. There are similar session concepts in the system, related but not necessarily
  117. completely congruous. In particular, graphics sessions track security sessions
  118. (but only for graphic logins).
  119. }
  120. {!
  121. @typedef SecuritySessionId
  122. These are externally visible identifiers for authorization sessions.
  123. Different sessions have different identifiers; beyond that, you can't
  124. tell anything from these values.
  125. SessionIds can be compared for equality as you'd expect, but you should be careful
  126. to use attribute bits wherever appropriate.
  127. }
  128. type
  129. SecuritySessionId = UInt32;
  130. SecuritySessionIdPtr = ^SecuritySessionId;
  131. {!
  132. @enum SecuritySessionId
  133. Here are some special values for SecuritySessionId. You may specify those
  134. on input to SessionAPI functions. They will never be returned from such
  135. functions.
  136. }
  137. const
  138. noSecuritySession = 0; { definitely not a valid SecuritySessionId }
  139. callerSecuritySession = -1; { the Session I (the caller) am in }
  140. {!
  141. @enum SessionAttributeBits
  142. Each Session has a set of attribute bits. You can get those from the
  143. SessionGetInfo API function.
  144. }
  145. type
  146. SessionAttributeBits = UInt32;
  147. SessionAttributeBitsPtr = ^SessionAttributeBits;
  148. const
  149. sessionIsRoot = $0001; { is the root session (startup/system programs) }
  150. sessionHasGraphicAccess = $0010; { graphic subsystem (CoreGraphics et al) available }
  151. sessionHasTTY = $0020; { /dev/tty is available }
  152. sessionIsRemote = $1000; { session was established over the network }
  153. // the following bits are used internally; do not try to set them
  154. sessionWasInitialized = $8000; { session has been set up by its leader }
  155. {!
  156. @enum SessionCreationFlags
  157. These flags control how a new session is created by SessionCreate.
  158. They have no permanent meaning beyond that.
  159. }
  160. type
  161. SessionCreationFlags = UInt32;
  162. SessionCreationFlagsPtr = ^SessionCreationFlags;
  163. const
  164. sessionKeepCurrentBootstrap = $8000; { caller has allocated sub-bootstrap (expert use only) }
  165. {!
  166. @enum SessionStatus
  167. Error codes returned by AuthSession API.
  168. Note that the AuthSession APIs can also return Authorization API error codes.
  169. }
  170. const
  171. errSessionSuccess = 0; { all is well }
  172. errSessionInvalidId = -60500; { invalid session id specified }
  173. errSessionInvalidAttributes = -60501; { invalid set of requested attribute bits }
  174. errSessionAuthorizationDenied = -60502; { you are not allowed to do this }
  175. errSessionInternal = errAuthorizationInternal; { internal error }
  176. errSessionInvalidFlags = errAuthorizationInvalidFlags; { invalid flags/options }
  177. {!
  178. @function SessionGetInfo
  179. Obtain information about a session. You can ask about any session whose
  180. identifier you know. Use the callerSecuritySession constant to ask about
  181. your own session (the one your process is in).
  182. @param session (input) The Session you are asking about. Can be one of the
  183. special constants defined above.
  184. @param sessionId (output/optional) The actual SecuritySessionId for the session you asked about.
  185. Will never be one of those constants.
  186. @param attributes (output/optional) Receives the attribute bits for the session.
  187. @result An OSStatus indicating success (noErr) or an error cause.
  188. errSessionInvalidId -60500 Invalid session id specified
  189. }
  190. function SessionGetInfo( session: SecuritySessionId; sessionId: SecuritySessionIdPtr; attributes: SessionAttributeBitsPtr ): OSStatus; external name '_SessionGetInfo';
  191. {!
  192. @function SessionCreate
  193. This (very specialized) function creates a security session.
  194. Upon completion, the new session contains the calling process (and none other).
  195. You cannot create a session for someone else, and cannot avoid being placed
  196. into the new session. This is (currently) the only call that changes a process's
  197. session membership.
  198. By default, a new bootstrap subset port is created for the calling process. The process
  199. acquires this new port as its bootstrap port, which all its children will inherit.
  200. If you happen to have created the subset port on your own, you can pass the
  201. sessionKeepCurrentBootstrap flag, and SessionCreate will use it. Note however that
  202. you cannot supersede a prior SessionCreate call that way; only a single SessionCreate
  203. call is allowed for each Session (however made).
  204. This call will discard any security information established for the calling process.
  205. In particular, any authorization handles acquired will become invalid, and so will any
  206. keychain related information. We recommend that you call SessionCreate before
  207. making any other security-related calls that establish rights of any kind, to the
  208. extent this is practical. Also, we strongly recommend that you do not perform
  209. security-related calls in any other threads while calling SessionCreate.
  210. @param flags Flags controlling how the session is created.
  211. @param attributes The set of attribute bits to set for the new session.
  212. Not all bits can be set this way.
  213. @result An OSStatus indicating success (noErr) or an error cause.
  214. errSessionInvalidAttributes -60501 Attempt to set invalid attribute bits
  215. errSessionAuthorizationDenied -60502 Attempt to re-initialize a session
  216. errSessionInvalidFlags -60011 Attempt to specify unsupported flag bits
  217. }
  218. function SessionCreate( flags: SessionCreationFlags; attributes: SessionAttributeBits ): OSStatus; external name '_SessionCreate';
  219. end.