2 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
18 #include <Security/SecACL.h>
19 #include <Security/ACL.h>
20 #include <Security/Access.h>
22 #include "SecBridge.h"
28 static void setApplications(ACL
*acl
, CFArrayRef applicationList
);
36 return gTypes().ACL
.typeID
;
38 END_SECAPI1(_kCFRuntimeNotATypeID
)
44 OSStatus
SecACLCreateFromSimpleContents(SecAccessRef accessRef
,
45 CFArrayRef applicationList
,
46 CFStringRef description
, const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
*promptSelector
,
50 SecPointer
<Access
> access
= Access::required(accessRef
);
51 SecPointer
<ACL
> acl
= new ACL(*access
, cfString(description
), *promptSelector
);
52 if (applicationList
) {
53 // application-list + prompt
54 acl
->form(ACL::appListForm
);
55 setApplications(acl
, applicationList
);
58 acl
->form(ACL::allowAllForm
);
60 access
->add(acl
.get());
61 Required(newAcl
) = acl
->handle();
68 OSStatus
SecACLRemove(SecACLRef aclRef
)
71 ACL::required(aclRef
)->remove();
76 static SecTrustedApplicationRef
77 convert(const SecPointer
<TrustedApplication
> &trustedApplication
)
79 return *trustedApplication
;
84 OSStatus
SecACLCopySimpleContents(SecACLRef aclRef
,
85 CFArrayRef
*applicationList
,
86 CFStringRef
*promptDescription
, CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
*promptSelector
)
89 SecPointer
<ACL
> acl
= ACL::required(aclRef
);
90 switch (acl
->form()) {
91 case ACL::allowAllForm
:
92 Required(applicationList
) = NULL
;
93 Required(promptDescription
) =
94 acl
->promptDescription().empty() ? NULL
95 : makeCFString(acl
->promptDescription());
96 Required(promptSelector
) = acl
->promptSelector();
98 case ACL::appListForm
:
99 Required(applicationList
) =
100 makeCFArray(convert
, acl
->applications());
101 Required(promptDescription
) = makeCFString(acl
->promptDescription());
102 Required(promptSelector
) = acl
->promptSelector();
105 return errSecACLNotSimple
; // custom or unknown
110 OSStatus
SecACLSetSimpleContents(SecACLRef aclRef
,
111 CFArrayRef applicationList
,
112 CFStringRef description
, const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
*promptSelector
)
115 SecPointer
<ACL
> acl
= ACL::required(aclRef
);
116 acl
->promptDescription() = description
? cfString(description
) : "";
117 acl
->promptSelector() = promptSelector
? *promptSelector
: ACL::defaultSelector
;
118 if (applicationList
) {
119 // application-list + prompt
120 acl
->form(ACL::appListForm
);
121 setApplications(acl
, applicationList
);
124 acl
->form(ACL::allowAllForm
);
132 // Stuff a CFArray-of-SecTrustedApplications into an ACL object
134 static void setApplications(ACL
*acl
, CFArrayRef applicationList
)
136 ACL::ApplicationList
&appList
= acl
->applications();
138 //@@@ should really use STL iterator overlay on CFArray. By hand...
139 CFIndex count
= CFArrayGetCount(applicationList
);
140 for (CFIndex n
= 0; n
< count
; n
++)
141 appList
.push_back(TrustedApplication::required(
142 SecTrustedApplicationRef(CFArrayGetValueAtIndex(applicationList
, n
))));
147 // Set and get the authorization tags of an ACL entry
149 OSStatus
SecACLGetAuthorizations(SecACLRef acl
,
150 CSSM_ACL_AUTHORIZATION_TAG
*tags
, uint32
*tagCount
)
153 AclAuthorizationSet auths
= ACL::required(acl
)->authorizations();
154 if (Required(tagCount
) < auths
.size()) { // overflow
155 *tagCount
= auths
.size(); // report size required
156 CssmError::throwMe(paramErr
);
158 *tagCount
= auths
.size();
159 copy(auths
.begin(), auths
.end(), tags
);
163 OSStatus
SecACLSetAuthorizations(SecACLRef aclRef
,
164 CSSM_ACL_AUTHORIZATION_TAG
*tags
, uint32 tagCount
)
167 SecPointer
<ACL
> acl
= ACL::required(aclRef
);
168 if (acl
->isOwner()) // can't change rights of the owner ACL
169 MacOSError::throwMe(errSecInvalidOwnerEdit
);
170 AclAuthorizationSet
&auths
= acl
->authorizations();
172 copy(tags
, tags
+ tagCount
, insert_iterator
<AclAuthorizationSet
>(auths
, auths
.begin()));