2 // KeychainSyncAccountNotification.m
5 // Created by keith on 5/2/13.
9 #import "KeychainSyncAccountNotification.h"
10 #import <Accounts/ACLogging.h>
11 #import <Accounts/Accounts.h>
12 #import <Accounts/Accounts_Private.h>
13 #import <AppleAccount/ACAccount+AppleAccount.h>
14 #import <AccountsDaemon/ACDAccountStore.h>
15 #import <AccountsDaemon/ACDClientAuthorizationManager.h>
16 #import <AccountsDaemon/ACDClientAuthorization.h>
17 #import <Security/SOSCloudCircle.h>
19 @implementation KeychainSyncAccountNotification
21 - (BOOL)account:(ACAccount *)account willChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
23 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
24 if(oldAccount.identifier != NULL && oldAccount.username !=NULL){
26 if ([oldAccount aa_isPrimaryAccount]) {
28 CFErrorRef removalError = NULL;
30 ACLogDebug(@"Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
32 if (!SOSCCLoggedOutOfAccount(&removalError)) {
33 ACLogError(@"Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
36 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
40 ACLogDebug(@"Already logged out of account");
48 - (void)account:(ACAccount *)account didChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
49 if (changeType == kACAccountChangeTypeDeleted) {
50 if (oldAccount.identifier != NULL && oldAccount.username != NULL){
51 if ([oldAccount aa_isPrimaryAccount]) {
52 CFErrorRef removalError = NULL;
53 ACLogDebug(@"Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
54 if (!SOSCCLoggedOutOfAccount(&removalError)) {
55 ACLogError(@"Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
58 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
61 ACLogDebug(@"Already logged out of account");