objc2_security/generated/
AuthSession.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3#[cfg(feature = "objc2")]
4use objc2::__framework_prelude::*;
5
6use crate::*;
7
8/// These are externally visible identifiers for authorization sessions.
9/// Different sessions have different identifiers; beyond that, you can't
10/// tell anything from these values.
11/// SessionIds can be compared for equality as you'd expect, but you should be careful
12/// to use attribute bits wherever appropriate.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/security/securitysessionid?language=objc)
15pub type SecuritySessionId = u32;
16
17/// [Apple's documentation](https://developer.apple.com/documentation/security/nosecuritysession?language=objc)
18pub const noSecuritySession: SecuritySessionId = 0;
19/// [Apple's documentation](https://developer.apple.com/documentation/security/callersecuritysession?language=objc)
20pub const callerSecuritySession: SecuritySessionId = 4294967295;
21
22/// Each Session has a set of attribute bits. You can get those from the
23/// SessionGetInfo API function.
24///
25/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sessionattributebits?language=objc)
26// NS_OPTIONS
27#[repr(transparent)]
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29pub struct SessionAttributeBits(pub u32);
30bitflags::bitflags! {
31    impl SessionAttributeBits: u32 {
32        const sessionIsRoot = 0x0001;
33        const sessionHasGraphicAccess = 0x0010;
34        const sessionHasTTY = 0x0020;
35        const sessionIsRemote = 0x1000;
36    }
37}
38
39#[cfg(feature = "objc2")]
40unsafe impl Encode for SessionAttributeBits {
41    const ENCODING: Encoding = u32::ENCODING;
42}
43
44#[cfg(feature = "objc2")]
45unsafe impl RefEncode for SessionAttributeBits {
46    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
47}
48
49/// These flags control how a new session is created by SessionCreate.
50/// They have no permanent meaning beyond that.
51///
52/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sessioncreationflags?language=objc)
53// NS_OPTIONS
54#[repr(transparent)]
55#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
56pub struct SessionCreationFlags(pub u32);
57bitflags::bitflags! {
58    impl SessionCreationFlags: u32 {
59        const sessionKeepCurrentBootstrap = 0x8000;
60    }
61}
62
63#[cfg(feature = "objc2")]
64unsafe impl Encode for SessionCreationFlags {
65    const ENCODING: Encoding = u32::ENCODING;
66}
67
68#[cfg(feature = "objc2")]
69unsafe impl RefEncode for SessionCreationFlags {
70    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
71}
72
73/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessionsuccess?language=objc)
74pub const errSessionSuccess: OSStatus = 0;
75/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessioninvalidid?language=objc)
76pub const errSessionInvalidId: OSStatus = -60500;
77/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessioninvalidattributes?language=objc)
78pub const errSessionInvalidAttributes: OSStatus = -60501;
79/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessionauthorizationdenied?language=objc)
80pub const errSessionAuthorizationDenied: OSStatus = -60502;
81/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessionvaluenotset?language=objc)
82pub const errSessionValueNotSet: OSStatus = -60503;
83/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessioninternal?language=objc)
84pub const errSessionInternal: OSStatus = -60008;
85/// [Apple's documentation](https://developer.apple.com/documentation/security/errsessioninvalidflags?language=objc)
86pub const errSessionInvalidFlags: OSStatus = -60011;
87
88extern "C-unwind" {
89    /// Obtain information about a session. You can ask about any session whose
90    /// identifier you know. Use the callerSecuritySession constant to ask about
91    /// your own session (the one your process is in).
92    ///
93    ///
94    /// Parameter `session`: (input) The Session you are asking about. Can be one of the
95    /// special constants defined above.
96    ///
97    ///
98    /// Parameter `sessionId`: (output/optional) The actual SecuritySessionId for the session you asked about.
99    /// Will never be one of those constants.
100    ///
101    ///
102    /// Parameter `attributes`: (output/optional) Receives the attribute bits for the session.
103    ///
104    ///
105    /// Returns: An OSStatus indicating success (errSecSuccess) or an error cause.
106    ///
107    /// errSessionInvalidId -60500 Invalid session id specified
108    pub fn SessionGetInfo(
109        session: SecuritySessionId,
110        session_id: *mut SecuritySessionId,
111        attributes: *mut SessionAttributeBits,
112    ) -> OSStatus;
113}
114
115extern "C-unwind" {
116    /// This (very specialized) function creates a security session.
117    /// Upon completion, the new session contains the calling process (and none other).
118    /// You cannot create a session for someone else, and cannot avoid being placed
119    /// into the new session. This is (currently) the only call that changes a process's
120    /// session membership.
121    /// By default, a new bootstrap subset port is created for the calling process. The process
122    /// acquires this new port as its bootstrap port, which all its children will inherit.
123    /// If you happen to have created the subset port on your own, you can pass the
124    /// sessionKeepCurrentBootstrap flag, and SessionCreate will use it. Note however that
125    /// you cannot supersede a prior SessionCreate call that way; only a single SessionCreate
126    /// call is allowed for each Session (however made).
127    /// This call will discard any security information established for the calling process.
128    /// In particular, any authorization handles acquired will become invalid, and so will any
129    /// keychain related information. We recommend that you call SessionCreate before
130    /// making any other security-related calls that establish rights of any kind, to the
131    /// extent this is practical. Also, we strongly recommend that you do not perform
132    /// security-related calls in any other threads while calling SessionCreate.
133    ///
134    ///
135    /// Parameter `flags`: Flags controlling how the session is created.
136    ///
137    ///
138    /// Parameter `attributes`: The set of attribute bits to set for the new session.
139    /// Not all bits can be set this way.
140    ///
141    ///
142    /// Returns: An OSStatus indicating success (errSecSuccess) or an error cause.
143    ///
144    /// errSessionInvalidAttributes -60501 Attempt to set invalid attribute bits
145    /// errSessionAuthorizationDenied -60502 Attempt to re-initialize a session
146    /// errSessionInvalidFlags -60011 Attempt to specify unsupported flag bits
147    pub fn SessionCreate(flags: SessionCreationFlags, attributes: SessionAttributeBits)
148        -> OSStatus;
149}