]> git.saurik.com Git - apple/security.git/blob - OSX/sec/SOSCircle/Tool/keychain_sync_test.m
834aea63aebfa50d39bcc0060e9a34dbff849729
[apple/security.git] / OSX / sec / SOSCircle / Tool / keychain_sync_test.m
1 //
2 // keychain_sync_test.c
3 // sec
4 //
5 // Created by Mitch Adler on 7/8/16.
6 //
7 //
8
9 #include "keychain_sync_test.h"
10
11 #include "secToolFileIO.h"
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <getopt.h>
16
17 #import <Foundation/Foundation.h>
18
19 #include <Security/SecureObjectSync/SOSCloudCircle.h>
20
21 #import "NSFileHandle+Formatting.h"
22
23 int
24 keychain_sync_test(int argc, char * const *argv)
25 {
26 NSFileHandle *fhout = [NSFileHandle fileHandleWithStandardOutput];
27 NSFileHandle *fherr = [NSFileHandle fileHandleWithStandardError];
28 /*
29 "Keychain Syncing test"
30
31 */
32 int result = 0;
33 NSError* error = nil;
34 CFErrorRef cfError = NULL;
35
36 static int verbose_flag = 0;
37 static struct option long_options[] =
38 {
39 /* These options set a flag. */
40 {"verbose", no_argument, &verbose_flag, 1},
41 {"brief", no_argument, &verbose_flag, 0},
42 /* These options don’t set a flag.
43 We distinguish them by their indices. */
44 {"enabled-peer-views", required_argument, 0, 'p'},
45 {0, 0, 0, 0}
46 };
47 static const char * params = "abc:d:f:";
48
49 /* getopt_long stores the option index here. */
50 int option_index = 0;
51
52 NSArray<NSString*>* viewList = nil;
53
54 int opt_result = 0;
55 while (opt_result != -1) {
56 opt_result = getopt_long (argc, argv, params, long_options, &option_index);
57 switch (opt_result) {
58 case 'p': {
59 NSString* parameter = [NSString stringWithCString: optarg encoding:NSUTF8StringEncoding];
60
61 viewList = [parameter componentsSeparatedByString:@","];
62
63 }
64 break;
65 case -1:
66 break;
67 default:
68 return 2;
69 }
70
71 }
72
73 if (viewList) {
74 CFBooleanRef result = SOSCCPeersHaveViewsEnabled((__bridge CFArrayRef) viewList, &cfError);
75 if (result != NULL) {
76 [fhout writeFormat: @"Views: %@\n", viewList];
77 [fhout writeFormat: @"Enabled on other peers: %@\n", CFBooleanGetValue(result) ? @"yes" : @"no"];
78 }
79 }
80
81 if (cfError != NULL) {
82 [fherr writeFormat: @"Error: %@\n", cfError];
83 }
84
85 if (error != NULL) {
86 [fherr writeFormat: @"Error: %@\n", error];
87 }
88
89 return result;
90 }