]> git.saurik.com Git - apple/security.git/blob - KeychainSyncAccountNotification/KeychainSyncAccountNotification.m
Security-57337.50.23.tar.gz
[apple/security.git] / KeychainSyncAccountNotification / KeychainSyncAccountNotification.m
1 //
2 // KeychainSyncAccountNotification.m
3 // Security
4 //
5 // Created by keith on 5/2/13.
6 //
7 //
8
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>
18
19 @implementation KeychainSyncAccountNotification
20
21 - (BOOL)account:(ACAccount *)account willChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
22
23 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
24 if(oldAccount.identifier != NULL && oldAccount.username !=NULL){
25
26 if ([oldAccount aa_isPrimaryAccount]) {
27
28 CFErrorRef removalError = NULL;
29
30 ACLogDebug(@"Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
31
32 if (!SOSCCLoggedOutOfAccount(&removalError)) {
33 ACLogError(@"Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
34 }
35 } else {
36 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
37 }
38 }
39 else{
40 ACLogDebug(@"Already logged out of account");
41
42 }
43 }
44
45 return YES;
46 }
47
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);
56 }
57 } else {
58 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
59 }
60 }
61 ACLogDebug(@"Already logged out of account");
62 }
63 }
64
65 @end