2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // SSDatabase.h - Security Server database object
22 #ifndef _H_SSDATABASE_
23 #define _H_SSDATABASE_
25 #include <Security/dlclient.h>
26 #include <Security/unix++.h>
27 #include <Security/SecurityServerClient.h>
33 // Protected please ignore this class unless subclassing SSDatabase.
35 class SSDatabaseImpl
: public CssmClient::DbImpl
37 static const char *const DBBlobRelationName
;
39 DBBlobRelationID
= CSSM_DB_RECORDTYPE_APP_DEFINED_START
+ 0x8000
43 SSDatabaseImpl(SecurityServer::ClientSession
&inClientSession
,
44 const CssmClient::DL
&dl
,
45 const char *inDbName
, const CSSM_NET_ADDRESS
*inDbLocation
);
46 virtual ~SSDatabaseImpl();
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);
54 // Passthrough functions (only implemented by AppleCSPDL).
57 void unlock(const CSSM_DATA
&password
);
58 void getSettings(uint32
&outIdleTimeout
, bool &outLockOnSleep
);
59 void setSettings(uint32 inIdleTimeout
, bool inLockOnSleep
);
61 void changePassphrase(const CSSM_ACCESS_CREDENTIALS
*cred
);
63 // DbUniqueRecordMaker
64 CssmClient::DbUniqueRecordImpl
*newDbUniqueRecord();
66 // New methods not inherited from DbImpl
67 SecurityServer::DbHandle
dbHandle();
72 kDefaultIdleTimeout
= 5 * 60, // 5 minute default autolock time
73 kDefaultLockOnSleep
= true
76 DLDbIdentifier mIdentifier
;
77 UnixPlusPlus::ForkMonitor mForked
;
79 SecurityServer::ClientSession
&mClientSession
;
80 SecurityServer::DbHandle mSSDbHandle
;
81 CssmClient::DbUniqueRecord mDbBlobId
;
86 // SSDatabase -- A Security Server aware Db object.
88 class SSDatabase
: public CssmClient::Db
91 typedef SSDatabaseImpl Impl
;
93 explicit SSDatabase(SSDatabaseImpl
*impl
) : CssmClient::Db(impl
) {}
94 SSDatabase() : CssmClient::Db(NULL
) {}
95 SSDatabase(SecurityServer::ClientSession
&inClientSession
,
96 const CssmClient::DL
&dl
,
97 const char *inDbName
, const CSSM_NET_ADDRESS
*inDbLocation
)
98 : CssmClient::Db(new SSDatabaseImpl(inClientSession
, dl
, inDbName
, inDbLocation
)) {}
100 SSDatabaseImpl
*operator ->() const { return &impl
<SSDatabaseImpl
>(); }
101 SSDatabaseImpl
&operator *() const { return impl
<SSDatabaseImpl
>(); }
103 // For convinience only
104 SecurityServer::DbHandle
dbHandle() { return (*this) ? (*this)->dbHandle() : SecurityServer::noDb
; }
108 class SSUniqueRecordImpl
: public CssmClient::DbUniqueRecordImpl
111 SSUniqueRecordImpl(const SSDatabase
&db
);
112 virtual ~SSUniqueRecordImpl();
114 SSDatabase
database() const;
118 class SSUniqueRecord
: public CssmClient::DbUniqueRecord
121 typedef SSUniqueRecordImpl Impl
;
123 explicit SSUniqueRecord(SSUniqueRecordImpl
*impl
) : CssmClient::DbUniqueRecord(impl
) {}
124 SSUniqueRecord() : CssmClient::DbUniqueRecord(NULL
) {}
125 SSUniqueRecord(const SSDatabase
&db
) : CssmClient::DbUniqueRecord(new SSUniqueRecordImpl(db
)) {}
127 SSUniqueRecordImpl
*operator ->() const { return &impl
<SSUniqueRecordImpl
>(); }
128 SSUniqueRecordImpl
&operator *() const { return impl
<SSUniqueRecordImpl
>(); }
132 #endif // _H_SSDATABASE_