]> git.saurik.com Git - apple/security.git/blob - cdsa/cssm/manager.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cssm / manager.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 // manager - CSSM manager/supervisor objects.
21 //
22 #ifndef _H_MANAGER
23 #define _H_MANAGER
24
25 #include <Security/modloader.h>
26 #include <Security/callback.h>
27 #include "cssmmds.h"
28 #include "attachfactory.h"
29
30
31 //
32 // The CssmManager class embodies one instance of CSSM. It can interact with multiple
33 // callers in multiple threads.
34 // As far as CssmManager is concerned, it doesn't mind for multiple instances of it to
35 // exist. Such instances are strictly separated; they do not share anything (module info,
36 // attachments, callbacks, etc.) and live their lives in splendid isolation. Of course,
37 // other subsystems they deal with (e.g. the ModuleLoader) may multiplex them, but such
38 // components should take pains not to "leak" information from one CssmManager instance
39 // to another.
40 //
41 class CssmManager : public MdsComponent, public AttachmentFactory {
42 NOCOPY(CssmManager)
43 static const CSSM_GUID theGuidForCssmItself;
44 public:
45 CssmManager();
46 virtual ~CssmManager();
47
48 void initialize (const CSSM_VERSION &version,
49 CSSM_PRIVILEGE_SCOPE scope,
50 const Guid &callerGuid,
51 CSSM_KEY_HIERARCHY keyHierarchy,
52 CSSM_PVC_MODE &pvcPolicy);
53 bool terminate();
54
55 void loadModule (const Guid &guid,
56 CSSM_KEY_HIERARCHY keyHierarchy,
57 const ModuleCallback &callback);
58 void unloadModule (const Guid &guid,
59 const ModuleCallback &callback);
60
61 void introduce(const Guid &guid, CSSM_KEY_HIERARCHY keyHierarchy);
62 void unIntroduce(const Guid &guid);
63
64 //
65 // Polite inquiries
66 //
67
68 // these values are constant (after init time) and need no locking
69 const Guid &callerGuid() const { return mCallerGuid; }
70 CSSM_PRIVILEGE_SCOPE privilegeScope() const { return mPrivilegeScope; }
71 CSSM_KEY_HIERARCHY keyHierarchy() const { return mKeyHierarchy; }
72 CSSM_PVC_MODE pvcMode() const { return mPvcPolicy; }
73
74 //@@@ for these two, consider locking (as of the C shims AND the transition layer use)
75 const CSSM_PRIVILEGE &getPrivilege() const { return mPrivilege; }
76 void setPrivilege(const CSSM_PRIVILEGE &priv) { mPrivilege = priv; }
77
78 public:
79 Module *getModule(const Guid &guid);
80
81 private:
82 typedef map<Guid, Module *> ModuleMap;
83 ModuleMap moduleMap;
84
85 Mutex mLock; // object lock
86 unsigned int initCount; // number of times successfully initialized
87
88 private:
89 ModuleLoader loader; // our ticket to module land
90
91 private:
92 // state acquired from initialize (instance constants - not guarded)
93 CSSM_PRIVILEGE_SCOPE mPrivilegeScope;
94 CSSM_KEY_HIERARCHY mKeyHierarchy;
95 CSSM_PVC_MODE mPvcPolicy;
96 Guid mCallerGuid;
97
98 // persistent state of the CSSM (guarded by module lock)
99 CSSM_PRIVILEGE mPrivilege; // established privileges
100
101 private:
102 void checkVersion(const CSSM_VERSION &version);
103 };
104
105 #ifdef _CPP_MANAGER
106 # pragma export off
107 #endif
108
109 #endif //_H_MANAGER