2 * Copyright (c) 2000-2001,2011-2014 Apple 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_cdsa_client/dlclient.h>
26 #include <security_utilities/unix++.h>
27 #include <securityd_client/ssclient.h>
33 // Protected please ignore this class unless subclassing SSDatabase.
37 class SSDatabaseImpl
: public CssmClient::DbImpl
40 static const char *const DBBlobRelationName
;
41 static const CSSM_DB_RECORDTYPE DBBlobRelationID
=
42 CSSM_DB_RECORDTYPE_APP_DEFINED_START
+ 0x8000;
45 SSDatabaseImpl(SecurityServer::ClientSession
&inClientSession
,
46 const CssmClient::DL
&dl
,
47 const char *inDbName
, const CSSM_NET_ADDRESS
*inDbLocation
);
48 virtual ~SSDatabaseImpl();
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
);
59 // Passthrough functions (only implemented by AppleCSPDL).
62 void unlock(const CSSM_DATA
&password
);
65 void getSettings(uint32
&outIdleTimeout
, bool &outLockOnSleep
);
66 void setSettings(uint32 inIdleTimeout
, bool inLockOnSleep
);
68 void changePassphrase(const CSSM_ACCESS_CREDENTIALS
*cred
);
69 void recode(const CssmData
&data
, const CssmData
&extraData
);
70 // DbUniqueRecordMaker
71 CssmClient::DbUniqueRecordImpl
*newDbUniqueRecord();
73 // New methods not inherited from DbImpl
74 SecurityServer::DbHandle
dbHandle();
76 void getRecordIdentifier(const CSSM_DB_UNIQUE_RECORD_PTR uniqueRecord
, CSSM_DATA
&data
);
77 void copyBlob(CSSM_DATA
&blob
);
80 CssmClient::DbUniqueRecord
getDbBlobId(CssmDataContainer
*dbb
= NULL
);
81 void commonCreate (const DLDbIdentifier
&dlDbIdentifier
, bool &autocommit
);
84 // 5 minute default autolock time
85 static const uint32 kDefaultIdleTimeout
= 5 * 60;
86 static const uint8 kDefaultLockOnSleep
= true;
87 static const unsigned kNumIDWords
= 4;
89 DLDbIdentifier mIdentifier
;
90 UnixPlusPlus::ForkMonitor mForked
;
92 SecurityServer::ClientSession
&mClientSession
;
93 SecurityServer::DbHandle mSSDbHandle
;
98 // SSDatabase -- A Security Server aware Db object.
100 class SSDatabase
: public CssmClient::Db
103 typedef SSDatabaseImpl Impl
;
105 explicit SSDatabase(SSDatabaseImpl
*impl
) : CssmClient::Db(impl
) {}
106 SSDatabase() : CssmClient::Db(NULL
) {}
107 SSDatabase(SecurityServer::ClientSession
&inClientSession
,
108 const CssmClient::DL
&dl
,
109 const char *inDbName
, const CSSM_NET_ADDRESS
*inDbLocation
)
110 : CssmClient::Db(new SSDatabaseImpl(inClientSession
, dl
, inDbName
, inDbLocation
)) {}
112 SSDatabaseImpl
*operator ->() const { return &impl
<SSDatabaseImpl
>(); }
113 SSDatabaseImpl
&operator *() const { return impl
<SSDatabaseImpl
>(); }
115 // For convinience only
116 SecurityServer::DbHandle
dbHandle() { return (*this) ? (*this)->dbHandle() : SecurityServer::noDb
; }
120 class SSUniqueRecordImpl
: public CssmClient::DbUniqueRecordImpl
123 SSUniqueRecordImpl(const SSDatabase
&db
);
124 virtual ~SSUniqueRecordImpl();
126 SSDatabase
database() const;
130 class SSUniqueRecord
: public CssmClient::DbUniqueRecord
133 typedef SSUniqueRecordImpl Impl
;
135 explicit SSUniqueRecord(SSUniqueRecordImpl
*impl
) : CssmClient::DbUniqueRecord(impl
) {}
136 SSUniqueRecord() : CssmClient::DbUniqueRecord(NULL
) {}
137 SSUniqueRecord(const SSDatabase
&db
) : CssmClient::DbUniqueRecord(new SSUniqueRecordImpl(db
)) {}
139 SSUniqueRecordImpl
*operator ->() const { return &impl
<SSUniqueRecordImpl
>(); }
140 SSUniqueRecordImpl
&operator *() const { return impl
<SSUniqueRecordImpl
>(); }
144 #endif // _H_SSDATABASE_