Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 5 | #include <base/command_line.h> |
Gwendal Grignou | dcdc1a4 | 2016-06-30 09:41:01 -0700 | [diff] [blame] | 6 | #include <base/files/file_path.h> |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 7 | #include <base/logging.h> |
Alex Vakulenko | e769653 | 2015-10-16 16:27:29 -0700 | [diff] [blame] | 8 | #include <brillo/syslog_logging.h> |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 9 | |
Alex Vakulenko | b4b694a | 2014-07-18 17:21:35 -0700 | [diff] [blame] | 10 | #include "cryptohome/lockbox-cache.h" |
Alex Vakulenko | a7dfe81 | 2014-07-31 09:47:14 -0700 | [diff] [blame] | 11 | #include "cryptohome/platform.h" |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 12 | |
| 13 | namespace switches { |
Tom Hughes | 6711cdc | 2020-09-14 08:34:01 -0700 | [diff] [blame] | 14 | static const char* kNvramPath = "nvram"; |
| 15 | static const char* kUnlinkNvram = "unlink-nvram"; |
| 16 | static const char* kLockboxPath = "lockbox"; |
| 17 | static const char* kCachePath = "cache"; |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 18 | } // namespace switches |
| 19 | |
Tom Hughes | 6711cdc | 2020-09-14 08:34:01 -0700 | [diff] [blame] | 20 | int main(int argc, char** argv) { |
Alex Vakulenko | 274c74a | 2015-04-02 14:31:10 -0700 | [diff] [blame] | 21 | base::CommandLine::Init(argc, argv); |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 22 | |
Alex Vakulenko | e769653 | 2015-10-16 16:27:29 -0700 | [diff] [blame] | 23 | brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderr); |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 24 | |
| 25 | // Allow the commands to be configurable. |
Tom Hughes | 6711cdc | 2020-09-14 08:34:01 -0700 | [diff] [blame] | 26 | base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
Mattias Nissler | d454150 | 2018-09-03 16:48:16 +0200 | [diff] [blame] | 27 | base::FilePath nvram_path(cl->GetSwitchValueASCII(switches::kNvramPath)); |
| 28 | base::FilePath lockbox_path(cl->GetSwitchValueASCII(switches::kLockboxPath)); |
| 29 | base::FilePath cache_path(cl->GetSwitchValueASCII(switches::kCachePath)); |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 30 | if (nvram_path.empty() || lockbox_path.empty() || cache_path.empty()) { |
| 31 | LOG(ERROR) << "Paths for --cache, --lockbox, and --nvram must be supplied."; |
| 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | cryptohome::Platform platform; |
| 36 | bool ok = CacheLockbox(&platform, nvram_path, lockbox_path, cache_path); |
| 37 | if (cl->HasSwitch(switches::kUnlinkNvram)) |
hscham | eb398b4 | 2020-11-24 12:33:06 +0900 | [diff] [blame] | 38 | platform.DeleteFile(nvram_path); |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 39 | if (!ok) |
hscham | eb398b4 | 2020-11-24 12:33:06 +0900 | [diff] [blame] | 40 | platform.DeleteFile(cache_path); |
Will Drewry | 831b74b | 2013-01-16 11:03:24 -0600 | [diff] [blame] | 41 | return !ok; |
| 42 | } |