]> git.saurik.com Git - apple/security.git/blob - AppleCSPDL/SSDatabase.h
Security-179.tar.gz
[apple/security.git] / AppleCSPDL / SSDatabase.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 // SSDatabase.h - Security Server database object
21 //
22 #ifndef _H_SSDATABASE_
23 #define _H_SSDATABASE_
24
25 #include <Security/dlclient.h>
26 #include <Security/unix++.h>
27 #include <Security/SecurityServerClient.h>
28
29 class SSCSPDLSession;
30 class SSUniqueRecord;
31
32 //
33 // Protected please ignore this class unless subclassing SSDatabase.
34 //
35 class SSDatabaseImpl : public CssmClient::DbImpl
36 {
37 static const char *const DBBlobRelationName;
38 enum {
39 DBBlobRelationID = CSSM_DB_RECORDTYPE_APP_DEFINED_START + 0x8000
40 };
41
42 public:
43 SSDatabaseImpl(SecurityServer::ClientSession &inClientSession,
44 const CssmClient::DL &dl,
45 const char *inDbName, const CSSM_NET_ADDRESS *inDbLocation);
46 virtual ~SSDatabaseImpl();
47
48 void create(const DLDbIdentifier &dlDbIdentifier);
49 void open(const DLDbIdentifier &dlDbIdentifier);
50 SSUniqueRecord insert(CSSM_DB_RECORDTYPE recordType,
51 const CSSM_DB_RECORD_ATTRIBUTE_DATA *attributes,
52 const CSSM_DATA *data, bool);
53 void authenticate(CSSM_DB_ACCESS_TYPE inAccessRequest,
54 const CSSM_ACCESS_CREDENTIALS *inAccessCredentials);
55
56 // Passthrough functions (only implemented by AppleCSPDL).
57 void lock();
58 void unlock();
59 void unlock(const CSSM_DATA &password);
60 void getSettings(uint32 &outIdleTimeout, bool &outLockOnSleep);
61 void setSettings(uint32 inIdleTimeout, bool inLockOnSleep);
62 bool isLocked();
63 void changePassphrase(const CSSM_ACCESS_CREDENTIALS *cred);
64
65 // DbUniqueRecordMaker
66 CssmClient::DbUniqueRecordImpl *newDbUniqueRecord();
67
68 // New methods not inherited from DbImpl
69 SecurityServer::DbHandle dbHandle();
70
71 protected:
72 CssmClient::DbUniqueRecord getDbBlobId(CssmDataContainer *dbb);
73
74 private:
75 enum
76 {
77 kDefaultIdleTimeout = 5 * 60, // 5 minute default autolock time
78 kDefaultLockOnSleep = true
79 };
80
81 DLDbIdentifier mIdentifier;
82 UnixPlusPlus::ForkMonitor mForked;
83
84 SecurityServer::ClientSession &mClientSession;
85 SecurityServer::DbHandle mSSDbHandle;
86 };
87
88
89 //
90 // SSDatabase -- A Security Server aware Db object.
91 //
92 class SSDatabase : public CssmClient::Db
93 {
94 public:
95 typedef SSDatabaseImpl Impl;
96
97 explicit SSDatabase(SSDatabaseImpl *impl) : CssmClient::Db(impl) {}
98 SSDatabase() : CssmClient::Db(NULL) {}
99 SSDatabase(SecurityServer::ClientSession &inClientSession,
100 const CssmClient::DL &dl,
101 const char *inDbName, const CSSM_NET_ADDRESS *inDbLocation)
102 : CssmClient::Db(new SSDatabaseImpl(inClientSession, dl, inDbName, inDbLocation)) {}
103
104 SSDatabaseImpl *operator ->() const { return &impl<SSDatabaseImpl>(); }
105 SSDatabaseImpl &operator *() const { return impl<SSDatabaseImpl>(); }
106
107 // For convinience only
108 SecurityServer::DbHandle dbHandle() { return (*this) ? (*this)->dbHandle() : SecurityServer::noDb; }
109 };
110
111
112 class SSUniqueRecordImpl : public CssmClient::DbUniqueRecordImpl
113 {
114 public:
115 SSUniqueRecordImpl(const SSDatabase &db);
116 virtual ~SSUniqueRecordImpl();
117
118 SSDatabase database() const;
119 };
120
121
122 class SSUniqueRecord : public CssmClient::DbUniqueRecord
123 {
124 public:
125 typedef SSUniqueRecordImpl Impl;
126
127 explicit SSUniqueRecord(SSUniqueRecordImpl *impl) : CssmClient::DbUniqueRecord(impl) {}
128 SSUniqueRecord() : CssmClient::DbUniqueRecord(NULL) {}
129 SSUniqueRecord(const SSDatabase &db) : CssmClient::DbUniqueRecord(new SSUniqueRecordImpl(db)) {}
130
131 SSUniqueRecordImpl *operator ->() const { return &impl<SSUniqueRecordImpl>(); }
132 SSUniqueRecordImpl &operator *() const { return impl<SSUniqueRecordImpl>(); }
133 };
134
135
136 #endif // _H_SSDATABASE_