]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_cdsa_client/lib/dlclient.cpp
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_client / lib / dlclient.cpp
index 127f9b1308799fd2e2b4350197f5767f9d3142b6..3fb96df8d5d27a0cf86b7a8b20fc52d03154ec65 100644 (file)
@@ -195,6 +195,7 @@ DbImpl::close()
 void
 DbImpl::activate()
 {
+    StLock<Mutex> _(mActivateMutex);
        if (!mActive)
        {
                if (mDbInfo)
@@ -481,7 +482,7 @@ uint32 DbImpl::dbBlobVersion() {
     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");
+        secnotice("integrity", "Non-Apple CSPDL keychains don't have keychain versions");
     }
     return dbBlobVersion;
 }
@@ -493,6 +494,10 @@ uint32 DbImpl::recodeDbToVersion(uint32 version) {
     return newDbVersion;
 }
 
+void DbImpl::recodeFinished() {
+    check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_RECODE_FINISHED, NULL, NULL));
+}
+
 void DbImpl::takeFileLock() {
     passThrough(CSSM_APPLECSPDL_DB_TAKE_FILE_LOCK, NULL, NULL);
 }
@@ -505,6 +510,52 @@ void DbImpl::makeBackup() {
     passThrough(CSSM_APPLECSPDL_DB_MAKE_BACKUP, NULL, NULL);
 }
 
+void DbImpl::makeCopy(const char* path) {
+    passThrough(CSSM_APPLECSPDL_DB_MAKE_COPY, path, NULL);
+}
+
+void DbImpl::deleteFile() {
+    passThrough(CSSM_APPLECSPDL_DB_DELETE_FILE, NULL, NULL);
+}
+
+void DbImpl::transferTo(const DLDbIdentifier& dldbidentifier) {
+    if (dldbidentifier.ssuid().subserviceType() & CSSM_SERVICE_CSP) {
+        // if we're an Apple CSPDL, do the fancy transfer:
+        //  clone the file, clone the db, remove the original file
+        string oldPath = name();
+
+        CSSM_DB_HANDLE dbhandle;
+        passThrough(CSSM_APPLECSPDL_DB_CLONE, &dldbidentifier, &dbhandle);
+
+        mDbName = dldbidentifier.dbName();
+        mHandle.DBHandle = dbhandle;
+
+        unlink(oldPath.c_str());
+
+        // Don't cache this name
+        if (mNameFromHandle) {
+            allocator().free(mNameFromHandle);
+            mNameFromHandle = NULL;
+        }
+    } else {
+        // if we're not an Apple CSPDL, just call rename
+        this->rename(dldbidentifier.dbName());
+    }
+}
+
+
+// cloneTo only makes sense if you're on an Apple CSPDL
+Db DbImpl::cloneTo(const DLDbIdentifier& dldbidentifier) {
+    CSSM_DB_HANDLE dbhandle;
+    passThrough(CSSM_APPLECSPDL_DB_CLONE, &dldbidentifier, &dbhandle);
+
+    // This is the only reasonable way to make a SSDbImpl at this layer.
+    CssmClient::Db db(dl(), dldbidentifier.dbName(), dldbidentifier.dbLocation());
+    db->mHandle.DBHandle = dbhandle;
+
+    return db;
+}
+
 //
 // DbCursorMaker
 //
@@ -577,7 +628,6 @@ CSSM_HANDLE Db::dlGetFirst(const CSSM_QUERY &query, CSSM_DB_RECORD_ATTRIBUTE_DAT
                return CSSM_INVALID_HANDLE;
        default:
                CssmError::throwMe(rc);
-               return CSSM_INVALID_HANDLE; // placebo
        }
 }
 
@@ -592,7 +642,6 @@ bool Db::dlGetNext(CSSM_HANDLE query, CSSM_DB_RECORD_ATTRIBUTE_DATA &attributes,
                return false;
        default:
                CssmError::throwMe(rc);
-               return false;   // placebo
        }
 }