]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/aclclient.h
Security-163.tar.gz
[apple/security.git] / cdsa / cdsa_client / aclclient.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 //
20 // keyclient
21 //
22 #ifndef _H_CDSA_CLIENT_ACLCLIENT
23 #define _H_CDSA_CLIENT_ACLCLIENT 1
24
25 #include <Security/cssmaclpod.h>
26 #include <Security/cssmacl.h>
27 #include <Security/cssmcred.h>
28 #include <Security/refcount.h>
29 #include <Security/globalizer.h>
30
31 namespace Security {
32 namespace CssmClient {
33
34 class CSP;
35
36
37 //
38 // Any client-side object that has CSSM-layer ACLs shall be
39 // derived from AclBearer and implement its methods accordingly.
40 // Note the (shared/virtual) RefCount - you should handle AclBearer
41 // references via RefPointers.
42 //
43 class AclBearer : public virtual RefCount {
44 public:
45 virtual ~AclBearer();
46
47 // Acl manipulation
48 virtual void getAcl(AutoAclEntryInfoList &aclInfos,
49 const char *selectionTag = NULL) const = 0;
50 virtual void changeAcl(const CSSM_ACL_EDIT &aclEdit,
51 const CSSM_ACCESS_CREDENTIALS *cred = NULL) = 0;
52
53 void addAcl(const AclEntryInput &input, const CSSM_ACCESS_CREDENTIALS *cred = NULL);
54 void changeAcl(CSSM_ACL_HANDLE handle, const AclEntryInput &input,
55 const CSSM_ACCESS_CREDENTIALS *cred = NULL);
56 void deleteAcl(CSSM_ACL_HANDLE handle, const CSSM_ACCESS_CREDENTIALS *cred = NULL);
57 void deleteAcl(const char *tag = NULL, const CSSM_ACCESS_CREDENTIALS *cred = NULL);
58
59 // Acl owner manipulation
60 virtual void getOwner(AutoAclOwnerPrototype &owner) const = 0;
61 virtual void changeOwner(const CSSM_ACL_OWNER_PROTOTYPE &newOwner,
62 const CSSM_ACCESS_CREDENTIALS *cred = NULL) = 0;
63 };
64
65
66 //
67 // An AclFactory helps create and maintain CSSM-layer AccessCredentials
68 // and matching samples. There is state in an AclFactory, though simple
69 // uses may not care about it.
70 //
71 class AclFactory {
72 public:
73 AclFactory();
74 virtual ~AclFactory();
75
76 // these values are owned by the AclFactory and persist
77 // until it is destroyed. You don't own the memory.
78 const AccessCredentials *nullCred() const;
79 const AccessCredentials *promptCred() const;
80 const AccessCredentials *unlockCred() const;
81
82 protected:
83 class KeychainCredentials {
84 public:
85 KeychainCredentials(CssmAllocator &alloc)
86 : allocator(alloc), mCredentials(new AutoCredentials(alloc)) { }
87 virtual ~KeychainCredentials();
88
89 CssmAllocator &allocator;
90
91 operator const AccessCredentials* () { return mCredentials; }
92
93 protected:
94 AutoCredentials *mCredentials;
95 };
96
97 public:
98 // create a self-managed AccessCredentials to explicitly provide a keychain passphrase
99 class PassphraseUnlockCredentials : public KeychainCredentials {
100 public:
101 PassphraseUnlockCredentials (const CssmData& password, CssmAllocator& allocator);
102 };
103
104 // create a self-managed AccessCredentials to change a keychain passphrase
105 class PasswordChangeCredentials : public KeychainCredentials {
106 public:
107 PasswordChangeCredentials (const CssmData& password, CssmAllocator& allocator);
108 };
109
110 public:
111 class AnyResourceContext : public ResourceControlContext {
112 public:
113 AnyResourceContext(const CSSM_ACCESS_CREDENTIALS *cred = NULL);
114
115 private:
116 ListElement mAny;
117 CSSM_ACL_AUTHORIZATION_TAG mTag;
118 };
119 };
120
121
122 } // end namespace CssmClient
123 } // end namespace Security
124
125 #endif // _H_CDSA_CLIENT_ACLCLIENT