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, SYSTEM, DEFAULTSETTING, INITIALSYNCSETTING, ALWAYSONSETTING, BACKUPSETTING, V0SETTING) \
45 { CMDSTRING, &k##SYSTEM##View##VIEWNAME, },
46 #include "Security/SecureObjectSync/ViewList.list"
49 static CFStringRef
convertStringToView(char *viewname
) {
52 for (n
= 0; n
< sizeof(string2View
)/sizeof(string2View
[0]); n
++) {
53 if (strcmp(string2View
[n
].name
, viewname
) == 0)
54 return *string2View
[n
].viewspec
;
57 // Leak this, since it's a getter.
58 return CFStringCreateWithCString(kCFAllocatorDefault
, viewname
, kCFStringEncodingUTF8
);
61 static CFStringRef
convertViewReturnCodeToString(SOSViewActionCode ac
) {
62 CFStringRef retval
= NULL
;
64 case kSOSCCGeneralViewError
:
65 retval
= CFSTR("General Error"); break;
66 case kSOSCCViewMember
:
67 retval
= CFSTR("Is Member of View"); break;
68 case kSOSCCViewNotMember
:
69 retval
= CFSTR("Is Not Member of View"); break;
70 case kSOSCCViewNotQualified
:
71 retval
= CFSTR("Is not qualified for View"); break;
72 case kSOSCCNoSuchView
:
73 retval
= CFSTR("No Such View"); break;
78 bool viewcmd(char *itemName
, CFErrorRef
*err
) {
80 SOSViewActionCode ac
= kSOSCCViewQuery
;
83 viewname
= strchr(itemName
, ':');
84 if(viewname
== NULL
) return false;
89 if(strcmp(cmd
, "enable") == 0) {
90 ac
= kSOSCCViewEnable
;
91 } else if(strcmp(cmd
, "disable") == 0) {
92 ac
= kSOSCCViewDisable
;
93 } else if(strcmp(cmd
, "query") == 0) {
99 if(strchr(viewname
, ',') == NULL
) { // original single value version
100 viewspec
= convertStringToView(viewname
);
101 if(!viewspec
) return false;
103 SOSViewResultCode rc
= SOSCCView(viewspec
, ac
, err
);
104 CFStringRef resultString
= convertViewReturnCodeToString(rc
);
106 printmsg(CFSTR("View Result: %@ : %@\n"), resultString
, viewspec
);
110 if(ac
== kSOSCCViewQuery
) return false;
112 // new multi-view version
113 char *viewlist
= strdup(viewname
);
115 char *tofree
= viewlist
;
116 CFMutableSetRef viewSet
= CFSetCreateMutable(NULL
, 0, &kCFCopyStringSetCallBacks
);
118 while ((token
= strsep(&viewlist
, ",")) != NULL
) {
119 CFStringRef resultString
= convertStringToView(token
);
120 CFSetAddValue(viewSet
, resultString
);
123 printmsg(CFSTR("viewSet provided is %@\n"), viewSet
);
128 if(ac
== kSOSCCViewEnable
) retcode
= SOSCCViewSet(viewSet
, NULL
);
129 else retcode
= SOSCCViewSet(NULL
, viewSet
);
131 fprintf(outFile
, "SOSCCViewSet returned %s\n", (retcode
)? "true": "false");
136 bool listviewcmd(CFErrorRef
*err
) {
139 for (n
= 0; n
< sizeof(string2View
)/sizeof(string2View
[0]); n
++) {
140 CFStringRef viewspec
= *string2View
[n
].viewspec
;
142 SOSViewResultCode rc
= SOSCCView(viewspec
, kSOSCCViewQuery
, err
);
143 CFStringRef resultString
= convertViewReturnCodeToString(rc
);
145 printmsg(CFSTR("View Result: %@ : %@\n"), resultString
, viewspec
);