Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: components/os_crypt/key_storage_util_linux.cc

Issue 2948783002: Create setting that disables password stores (Closed)
Patch Set: lint Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/os_crypt/key_storage_util_linux.h" 5 #include "components/os_crypt/key_storage_util_linux.h"
6 6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/pickle.h"
vabr (Chromium) 2017/07/03 19:27:14 Unused?
cfroussios 2017/07/04 09:58:15 Done.
11
12 namespace {
13 // OSCrypt has a setting that determines whether a backend will be used.
14 // The presense of this file in the file system means that the backend
15 // should be ignored. It's absence means we should use the backend.
16 const char kPreferencesFileName[] = "Disable OSCrypt";
vabr (Chromium) 2017/07/03 19:27:14 nit: constexpr?
cfroussios 2017/07/04 09:58:15 Done.
17 }
18
19 namespace {
vabr (Chromium) 2017/07/03 19:27:14 nit: Why not merge the two consecutive anonymous n
cfroussios 2017/07/04 09:58:15 Done.
20
21 bool ReadBackendUse(const base::FilePath& user_data_dir, bool* use) {
22 if (user_data_dir.empty())
23 return false;
24 base::FilePath pref_path = user_data_dir.Append(kPreferencesFileName);
25 *use = !base::PathExists(pref_path);
26 return true;
27 }
28
29 } // namespace
8 30
9 namespace os_crypt { 31 namespace os_crypt {
10 32
11 SelectedLinuxBackend SelectBackend(const std::string& type, 33 SelectedLinuxBackend SelectBackend(const std::string& type,
34 bool use_backend,
12 base::nix::DesktopEnvironment desktop_env) { 35 base::nix::DesktopEnvironment desktop_env) {
13 if (type == "kwallet") 36 if (type == "kwallet")
14 return SelectedLinuxBackend::KWALLET; 37 return SelectedLinuxBackend::KWALLET;
15 if (type == "kwallet5") 38 if (type == "kwallet5")
16 return SelectedLinuxBackend::KWALLET5; 39 return SelectedLinuxBackend::KWALLET5;
17 if (type == "gnome") 40 if (type == "gnome")
18 return SelectedLinuxBackend::GNOME_ANY; 41 return SelectedLinuxBackend::GNOME_ANY;
19 if (type == "gnome-keyring") 42 if (type == "gnome-keyring")
20 return SelectedLinuxBackend::GNOME_KEYRING; 43 return SelectedLinuxBackend::GNOME_KEYRING;
21 if (type == "gnome-libsecret") 44 if (type == "gnome-libsecret")
22 return SelectedLinuxBackend::GNOME_LIBSECRET; 45 return SelectedLinuxBackend::GNOME_LIBSECRET;
23 if (type == "basic") 46 if (type == "basic")
24 return SelectedLinuxBackend::BASIC_TEXT; 47 return SelectedLinuxBackend::BASIC_TEXT;
25 48
49 if (!use_backend)
vabr (Chromium) 2017/07/03 19:27:14 nit: Please comment on the need to place this unde
cfroussios 2017/07/04 09:58:15 Done.
50 return SelectedLinuxBackend::BASIC_TEXT;
51
26 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); 52 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env);
27 VLOG(1) << "Password storage detected desktop environment: " 53 VLOG(1) << "Password storage detected desktop environment: "
28 << (name ? name : "(unknown)"); 54 << (name ? name : "(unknown)");
29 55
30 // Detect the store to use automatically. 56 // Detect the store to use automatically.
31 switch (desktop_env) { 57 switch (desktop_env) {
32 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 58 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
33 return SelectedLinuxBackend::KWALLET; 59 return SelectedLinuxBackend::KWALLET;
34 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 60 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
35 return SelectedLinuxBackend::KWALLET5; 61 return SelectedLinuxBackend::KWALLET5;
36 case base::nix::DESKTOP_ENVIRONMENT_GNOME: 62 case base::nix::DESKTOP_ENVIRONMENT_GNOME:
37 case base::nix::DESKTOP_ENVIRONMENT_UNITY: 63 case base::nix::DESKTOP_ENVIRONMENT_UNITY:
38 case base::nix::DESKTOP_ENVIRONMENT_XFCE: 64 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
39 return SelectedLinuxBackend::GNOME_ANY; 65 return SelectedLinuxBackend::GNOME_ANY;
40 // KDE3 didn't use DBus, which our KWallet store uses. 66 // KDE3 didn't use DBus, which our KWallet store uses.
41 case base::nix::DESKTOP_ENVIRONMENT_KDE3: 67 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
42 case base::nix::DESKTOP_ENVIRONMENT_OTHER: 68 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
43 return SelectedLinuxBackend::BASIC_TEXT; 69 return SelectedLinuxBackend::BASIC_TEXT;
44 } 70 }
45 71
46 NOTREACHED(); 72 NOTREACHED();
47 return SelectedLinuxBackend::BASIC_TEXT; 73 return SelectedLinuxBackend::BASIC_TEXT;
48 } 74 }
49 75
76 bool WriteBackendUse(const base::FilePath& user_data_dir, bool use) {
77 if (user_data_dir.empty())
78 return false;
79 base::FilePath pref_path = user_data_dir.Append(kPreferencesFileName);
80 if (use) {
81 return base::DeleteFile(pref_path, false);
82 }
83 FILE* f = base::OpenFile(pref_path, "w");
84 return f != nullptr && base::CloseFile(f);
85 }
86
87 bool GetBackendUse(const base::FilePath& user_data_dir) {
88 bool setting;
89 if (ReadBackendUse(user_data_dir, &setting))
90 return setting;
91 return true;
92 }
93
50 } // namespace os_crypt 94 } // namespace os_crypt
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698