1 use core_foundation_sys::base::CFTypeRef;
2 use core_foundation_sys::base::OSStatus;
3 use core_foundation_sys::bundle::CFBundleRef;
4 use core_foundation_sys::dictionary::CFDictionaryRef;
5 use core_foundation_sys::string::CFStringRef;
6 use std::os::raw::{c_char, c_void};
7 
8 pub const errAuthorizationSuccess: OSStatus = 0;
9 pub const errAuthorizationInvalidSet: OSStatus = -60001;
10 pub const errAuthorizationInvalidRef: OSStatus = -60002;
11 pub const errAuthorizationInvalidTag: OSStatus = -60003;
12 pub const errAuthorizationInvalidPointer: OSStatus = -60004;
13 pub const errAuthorizationDenied: OSStatus = -60005;
14 pub const errAuthorizationCanceled: OSStatus = -60006;
15 pub const errAuthorizationInteractionNotAllowed: OSStatus = -60007;
16 pub const errAuthorizationInternal: OSStatus = -60008;
17 pub const errAuthorizationExternalizeNotAllowed: OSStatus = -60009;
18 pub const errAuthorizationInternalizeNotAllowed: OSStatus = -60010;
19 pub const errAuthorizationInvalidFlags: OSStatus = -60011;
20 pub const errAuthorizationToolExecuteFailure: OSStatus = -60031;
21 pub const errAuthorizationToolEnvironmentError: OSStatus = -60032;
22 pub const errAuthorizationBadAddress: OSStatus = -60033;
23 
24 pub type AuthorizationFlags = u32;
25 pub const kAuthorizationFlagDefaults: AuthorizationFlags = 0;
26 pub const kAuthorizationFlagInteractionAllowed: AuthorizationFlags = 1;
27 pub const kAuthorizationFlagExtendRights: AuthorizationFlags = 2;
28 pub const kAuthorizationFlagPartialRights: AuthorizationFlags = 4;
29 pub const kAuthorizationFlagDestroyRights: AuthorizationFlags = 8;
30 pub const kAuthorizationFlagPreAuthorize: AuthorizationFlags = 16;
31 
32 pub type AuthorizationRef = *mut c_void;
33 pub type AuthorizationString = *const c_char;
34 
35 #[repr(C)]
36 #[derive(Copy, Clone, Debug)]
37 pub struct AuthorizationItem {
38     pub name: AuthorizationString,
39     pub valueLength: usize,
40     pub value: *mut c_void,
41     pub flags: u32,
42 }
43 
44 #[repr(C)]
45 #[derive(Copy, Clone, Debug)]
46 pub struct AuthorizationItemSet {
47     pub count: u32,
48     pub items: *mut AuthorizationItem,
49 }
50 
51 pub const kAuthorizationExternalFormLength: usize = 32;
52 
53 #[repr(C)]
54 #[derive(Copy, Clone, Debug)]
55 pub struct AuthorizationExternalForm {
56     pub bytes: [c_char; kAuthorizationExternalFormLength],
57 }
58 
59 pub type AuthorizationRights = AuthorizationItemSet;
60 pub type AuthorizationEnvironment = AuthorizationItemSet;
61 
62 pub type AuthorizationAsyncCallback =
63     unsafe extern "C" fn(err: OSStatus, blockAuthorizedRights: *mut AuthorizationRights);
64 
65 extern "C" {
AuthorizationCreate( rights: *const AuthorizationRights, environment: *const AuthorizationEnvironment, flags: AuthorizationFlags, authorization: *mut AuthorizationRef, ) -> OSStatus66     pub fn AuthorizationCreate(
67         rights: *const AuthorizationRights,
68         environment: *const AuthorizationEnvironment,
69         flags: AuthorizationFlags,
70         authorization: *mut AuthorizationRef,
71     ) -> OSStatus;
72 
AuthorizationFree( authorization: AuthorizationRef, flags: AuthorizationFlags, ) -> OSStatus73     pub fn AuthorizationFree(
74         authorization: AuthorizationRef,
75         flags: AuthorizationFlags,
76     ) -> OSStatus;
77 
AuthorizationCopyRights( authorization: AuthorizationRef, rights: *const AuthorizationRights, environment: *const AuthorizationEnvironment, flags: AuthorizationFlags, authorizedRights: *mut *mut AuthorizationRights, ) -> OSStatus78     pub fn AuthorizationCopyRights(
79         authorization: AuthorizationRef,
80         rights: *const AuthorizationRights,
81         environment: *const AuthorizationEnvironment,
82         flags: AuthorizationFlags,
83         authorizedRights: *mut *mut AuthorizationRights,
84     ) -> OSStatus;
85 
AuthorizationCopyRightsAsync( authorization: AuthorizationRef, rights: *const AuthorizationRights, environment: *const AuthorizationEnvironment, flags: AuthorizationFlags, callbackBlock: AuthorizationAsyncCallback, )86     pub fn AuthorizationCopyRightsAsync(
87         authorization: AuthorizationRef,
88         rights: *const AuthorizationRights,
89         environment: *const AuthorizationEnvironment,
90         flags: AuthorizationFlags,
91         callbackBlock: AuthorizationAsyncCallback,
92     );
93 
AuthorizationCopyInfo( authorization: AuthorizationRef, tag: AuthorizationString, info: *mut *mut AuthorizationItemSet, ) -> OSStatus94     pub fn AuthorizationCopyInfo(
95         authorization: AuthorizationRef,
96         tag: AuthorizationString,
97         info: *mut *mut AuthorizationItemSet,
98     ) -> OSStatus;
99 
AuthorizationMakeExternalForm( authorization: AuthorizationRef, extForm: *mut AuthorizationExternalForm, ) -> OSStatus100     pub fn AuthorizationMakeExternalForm(
101         authorization: AuthorizationRef,
102         extForm: *mut AuthorizationExternalForm,
103     ) -> OSStatus;
104 
AuthorizationCreateFromExternalForm( extForm: *const AuthorizationExternalForm, authorization: *mut AuthorizationRef, ) -> OSStatus105     pub fn AuthorizationCreateFromExternalForm(
106         extForm: *const AuthorizationExternalForm,
107         authorization: *mut AuthorizationRef,
108     ) -> OSStatus;
109 
AuthorizationFreeItemSet(set: *mut AuthorizationItemSet) -> OSStatus110     pub fn AuthorizationFreeItemSet(set: *mut AuthorizationItemSet) -> OSStatus;
111 
AuthorizationRightGet( rightName: *const c_char, rightDefinition: *mut CFDictionaryRef, ) -> OSStatus112     pub fn AuthorizationRightGet(
113         rightName: *const c_char,
114         rightDefinition: *mut CFDictionaryRef,
115     ) -> OSStatus;
116 
AuthorizationRightSet( authorization: AuthorizationRef, rightName: *const c_char, rightDefinition: CFTypeRef, descriptionKey: CFStringRef, bundle: CFBundleRef, localeTableName: CFStringRef, ) -> OSStatus117     pub fn AuthorizationRightSet(
118         authorization: AuthorizationRef,
119         rightName: *const c_char,
120         rightDefinition: CFTypeRef,
121         descriptionKey: CFStringRef,
122         bundle: CFBundleRef,
123         localeTableName: CFStringRef,
124     ) -> OSStatus;
125 
AuthorizationRightRemove( authorization: AuthorizationRef, rightName: *const c_char, ) -> OSStatus126     pub fn AuthorizationRightRemove(
127         authorization: AuthorizationRef,
128         rightName: *const c_char,
129     ) -> OSStatus;
130 
131     #[cfg(target_os = "macos")]
AuthorizationExecuteWithPrivileges( authorization: AuthorizationRef, pathToTool: *const c_char, options: AuthorizationFlags, arguments: *const *mut c_char, communicationsPipe: *mut *mut libc::FILE, ) -> OSStatus132     pub fn AuthorizationExecuteWithPrivileges(
133         authorization: AuthorizationRef,
134         pathToTool: *const c_char,
135         options: AuthorizationFlags,
136         arguments: *const *mut c_char,
137         communicationsPipe: *mut *mut libc::FILE,
138     ) -> OSStatus;
139 
140     #[cfg(target_os = "macos")]
AuthorizationCopyPrivilegedReference( authorization: *mut AuthorizationRef, flags: AuthorizationFlags, ) -> OSStatus141     pub fn AuthorizationCopyPrivilegedReference(
142         authorization: *mut AuthorizationRef,
143         flags: AuthorizationFlags,
144     ) -> OSStatus;
145 }
146