]> git.saurik.com Git - apple/security.git/blame - KeychainSyncAccountNotification/KeychainSyncAccountNotification.m
Security-57337.40.85.tar.gz
[apple/security.git] / KeychainSyncAccountNotification / KeychainSyncAccountNotification.m
CommitLineData
d8f41ccd
A
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>
d8f41ccd 13#import <AppleAccount/ACAccount+AppleAccount.h>
d8f41ccd
A
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 {
5c19dc3a 22
d8f41ccd 23 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
5c19dc3a 24 if(oldAccount.identifier != NULL && oldAccount.username !=NULL){
d8f41ccd 25
5c19dc3a
A
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);
d8f41ccd 37 }
5c19dc3a
A
38 }
39 else{
40 ACLogDebug(@"Already logged out of account");
41
d8f41ccd
A
42 }
43 }
44
45 return YES;
46}
47
48- (void)account:(ACAccount *)account didChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
5c19dc3a
A
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);
d8f41ccd
A
56 }
57 } else {
5c19dc3a 58 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
d8f41ccd 59 }
d8f41ccd 60 }
5c19dc3a 61 ACLogDebug(@"Already logged out of account");
d8f41ccd
A
62 }
63}
64
65@end