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>
20 #include "SecBridge.h"
26 static void setApplications(ACL
*acl
, CFArrayRef applicationList
);
34 return gTypes().acl
.typeId
;
36 END_SECAPI1(_kCFRuntimeNotATypeID
)
42 OSStatus
SecACLCreateFromSimpleContents(SecAccessRef accessRef
,
43 CFArrayRef applicationList
,
44 CFStringRef description
, const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
*promptSelector
,
48 RefPointer
<Access
> access
= gTypes().access
.required(accessRef
);
49 RefPointer
<ACL
> acl
= new ACL(*access
, cfString(description
), *promptSelector
);
50 setApplications(acl
, applicationList
);
51 access
->add(acl
.get());
52 Required(newAcl
) = gTypes().acl
.handle(*acl
);
59 OSStatus
SecACLRemove(SecACLRef aclRef
)
62 gTypes().acl
.required(aclRef
)->remove();
69 OSStatus
SecACLCopySimpleContents(SecACLRef aclRef
,
70 CFArrayRef
*applicationList
,
71 CFStringRef
*promptDescription
, CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
*promptSelector
)
74 RefPointer
<ACL
> acl
= gTypes().acl
.required(aclRef
);
75 switch (acl
->form()) {
76 case ACL::allowAllForm
:
77 Required(applicationList
) = NULL
;
78 Required(promptDescription
) =
79 acl
->promptDescription().empty() ? NULL
80 : makeCFString(acl
->promptDescription());
81 Required(promptSelector
) = acl
->promptSelector();
83 case ACL::appListForm
:
84 Required(applicationList
) =
85 makeCFArray(gTypes().trustedApplication
, acl
->applications());
86 Required(promptDescription
) = makeCFString(acl
->promptDescription());
87 Required(promptSelector
) = acl
->promptSelector();
90 return errSecACLNotSimple
; // custom or unknown
95 OSStatus
SecACLSetSimpleContents(SecACLRef aclRef
,
96 CFArrayRef applicationList
,
97 CFStringRef description
, const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR
*promptSelector
)
100 RefPointer
<ACL
> acl
= gTypes().acl
.required(aclRef
);
101 acl
->promptDescription() = description
? cfString(description
) : "";
102 acl
->promptSelector() = promptSelector
? *promptSelector
: ACL::defaultSelector
;
103 if (applicationList
) {
104 // application-list + prompt
105 acl
->form(ACL::appListForm
);
106 setApplications(acl
, applicationList
);
109 acl
->form(ACL::allowAllForm
);
117 // Stuff a CFArray-of-SecTrustedApplications into an ACL object
119 static void setApplications(ACL
*acl
, CFArrayRef applicationList
)
121 ACL::ApplicationList
&appList
= acl
->applications();
123 //@@@ should really use STL iterator overlay on CFArray. By hand...
124 CFIndex count
= CFArrayGetCount(applicationList
);
125 for (CFIndex n
= 0; n
< count
; n
++)
126 appList
.push_back(gTypes().trustedApplication
.required(
127 SecTrustedApplicationRef(CFArrayGetValueAtIndex(applicationList
, n
))));
132 // Set and get the authorization tags of an ACL entry
134 OSStatus
SecACLGetAuthorizations(SecACLRef acl
,
135 CSSM_ACL_AUTHORIZATION_TAG
*tags
, uint32
*tagCount
)
138 AclAuthorizationSet auths
= gTypes().acl
.required(acl
)->authorizations();
139 if (Required(tagCount
) < auths
.size()) { // overflow
140 *tagCount
= auths
.size(); // report size required
141 CssmError::throwMe(paramErr
);
143 *tagCount
= auths
.size();
144 copy(auths
.begin(), auths
.end(), tags
);
148 OSStatus
SecACLSetAuthorizations(SecACLRef aclRef
,
149 CSSM_ACL_AUTHORIZATION_TAG
*tags
, uint32 tagCount
)
152 RefPointer
<ACL
> acl
= gTypes().acl
.required(aclRef
);
153 if (acl
->isOwner()) // can't change rights of the owner ACL
154 MacOSError::throwMe(errSecInvalidOwnerEdit
);
155 AclAuthorizationSet
&auths
= acl
->authorizations();
157 copy(tags
, tags
+ tagCount
, insert_iterator
<AclAuthorizationSet
>(auths
, auths
.begin()));