2 // KeychainSyncAccountNotification.m
6 #import "KeychainSyncAccountNotification.h"
7 #import <Accounts/Accounts.h>
8 #import <Accounts/Accounts_Private.h>
10 #import <AppleAccount/ACAccount+AppleAccount.h>
12 #import <AOSAccounts/ACAccount+iCloudAccount.h>
14 #import <AccountsDaemon/ACDAccountStore.h>
15 #import <AccountsDaemon/ACDClientAuthorizationManager.h>
16 #import <AccountsDaemon/ACDClientAuthorization.h>
17 #import <Security/SecureObjectSync/SOSCloudCircle.h>
19 #import "utilities/debugging.h"
21 @implementation KeychainSyncAccountNotification
24 - (bool)accountIsPrimary:(ACAccount *)account
27 return [account aa_isPrimaryAccount];
29 return [account icaIsPrimaryAccount];
33 - (BOOL)account:(ACAccount *)account willChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
35 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
36 if(oldAccount.identifier != NULL && oldAccount.username !=NULL){
38 if ([self accountIsPrimary:oldAccount]) {
40 CFErrorRef removalError = NULL;
42 secinfo("accounts", "Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
44 if (!SOSCCLoggedOutOfAccount(&removalError)) {
45 secerror("Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
48 secinfo("accounts", "NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
52 secinfo("accounts", "Already logged out of account");
60 - (void)account:(ACAccount *)account didChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
61 if (changeType == kACAccountChangeTypeDeleted) {
62 if (oldAccount.identifier != NULL && oldAccount.username != NULL){
64 if ([self accountIsPrimary:oldAccount]) {
65 CFErrorRef removalError = NULL;
66 secinfo("accounts", "Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
67 if (!SOSCCLoggedOutOfAccount(&removalError)) {
68 secerror("Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
71 secinfo("accounts", "NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
74 secinfo("accounts", "Already logged out of account");