| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/nss_util.h" | 5 #include "crypto/nss_util.h" |
| 6 #include "crypto/nss_util_internal.h" | 6 #include "crypto/nss_util_internal.h" |
| 7 | 7 |
| 8 #include <nss.h> | 8 #include <nss.h> |
| 9 #include <plarena.h> | 9 #include <plarena.h> |
| 10 #include <prerror.h> | 10 #include <prerror.h> |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (buf.f_type == NFS_SUPER_MAGIC) { | 148 if (buf.f_type == NFS_SUPER_MAGIC) { |
| 149 scoped_ptr<base::Environment> env(base::Environment::Create()); | 149 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 150 const char* use_cache_env_var = "NSS_SDB_USE_CACHE"; | 150 const char* use_cache_env_var = "NSS_SDB_USE_CACHE"; |
| 151 if (!env->HasVar(use_cache_env_var)) | 151 if (!env->HasVar(use_cache_env_var)) |
| 152 env->SetVar(use_cache_env_var, "yes"); | 152 env->SetVar(use_cache_env_var, "yes"); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 #endif // defined(OS_LINUX) | 155 #endif // defined(OS_LINUX) |
| 156 } | 156 } |
| 157 | 157 |
| 158 // A helper class that acquires the SECMOD list read lock while the | |
| 159 // AutoSECMODListReadLock is in scope. | |
| 160 class AutoSECMODListReadLock { | |
| 161 public: | |
| 162 AutoSECMODListReadLock() | |
| 163 : lock_(SECMOD_GetDefaultModuleListLock()) { | |
| 164 SECMOD_GetReadLock(lock_); | |
| 165 } | |
| 166 | |
| 167 ~AutoSECMODListReadLock() { | |
| 168 SECMOD_ReleaseReadLock(lock_); | |
| 169 } | |
| 170 | |
| 171 private: | |
| 172 SECMODListLock* lock_; | |
| 173 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock); | |
| 174 }; | |
| 175 | |
| 176 PK11SlotInfo* FindSlotWithTokenName(const std::string& token_name) { | 158 PK11SlotInfo* FindSlotWithTokenName(const std::string& token_name) { |
| 177 AutoSECMODListReadLock auto_lock; | 159 AutoSECMODListReadLock auto_lock; |
| 178 SECMODModuleList* head = SECMOD_GetDefaultModuleList(); | 160 SECMODModuleList* head = SECMOD_GetDefaultModuleList(); |
| 179 for (SECMODModuleList* item = head; item != NULL; item = item->next) { | 161 for (SECMODModuleList* item = head; item != NULL; item = item->next) { |
| 180 int slot_count = item->module->loaded ? item->module->slotCount : 0; | 162 int slot_count = item->module->loaded ? item->module->slotCount : 0; |
| 181 for (int i = 0; i < slot_count; i++) { | 163 for (int i = 0; i < slot_count; i++) { |
| 182 PK11SlotInfo* slot = item->module->slots[i]; | 164 PK11SlotInfo* slot = item->module->slots[i]; |
| 183 if (PK11_GetTokenName(slot) == token_name) | 165 if (PK11_GetTokenName(slot) == token_name) |
| 184 return PK11_ReferenceSlot(slot); | 166 return PK11_ReferenceSlot(slot); |
| 185 } | 167 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 if (lock_) | 645 if (lock_) |
| 664 lock_->Acquire(); | 646 lock_->Acquire(); |
| 665 } | 647 } |
| 666 | 648 |
| 667 AutoNSSWriteLock::~AutoNSSWriteLock() { | 649 AutoNSSWriteLock::~AutoNSSWriteLock() { |
| 668 if (lock_) { | 650 if (lock_) { |
| 669 lock_->AssertAcquired(); | 651 lock_->AssertAcquired(); |
| 670 lock_->Release(); | 652 lock_->Release(); |
| 671 } | 653 } |
| 672 } | 654 } |
| 655 |
| 656 AutoSECMODListReadLock::AutoSECMODListReadLock() |
| 657 : lock_(SECMOD_GetDefaultModuleListLock()) { |
| 658 SECMOD_GetReadLock(lock_); |
| 659 } |
| 660 |
| 661 AutoSECMODListReadLock::~AutoSECMODListReadLock() { |
| 662 SECMOD_ReleaseReadLock(lock_); |
| 663 } |
| 664 |
| 673 #endif // defined(USE_NSS) | 665 #endif // defined(USE_NSS) |
| 674 | 666 |
| 675 #if defined(OS_CHROMEOS) | 667 #if defined(OS_CHROMEOS) |
| 676 void OpenPersistentNSSDB() { | 668 void OpenPersistentNSSDB() { |
| 677 g_nss_singleton.Get().OpenPersistentNSSDB(); | 669 g_nss_singleton.Get().OpenPersistentNSSDB(); |
| 678 } | 670 } |
| 679 | 671 |
| 680 TPMTokenInfoDelegate::TPMTokenInfoDelegate() {} | 672 TPMTokenInfoDelegate::TPMTokenInfoDelegate() {} |
| 681 TPMTokenInfoDelegate::~TPMTokenInfoDelegate() {} | 673 TPMTokenInfoDelegate::~TPMTokenInfoDelegate() {} |
| 682 | 674 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 | 707 |
| 716 PK11SlotInfo* GetPublicNSSKeySlot() { | 708 PK11SlotInfo* GetPublicNSSKeySlot() { |
| 717 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 709 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
| 718 } | 710 } |
| 719 | 711 |
| 720 PK11SlotInfo* GetPrivateNSSKeySlot() { | 712 PK11SlotInfo* GetPrivateNSSKeySlot() { |
| 721 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 713 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
| 722 } | 714 } |
| 723 | 715 |
| 724 } // namespace crypto | 716 } // namespace crypto |
| OLD | NEW |