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