]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_cdsa_client/lib/dlclient.cpp
Security-57337.60.2.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_client / lib / dlclient.cpp
index 882fde1e21e082de2761d9043d0972c9965e4d4e..127f9b1308799fd2e2b4350197f5767f9d3142b6 100644 (file)
@@ -24,6 +24,7 @@
 #include <Security/cssmapple.h>
 #include <Security/cssmapplePriv.h>
 #include <Security/SecBase.h>
 #include <Security/cssmapple.h>
 #include <Security/cssmapplePriv.h>
 #include <Security/SecBase.h>
+#include <security_cdsa_utilities/Schema.h>
 
 using namespace CssmClient;
 
 
 using namespace CssmClient;
 
@@ -472,6 +473,38 @@ void DbImpl::setBatchMode(Boolean mode, Boolean rollback)
        }
 }
 
        }
 }
 
+uint32 DbImpl::dbBlobVersion() {
+    uint32 dbBlobVersion = 0;
+    uint32* dbBlobVersionPtr = &dbBlobVersion;
+
+    // We only have a blob version if we're an apple CSPDL
+    if(dl()->guid() == gGuidAppleCSPDL) {
+        check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_GET_BLOB_VERSION, NULL, (void**) &dbBlobVersionPtr));
+    } else {
+        secdebugfunc("integrity", "Non-Apple CSPDL keychains don't have keychain versions");
+    }
+    return dbBlobVersion;
+}
+
+uint32 DbImpl::recodeDbToVersion(uint32 version) {
+    uint32 newDbVersion;
+    uint32* newDbVersionPtr = &newDbVersion;
+    check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_RECODE_TO_BLOB_VERSION, &version, (void**) &newDbVersionPtr));
+    return newDbVersion;
+}
+
+void DbImpl::takeFileLock() {
+    passThrough(CSSM_APPLECSPDL_DB_TAKE_FILE_LOCK, NULL, NULL);
+}
+
+void DbImpl::releaseFileLock(bool success) {
+    passThrough(CSSM_APPLECSPDL_DB_RELEASE_FILE_LOCK, &success, NULL);
+}
+
+void DbImpl::makeBackup() {
+    passThrough(CSSM_APPLECSPDL_DB_MAKE_BACKUP, NULL, NULL);
+}
+
 //
 // DbCursorMaker
 //
 //
 // DbCursorMaker
 //
@@ -903,3 +936,34 @@ DbAttributes::DbAttributes(const Db &db, uint32 capacity, Allocator &allocator)
 :  CssmAutoDbRecordAttributeData(capacity, db->allocator(), allocator)
 {
 }
 :  CssmAutoDbRecordAttributeData(capacity, db->allocator(), allocator)
 {
 }
+
+void DbAttributes::updateWithDbAttributes(DbAttributes* newValues) {
+    if(!newValues) {
+        return;
+    }
+
+    canonicalize();
+    newValues->canonicalize();
+
+    updateWith(newValues);
+}
+
+void
+DbAttributes::canonicalize() {
+    for(int i = 0; i < size(); i++) {
+        CssmDbAttributeData& data = attributes()[i];
+        CssmDbAttributeInfo& datainfo = data.info();
+
+        // Calling Schema::attributeInfo is the best way to canonicalize.
+        // There's no way around the try-catch structure, since it throws if it
+        // can't find something.
+
+        try {
+            if(datainfo.nameFormat() == CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER) {
+                data.info() = Security::KeychainCore::Schema::attributeInfo(datainfo.intName());
+            }
+        } catch(...) {
+            // Don't worry about it
+        }
+    }
+}