X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..7e6b461318c8a779d91381531435a68ee4e8b6ed:/OSX/libsecurity_cdsa_client/lib/securestorage.cpp?ds=inline diff --git a/OSX/libsecurity_cdsa_client/lib/securestorage.cpp b/OSX/libsecurity_cdsa_client/lib/securestorage.cpp index 6fb56f0d..676a1ad2 100644 --- a/OSX/libsecurity_cdsa_client/lib/securestorage.cpp +++ b/OSX/libsecurity_cdsa_client/lib/securestorage.cpp @@ -46,6 +46,7 @@ try } catch (...) { + return; // Prevent re-throw of exception [function-try-block] } Allocator &CSPDLImpl::allocator() const @@ -129,8 +130,16 @@ SSDbImpl::open() DbImpl::open(); } -SSDbUniqueRecord +DbUniqueRecord SSDbImpl::insert(CSSM_DB_RECORDTYPE recordType, + const CSSM_DB_RECORD_ATTRIBUTE_DATA *attributes, + const CSSM_DATA *data) +{ + return DbImpl::insert(recordType, attributes, data); +} + +SSDbUniqueRecord +SSDbImpl::ssInsert(CSSM_DB_RECORDTYPE recordType, const CSSM_DB_RECORD_ATTRIBUTE_DATA *attributes, const CSSM_DATA *data, const CSSM_RESOURCE_CONTROL_CONTEXT *rc) @@ -148,7 +157,7 @@ SSDbImpl::insert(CSSM_DB_RECORDTYPE recordType, const CSSM_ACCESS_CREDENTIALS *cred = rc ? rc->AccessCred : NULL; try { - return insert(recordType, attributes, data, group, cred); + SSDbUniqueRecord ssdbur = ssInsert(recordType, attributes, data, group, cred); if (autoCommit) { // autoCommit was on so commit now that we are done and turn @@ -157,6 +166,7 @@ SSDbImpl::insert(CSSM_DB_RECORDTYPE recordType, CSSM_DL_PassThrough(dldbh, CSSM_APPLEFILEDL_TOGGLE_AUTOCOMMIT, reinterpret_cast(autoCommit), NULL); } + return ssdbur; } catch(...) { @@ -171,13 +181,10 @@ SSDbImpl::insert(CSSM_DB_RECORDTYPE recordType, } throw; } - - // keep the compiler happy -- this path is NEVER taken - CssmError::throwMe(0); } SSDbUniqueRecord -SSDbImpl::insert(CSSM_DB_RECORDTYPE recordType, +SSDbImpl::ssInsert(CSSM_DB_RECORDTYPE recordType, const CSSM_DB_RECORD_ATTRIBUTE_DATA *attributes, const CSSM_DATA *data, const SSGroup &group, const CSSM_ACCESS_CREDENTIALS *cred) @@ -411,12 +418,16 @@ SSDbCursorImpl::next(DbAttributes *attributes, ::CssmDataContainer *data, DbUniqueRecord &uniqueId, const CSSM_ACCESS_CREDENTIALS *cred) { - if (!data) - return DbDbCursorImpl::next(attributes, data, uniqueId); + if (!data) { + return DbDbCursorImpl::next(attributes, data, uniqueId); + } DbAttributes noAttrs, *attrs; attrs = attributes ? attributes : &noAttrs; + // To comply with previous behavior, this method will not find symmetric or public/private keys + // if you ask for the data of each item. + // Get the datablob for this record CssmDataContainer dataBlob(allocator()); for (;;) @@ -424,36 +435,42 @@ SSDbCursorImpl::next(DbAttributes *attributes, ::CssmDataContainer *data, if (!DbDbCursorImpl::next(attrs, &dataBlob, uniqueId)) return false; - // Keep going until we find a non key type record. CSSM_DB_RECORDTYPE rt = attrs->recordType(); - if (rt != CSSM_DL_DB_RECORD_SYMMETRIC_KEY - && rt != CSSM_DL_DB_RECORD_PRIVATE_KEY - && rt != CSSM_DL_DB_RECORD_PUBLIC_KEY) + if (rt == CSSM_DL_DB_RECORD_SYMMETRIC_KEY || + rt == CSSM_DL_DB_RECORD_PRIVATE_KEY || + rt == CSSM_DL_DB_RECORD_PUBLIC_KEY) { - // @@@ Check the label and if it doesn't start with the magic for a SSKey return the key. + // This is a key. Free it, and then check if we should return the item (but not the data) + database()->csp()->freeKey(*reinterpret_cast(dataBlob.Data)); + + if(!data) { + break; + } + } else { + // This is a non-key item. Return it. break; } - else + } + + // If the caller requested any data, return the data. + if(data) { + if (!SSGroupImpl::isGroup(dataBlob)) { - // Free the key we just retrieved - database()->csp()->freeKey(*reinterpret_cast(dataBlob.Data)); + data->Data = dataBlob.Data; + data->Length = dataBlob.Length; + dataBlob.Data = NULL; + dataBlob.Length = 0; + return true; } - } - if (!SSGroupImpl::isGroup(dataBlob)) - { - data->Data = dataBlob.Data; - data->Length = dataBlob.Length; - dataBlob.Data = NULL; - dataBlob.Length = 0; - return true; - } + // Get the group for dataBlob + SSGroup group(database(), dataBlob); - // Get the group for dataBlob - SSGroup group(database(), dataBlob); + // TODO: Add attrs to cred - // Decode the dataBlob, pass in the DL allocator. - group->decodeDataBlob(dataBlob, cred, database()->allocator(), *data); + // Decode the dataBlob, pass in the DL allocator. + group->decodeDataBlob(dataBlob, cred, database()->allocator(), *data); + } return true; }