]> git.saurik.com Git - apple/security.git/blobdiff - libsecurity_cdsa_client/lib/dlclient.cpp
Security-55471.14.4.tar.gz
[apple/security.git] / libsecurity_cdsa_client / lib / dlclient.cpp
index 6fa631bf7495154abd48c66d472f1006c26657f8..31510a53255be31380c778d6ee22e5c4a05ae23c 100644 (file)
@@ -23,6 +23,7 @@
 #include <security_cdsa_client/aclclient.h>
 #include <Security/cssmapple.h>
 #include <Security/cssmapplePriv.h>
 #include <security_cdsa_client/aclclient.h>
 #include <Security/cssmapple.h>
 #include <Security/cssmapplePriv.h>
+#include <Security/SecBase.h>
 
 using namespace CssmClient;
 
 
 using namespace CssmClient;
 
@@ -104,21 +105,23 @@ DbImpl::~DbImpl()
 void
 DbImpl::open()
 {
 void
 DbImpl::open()
 {
-       if (!mActive)
-       {
-               assert(mDbInfo == nil);
-               mHandle.DLHandle = dl()->handle();
-               check(CSSM_DL_DbOpen(mHandle.DLHandle, mDbName.canonicalName(), dbLocation(),
-                                                               mAccessRequest, mAccessCredentials,
-                                                               mOpenParameters, &mHandle.DBHandle));
-
+    {
         StLock<Mutex> _(mActivateMutex);
         StLock<Mutex> _(mActivateMutex);
-               mActive = true;
-               
-               if (!mAccessCredentials && mDefaultCredentials)
-                       if (const AccessCredentials *creds = mDefaultCredentials->makeCredentials())
-                               CSSM_DL_Authenticate(handle(), mAccessRequest, creds);  // ignore error
+        if (!mActive)
+        {
+            assert(mDbInfo == nil);
+            mHandle.DLHandle = dl()->handle();
+            check(CSSM_DL_DbOpen(mHandle.DLHandle, mDbName.canonicalName(), dbLocation(),
+                                    mAccessRequest, mAccessCredentials,
+                                    mOpenParameters, &mHandle.DBHandle));
+
+            mActive = true;
+        }
        }
        }
+
+    if (!mAccessCredentials && mDefaultCredentials)
+        if (const AccessCredentials *creds = mDefaultCredentials->makeCredentials())
+            CSSM_DL_Authenticate(handle(), mAccessRequest, creds);     // ignore error
 }
 
 void
 }
 
 void
@@ -190,7 +193,6 @@ DbImpl::close()
 void
 DbImpl::activate()
 {
 void
 DbImpl::activate()
 {
-    StLock<Mutex> _(mActivateMutex);
        if (!mActive)
        {
                if (mDbInfo)
        if (!mActive)
        {
                if (mDbInfo)
@@ -366,6 +368,18 @@ DbImpl::unlock(const CSSM_DATA &password)
        check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_UNLOCK, &password, NULL));
 }
 
        check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_UNLOCK, &password, NULL));
 }
 
+void
+DbImpl::stash()
+{
+    check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_STASH, NULL, NULL));
+}
+
+void
+DbImpl::stashCheck()
+{
+    check(CSSM_DL_PassThrough(handle(), CSSM_APPLECSPDL_DB_STASH_CHECK, NULL, NULL));
+}
+
 void
 DbImpl::getSettings(uint32 &outIdleTimeout, bool &outLockOnSleep)
 {
 void
 DbImpl::getSettings(uint32 &outIdleTimeout, bool &outLockOnSleep)
 {
@@ -436,7 +450,7 @@ void DbImpl::setBatchMode(Boolean mode, Boolean rollback)
        //
        // Now, toggle the autocommit...
        //
        //
        // Now, toggle the autocommit...
        //
-       if ( result == noErr )
+       if ( result == errSecSuccess )
        {
                CSSM_BOOL modeToUse = !mode;
                if (rollback)
        {
                CSSM_BOOL modeToUse = !mode;
                if (rollback)
@@ -447,7 +461,7 @@ void DbImpl::setBatchMode(Boolean mode, Boolean rollback)
 
                result = CSSM_DL_PassThrough(dldbHandleOfUnderlyingDL,
                                                                         CSSM_APPLEFILEDL_TOGGLE_AUTOCOMMIT,
 
                result = CSSM_DL_PassThrough(dldbHandleOfUnderlyingDL,
                                                                         CSSM_APPLEFILEDL_TOGGLE_AUTOCOMMIT,
-                                                                        (void *)(modeToUse),
+                                                                        (void *)((size_t) modeToUse),
                                                                         NULL);
                if (!rollback && modeToUse)
                        result = CSSM_DL_PassThrough(dldbHandleOfUnderlyingDL,
                                                                         NULL);
                if (!rollback && modeToUse)
                        result = CSSM_DL_PassThrough(dldbHandleOfUnderlyingDL,