AuthSession.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. {
  2. * Copyright (c) 2000-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: Peter N Lewis, <[email protected]>, 2004 }
  24. { Pascal Translation Update: Gorazd Krosl <[email protected]>, October 2009 }
  25. { Pascal Translation Update: Jonas Maebe <[email protected]>, October 2012 }
  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 AuthSession;
  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. {$setc TARGET_OS_EMBEDDED := FALSE}
  93. {$elifc defined __ppc64__ and __ppc64__}
  94. {$setc TARGET_CPU_PPC := FALSE}
  95. {$setc TARGET_CPU_PPC64 := TRUE}
  96. {$setc TARGET_CPU_X86 := FALSE}
  97. {$setc TARGET_CPU_X86_64 := FALSE}
  98. {$setc TARGET_CPU_ARM := FALSE}
  99. {$setc TARGET_OS_MAC := TRUE}
  100. {$setc TARGET_OS_IPHONE := FALSE}
  101. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  102. {$setc TARGET_OS_EMBEDDED := FALSE}
  103. {$elifc defined __i386__ and __i386__}
  104. {$setc TARGET_CPU_PPC := FALSE}
  105. {$setc TARGET_CPU_PPC64 := FALSE}
  106. {$setc TARGET_CPU_X86 := TRUE}
  107. {$setc TARGET_CPU_X86_64 := FALSE}
  108. {$setc TARGET_CPU_ARM := FALSE}
  109. {$ifc defined(iphonesim)}
  110. {$setc TARGET_OS_MAC := FALSE}
  111. {$setc TARGET_OS_IPHONE := TRUE}
  112. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  113. {$elsec}
  114. {$setc TARGET_OS_MAC := TRUE}
  115. {$setc TARGET_OS_IPHONE := FALSE}
  116. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  117. {$endc}
  118. {$setc TARGET_OS_EMBEDDED := FALSE}
  119. {$elifc defined __x86_64__ and __x86_64__}
  120. {$setc TARGET_CPU_PPC := FALSE}
  121. {$setc TARGET_CPU_PPC64 := FALSE}
  122. {$setc TARGET_CPU_X86 := FALSE}
  123. {$setc TARGET_CPU_X86_64 := TRUE}
  124. {$setc TARGET_CPU_ARM := FALSE}
  125. {$setc TARGET_OS_MAC := TRUE}
  126. {$setc TARGET_OS_IPHONE := FALSE}
  127. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  128. {$setc TARGET_OS_EMBEDDED := FALSE}
  129. {$elifc defined __arm__ and __arm__}
  130. {$setc TARGET_CPU_PPC := FALSE}
  131. {$setc TARGET_CPU_PPC64 := FALSE}
  132. {$setc TARGET_CPU_X86 := FALSE}
  133. {$setc TARGET_CPU_X86_64 := FALSE}
  134. {$setc TARGET_CPU_ARM := TRUE}
  135. { will require compiler define when/if other Apple devices with ARM cpus ship }
  136. {$setc TARGET_OS_MAC := FALSE}
  137. {$setc TARGET_OS_IPHONE := TRUE}
  138. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  139. {$setc TARGET_OS_EMBEDDED := TRUE}
  140. {$elsec}
  141. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  142. {$endc}
  143. {$ifc defined __LP64__ and __LP64__ }
  144. {$setc TARGET_CPU_64 := TRUE}
  145. {$elsec}
  146. {$setc TARGET_CPU_64 := FALSE}
  147. {$endc}
  148. {$ifc defined FPC_BIG_ENDIAN}
  149. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  150. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  151. {$elifc defined FPC_LITTLE_ENDIAN}
  152. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  153. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  154. {$elsec}
  155. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  156. {$endc}
  157. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  158. {$setc CALL_NOT_IN_CARBON := FALSE}
  159. {$setc OLDROUTINENAMES := FALSE}
  160. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  161. {$setc OPAQUE_UPP_TYPES := TRUE}
  162. {$setc OTCARBONAPPLICATION := TRUE}
  163. {$setc OTKERNEL := FALSE}
  164. {$setc PM_USE_SESSION_APIS := TRUE}
  165. {$setc TARGET_API_MAC_CARBON := TRUE}
  166. {$setc TARGET_API_MAC_OS8 := FALSE}
  167. {$setc TARGET_API_MAC_OSX := TRUE}
  168. {$setc TARGET_CARBON := TRUE}
  169. {$setc TARGET_CPU_68K := FALSE}
  170. {$setc TARGET_CPU_MIPS := FALSE}
  171. {$setc TARGET_CPU_SPARC := FALSE}
  172. {$setc TARGET_OS_UNIX := FALSE}
  173. {$setc TARGET_OS_WIN32 := FALSE}
  174. {$setc TARGET_RT_MAC_68881 := FALSE}
  175. {$setc TARGET_RT_MAC_CFM := FALSE}
  176. {$setc TARGET_RT_MAC_MACHO := TRUE}
  177. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  178. {$setc TYPE_BOOL := FALSE}
  179. {$setc TYPE_EXTENDED := FALSE}
  180. {$setc TYPE_LONGLONG := TRUE}
  181. uses MacTypes,Authorization;
  182. {$endc} {not MACOSALLINCLUDE}
  183. {$ifc TARGET_OS_MAC}
  184. {$ALIGN POWER}
  185. {
  186. * AuthSession.h
  187. * AuthSession - APIs for managing login, authorization, and security Sessions.
  188. }
  189. {!
  190. @header AuthSession
  191. The Session API provides specialized applications access to Session management and inquiry
  192. functions. This is a specialized API that should not be of interest to most people.
  193. The Security subsystem separates all processes into Security "sessions". Each process is in
  194. exactly one session, and session membership inherits across fork/exec. Sessions form boundaries
  195. for security-related state such as authorizations, keychain lock status, and the like.
  196. Typically, each successful login (whether graphical or through ssh & friends) creates
  197. a separate session. System daemons (started at system startup) belong to the "root session"
  198. which has no user nor graphics access.
  199. Sessions are identified with SecuritySessionIds. A session has a set of attributes
  200. that are set on creation and can be retrieved with SessionGetInfo().
  201. There are similar session concepts in the system, related but not necessarily
  202. completely congruous. In particular, graphics sessions track security sessions
  203. (but only for graphic logins).
  204. }
  205. {!
  206. @typedef SecuritySessionId
  207. These are externally visible identifiers for authorization sessions.
  208. Different sessions have different identifiers; beyond that, you can't
  209. tell anything from these values.
  210. SessionIds can be compared for equality as you'd expect, but you should be careful
  211. to use attribute bits wherever appropriate.
  212. }
  213. type
  214. SecuritySessionId = UInt32;
  215. SecuritySessionIdPtr = ^SecuritySessionId;
  216. {!
  217. @enum SecuritySessionId
  218. Here are some special values for SecuritySessionId. You may specify those
  219. on input to SessionAPI functions. They will never be returned from such
  220. functions.
  221. Note: -2 is reserved (see 4487137).
  222. }
  223. const
  224. noSecuritySession = 0; { definitely not a valid SecuritySessionId }
  225. callerSecuritySession = -1; { the Session I (the caller) am in }
  226. {!
  227. @enum SessionAttributeBits
  228. Each Session has a set of attribute bits. You can get those from the
  229. SessionGetInfo API function.
  230. }
  231. type
  232. SessionAttributeBits = UInt32;
  233. SessionAttributeBitsPtr = ^SessionAttributeBits;
  234. const
  235. sessionIsRoot = $0001; { is the root session (startup/system programs) }
  236. sessionHasGraphicAccess = $0010; { graphic subsystem (CoreGraphics et al) available }
  237. sessionHasTTY = $0020; { /dev/tty is available }
  238. sessionIsRemote = $1000; { session was established over the network }
  239. // the following bits are used internally; do not try to set them
  240. sessionWasInitialized = $8000; { session has been set up by its leader }
  241. {!
  242. @enum SessionCreationFlags
  243. These flags control how a new session is created by SessionCreate.
  244. They have no permanent meaning beyond that.
  245. }
  246. type
  247. SessionCreationFlags = UInt32;
  248. SessionCreationFlagsPtr = ^SessionCreationFlags;
  249. const
  250. sessionKeepCurrentBootstrap = $8000; { caller has allocated sub-bootstrap (expert use only) }
  251. {!
  252. @enum SessionStatus
  253. Error codes returned by AuthSession API.
  254. Note that the AuthSession APIs can also return Authorization API error codes.
  255. }
  256. const
  257. errSessionSuccess = 0; { all is well }
  258. errSessionInvalidId = -60500; { invalid session id specified }
  259. errSessionInvalidAttributes = -60501; { invalid set of requested attribute bits }
  260. errSessionAuthorizationDenied = -60502; { you are not allowed to do this }
  261. errSessionValueNotSet = -60503; { the session attribute you requested has not been set }
  262. errSessionInternal = errAuthorizationInternal; { internal error }
  263. errSessionInvalidFlags = errAuthorizationInvalidFlags; { invalid flags/options }
  264. {!
  265. @function SessionGetInfo
  266. Obtain information about a session. You can ask about any session whose
  267. identifier you know. Use the callerSecuritySession constant to ask about
  268. your own session (the one your process is in).
  269. @param session (input) The Session you are asking about. Can be one of the
  270. special constants defined above.
  271. @param sessionId (output/optional) The actual SecuritySessionId for the session you asked about.
  272. Will never be one of those constants.
  273. @param attributes (output/optional) Receives the attribute bits for the session.
  274. @result An OSStatus indicating success (noErr) or an error cause.
  275. errSessionInvalidId -60500 Invalid session id specified
  276. }
  277. function SessionGetInfo( session: SecuritySessionId; sessionId: SecuritySessionIdPtr; attributes: SessionAttributeBitsPtr ): OSStatus; external name '_SessionGetInfo';
  278. {!
  279. @function SessionCreate
  280. This (very specialized) function creates a security session.
  281. Upon completion, the new session contains the calling process (and none other).
  282. You cannot create a session for someone else, and cannot avoid being placed
  283. into the new session. This is (currently) the only call that changes a process's
  284. session membership.
  285. By default, a new bootstrap subset port is created for the calling process. The process
  286. acquires this new port as its bootstrap port, which all its children will inherit.
  287. If you happen to have created the subset port on your own, you can pass the
  288. sessionKeepCurrentBootstrap flag, and SessionCreate will use it. Note however that
  289. you cannot supersede a prior SessionCreate call that way; only a single SessionCreate
  290. call is allowed for each Session (however made).
  291. This call will discard any security information established for the calling process.
  292. In particular, any authorization handles acquired will become invalid, and so will any
  293. keychain related information. We recommend that you call SessionCreate before
  294. making any other security-related calls that establish rights of any kind, to the
  295. extent this is practical. Also, we strongly recommend that you do not perform
  296. security-related calls in any other threads while calling SessionCreate.
  297. @param flags Flags controlling how the session is created.
  298. @param attributes The set of attribute bits to set for the new session.
  299. Not all bits can be set this way.
  300. @result An OSStatus indicating success (noErr) or an error cause.
  301. errSessionInvalidAttributes -60501 Attempt to set invalid attribute bits
  302. errSessionAuthorizationDenied -60502 Attempt to re-initialize a session
  303. errSessionInvalidFlags -60011 Attempt to specify unsupported flag bits
  304. }
  305. function SessionCreate( flags: SessionCreationFlags; attributes: SessionAttributeBits ): OSStatus; external name '_SessionCreate';
  306. {$endc} {TARGET_OS_MAC}
  307. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  308. end.
  309. {$endc} {not MACOSALLINCLUDE}