2 * Copyright (c) 2002-2004 Apple Computer, 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@
24 #include <Security/SecAccess.h>
25 #include <Security/SecAccessPriv.h>
26 #include <security_keychain/Access.h>
27 #include "SecBridge.h"
28 #include <sys/param.h>
30 /* No restrictions. Permission to perform all operations on
31 the resource or available to an ACL owner. */
34 CFTypeRef kSecACLAuthorizationAny
= (CFTypeRef
)(CFSTR("ACLAuthorizationAny"));
36 CFTypeRef kSecACLAuthorizationLogin
= (CFTypeRef
)(CFSTR("ACLAuthorizationLogin"));
37 CFTypeRef kSecACLAuthorizationGenKey
= (CFTypeRef
)(CFSTR("ACLAuthorizationGenKey"));
38 CFTypeRef kSecACLAuthorizationDelete
= (CFTypeRef
)(CFSTR("ACLAuthorizationDelete"));
39 CFTypeRef kSecACLAuthorizationExportWrapped
= (CFTypeRef
)(CFSTR("ACLAuthorizationExportWrapped"));
40 CFTypeRef kSecACLAuthorizationExportClear
= (CFTypeRef
)(CFSTR("ACLAuthorizationExportClear"));
41 CFTypeRef kSecACLAuthorizationImportWrapped
= (CFTypeRef
)(CFSTR("ACLAuthorizationImportWrapped"));
42 CFTypeRef kSecACLAuthorizationImportClear
= (CFTypeRef
)(CFSTR("ACLAuthorizationImportClear"));
43 CFTypeRef kSecACLAuthorizationSign
= (CFTypeRef
)(CFSTR("ACLAuthorizationSign"));
44 CFTypeRef kSecACLAuthorizationEncrypt
= (CFTypeRef
)(CFSTR("ACLAuthorizationEncrypt"));
45 CFTypeRef kSecACLAuthorizationDecrypt
= (CFTypeRef
)(CFSTR("ACLAuthorizationDecrypt"));
46 CFTypeRef kSecACLAuthorizationMAC
= (CFTypeRef
)(CFSTR("ACLAuthorizationMAC"));
47 CFTypeRef kSecACLAuthorizationDerive
= (CFTypeRef
)(CFSTR("ACLAuthorizationDerive"));
49 /* Defined authorization tag values for Keychain */
53 CFTypeRef kSecACLAuthorizationKeychainCreate
= (CFTypeRef
)(CFSTR("ACLAuthorizationKeychainCreate"));
54 CFTypeRef kSecACLAuthorizationKeychainDelete
= (CFTypeRef
)(CFSTR("ACLAuthorizationKeychainDelete"));
55 CFTypeRef kSecACLAuthorizationKeychainItemRead
= (CFTypeRef
)(CFSTR("ACLAuthorizationKeychainItemRead"));
56 CFTypeRef kSecACLAuthorizationKeychainItemInsert
= (CFTypeRef
)(CFSTR("ACLAuthorizationKeychainItemInsert"));
57 CFTypeRef kSecACLAuthorizationKeychainItemModify
= (CFTypeRef
)(CFSTR("ACLAuthorizationKeychainItemModify"));
58 CFTypeRef kSecACLAuthorizationKeychainItemDelete
= (CFTypeRef
)(CFSTR("ACLAuthorizationKeychainItemDelete"));
60 CFTypeRef kSecACLAuthorizationChangeACL
= (CFTypeRef
)(CFSTR("ACLAuthorizationChangeACL"));
61 CFTypeRef kSecACLAuthorizationChangeOwner
= (CFTypeRef
)(CFSTR("ACLAuthorizationChangeOwner"));
64 static CFArrayRef
copyTrustedAppListFromBundle(CFStringRef bundlePath
, CFStringRef trustedAppListFileName
);
66 static CFStringRef gKeys
[] =
68 (CFStringRef
)kSecACLAuthorizationAny
,
69 (CFStringRef
)kSecACLAuthorizationLogin
,
70 (CFStringRef
)kSecACLAuthorizationGenKey
,
71 (CFStringRef
)kSecACLAuthorizationDelete
,
72 (CFStringRef
)kSecACLAuthorizationExportWrapped
,
73 (CFStringRef
)kSecACLAuthorizationExportClear
,
74 (CFStringRef
)kSecACLAuthorizationImportWrapped
,
75 (CFStringRef
)kSecACLAuthorizationImportClear
,
76 (CFStringRef
)kSecACLAuthorizationSign
,
77 (CFStringRef
)kSecACLAuthorizationEncrypt
,
78 (CFStringRef
)kSecACLAuthorizationDecrypt
,
79 (CFStringRef
)kSecACLAuthorizationMAC
,
80 (CFStringRef
)kSecACLAuthorizationDerive
,
82 /* Defined authorization tag values for Keychain */
83 (CFStringRef
)kSecACLAuthorizationKeychainCreate
,
84 (CFStringRef
)kSecACLAuthorizationKeychainDelete
,
85 (CFStringRef
)kSecACLAuthorizationKeychainItemRead
,
86 (CFStringRef
)kSecACLAuthorizationKeychainItemInsert
,
87 (CFStringRef
)kSecACLAuthorizationKeychainItemModify
,
88 (CFStringRef
)kSecACLAuthorizationKeychainItemDelete
,
90 (CFStringRef
)kSecACLAuthorizationChangeACL
,
91 (CFStringRef
)kSecACLAuthorizationChangeOwner
95 static sint32 gValues
[] =
97 CSSM_ACL_AUTHORIZATION_ANY
,
98 CSSM_ACL_AUTHORIZATION_LOGIN
,
99 CSSM_ACL_AUTHORIZATION_GENKEY
,
100 CSSM_ACL_AUTHORIZATION_DELETE
,
101 CSSM_ACL_AUTHORIZATION_EXPORT_WRAPPED
,
102 CSSM_ACL_AUTHORIZATION_EXPORT_CLEAR
,
103 CSSM_ACL_AUTHORIZATION_IMPORT_WRAPPED
,
104 CSSM_ACL_AUTHORIZATION_IMPORT_CLEAR
,
105 CSSM_ACL_AUTHORIZATION_SIGN
,
106 CSSM_ACL_AUTHORIZATION_ENCRYPT
,
107 CSSM_ACL_AUTHORIZATION_DECRYPT
,
108 CSSM_ACL_AUTHORIZATION_MAC
,
109 CSSM_ACL_AUTHORIZATION_DERIVE
,
110 CSSM_ACL_AUTHORIZATION_DBS_CREATE
,
111 CSSM_ACL_AUTHORIZATION_DBS_DELETE
,
112 CSSM_ACL_AUTHORIZATION_DB_READ
,
113 CSSM_ACL_AUTHORIZATION_DB_INSERT
,
114 CSSM_ACL_AUTHORIZATION_DB_MODIFY
,
115 CSSM_ACL_AUTHORIZATION_DB_DELETE
,
116 CSSM_ACL_AUTHORIZATION_CHANGE_ACL
,
117 CSSM_ACL_AUTHORIZATION_CHANGE_OWNER
120 CFDictionaryRef
CreateStringToNumDictionary()
122 int numItems
= (sizeof(gValues
) / sizeof(sint32
));
123 CFMutableDictionaryRef tempDict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, numItems
, &kCFCopyStringDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
125 for (int iCnt
= 0; iCnt
< numItems
; iCnt
++)
127 sint32 aNumber
= gValues
[iCnt
];
128 CFNumberRef aNum
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberSInt32Type
, &aNumber
);
130 CFStringRef aString
= gKeys
[iCnt
];
131 CFDictionaryAddValue(tempDict
, aString
, aNum
);
135 CFDictionaryRef result
= CFDictionaryCreateCopy(kCFAllocatorDefault
, tempDict
);
141 CFDictionaryRef
CreateNumToStringDictionary()
143 int numItems
= (sizeof(gValues
) / sizeof(sint32
));
145 CFMutableDictionaryRef tempDict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, numItems
, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
147 for (int iCnt
= 0; iCnt
< numItems
; iCnt
++)
149 sint32 aNumber
= gValues
[iCnt
];
150 CFNumberRef aNum
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberSInt32Type
, &aNumber
);
152 CFStringRef aString
= gKeys
[iCnt
];
153 CFDictionaryAddValue(tempDict
, aNum
, aString
);
158 CFDictionaryRef result
= CFDictionaryCreateCopy(kCFAllocatorDefault
, tempDict
);
165 sint32
GetACLAuthorizationTagFromString(CFStringRef aclStr
)
170 CFShow(CFSTR("GetACLAuthorizationTagFromString aclStr is NULL"));
175 static CFDictionaryRef gACLMapping
= NULL
;
177 if (NULL
== gACLMapping
)
179 gACLMapping
= CreateStringToNumDictionary();
183 CFNumberRef valueResult
= (CFNumberRef
)CFDictionaryGetValue(gACLMapping
, aclStr
);
184 if (NULL
!= valueResult
)
186 if (!CFNumberGetValue(valueResult
, kCFNumberSInt32Type
, &result
))
201 CFStringRef
GetAuthStringFromACLAuthorizationTag(sint32 tag
)
203 static CFDictionaryRef gTagMapping
= NULL
;
204 CFNumberRef aNum
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberSInt32Type
, &tag
);
206 if (NULL
== gTagMapping
)
208 gTagMapping
= CreateNumToStringDictionary();
211 CFStringRef result
= (CFStringRef
)kSecACLAuthorizationAny
;
213 if (NULL
!= gTagMapping
&& CFDictionaryContainsKey(gTagMapping
, aNum
))
215 result
= (CFStringRef
)CFDictionaryGetValue(gTagMapping
, aNum
);
223 CFTypeID
SecAccessGetTypeID(void)
226 return gTypes().Access
.typeID
;
227 END_SECAPI1(_kCFRuntimeNotATypeID
)
235 * Create a new SecAccessRef that is set to the default configuration
236 * of a (newly created) security object.
238 OSStatus
SecAccessCreate(CFStringRef descriptor
, CFArrayRef trustedList
, SecAccessRef
*accessRef
)
241 Required(descriptor
);
242 SecPointer
<Access
> access
;
244 CFIndex length
= CFArrayGetCount(trustedList
);
245 ACL::ApplicationList trusted
;
246 for (CFIndex n
= 0; n
< length
; n
++)
247 trusted
.push_back(TrustedApplication::required(
248 SecTrustedApplicationRef(CFArrayGetValueAtIndex(trustedList
, n
))));
249 access
= new Access(cfString(descriptor
), trusted
);
251 access
= new Access(cfString(descriptor
));
253 Required(accessRef
) = access
->handle();
260 OSStatus
SecAccessCreateFromOwnerAndACL(const CSSM_ACL_OWNER_PROTOTYPE
*owner
,
261 uint32 aclCount
, const CSSM_ACL_ENTRY_INFO
*acls
,
262 SecAccessRef
*accessRef
)
265 Required(accessRef
); // preflight
266 SecPointer
<Access
> access
= new Access(Required(owner
), aclCount
, &Required(acls
));
267 *accessRef
= access
->handle();
271 SecAccessRef
SecAccessCreateWithOwnerAndACL(uid_t userId
, gid_t groupId
, SecAccessOwnerType ownerType
, CFArrayRef acls
, CFErrorRef
*error
)
273 SecAccessRef result
= NULL
;
275 CSSM_ACL_PROCESS_SUBJECT_SELECTOR selector
=
277 CSSM_ACL_PROCESS_SELECTOR_CURRENT_VERSION
, // selector version
283 CSSM_LIST_ELEMENT subject2
= { NULL
, 0 };
284 subject2
.Element
.Word
.Data
= (UInt8
*)&selector
;
285 subject2
.Element
.Word
.Length
= sizeof(selector
);
286 CSSM_LIST_ELEMENT subject1
=
288 &subject2
, CSSM_ACL_SUBJECT_TYPE_PROCESS
, CSSM_LIST_ELEMENT_WORDID
295 numAcls
= CFArrayGetCount(acls
);
299 CFStringRef debugStr
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
300 CFSTR("SecAccessCreateWithOwnerAndACL: processing %d acls"), numAcls
);
305 CSSM_ACL_AUTHORIZATION_TAG rights
[numAcls
];
306 memset(rights
, 0, sizeof(rights
));
308 for (CFIndex iCnt
= 0; iCnt
< numAcls
; iCnt
++)
310 CFStringRef aclStr
= (CFStringRef
)CFArrayGetValueAtIndex(acls
, iCnt
);
313 debugStr
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
314 CFSTR("SecAccessCreateWithOwnerAndACL: acls[%d] = %@"), iCnt
, aclStr
);
320 CSSM_ACL_AUTHORIZATION_TAG aTag
= GetACLAuthorizationTagFromString(aclStr
);
323 debugStr
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
324 CFSTR("SecAccessCreateWithOwnerAndACL: rights[%d] = %d"), iCnt
, aTag
);
334 for (CFIndex iCnt
= 0; iCnt
< numAcls
; iCnt
++)
337 debugStr
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
338 CFSTR("SecAccessCreateWithOwnerAndACL: rights[%d] = %d"), iCnt
, rights
[iCnt
]);
347 CSSM_ACL_OWNER_PROTOTYPE owner
=
350 { CSSM_LIST_TYPE_UNKNOWN
, &subject1
, &subject2
},
356 // ACL entries (any number, just one here)
357 CSSM_ACL_ENTRY_INFO acl_rights
[] =
363 { CSSM_LIST_TYPE_UNKNOWN
, &subject1
, &subject2
},
365 // rights for this entry
366 { sizeof(rights
) / sizeof(rights
[0]), rights
},
372 OSStatus err
= SecAccessCreateFromOwnerAndACL(&owner
,
373 sizeof(acl_rights
) / sizeof(acl_rights
[0]), acl_rights
, &result
);
380 *error
= CFErrorCreate(kCFAllocatorDefault
, CFSTR("FIX ME"), err
, NULL
);
389 OSStatus
SecAccessGetOwnerAndACL(SecAccessRef accessRef
,
390 CSSM_ACL_OWNER_PROTOTYPE_PTR
*owner
,
391 uint32
*aclCount
, CSSM_ACL_ENTRY_INFO_PTR
*acls
)
394 Access::required(accessRef
)->copyOwnerAndAcl(
395 Required(owner
), Required(aclCount
), Required(acls
));
399 OSStatus
SecAccessCopyOwnerAndACL(SecAccessRef accessRef
, uid_t
* userId
, gid_t
* groupId
, SecAccessOwnerType
* ownerType
, CFArrayRef
* aclList
)
401 CSSM_ACL_OWNER_PROTOTYPE_PTR owner
= NULL
;
402 CSSM_ACL_ENTRY_INFO_PTR acls
= NULL
;
404 OSStatus result
= SecAccessGetOwnerAndACL(accessRef
, &owner
, &aclCount
, &acls
);
405 if (noErr
!= result
)
412 CSSM_LIST_ELEMENT_PTR listHead
= owner
->TypedSubject
.Head
;
413 if (listHead
!= NULL
&& listHead
->ElementType
== CSSM_LIST_ELEMENT_WORDID
)
415 CSSM_LIST_ELEMENT_PTR nextElement
= listHead
->NextElement
;
416 if (listHead
->WordID
== CSSM_ACL_SUBJECT_TYPE_PROCESS
&& listHead
->ElementType
== CSSM_LIST_ELEMENT_WORDID
)
418 // nextElement contains the required data
419 CSSM_ACL_PROCESS_SUBJECT_SELECTOR
* selectorPtr
= (CSSM_ACL_PROCESS_SUBJECT_SELECTOR
*)nextElement
->Element
.Word
.Data
;
420 if (NULL
!= selectorPtr
)
424 *userId
= (uid_t
)selectorPtr
->uid
;
429 *groupId
= (gid_t
)selectorPtr
->gid
;
432 if (NULL
!= ownerType
)
434 *ownerType
= (SecAccessOwnerType
)selectorPtr
->mask
;
446 CFShow(CFSTR("SecAccessCopyOwnerAndACL: processing the ACL list"));
449 CFMutableArrayRef stringArray
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
450 CSSM_ACL_OWNER_PROTOTYPE_PTR protoPtr
= NULL
;
452 CSSM_ACL_ENTRY_INFO_PTR aclEntry
= NULL
;
454 result
= SecAccessGetOwnerAndACL(accessRef
, &protoPtr
, &numAcls
, &aclEntry
);
458 CFStringRef tempStr
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("SecAccessCopyOwnerAndACL: numAcls = %d"), numAcls
);
463 for (uint32 iCnt
= 0; iCnt
< numAcls
; iCnt
++)
465 CSSM_ACL_ENTRY_PROTOTYPE prototype
= aclEntry
[iCnt
].EntryPublicInfo
;
466 CSSM_AUTHORIZATIONGROUP authGroup
= prototype
.Authorization
;
467 int numAuthTags
= (int)authGroup
.NumberOfAuthTags
;
469 for (int jCnt
= 0; jCnt
< numAuthTags
; jCnt
++)
472 sint32 aTag
= authGroup
.AuthTags
[jCnt
];
473 CFStringRef aString
= GetAuthStringFromACLAuthorizationTag(aTag
);
475 CFArrayAppendValue(stringArray
, aString
);
480 if (NULL
!= stringArray
)
482 if (0 < CFArrayGetCount(stringArray
))
484 *aclList
= CFArrayCreateCopy(kCFAllocatorDefault
, stringArray
);
486 CFRelease(stringArray
);
495 OSStatus
SecAccessCopyACLList(SecAccessRef accessRef
,
499 Required(aclList
) = Access::required(accessRef
)->copySecACLs();
506 OSStatus
SecAccessCopySelectedACLList(SecAccessRef accessRef
,
507 CSSM_ACL_AUTHORIZATION_TAG action
,
511 Required(aclList
) = Access::required(accessRef
)->copySecACLs(action
);
515 CFArrayRef
SecAccessCopyMatchingACLList(SecAccessRef accessRef
, CFTypeRef authorizationTag
)
517 CFArrayRef result
= NULL
;
518 CSSM_ACL_AUTHORIZATION_TAG tag
= GetACLAuthorizationTagFromString((CFStringRef
)authorizationTag
);
519 OSStatus err
= SecAccessCopySelectedACLList(accessRef
, tag
, &result
);
527 CFArrayRef
copyTrustedAppListFromBundle(CFStringRef bundlePath
, CFStringRef trustedAppListFileName
)
529 CFStringRef errorString
= nil
;
530 CFURLRef bundleURL
,trustedAppsURL
= NULL
;
531 CFBundleRef secBundle
= NULL
;
532 CFPropertyListRef trustedAppsPlist
= NULL
;
533 CFDataRef xmlDataRef
= NULL
;
535 CFArrayRef trustedAppList
= NULL
;
536 CFMutableStringRef trustedAppListFileNameWithoutExtension
= NULL
;
538 // Make a CFURLRef from the CFString representation of the bundleĆs path.
539 bundleURL
= CFURLCreateWithFileSystemPath(
540 kCFAllocatorDefault
,bundlePath
,kCFURLPOSIXPathStyle
,true);
542 CFRange wholeStrRange
;
547 // Make a bundle instance using the URLRef.
548 secBundle
= CFBundleCreate(kCFAllocatorDefault
,bundleURL
);
552 trustedAppListFileNameWithoutExtension
=
553 CFStringCreateMutableCopy(NULL
,CFStringGetLength(trustedAppListFileName
),trustedAppListFileName
);
554 wholeStrRange
= CFStringFind(trustedAppListFileName
,CFSTR(".plist"),0);
556 CFStringDelete(trustedAppListFileNameWithoutExtension
,wholeStrRange
);
558 // Look for a resource in the bundle by name and type
559 trustedAppsURL
= CFBundleCopyResourceURL(secBundle
,trustedAppListFileNameWithoutExtension
,CFSTR("plist"),NULL
);
563 if ( trustedAppListFileNameWithoutExtension
)
564 CFRelease(trustedAppListFileNameWithoutExtension
);
566 if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault
,trustedAppsURL
,&xmlDataRef
,NULL
,NULL
,&errorCode
))
569 trustedAppsPlist
= CFPropertyListCreateFromXMLData(kCFAllocatorDefault
,xmlDataRef
,kCFPropertyListImmutable
,&errorString
);
570 trustedAppList
= (CFArrayRef
)trustedAppsPlist
;
574 CFRelease(bundleURL
);
576 CFRelease(secBundle
);
578 CFRelease(trustedAppsURL
);
580 CFRelease(xmlDataRef
);
582 CFRelease(errorString
);
584 return trustedAppList
;
587 OSStatus
SecAccessCreateWithTrustedApplications(CFStringRef trustedApplicationsPListPath
, CFStringRef accessLabel
, Boolean allowAny
, SecAccessRef
* returnedAccess
)
589 OSStatus err
= noErr
;
590 SecAccessRef accessToReturn
=nil
;
591 CFMutableArrayRef trustedApplications
=nil
;
593 if (!allowAny
) // use default access ("confirm access")
595 // make an exception list of applications you want to trust,
596 // which are allowed to access the item without requiring user confirmation
597 SecTrustedApplicationRef myself
=NULL
, someOther
=NULL
;
598 CFArrayRef trustedAppListFromBundle
=NULL
;
600 trustedApplications
=CFArrayCreateMutable(kCFAllocatorDefault
,0,&kCFTypeArrayCallBacks
);
601 err
= SecTrustedApplicationCreateFromPath(NULL
, &myself
);
603 CFArrayAppendValue(trustedApplications
,myself
);
605 CFURLRef url
= CFURLCreateWithFileSystemPath(NULL
, trustedApplicationsPListPath
, kCFURLPOSIXPathStyle
, 0);
606 CFStringRef leafStr
= NULL
;
607 leafStr
= CFURLCopyLastPathComponent(url
);
609 CFURLRef bndlPathURL
= NULL
;
610 bndlPathURL
= CFURLCreateCopyDeletingLastPathComponent(NULL
, url
);
611 CFStringRef bndlPath
= NULL
;
612 bndlPath
= CFURLCopyFileSystemPath(bndlPathURL
, kCFURLPOSIXPathStyle
);
613 trustedAppListFromBundle
=copyTrustedAppListFromBundle(bndlPath
, leafStr
);
621 CFRelease(bndlPathURL
);
622 if (trustedAppListFromBundle
)
625 char buffer
[MAXPATHLEN
];
626 top
= CFArrayGetCount(trustedAppListFromBundle
);
627 for (ix
=0;ix
<top
;ix
++)
629 CFStringRef filename
= (CFStringRef
)CFArrayGetValueAtIndex(trustedAppListFromBundle
,ix
);
630 CFIndex stringLength
= CFStringGetLength(filename
);
633 if (stringLength
!= CFStringGetBytes(filename
,CFRangeMake(0,stringLength
),kCFStringEncodingUTF8
,0,
634 false,(UInt8
*)&buffer
,MAXPATHLEN
, &usedBufLen
))
636 buffer
[usedBufLen
] = 0;
637 err
= SecTrustedApplicationCreateFromPath(buffer
,&someOther
);
639 CFArrayAppendValue(trustedApplications
,someOther
);
641 CFRelease(trustedAppListFromBundle
);
645 err
= SecAccessCreate((CFStringRef
)accessLabel
, (CFArrayRef
)trustedApplications
, &accessToReturn
);
648 if (allowAny
) // change access to be wide-open for decryption ("always allow access")
650 // get the access control list for decryption operations
651 CFArrayRef aclList
=nil
;
652 err
= SecAccessCopySelectedACLList(accessToReturn
, CSSM_ACL_AUTHORIZATION_DECRYPT
, &aclList
);
655 // get the first entry in the access control list
656 SecACLRef aclRef
=(SecACLRef
)CFArrayGetValueAtIndex(aclList
, 0);
657 CFArrayRef appList
=nil
;
658 CFStringRef promptDescription
=nil
;
659 CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR promptSelector
;
660 err
= SecACLCopySimpleContents(aclRef
, &appList
, &promptDescription
, &promptSelector
);
662 // modify the default ACL to not require the passphrase, and have a nil application list
663 promptSelector
.flags
&= ~CSSM_ACL_KEYCHAIN_PROMPT_REQUIRE_PASSPHRASE
;
664 err
= SecACLSetSimpleContents(aclRef
, NULL
, promptDescription
, &promptSelector
);
666 if (appList
) CFRelease(appList
);
667 if (promptDescription
) CFRelease(promptDescription
);
671 *returnedAccess
= accessToReturn
;