AuthSession.pas 14 KB

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