2 * Copyright (c) 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@
30 #include "secViewDisplay.h"
31 #include "secToolFileIO.h"
33 #include <Security/SecureObjectSync/SOSCloudCircle.h>
34 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
35 #include <Security/SecureObjectSync/SOSViews.h>
40 const CFStringRef
*viewspec
;
42 { "keychain", &kSOSViewKeychainV0
},
44 #define DOVIEWMACRO(VIEWNAME, DEFSTRING, CMDSTRING, DEFAULTSETTING, INITIALSYNCSETTING, ALWAYSONSETTING, BACKUPSETTING, V0SETTING) { CMDSTRING, &kSOSView##VIEWNAME, },
45 #include "Security/SecureObjectSync/ViewList.list"
48 static CFStringRef
convertStringToView(char *viewname
) {
51 for (n
= 0; n
< sizeof(string2View
)/sizeof(string2View
[0]); n
++) {
52 if (strcmp(string2View
[n
].name
, viewname
) == 0)
53 return *string2View
[n
].viewspec
;
56 // Leak this, since it's a getter.
57 return CFStringCreateWithCString(kCFAllocatorDefault
, viewname
, kCFStringEncodingUTF8
);
60 static CFStringRef
convertViewReturnCodeToString(SOSViewActionCode ac
) {
61 CFStringRef retval
= NULL
;
63 case kSOSCCGeneralViewError
:
64 retval
= CFSTR("General Error"); break;
65 case kSOSCCViewMember
:
66 retval
= CFSTR("Is Member of View"); break;
67 case kSOSCCViewNotMember
:
68 retval
= CFSTR("Is Not Member of View"); break;
69 case kSOSCCViewNotQualified
:
70 retval
= CFSTR("Is not qualified for View"); break;
71 case kSOSCCNoSuchView
:
72 retval
= CFSTR("No Such View"); break;
77 bool viewcmd(char *itemName
, CFErrorRef
*err
) {
79 SOSViewActionCode ac
= kSOSCCViewQuery
;
82 viewname
= strchr(itemName
, ':');
83 if(viewname
== NULL
) return false;
88 if(strcmp(cmd
, "enable") == 0) {
89 ac
= kSOSCCViewEnable
;
90 } else if(strcmp(cmd
, "disable") == 0) {
91 ac
= kSOSCCViewDisable
;
92 } else if(strcmp(cmd
, "query") == 0) {
98 if(strchr(viewname
, ',') == NULL
) { // original single value version
99 viewspec
= convertStringToView(viewname
);
100 if(!viewspec
) return false;
102 SOSViewResultCode rc
= SOSCCView(viewspec
, ac
, err
);
103 CFStringRef resultString
= convertViewReturnCodeToString(rc
);
105 printmsg(CFSTR("View Result: %@ : %@\n"), resultString
, viewspec
);
109 if(ac
== kSOSCCViewQuery
) return false;
111 // new multi-view version
112 char *viewlist
= strdup(viewname
);
114 char *tofree
= viewlist
;
115 CFMutableSetRef viewSet
= CFSetCreateMutable(NULL
, 0, &kCFCopyStringSetCallBacks
);
117 while ((token
= strsep(&viewlist
, ",")) != NULL
) {
118 CFStringRef resultString
= convertStringToView(token
);
119 CFSetAddValue(viewSet
, resultString
);
122 printmsg(CFSTR("viewSet provided is %@\n"), viewSet
);
127 if(ac
== kSOSCCViewEnable
) retcode
= SOSCCViewSet(viewSet
, NULL
);
128 else retcode
= SOSCCViewSet(NULL
, viewSet
);
130 fprintf(outFile
, "SOSCCViewSet returned %s\n", (retcode
)? "true": "false");
135 bool listviewcmd(CFErrorRef
*err
) {
138 for (n
= 0; n
< sizeof(string2View
)/sizeof(string2View
[0]); n
++) {
139 CFStringRef viewspec
= *string2View
[n
].viewspec
;
141 SOSViewResultCode rc
= SOSCCView(viewspec
, kSOSCCViewQuery
, err
);
142 CFStringRef resultString
= convertViewReturnCodeToString(rc
);
144 printmsg(CFSTR("View Result: %@ : %@\n"), resultString
, viewspec
);