]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/utilities/setup_assistant_helper.m
mDNSResponder-1310.40.42.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / utilities / setup_assistant_helper.m
1 /*
2 * Copyright (c) 2020 Apple Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #import "setup_assistant_helper.h"
18
19 #import <SoftLinking/SoftLinking.h>
20
21 #if TARGET_OS_OSX
22
23 #import <SetupAssistantFramework/SAUserSetupState.h>
24 #import <SystemConfiguration/SystemConfiguration.h>
25
26 SOFT_LINK_FRAMEWORK(PrivateFrameworks, SetupAssistantFramework)
27 SOFT_LINK_CLASS(SetupAssistantFramework, SAUserSetupState)
28
29 #endif // TARGET_OS_OSX
30
31 #if TARGET_OS_OSX
32 static uid_t s_last_uid = 0;
33 static void
34 _update_console_user_id(void)
35 {
36 CFStringRef userName = SCDynamicStoreCopyConsoleUser(NULL, &s_last_uid, NULL);
37 if (userName) {
38 CFRelease(userName);
39 }
40 }
41 #endif // TARGET_OS_OSX
42
43 buddy_state_t
44 assistant_helper_get_buddy_state(void)
45 {
46 #if TARGET_OS_OSX
47 buddy_state_t buddy_state = buddy_state_indeterminate;
48 _update_console_user_id();
49 SAUserSetupStateEnum state = [SAUserSetupState getSetupStateForUser:s_last_uid];
50 switch (state) {
51 case SAUserSetupStateSetupDone:
52 buddy_state = buddy_state_done;
53 break;
54
55 case SAUserSetupStateSetupUser:
56 case SAUserSetupStateSetupInProcess:
57 buddy_state = buddy_state_in_process;
58 break;
59
60 case SAUserSetupStateIndeterminate:
61 default:
62 buddy_state = buddy_state_indeterminate;
63 break;
64 }
65 return buddy_state;
66 #else
67 return buddy_state_done;
68 #endif // TARGET_OS_OSX
69 }
70
71 void
72 assistant_helper_notify_when_buddy_done(buddy_done_handler_t handler)
73 {
74 #if TARGET_OS_OSX
75 [SAUserSetupState notifyWhenUserIsSetup:s_last_uid withCompletionBlock:handler];
76 #else
77 (void)handler;
78 #endif // TARGET_OS_OSX
79 }
80