| 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> |
| 11 #include <prinit.h> | 11 #include <prinit.h> |
| 12 #include <prtime.h> | 12 #include <prtime.h> |
| 13 #include <pk11pub.h> | 13 #include <pk11pub.h> |
| 14 #include <secmod.h> | 14 #include <secmod.h> |
| 15 | 15 |
| 16 #if defined(OS_LINUX) | 16 #if defined(OS_LINUX) |
| 17 #include <linux/nfs_fs.h> | 17 #include <linux/nfs_fs.h> |
| 18 #include <sys/vfs.h> | 18 #include <sys/vfs.h> |
| 19 #elif defined(OS_OPENBSD) |
| 20 #include <sys/mount.h> |
| 21 #include <sys/param.h> |
| 19 #endif | 22 #endif |
| 20 | 23 |
| 21 #include <vector> | 24 #include <vector> |
| 22 | 25 |
| 23 #include "base/environment.h" | 26 #include "base/environment.h" |
| 24 #include "base/file_path.h" | 27 #include "base/file_path.h" |
| 25 #include "base/file_util.h" | 28 #include "base/file_util.h" |
| 26 #include "base/lazy_instance.h" | 29 #include "base/lazy_instance.h" |
| 27 #include "base/logging.h" | 30 #include "base/logging.h" |
| 28 #include "base/memory/scoped_ptr.h" | 31 #include "base/memory/scoped_ptr.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 147 } |
| 145 | 148 |
| 146 // NSS creates a local cache of the sqlite database if it detects that the | 149 // NSS creates a local cache of the sqlite database if it detects that the |
| 147 // filesystem the database is on is much slower than the local disk. The | 150 // filesystem the database is on is much slower than the local disk. The |
| 148 // detection doesn't work with the latest versions of sqlite, such as 3.6.22 | 151 // detection doesn't work with the latest versions of sqlite, such as 3.6.22 |
| 149 // (NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=578561). So we set | 152 // (NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=578561). So we set |
| 150 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's | 153 // the NSS environment variable NSS_SDB_USE_CACHE to "yes" to override NSS's |
| 151 // detection when database_dir is on NFS. See http://crbug.com/48585. | 154 // detection when database_dir is on NFS. See http://crbug.com/48585. |
| 152 // | 155 // |
| 153 // TODO(wtc): port this function to other USE_NSS platforms. It is defined | 156 // TODO(wtc): port this function to other USE_NSS platforms. It is defined |
| 154 // only for OS_LINUX simply because the statfs structure is OS-specific. | 157 // only for OS_LINUX and OS_OPENBSD simply because the statfs structure |
| 158 // is OS-specific. |
| 155 // | 159 // |
| 156 // Because this function sets an environment variable it must be run before we | 160 // Because this function sets an environment variable it must be run before we |
| 157 // go multi-threaded. | 161 // go multi-threaded. |
| 158 void UseLocalCacheOfNSSDatabaseIfNFS(const FilePath& database_dir) { | 162 void UseLocalCacheOfNSSDatabaseIfNFS(const FilePath& database_dir) { |
| 159 #if defined(OS_LINUX) | 163 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 160 struct statfs buf; | 164 struct statfs buf; |
| 161 if (statfs(database_dir.value().c_str(), &buf) == 0) { | 165 if (statfs(database_dir.value().c_str(), &buf) == 0) { |
| 166 #if defined(OS_LINUX) |
| 162 if (buf.f_type == NFS_SUPER_MAGIC) { | 167 if (buf.f_type == NFS_SUPER_MAGIC) { |
| 168 #elif defined(OS_OPENBSD) |
| 169 if (strcmp(buf.f_fstypename, MOUNT_NFS) == 0) { |
| 170 #endif |
| 163 scoped_ptr<base::Environment> env(base::Environment::Create()); | 171 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 164 const char* use_cache_env_var = "NSS_SDB_USE_CACHE"; | 172 const char* use_cache_env_var = "NSS_SDB_USE_CACHE"; |
| 165 if (!env->HasVar(use_cache_env_var)) | 173 if (!env->HasVar(use_cache_env_var)) |
| 166 env->SetVar(use_cache_env_var, "yes"); | 174 env->SetVar(use_cache_env_var, "yes"); |
| 167 } | 175 } |
| 168 } | 176 } |
| 169 #endif // defined(OS_LINUX) | 177 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) |
| 170 } | 178 } |
| 171 | 179 |
| 172 PK11SlotInfo* FindSlotWithTokenName(const std::string& token_name) { | 180 PK11SlotInfo* FindSlotWithTokenName(const std::string& token_name) { |
| 173 AutoSECMODListReadLock auto_lock; | 181 AutoSECMODListReadLock auto_lock; |
| 174 SECMODModuleList* head = SECMOD_GetDefaultModuleList(); | 182 SECMODModuleList* head = SECMOD_GetDefaultModuleList(); |
| 175 for (SECMODModuleList* item = head; item != NULL; item = item->next) { | 183 for (SECMODModuleList* item = head; item != NULL; item = item->next) { |
| 176 int slot_count = item->module->loaded ? item->module->slotCount : 0; | 184 int slot_count = item->module->loaded ? item->module->slotCount : 0; |
| 177 for (int i = 0; i < slot_count; i++) { | 185 for (int i = 0; i < slot_count; i++) { |
| 178 PK11SlotInfo* slot = item->module->slots[i]; | 186 PK11SlotInfo* slot = item->module->slots[i]; |
| 179 if (PK11_GetTokenName(slot) == token_name) | 187 if (PK11_GetTokenName(slot) == token_name) |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 | 790 |
| 783 PK11SlotInfo* GetPublicNSSKeySlot() { | 791 PK11SlotInfo* GetPublicNSSKeySlot() { |
| 784 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 792 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
| 785 } | 793 } |
| 786 | 794 |
| 787 PK11SlotInfo* GetPrivateNSSKeySlot() { | 795 PK11SlotInfo* GetPrivateNSSKeySlot() { |
| 788 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 796 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
| 789 } | 797 } |
| 790 | 798 |
| 791 } // namespace crypto | 799 } // namespace crypto |
| OLD | NEW |