]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cdsa_plugin/lib/DatabaseSession.cpp
Security-59754.41.1.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_plugin / lib / DatabaseSession.cpp
1 /*
2 * Copyright (c) 2000-2001,2011-2012,2014 Apple 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 // DatabaseSession.cpp - DL Session.
21 //
22 #include <security_cdsa_plugin/DatabaseSession.h>
23
24 #include <security_cdsa_plugin/Database.h>
25 #include <security_cdsa_plugin/DbContext.h>
26 #include <security_cdsa_utilities/cssmbridge.h>
27 #include <memory>
28 #include <security_utilities/debugging.h>
29
30 /* log open/close events */
31 #define DOCDebug(args...) secinfo("DBOpen", ## args)
32
33
34 using namespace std;
35
36 extern "C" char* cssmErrorString(CSSM_RETURN errCode);
37
38 //
39 // Session constructor
40 //
41 DatabaseSession::DatabaseSession(DatabaseManager &inDatabaseManager)
42 : mDatabaseManager(inDatabaseManager)
43 {
44 }
45
46 DatabaseSession::~DatabaseSession()
47 {
48 }
49
50
51 // Utility functions
52 void
53 DatabaseSession::GetDbNames(CSSM_NAME_LIST_PTR &outNameList)
54 {
55 secinfo("dbsession", "GetDbNames");
56 outNameList = mDatabaseManager.getDbNames (*this);
57
58 #ifndef NDEBUG
59 // dump the returned names
60 uint32 n;
61 secinfo("dbsession", "GetDbNames returned %d names", outNameList->NumStrings);
62 for (n = 0; n < outNameList->NumStrings; ++n)
63 {
64 secinfo("dbsession", "%d: %s", n, outNameList->String[n]);
65 }
66 #endif
67 }
68
69
70 void
71 DatabaseSession::FreeNameList(CSSM_NAME_LIST &inNameList)
72 {
73 secinfo("dbsession", "FreeNameList");
74 mDatabaseManager.freeNameList (*this, inNameList);
75 }
76
77
78 void
79 DatabaseSession::DbDelete(const char *inDbName,
80 const CSSM_NET_ADDRESS *inDbLocation,
81 const AccessCredentials *inAccessCred)
82 {
83 // The databaseManager will notify all its DbContext instances
84 // that the database is question is being deleted.
85 secinfo("dbsession", "DbDelete of %s", inDbName);
86 mDatabaseManager.dbDelete(*this, DbName(inDbName, CssmNetAddress::optional(inDbLocation)), inAccessCred);
87 }
88
89 // DbContext creation and destruction.
90 void
91 DatabaseSession::DbCreate(const char *inDbName,
92 const CSSM_NET_ADDRESS *inDbLocation,
93 const CSSM_DBINFO &inDBInfo,
94 CSSM_DB_ACCESS_TYPE inAccessRequest,
95 const CSSM_RESOURCE_CONTROL_CONTEXT *inCredAndAclEntry,
96 const void *inOpenParameters,
97 CSSM_DB_HANDLE &outDbHandle)
98 {
99 outDbHandle = CSSM_INVALID_HANDLE; // CDSA 2.0 says to set this if we fail
100 secinfo("dbsession", "DbCreate of %s", inDbName);
101
102 outDbHandle = insertDbContext(mDatabaseManager.dbCreate(*this,
103 DbName(inDbName, CssmNetAddress::optional(inDbLocation)),
104 inDBInfo,
105 inAccessRequest,
106 inCredAndAclEntry,
107 inOpenParameters));
108 secinfo("dbsession", "DbCreate returned handle %#lx", outDbHandle);
109 }
110
111 void
112 DatabaseSession::DbOpen(const char *inDbName,
113 const CSSM_NET_ADDRESS *inDbLocation,
114 CSSM_DB_ACCESS_TYPE inAccessRequest,
115 const AccessCredentials *inAccessCred,
116 const void *inOpenParameters,
117 CSSM_DB_HANDLE &outDbHandle)
118 {
119 DOCDebug("DatabaseSession::DbOpen: dbName %s", inDbName);
120 secinfo("dbsession", "DbOpen of %s", inDbName);
121 outDbHandle = CSSM_INVALID_HANDLE; // CDSA 2.0 says to set this if we fail
122 outDbHandle = insertDbContext(mDatabaseManager.dbOpen(*this,
123 DbName(inDbName, CssmNetAddress::optional(inDbLocation)),
124 inAccessRequest,
125 inAccessCred,
126 inOpenParameters));
127 secinfo("dbsession", "DbOpen returned handle %#lx", outDbHandle);
128 }
129
130 CSSM_DB_HANDLE
131 DatabaseSession::insertDbContext(DbContext &inDbContext)
132 {
133 CSSM_DB_HANDLE aDbHandle;
134 try
135 {
136 aDbHandle = inDbContext.handle ();
137 StLock<Mutex> _(mDbContextMapLock);
138 mDbContextMap.insert(DbContextMap::value_type(aDbHandle, &inDbContext));
139 }
140 catch (...)
141 {
142 // Close the context
143 mDatabaseManager.dbClose(inDbContext);
144 throw;
145 }
146
147 return aDbHandle;
148 }
149
150 DbContext &
151 DatabaseSession::findDbContext(CSSM_DB_HANDLE inDbHandle)
152 {
153 StLock<Mutex> _(mDbContextMapLock);
154 DbContextMap::iterator it = mDbContextMap.find(inDbHandle);
155 if (it == mDbContextMap.end())
156 CssmError::throwMe(CSSM_ERRCODE_INVALID_DB_HANDLE);
157 return *it->second;
158 }
159
160 void
161 DatabaseSession::closeAll()
162 {
163 StLock<Mutex> _(mDbContextMapLock);
164 for (DbContextMap::iterator it = mDbContextMap.begin();
165 it != mDbContextMap.end();
166 it++)
167 {
168 DbContext *aDbContext = it->second;
169 try
170 {
171 mDatabaseManager.dbClose(*aDbContext);
172 // This is done by the database itself which owns the context.
173 //delete aDbContext;
174 }
175 catch (...)
176 {
177 // Ignore exceptions since we want to close as many DBs as possible.
178 // XXX @@@ log an error or something.
179 }
180 }
181
182 mDbContextMap.clear();
183 }
184
185 // Operations using DbContext instances.
186 void
187 DatabaseSession::DbClose(CSSM_DB_HANDLE inDbHandle)
188 {
189 StLock<Mutex> _(mDbContextMapLock);
190 DOCDebug("DatabaseSession::Close");
191 secinfo("dbsession", "DbClose of handle %ld", inDbHandle);
192 DbContextMap::iterator it = mDbContextMap.find(inDbHandle);
193 if (it == mDbContextMap.end())
194 CssmError::throwMe(CSSM_ERRCODE_INVALID_DB_HANDLE);
195 unique_ptr<DbContext> aDbContext(it->second);
196 mDbContextMap.erase(it);
197 mDatabaseManager.dbClose(*aDbContext);
198 }
199
200 void
201 DatabaseSession::CreateRelation(CSSM_DB_HANDLE inDbHandle,
202 CSSM_DB_RECORDTYPE inRelationID,
203 const char *inRelationName,
204 uint32 inNumberOfAttributes,
205 const CSSM_DB_SCHEMA_ATTRIBUTE_INFO *inAttributeInfo,
206 uint32 inNumberOfIndexes,
207 const CSSM_DB_SCHEMA_INDEX_INFO &inIndexInfo)
208 {
209 secinfo("dbsession", "CreateRelation from handle %ld of record type %X with relation name %s", inDbHandle, inRelationID, inRelationName);
210 secinfo("dbsession", "number of attributes = %d", inNumberOfAttributes);
211 #ifndef NDEBUG
212 unsigned n;
213 for (n = 0; n < inNumberOfAttributes; ++n)
214 {
215 secinfo("dbsession", "%d: id %d name %s, data type %d", n, inAttributeInfo[n].AttributeId,
216 inAttributeInfo[n].AttributeName,
217 inAttributeInfo[n].DataType);
218 }
219 #endif
220
221 secinfo("dbsession", "number of indexes: %d", inNumberOfIndexes);
222 #ifndef NDEBUG
223 for (n = 0; n < inNumberOfIndexes; ++n)
224 {
225 secinfo("dbsession", "%d: id %d indexid %d indextype %d location %d", n, inIndexInfo.AttributeId,
226 inIndexInfo.IndexedDataLocation,
227 inIndexInfo.IndexId,
228 inIndexInfo.IndexType);
229 }
230 #endif
231
232 DbContext &aDbContext = findDbContext(inDbHandle);
233 return aDbContext.mDatabase.createRelation(aDbContext, inRelationID, inRelationName,
234 inNumberOfAttributes, inAttributeInfo,
235 inNumberOfIndexes, inIndexInfo);
236 }
237
238 void
239 DatabaseSession::DestroyRelation(CSSM_DB_HANDLE inDbHandle,
240 CSSM_DB_RECORDTYPE inRelationID)
241 {
242 secinfo("dbsession", "DestroyRelation (handle %ld) %d", inDbHandle, inRelationID);
243 DbContext &aDbContext = findDbContext(inDbHandle);
244 aDbContext.mDatabase.destroyRelation(aDbContext, inRelationID);
245 }
246
247 void
248 DatabaseSession::Authenticate(CSSM_DB_HANDLE inDbHandle,
249 CSSM_DB_ACCESS_TYPE inAccessRequest,
250 const AccessCredentials &inAccessCred)
251 {
252 secinfo("dbsession", "Authenticate (handle %ld) inAccessRequest %d", inDbHandle, inAccessRequest);
253 DbContext &aDbContext = findDbContext(inDbHandle);
254 aDbContext.mDatabase.authenticate(aDbContext, inAccessRequest, inAccessCred);
255 }
256
257
258 void
259 DatabaseSession::GetDbAcl(CSSM_DB_HANDLE inDbHandle,
260 const CSSM_STRING *inSelectionTag,
261 uint32 &outNumberOfAclInfos,
262 CSSM_ACL_ENTRY_INFO_PTR &outAclInfos)
263 {
264 secinfo("dbsession", "GetDbAcl (handle %ld)", inDbHandle);
265 DbContext &aDbContext = findDbContext(inDbHandle);
266 aDbContext.mDatabase.getDbAcl(aDbContext, inSelectionTag, outNumberOfAclInfos, outAclInfos);
267 }
268
269 void
270 DatabaseSession::ChangeDbAcl(CSSM_DB_HANDLE inDbHandle,
271 const AccessCredentials &inAccessCred,
272 const CSSM_ACL_EDIT &inAclEdit)
273 {
274 secinfo("dbsession", "ChangeDbAcl (handle %ld)", inDbHandle);
275 DbContext &aDbContext = findDbContext(inDbHandle);
276 aDbContext.mDatabase.changeDbAcl(aDbContext, inAccessCred, inAclEdit);
277 }
278
279 void
280 DatabaseSession::GetDbOwner(CSSM_DB_HANDLE inDbHandle,
281 CSSM_ACL_OWNER_PROTOTYPE &outOwner)
282 {
283 secinfo("dbsession", "GetDbOwner (handle %ld)", inDbHandle);
284 DbContext &aDbContext = findDbContext(inDbHandle);
285 aDbContext.mDatabase.getDbOwner(aDbContext, outOwner);
286 }
287
288 void
289 DatabaseSession::ChangeDbOwner(CSSM_DB_HANDLE inDbHandle,
290 const AccessCredentials &inAccessCred,
291 const CSSM_ACL_OWNER_PROTOTYPE &inNewOwner)
292 {
293 secinfo("dbsession", "ChangeDbOwner (handle %ld)", inDbHandle);
294 DbContext &aDbContext = findDbContext(inDbHandle);
295 aDbContext.mDatabase.changeDbOwner(aDbContext, inAccessCred, inNewOwner);
296 }
297
298 void
299 DatabaseSession::GetDbNameFromHandle(CSSM_DB_HANDLE inDbHandle,
300 char **outDbName)
301 {
302 secinfo("dbsession", "GetDbNameFromHandle (handle %ld)", inDbHandle);
303 DbContext &aDbContext = findDbContext(inDbHandle);
304 Required(outDbName) = aDbContext.mDatabase.getDbNameFromHandle(aDbContext);
305 secinfo("dbsession", "name: %s", *outDbName);
306 }
307
308
309 #ifndef NDEBUG
310
311 #if 0 /* unusued functions */
312
313 static
314 void DumpAttributeInfo(const CSSM_DB_ATTRIBUTE_INFO &info)
315 {
316 const char* attrNameType;
317 switch (info.AttributeFormat)
318 {
319 case CSSM_DB_ATTRIBUTE_NAME_AS_STRING:
320 attrNameType = "CSSM_DB_ATTRIBUTE_NAME_AS_STRING";
321 break;
322
323 case CSSM_DB_ATTRIBUTE_NAME_AS_OID:
324 attrNameType = "CSSM_DB_ATTRIBUTE_NAME_AS_OID";
325 break;
326
327 case CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER:
328 attrNameType = "CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER";
329 break;
330 }
331
332 secinfo("dbsession", " Attribute name type: %s", attrNameType);
333 switch (info.AttributeFormat)
334 {
335 case CSSM_DB_ATTRIBUTE_NAME_AS_STRING:
336 secinfo("dbsession", " name: %s", info.Label.AttributeName);
337 break;
338
339 case CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER:
340 secinfo("dbsession", " name: %d", info.Label.AttributeID);
341 break;
342
343 case CSSM_DB_ATTRIBUTE_NAME_AS_OID:
344 secinfo("dbsession", " name is oid");
345 break;
346 }
347
348 const char* s;
349 switch (info.AttributeFormat)
350 {
351 case CSSM_DB_ATTRIBUTE_FORMAT_STRING:
352 s = "CSSM_DB_ATTRIBUTE_FORMAT_STRING";
353 break;
354 case CSSM_DB_ATTRIBUTE_FORMAT_SINT32:
355 s = "CSSM_DB_ATTRIBUTE_FORMAT_SINT32";
356 break;
357 case CSSM_DB_ATTRIBUTE_FORMAT_UINT32:
358 s = "CSSM_DB_ATTRIBUTE_FORMAT_UINT32";
359 break;
360 case CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM:
361 s = "CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM";
362 break;
363 case CSSM_DB_ATTRIBUTE_FORMAT_REAL:
364 s = "CSSM_DB_ATTRIBUTE_FORMAT_REAL";
365 break;
366 case CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE:
367 s = "CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE";
368 break;
369 case CSSM_DB_ATTRIBUTE_FORMAT_BLOB:
370 s = "CSSM_DB_ATTRIBUTE_FORMAT_BLOB";
371 break;
372 case CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32:
373 s = "CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32";
374 break;
375 case CSSM_DB_ATTRIBUTE_FORMAT_COMPLEX:
376 s = "CSSM_DB_ATTRIBUTE_FORMAT_COMPLEX";
377 break;
378 }
379
380 secinfo("dbsession", " attribute format: %s", s);
381 }
382
383
384 static
385 void DumpAttributes(const CSSM_DB_RECORD_ATTRIBUTE_DATA *inAttributes)
386 {
387 if (!inAttributes)
388 {
389 secinfo("dbsession", "No attributes defined.");
390 return;
391 }
392
393 secinfo("dbsession", "insert into %d", inAttributes->DataRecordType);
394 secinfo("dbsession", "Semantic information %d", inAttributes->SemanticInformation);
395 secinfo("dbsession", "Number of attributes: %d", inAttributes->NumberOfAttributes);
396
397 unsigned n;
398 for (n = 0; n < inAttributes->NumberOfAttributes; ++n)
399 {
400 DumpAttributeInfo(inAttributes->AttributeData[n].Info);
401 secinfo("dbsession", "Attribute %d\n", n);
402 secinfo("dbsession", " number of values: %d", inAttributes->AttributeData[n].NumberOfValues);
403 unsigned i;
404 for (i = 0; i < inAttributes->AttributeData[n].NumberOfValues; ++i)
405 {
406 switch (inAttributes->AttributeData[n].Info.AttributeFormat)
407 {
408 case CSSM_DB_ATTRIBUTE_FORMAT_STRING:
409 {
410 std::string ss((char*) inAttributes->AttributeData[n].Value[i].Data, inAttributes->AttributeData[n].Value[i].Length);
411 secinfo("dbsession", " Value %d: %s", i, ss.c_str());
412 break;
413 }
414 case CSSM_DB_ATTRIBUTE_FORMAT_SINT32:
415 secinfo("dbsession", " Value %d: %d", i, *(sint32*)inAttributes->AttributeData[n].Value[i].Data);
416 break;
417 case CSSM_DB_ATTRIBUTE_FORMAT_UINT32:
418 secinfo("dbsession", " Value %d: %u", i, *(uint32*)inAttributes->AttributeData[n].Value[i].Data);
419 break;
420 case CSSM_DB_ATTRIBUTE_FORMAT_BIG_NUM:
421 secinfo("dbsession", " Value %d: (bignum)", i);
422 break;
423 case CSSM_DB_ATTRIBUTE_FORMAT_REAL:
424 secinfo("dbsession", " Value %d: %f", i, *(double*)inAttributes->AttributeData[n].Value[i].Data);
425 break;
426 case CSSM_DB_ATTRIBUTE_FORMAT_TIME_DATE:
427 secinfo("dbsession", " Value %d: %s", i, (char*)inAttributes->AttributeData[n].Value[i].Data);
428 break;
429 case CSSM_DB_ATTRIBUTE_FORMAT_BLOB:
430 secinfo("dbsession", " Value %d: (blob)", i);
431 break;
432 case CSSM_DB_ATTRIBUTE_FORMAT_MULTI_UINT32:
433 {
434 unsigned long j;
435 unsigned long numInts = inAttributes->AttributeData[n].Value[i].Length / sizeof(UInt32);
436 for (j = 0; j < numInts; ++j)
437 {
438 uint32* nums = (uint32*) inAttributes->AttributeData[n].Value[i].Data;
439 secinfo("dbsession", " %d", nums[j]);
440 }
441
442 break;
443 }
444
445 case CSSM_DB_ATTRIBUTE_FORMAT_COMPLEX:
446 secinfo("dbsession", " Value %d: (complex)", i);
447 break;
448 }
449 }
450 }
451 }
452 #endif
453
454
455 static void
456 DumpUniqueRecord(const CSSM_DB_UNIQUE_RECORD &record)
457 {
458 /*
459 const char* s;
460
461 switch (record.RecordLocator.IndexType)
462 {
463 case CSSM_DB_INDEX_UNIQUE:
464 {
465 s = "CSSM_DB_INDEX_UNIQUE";
466 break;
467 }
468
469 case CSSM_DB_INDEX_NONUNIQUE:
470 {
471 s = "CSSM_DB_INDEX_NONUNIQUE";
472 break;
473 }
474 }
475
476 secinfo("dbsession", "RecordLocator.IndexType: %s", s);
477
478 switch (record.RecordLocator.IndexedDataLocation)
479 {
480 case CSSM_DB_INDEX_ON_UNKNOWN:
481 {
482 s = "CSSM_DB_INDEX_ON_UNKNOWN";
483 break;
484 }
485
486 case CSSM_DB_INDEX_ON_ATTRIBUTE:
487 {
488 s = "CSSM_DB_INDEX_ON_ATTRIBUTE";
489 break;
490 }
491
492 case CSSM_DB_INDEX_ON_RECORD:
493 {
494 s = "CSSM_DB_INDEX_ON_RECORD";
495 break;
496 }
497 }
498
499 secinfo("dbsession", "RecordLocator.IndexedDataLocation: %s", s);
500
501 secinfo("dbsession", "Attribute info:");
502
503 DumpAttributeInfo(record.RecordLocator.Info);
504 */
505
506 // put the record ID into hex
507 std::string output;
508 char hexBuffer[4];
509 unsigned i;
510 for (i = 0; i < record.RecordIdentifier.Length; ++i)
511 {
512 sprintf(hexBuffer, "%02X", record.RecordIdentifier.Data[i]);
513 output += hexBuffer;
514 }
515
516 secinfo("dbsession", " RecordIdentifier.Data: %s", output.c_str());
517 }
518 #endif /* NDEBUG */
519
520 void
521 DatabaseSession::DataInsert(CSSM_DB_HANDLE inDbHandle,
522 CSSM_DB_RECORDTYPE inRecordType,
523 const CSSM_DB_RECORD_ATTRIBUTE_DATA *inAttributes,
524 const CssmData *inData,
525 CSSM_DB_UNIQUE_RECORD_PTR &outUniqueId)
526 {
527 secinfo("dbsession", "%p DataInsert(%lx,%x)", this, inDbHandle, inRecordType);
528 DbContext &aDbContext = findDbContext(inDbHandle);
529 outUniqueId = aDbContext.mDatabase.dataInsert(aDbContext, inRecordType, inAttributes, inData);
530
531 #ifndef NDEBUG
532 secinfo("dbsession", "Returned unique id:");
533 DumpUniqueRecord(*outUniqueId);
534 #endif
535 }
536
537
538 void
539 DatabaseSession::DataDelete(CSSM_DB_HANDLE inDbHandle,
540 const CSSM_DB_UNIQUE_RECORD &inUniqueRecordIdentifier)
541 {
542 secinfo("dbsession", "%p DataDelete(%lx)", this, inDbHandle);
543 DbContext &aDbContext = findDbContext(inDbHandle);
544 aDbContext.mDatabase.dataDelete(aDbContext, inUniqueRecordIdentifier);
545
546 #ifndef NDEBUG
547 secinfo("dbsession", "Record identifier:");
548 DumpUniqueRecord(inUniqueRecordIdentifier);
549 #endif
550 }
551
552
553 void
554 DatabaseSession::DataModify(CSSM_DB_HANDLE inDbHandle,
555 CSSM_DB_RECORDTYPE inRecordType,
556 CSSM_DB_UNIQUE_RECORD &inoutUniqueRecordIdentifier,
557 const CSSM_DB_RECORD_ATTRIBUTE_DATA *inAttributesToBeModified,
558 const CssmData *inDataToBeModified,
559 CSSM_DB_MODIFY_MODE inModifyMode)
560 {
561 secinfo("dbsession", "%p DataModify(%lx,%x)", this, inDbHandle, inRecordType);
562 DbContext &aDbContext = findDbContext(inDbHandle);
563 aDbContext.mDatabase.dataModify(aDbContext, inRecordType, inoutUniqueRecordIdentifier,
564 inAttributesToBeModified, inDataToBeModified, inModifyMode);
565 #ifndef NDEBUG
566 secinfo("dbsession", "Out record identifier:");
567 DumpUniqueRecord(inoutUniqueRecordIdentifier);
568 #endif
569 }
570
571 CSSM_HANDLE
572 DatabaseSession::DataGetFirst(CSSM_DB_HANDLE inDbHandle,
573 const CssmQuery *inQuery,
574 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR inoutAttributes,
575 CssmData *inoutData,
576 CSSM_DB_UNIQUE_RECORD_PTR &outUniqueId)
577 {
578 secinfo("dbsession", "%p DataGetFirst(%lx)", this, inDbHandle);
579 DbContext &aDbContext = findDbContext(inDbHandle);
580
581 CSSM_HANDLE result = aDbContext.mDatabase.dataGetFirst(aDbContext, inQuery,
582 inoutAttributes, inoutData, outUniqueId);
583 #ifndef NDEBUG
584 secinfo("dbsession", "result handle: %lx", result);
585 if (result != 0)
586 {
587 secinfo("dbsession", "Returned ID:");
588 DumpUniqueRecord(*outUniqueId);
589 }
590 #endif
591
592 return result;
593 }
594
595 bool
596 DatabaseSession::DataGetNext(CSSM_DB_HANDLE inDbHandle,
597 CSSM_HANDLE inResultsHandle,
598 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR inoutAttributes,
599 CssmData *inoutData,
600 CSSM_DB_UNIQUE_RECORD_PTR &outUniqueRecord)
601 {
602 secinfo("dbsession", "DataGetNext(%lx)", inDbHandle);
603 DbContext &aDbContext = findDbContext(inDbHandle);
604
605 bool result = aDbContext.mDatabase.dataGetNext(aDbContext, inResultsHandle, inoutAttributes,
606 inoutData, outUniqueRecord);
607
608 #ifndef NDEBUG
609 if (result)
610 {
611 secinfo("dbsession", "Returned ID:");
612 DumpUniqueRecord(*outUniqueRecord);
613 }
614 #endif
615
616 return result;
617 }
618
619 void
620 DatabaseSession::DataAbortQuery(CSSM_DB_HANDLE inDbHandle,
621 CSSM_HANDLE inResultsHandle)
622 {
623 secinfo("dbsession", "%p DataAbortQuery(%lx)", this, inDbHandle);
624 DbContext &aDbContext = findDbContext(inDbHandle);
625 aDbContext.mDatabase.dataAbortQuery(aDbContext, inResultsHandle);
626 }
627
628 void
629 DatabaseSession::DataGetFromUniqueRecordId(CSSM_DB_HANDLE inDbHandle,
630 const CSSM_DB_UNIQUE_RECORD &inUniqueRecord,
631 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR inoutAttributes,
632 CssmData *inoutData)
633 {
634 secinfo("dbsession", "%p DataGetFromUniqueId(%lx)", this, inDbHandle);
635 #ifndef NDEBUG
636 secinfo("dbsession", "inUniqueRecord:");
637 DumpUniqueRecord(inUniqueRecord);
638 #endif
639
640 DbContext &aDbContext = findDbContext(inDbHandle);
641 aDbContext.mDatabase.dataGetFromUniqueRecordId(aDbContext, inUniqueRecord,
642 inoutAttributes, inoutData);
643 }
644
645 void
646 DatabaseSession::FreeUniqueRecord(CSSM_DB_HANDLE inDbHandle,
647 CSSM_DB_UNIQUE_RECORD &inUniqueRecordIdentifier)
648 {
649 secinfo("dbsession", "FreeUniqueRecord: %lx", inDbHandle);
650 #ifndef NDEBUG
651 secinfo("dbsession", "inUniqueRecordIdentifier follows:");
652 DumpUniqueRecord(inUniqueRecordIdentifier);
653 #endif
654 DbContext &aDbContext = findDbContext(inDbHandle);
655 aDbContext.mDatabase.freeUniqueRecord(aDbContext, inUniqueRecordIdentifier);
656 }
657
658 void
659 DatabaseSession::PassThrough(CSSM_DB_HANDLE inDbHandle,
660 uint32 passThroughId,
661 const void *inputParams,
662 void **outputParams)
663 {
664 DbContext &aDbContext = findDbContext(inDbHandle);
665 aDbContext.mDatabase.passThrough(aDbContext, passThroughId, inputParams, outputParams);
666 }