2 * Copyright (c) 2003-2007,2009-2010,2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
31 #include <sys/utsname.h>
35 #include <readpassphrase.h>
37 #include <Security/SecItem.h>
39 #include <CoreFoundation/CFNumber.h>
40 #include <CoreFoundation/CFString.h>
42 #include <Security/SecureObjectSync/SOSCloudCircle.h>
43 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
44 #include <Security/SecureObjectSync/SOSPeerInfo.h>
45 #include <Security/SecureObjectSync/SOSPeerInfoPriv.h>
46 #include <Security/SecureObjectSync/SOSPeerInfoV2.h>
47 #include <Security/SecureObjectSync/SOSUserKeygen.h>
48 #include <Security/SecureObjectSync/SOSKVSKeys.h>
49 #include <securityd/SOSCloudCircleServer.h>
50 #include <Security/SecureObjectSync/SOSBackupSliceKeyBag.h>
51 #include <Security/SecOTRSession.h>
52 #include <SOSCircle/CKBridge/SOSCloudKeychainClient.h>
54 #include <utilities/SecCFWrappers.h>
55 #include <utilities/debugging.h>
57 #include <SecurityTool/readline.h>
60 #include "keychain_sync.h"
61 #include "keychain_log.h"
62 #include "syncbackup.h"
64 #include "secToolFileIO.h"
65 #include "secViewDisplay.h"
66 #include "accountCirclesViewsPrint.h"
68 #include <Security/SecPasswordGenerate.h>
70 #define MAXKVSKEYTYPE kUnknownKey
71 #define DATE_LENGTH 18
74 static bool clearAllKVS(CFErrorRef *error)
76 __block bool result = false;
77 const uint64_t maxTimeToWaitInSeconds = 30ull * NSEC_PER_SEC;
78 dispatch_queue_t processQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
79 dispatch_semaphore_t waitSemaphore = dispatch_semaphore_create(0);
80 dispatch_time_t finishTime = dispatch_time(DISPATCH_TIME_NOW, maxTimeToWaitInSeconds);
82 SOSCloudKeychainClearAll(processQueue, ^(CFDictionaryRef returnedValues, CFErrorRef cerror)
84 result = (cerror != NULL);
85 dispatch_semaphore_signal(waitSemaphore);
88 dispatch_semaphore_wait(waitSemaphore, finishTime);
93 static bool enableDefaultViews()
96 CFMutableSetRef viewsToEnable = SOSViewCopyViewSet(kViewSetV0);
97 CFMutableSetRef viewsToDisable = CFSetCreateMutable(NULL, 0, NULL);
99 result = SOSCCViewSet(viewsToEnable, viewsToDisable);
100 CFRelease(viewsToEnable);
101 CFRelease(viewsToDisable);
105 static bool requestToJoinCircle(CFErrorRef *error)
107 // Set the visual state of switch based on membership in circle
108 bool hadError = false;
109 SOSCCStatus ccstatus = SOSCCThisDeviceIsInCircle(error);
113 case kSOSCCCircleAbsent:
114 hadError = !SOSCCResetToOffering(error);
115 hadError &= enableDefaultViews();
117 case kSOSCCNotInCircle:
118 hadError = !SOSCCRequestToJoinCircle(error);
119 hadError &= enableDefaultViews();
122 printerr(CFSTR("Request to join circle with bad status: %@ (%d)\n"), SOSCCGetStatusDescription(ccstatus), ccstatus);
128 static bool setPassword(char *labelAndPassword, CFErrorRef *err)
131 char *token0 = strtok_r(labelAndPassword, ":", &last);
132 char *token1 = strtok_r(NULL, "", &last);
133 CFStringRef label = token1 ? CFStringCreateWithCString(NULL, token0, kCFStringEncodingUTF8) : CFSTR("security command line tool");
134 char *password_token = token1 ? token1 : token0;
135 password_token = password_token ? password_token : "";
136 CFDataRef password = CFDataCreate(NULL, (const UInt8*) password_token, strlen(password_token));
137 bool returned = !SOSCCSetUserCredentials(label, password, err);
143 static bool tryPassword(char *labelAndPassword, CFErrorRef *err)
146 char *token0 = strtok_r(labelAndPassword, ":", &last);
147 char *token1 = strtok_r(NULL, "", &last);
148 CFStringRef label = token1 ? CFStringCreateWithCString(NULL, token0, kCFStringEncodingUTF8) : CFSTR("security command line tool");
149 char *password_token = token1 ? token1 : token0;
150 password_token = password_token ? password_token : "";
151 CFDataRef password = CFDataCreate(NULL, (const UInt8*) password_token, strlen(password_token));
152 bool returned = !SOSCCTryUserCredentials(label, password, err);
159 * Prompt user, call SOSCCTryUserCredentials.
160 * Does not support optional label syntax like -T/-P.
161 * Returns true on success.
164 promptAndTryPassword(CFErrorRef *error)
166 bool success = false;
170 if (readpassphrase("iCloud password: ", passbuf, sizeof(passbuf), RPP_REQUIRE_TTY) != NULL) {
171 password = CFDataCreate(NULL, (const UInt8 *)passbuf, strlen(passbuf));
172 if (password != NULL) {
173 success = SOSCCTryUserCredentials(CFSTR("security command line tool"), password, error);
174 CFReleaseNull(password);
181 static bool syncAndWait(CFErrorRef *err)
183 __block CFTypeRef objects = NULL;
185 dispatch_queue_t generalq = dispatch_queue_create("general", DISPATCH_QUEUE_SERIAL);
187 const uint64_t maxTimeToWaitInSeconds = 30ull * NSEC_PER_SEC;
188 dispatch_semaphore_t waitSemaphore = dispatch_semaphore_create(0);
189 dispatch_time_t finishTime = dispatch_time(DISPATCH_TIME_NOW, maxTimeToWaitInSeconds);
191 CloudKeychainReplyBlock replyBlock = ^ (CFDictionaryRef returnedValues, CFErrorRef error)
193 secinfo("sync", "SOSCloudKeychainSynchronizeAndWait returned: %@", returnedValues);
195 secerror("SOSCloudKeychainSynchronizeAndWait returned error: %@", error);
196 objects = CFRetainSafe(returnedValues);
198 secinfo("sync", "SOSCloudKeychainGetObjectsFromCloud block exit: %@", objects);
199 dispatch_semaphore_signal(waitSemaphore);
202 SOSCloudKeychainSynchronizeAndWait(generalq, replyBlock);
204 dispatch_semaphore_wait(waitSemaphore, finishTime);
206 (void)SOSCCDumpCircleKVSInformation(NULL);
207 fprintf(outFile, "\n");
211 static void dumpStringSet(CFStringRef label, CFSetRef s) {
212 if(!s || !label) return;
214 printmsg(CFSTR("%@: { "), label);
215 __block bool first = true;
216 CFSetForEach(s, ^(const void *p) {
217 CFStringRef fmt = CFSTR(", %@");
221 CFStringRef string = (CFStringRef) p;
222 printmsg(fmt, string);
225 printmsg(CFSTR(" }\n"), NULL);
228 static bool dumpMyPeer(CFErrorRef *error) {
229 SOSPeerInfoRef myPeer = SOSCCCopyMyPeerInfo(error);
231 if (!myPeer) return false;
233 CFStringRef peerID = SOSPeerInfoGetPeerID(myPeer);
234 CFStringRef peerName = SOSPeerInfoGetPeerName(myPeer);
235 CFIndex peerVersion = SOSPeerInfoGetVersion(myPeer);
236 bool retirement = SOSPeerInfoIsRetirementTicket(myPeer);
238 printmsg(CFSTR("Peer Name: %@ PeerID: %@ Version: %d\n"), peerName, peerID, peerVersion);
240 CFDateRef retdate = SOSPeerInfoGetRetirementDate(myPeer);
241 printmsg(CFSTR("Retired: %@\n"), retdate);
245 if(peerVersion >= 2) {
246 CFMutableSetRef views = SOSPeerInfoV2DictionaryCopySet(myPeer, sViewsKey);
247 CFStringRef serialNumber = SOSPeerInfoV2DictionaryCopyString(myPeer, sSerialNumberKey);
248 CFBooleanRef preferIDS = SOSPeerInfoV2DictionaryCopyBoolean(myPeer, sPreferIDS);
249 CFBooleanRef preferIDSFragmentation = SOSPeerInfoV2DictionaryCopyBoolean(myPeer, sPreferIDSFragmentation);
250 CFBooleanRef preferIDSACKModel = SOSPeerInfoV2DictionaryCopyBoolean(myPeer, sPreferIDSACKModel);
251 CFStringRef transportType = SOSPeerInfoV2DictionaryCopyString(myPeer, sTransportType);
252 CFStringRef idsDeviceID = SOSPeerInfoV2DictionaryCopyString(myPeer, sDeviceID);
254 printmsg(CFSTR("Serial#: %@ PrefIDS#: %@ PrefFragmentation#: %@ PrefACK#: %@ transportType#: %@ idsDeviceID#: %@\n"),
255 serialNumber, preferIDS, preferIDSFragmentation, preferIDSACKModel, transportType, idsDeviceID);
257 printmsg(CFSTR("Serial#: %@\n"),
259 dumpStringSet(CFSTR(" Views: "), views);
262 CFReleaseSafe(serialNumber);
263 CFReleaseSafe(preferIDS);
264 CFReleaseSafe(preferIDSFragmentation);
265 CFReleaseSafe(views);
266 CFReleaseSafe(transportType);
267 CFReleaseSafe(idsDeviceID);
270 bool ret = myPeer != NULL;
271 CFReleaseNull(myPeer);
275 static bool setBag(char *itemName, CFErrorRef *err)
277 __block bool success = false;
278 __block CFErrorRef error = NULL;
280 CFStringRef random = SecPasswordCreateWithRandomDigits(10, NULL);
282 CFStringPerformWithUTF8CFData(random, ^(CFDataRef stringAsData) {
283 if (0 == strncasecmp(optarg, "single", 6) || 0 == strncasecmp(optarg, "all", 3)) {
284 bool includeV0 = (0 == strncasecmp(optarg, "all", 3));
285 printmsg(CFSTR("Setting iCSC single using entropy from string: %@\n"), random);
286 CFDataRef aks_bag = SecAKSCopyBackupBagWithSecret(CFDataGetLength(stringAsData), (uint8_t*)CFDataGetBytePtr(stringAsData), &error);
289 success = SOSCCRegisterSingleRecoverySecret(aks_bag, includeV0, &error);
291 printmsg(CFSTR("Failed registering single secret %@"), error);
292 CFReleaseNull(aks_bag);
295 printmsg(CFSTR("Failed to create aks_bag: %@"), error);
297 CFReleaseNull(aks_bag);
298 } else if (0 == strncasecmp(optarg, "device", 6)) {
299 printmsg(CFSTR("Setting Device Secret using entropy from string: %@\n"), random);
301 SOSPeerInfoRef me = SOSCCCopyMyPeerWithNewDeviceRecoverySecret(stringAsData, &error);
303 success = me != NULL;
306 printmsg(CFSTR("Failed: %@\n"), err);
309 printmsg(CFSTR("Unrecognized argument to -b %s\n"), optarg);
317 static void prClientViewState(char *label, bool result) {
318 fprintf(outFile, "Sync Status for %s: %s\n", label, (result) ? "enabled": "not enabled");
321 static bool clientViewStatus(CFErrorRef *error) {
322 prClientViewState("KeychainV0", SOSCCIsIcloudKeychainSyncing());
323 prClientViewState("Safari", SOSCCIsSafariSyncing());
324 prClientViewState("AppleTV", SOSCCIsAppleTVSyncing());
325 prClientViewState("HomeKit", SOSCCIsHomeKitSyncing());
326 prClientViewState("Wifi", SOSCCIsWiFiSyncing());
327 prClientViewState("AlwaysOnNoInitialSync", SOSCCIsContinuityUnlockSyncing());
332 static bool dumpYetToSync(CFErrorRef *error) {
333 CFArrayRef yetToSyncViews = SOSCCCopyYetToSyncViewsList(error);
335 bool hadError = yetToSyncViews;
337 if (yetToSyncViews) {
338 __block CFStringRef separator = CFSTR("");
340 printmsg(CFSTR("Yet to sync views: ["), NULL);
342 CFArrayForEach(yetToSyncViews, ^(const void *value) {
343 if (isString(value)) {
344 printmsg(CFSTR("%@%@"), separator, value);
346 separator = CFSTR(", ");
349 printmsg(CFSTR("]\n"), NULL);
356 #pragma mark --remove-peer
359 add_matching_peerinfos(CFMutableArrayRef list, CFArrayRef spids, CFArrayRef (*copy_peer_func)(CFErrorRef *))
367 peers = copy_peer_func(&error);
369 for (i = 0; i < CFArrayGetCount(peers); i++) {
370 pi = (SOSPeerInfoRef)CFArrayGetValueAtIndex(peers, i);
371 for (j = 0; j < CFArrayGetCount(spids); j++) {
372 spid = (CFStringRef)CFArrayGetValueAtIndex(spids, j);
373 if (CFStringGetLength(spid) < 8) {
376 if (CFStringHasPrefix(SOSPeerInfoGetPeerID(pi), spid)) {
377 CFArrayAppendValue(list, pi);
390 copy_peerinfos(CFArrayRef spids)
392 CFMutableArrayRef matches;
394 matches = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
395 add_matching_peerinfos(matches, spids, SOSCCCopyValidPeerPeerInfo);
396 add_matching_peerinfos(matches, spids, SOSCCCopyNotValidPeerPeerInfo);
397 add_matching_peerinfos(matches, spids, SOSCCCopyRetirementPeerInfo);
403 doRemovePeers(CFArrayRef peerids, CFErrorRef *error)
405 bool success = false;
406 CFArrayRef peers = NULL;
407 CFErrorRef localError = NULL;
411 peers = copy_peerinfos(peerids);
412 if (peers == NULL || CFArrayGetCount(peers) == 0) {
413 fprintf(stdout, "No matching peers to remove.\n");
418 fprintf(stdout, "Matched the following devices:\n");
419 for (i = 0; i < CFArrayGetCount(peers); i++) {
421 CFShow(CFArrayGetValueAtIndex(peers, i));
424 if (readpassphrase("Confirm removal (y/N): ", buf, sizeof(buf), RPP_ECHO_ON | RPP_FORCEUPPER) == NULL) {
433 success = SOSCCRemovePeersFromCircle(peers, &localError);
434 if (!success && isSOSErrorCoded(localError, kSOSErrorPrivateKeyAbsent)) {
435 CFReleaseNull(localError);
437 success = promptAndTryPassword(&localError);
439 success = SOSCCRemovePeersFromCircle(peers, &localError);
444 CFReleaseNull(peers);
446 if (!success && error != NULL) {
449 CFReleaseNull(localError);
457 // enable, disable, accept, reject, status, Reset, Clear
459 keychain_sync(int argc, char * const *argv)
464 " -e enable (join/create circle)"
465 " -i info (current status)"
468 "Account/Circle Management"
469 " -a accept all applicants"
470 " -l [reason] sign out of circle + set custom departure reason"
471 " -q sign out of circle"
472 " -r reject all applicants"
473 " -E ensure fresh parameters"
474 " -b device|all|single Register a backup bag - THIS RESETS BACKUPS!\n"
475 " -A Apply to a ring\n"
476 " -B Withdrawl from a ring\n"
479 " -I Dump Ring Information\n"
481 " -N (re-)set to new account (USE WITH CARE: device will not leave circle before resetting account!)"
482 " -O reset to offering"
484 " -X [limit] best effort bail from circle in limit seconds"
485 " -o list view unaware peers in circle"
486 " -0 boot view unaware peers from circle"
487 " -1 grab account state from the keychain"
488 " -2 delete account state from the keychain"
489 " -3 grab engine state from the keychain"
490 " -4 delete engine state from the keychain"
491 " -5 cleanup old KVS keys in KVS"
492 " -6 [test]populate KVS with garbage KVS keys
495 " -P [label:]password set password (optionally for a given label) for sync"
496 " -T [label:]password try password (optionally for a given label) for sync"
499 " -k pend all registered kvs keys"
500 " -C clear all values from KVS"
501 " -D [itemName] dump contents of KVS"
505 " -v [enable|disable|query:viewname] enable, disable, or query my PeerInfo's view set"
506 " viewnames are: keychain|masterkey|iclouddrive|photos|cloudkit|escrow|fde|maildrop|icloudbackup|notes|imessage|appletv|homekit|"
507 " wifi|passwords|creditcards|icloudidentity|othersyncable"
508 " -L list all known view and their status"
509 " -U purge private key material cache\n"
510 " -V Report View Sync Status on all known clients.\n"
511 " -H Set escrow record.\n"
512 " -J Get the escrow record.\n"
513 " -M Check peer availability.\n"
519 const struct option longopts[] = {
520 { "remove-peer", required_argument, &action, SYNC_REMOVE_PEER, },
521 { NULL, 0, NULL, 0, },
524 CFErrorRef error = NULL;
525 bool hadError = false;
526 CFMutableArrayRef peers2remove = NULL;
527 SOSLogSetOutputTo(NULL, NULL);
529 while ((ch = getopt_long(argc, argv, "ab:deg:hikl:mopq:rSv:w:x:zA:B:MNJCDEF:HG:ILOP:RT:UWX:VY0123456", longopts, NULL)) != -1)
533 fprintf(outFile, "Signing out of circle\n");
534 hadError = !SOSCCSignedOut(true, &error);
537 int reason = (int) strtoul(optarg, NULL, 10);
539 reason < kSOSDepartureReasonError ||
540 reason >= kSOSNumDepartureReasons) {
541 fprintf(errFile, "Invalid custom departure reason %s\n", optarg);
543 fprintf(outFile, "Setting custom departure reason %d\n", reason);
544 hadError = !SOSCCSetLastDepartureReason(reason, &error);
545 notify_post(kSOSCCCircleChangedNotification);
553 fprintf(outFile, "Signing out of circle\n");
554 bool signOutImmediately = false;
555 if (strcasecmp(optarg, "true") == 0) {
556 signOutImmediately = true;
557 } else if (strcasecmp(optarg, "false") == 0) {
558 signOutImmediately = false;
560 fprintf(outFile, "Please provide a \"true\" or \"false\" whether you'd like to leave the circle immediately\n");
562 hadError = !SOSCCSignedOut(signOutImmediately, &error);
563 notify_post(kSOSCCCircleChangedNotification);
567 fprintf(outFile, "Turning ON keychain syncing\n");
568 hadError = requestToJoinCircle(&error);
572 fprintf(outFile, "Turning OFF keychain syncing\n");
573 hadError = !SOSCCRemoveThisDeviceFromCircle(&error);
578 CFArrayRef applicants = SOSCCCopyApplicantPeerInfo(NULL);
580 hadError = !SOSCCAcceptApplicants(applicants, &error);
581 CFRelease(applicants);
583 fprintf(errFile, "No applicants to accept\n");
590 CFArrayRef applicants = SOSCCCopyApplicantPeerInfo(NULL);
592 hadError = !SOSCCRejectApplicants(applicants, &error);
593 CFRelease(applicants);
595 fprintf(errFile, "No applicants to reject\n");
601 SOSCCDumpCircleInformation();
602 SOSCCDumpEngineInformation();
606 notify_post("com.apple.security.cloudkeychain.forceupdate");
611 SOSCCDumpViewUnwarePeers();
617 CFArrayRef unawares = SOSCCCopyViewUnawarePeerInfo(&error);
619 hadError = !SOSCCRemovePeersFromCircle(unawares, &error);
623 CFReleaseNull(unawares);
628 CFDataRef accountState = SOSCCCopyAccountState(&error);
630 printmsg(CFSTR(" %@\n"), CFDataCopyHexString(accountState));
634 CFReleaseNull(accountState);
639 bool status = SOSCCDeleteAccountState(&error);
641 printmsg(CFSTR("Deleted account from the keychain %d\n"), status);
649 CFDataRef engineState = SOSCCCopyEngineData(&error);
651 printmsg(CFSTR(" %@\n"), CFDataCopyHexString(engineState));
655 CFReleaseNull(engineState);
660 bool status = SOSCCDeleteEngineState(&error);
662 printmsg(CFSTR("Deleted engine-state from the keychain %d\n"), status);
670 bool result = SOSCCCleanupKVSKeys(&error);
673 printmsg(CFSTR("Got all the keys from KVS %d\n"), result);
681 bool result = SOSCCTestPopulateKVSWithBadKeys(&error);
684 printmsg(CFSTR("Populated KVS with garbage %d\n"), result);
692 fprintf(outFile, "Ensuring Fresh Parameters\n");
693 bool result = SOSCCRequestEnsureFreshParameters(&error);
699 fprintf(outFile, "Refreshed Parameters Ensured!\n");
701 fprintf(outFile, "Problem trying to ensure fresh parameters\n");
707 fprintf(outFile, "Applying to Ring\n");
708 CFStringRef ringName = CFStringCreateWithCString(kCFAllocatorDefault, (char *)optarg, kCFStringEncodingUTF8);
709 hadError = SOSCCApplyToARing(ringName, &error);
710 CFReleaseNull(ringName);
715 fprintf(outFile, "Withdrawing from Ring\n");
716 CFStringRef ringName = CFStringCreateWithCString(kCFAllocatorDefault, (char *)optarg, kCFStringEncodingUTF8);
717 hadError = SOSCCWithdrawlFromARing(ringName, &error);
718 CFReleaseNull(ringName);
723 fprintf(outFile, "Status of this device in the Ring\n");
724 CFStringRef ringName = CFStringCreateWithCString(kCFAllocatorDefault, (char *)optarg, kCFStringEncodingUTF8);
725 hadError = SOSCCRingStatus(ringName, &error);
726 CFReleaseNull(ringName);
731 fprintf(outFile, "Enabling Ring\n");
732 CFStringRef ringName = CFStringCreateWithCString(kCFAllocatorDefault, (char *)optarg, kCFStringEncodingUTF8);
733 hadError = SOSCCEnableRing(ringName, &error);
734 CFReleaseNull(ringName);
739 fprintf(outFile, "Setting random escrow record\n");
740 bool success = SOSCCSetEscrowRecord(CFSTR("label"), 8, &error);
749 CFDictionaryRef attempts = SOSCCCopyEscrowRecord(&error);
751 CFDictionaryForEach(attempts, ^(const void *key, const void *value) {
753 char *keyString = CFStringToCString(key);
754 fprintf(outFile, "%s:\n", keyString);
757 if(isDictionary(value)){
758 CFDictionaryForEach(value, ^(const void *key, const void *value) {
760 char *keyString = CFStringToCString(key);
761 fprintf(outFile, "%s: ", keyString);
765 char *time = CFStringToCString(value);
766 fprintf(outFile, "timestamp: %s\n", time);
769 else if(isNumber(value)){
771 CFNumberGetValue(value, kCFNumberLongLongType, &tries);
772 fprintf(outFile, "date: %llu\n", tries);
779 CFReleaseNull(attempts);
785 fprintf(outFile, "Printing all the rings\n");
786 CFStringRef ringdescription = SOSCCGetAllTheRings(&error);
790 fprintf(outFile, "Rings: %s", CFStringToCString(ringdescription));
796 hadError = !SOSCCAccountSetToNew(&error);
798 notify_post(kSOSCCCircleChangedNotification);
802 hadError = !SOSCCResetToEmpty(&error);
806 hadError = !SOSCCResetToOffering(&error);
810 hadError = !dumpMyPeer(&error);
814 hadError = clearAllKVS(&error);
818 hadError = setPassword(optarg, &error);
822 hadError = tryPassword(optarg, &error);
827 uint64_t limit = strtoul(optarg, NULL, 10);
828 hadError = !SOSCCBailFromCircle_BestEffort(limit, &error);
833 hadError = !SOSCCPurgeUserCredentials(&error);
837 (void)SOSCCDumpCircleKVSInformation(optarg);
841 hadError = syncAndWait(&error);
845 hadError = !viewcmd(optarg, &error);
849 hadError = clientViewStatus(&error);
852 hadError = !listviewcmd(&error);
856 hadError = setBag(optarg, &error);
860 hadError = dumpYetToSync(&error);
864 case SYNC_REMOVE_PEER: {
866 optstr = CFStringCreateWithCString(NULL, optarg, kCFStringEncodingUTF8);
867 if (peers2remove == NULL) {
868 peers2remove = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
870 CFArrayAppendValue(peers2remove, optstr);
875 return SHOW_USAGE_MESSAGE;
880 return SHOW_USAGE_MESSAGE;
883 if (peers2remove != NULL) {
884 hadError = !doRemovePeers(peers2remove, &error);
885 CFRelease(peers2remove);
889 printerr(CFSTR("Error: %@\n"), error);