]> git.saurik.com Git - apple/security.git/blob - KeychainSyncAccountNotification/KeychainSyncAccountNotification.m
Security-58286.1.32.tar.gz
[apple/security.git] / KeychainSyncAccountNotification / KeychainSyncAccountNotification.m
1 //
2 // KeychainSyncAccountNotification.m
3 // Security
4 //
5
6 #import "KeychainSyncAccountNotification.h"
7 #import <Accounts/Accounts.h>
8 #import <Accounts/Accounts_Private.h>
9 #if TARGET_OS_IPHONE
10 #import <AppleAccount/ACAccount+AppleAccount.h>
11 #else
12 #import <AOSAccounts/ACAccount+iCloudAccount.h>
13 #endif
14 #import <AccountsDaemon/ACDAccountStore.h>
15 #import <Security/SecureObjectSync/SOSCloudCircle.h>
16
17 #import "utilities/debugging.h"
18
19 @implementation KeychainSyncAccountNotification
20
21 - (bool)accountIsPrimary:(ACAccount *)account
22 {
23 #if TARGET_OS_IPHONE
24 return [account aa_isPrimaryAccount];
25 #else
26 return [account icaIsPrimaryAccount];
27 #endif
28 }
29
30 - (BOOL)account:(ACAccount *)account willChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
31 NSString* oldAccountIdentifier = oldAccount.identifier;
32 NSString* accountIdentifier = account.identifier;
33
34 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
35 if(oldAccountIdentifier != NULL && oldAccount.username !=NULL) {
36 if ([self accountIsPrimary:oldAccount]) {
37 CFErrorRef removalError = NULL;
38
39 secinfo("accounts", "Performing SOS circle credential removal for account %@: %@", oldAccountIdentifier, oldAccount.username);
40
41 if (!SOSCCLoggedOutOfAccount(&removalError)) {
42 secerror("Account %@ could not leave the SOS circle: %@", oldAccountIdentifier, removalError);
43 }
44 } else {
45 secinfo("accounts", "NOT performing SOS circle credential removal for secondary account %@: %@", accountIdentifier, account.username);
46 }
47 } else{
48 secinfo("accounts", "Already logged out of account");
49 }
50 }
51
52 return YES;
53 }
54
55 @end